Closed montefra closed 6 years ago
Yeah ... this probably is because I did not know what pyds9.DS9() ought to return if there are multiple instances with the same name. Right now, it's an error if pyds9.Ds9() is called and there are multiple instances satisfying the target:
d = pyds9.DS9("ds9")
And I think this is correct behavior: if you only want to open one instance, and there are two, you should be made to choose which one to open.
One could argue that pyds9.ds9_openlist() should happily open multiple instances with the same name, but the problem is that it uses pyds9.DS9(), which does not allow for multiple instances. I suppose we can pass a "returnMulti" or "returnArray" flag to pyds9.DS9() (default is false) to return an array of all opened instances -- in this case, pyds9.ds9_openlist() is just a very thin later setting the flag to true.
But I assume the Python community has already wrestled with this problem, so probably there is a canonical technique!
Right now, it's an error if pyds9.Ds9() is called and there are multiple instances satisfying the target:
d = pyds9.DS9("ds9")
And I think this is correct behavior: if you only want to open one instance, and there are two, you should be made to choose which one to open.
I agree that this is the correct behaviour
I suppose we can pass a "returnMulti" or "returnArray" flag to pyds9.DS9() (default is false) to return an array of all opened instances
I disagree here: DS9
is a class representing a ds9 instance. If it cannot decide which one it should crash
I think that the solution is quite simple: pyds9.ds9_targets()
returns a list of strings like:
['DS9:ds9 /tmp/.xpa/DS9_ds9.15900', 'DS9:ds9 /tmp/.xpa/DS9_ds9.24658']
or
['DS9:foo1 838e29d4:42873', 'DS9:foo2 838e29d4:35739']
each string is composed by a name and a path/address/..., e.g. /tmp/.xpa/DS9_ds9.15900
and 838e29d4:42873
. If they are unique, we can create the DS9 instances using the path, instead of the name. It should be enough to replace this line
with
ds9list.append(DS9(item.split()[1]))
Do you think that this the solution to the problem?
I think that will work for multiple instances -- very nice, actually -- but could be confusing for one instance, since the target is saved:
self.__dict__['target'] = target
In the single instance case, this change will result in saved target having an unexpected name. Perhaps you could split between [0] for single instances and [1] for multiple instances?
but could be confusing for one instance
do you mean that you would expect ds9.target
to be:
'DS9:ds9'
, when only one instance is present'/tmp/.xpa/DS9_ds9.15900'
when multiple instances are present?Perhaps you could split between [0] for single instances and [1] for multiple instances?
That's a way. I can also implement a way to have the nice name in target
if only one instance with that name is present and the path/address otherwise. Something along these lines. If
>>> pyds9.ds9_targets()
['DS9:ds9 /tmp/.xpa/DS9_ds9.15900', 'DS9:ds9 /tmp/.xpa/DS9_ds9.24658', 'DS9:name /tmp/.xpa/DS9_ds9.25042']
then pyds9.ds9_openlist()
returns 3 DS9
instances with target
attribute:
'/tmp/.xpa/DS9_ds9.15900'
'/tmp/.xpa/DS9_ds9.24658'
'DS9:name'
Would you prefer this latter option? This is a few more lines of code, but it's not more complicated
'DS9:ds9', when only one instance is present '/tmp/.xpa/DS9_ds9.15900' when multiple instances are present?
Precisely.
I'm not clear about the implementation alternatives (i.e. where you split one instance processing and multiple instance processing), but the output you show/describe for both ds9_targets() and ds9_openlist() is exactly what I think we need. So however you want to get there is fine ...
Actual Behavior
If there are multiple instances of ds9 opened without an explicit title,
pyds9.ds9_openlist
fails withValueError: too many ds9 instances for target: DS9:ds9
.pyds9.ds9_tragets
correctly returns two elements.Expected Behavior
pyds9.ds9_openlist
returns one instance ofpyds9.DS9
for each element ofpyds9.ds9_tragets
Steps to Reproduce the Problem
Open two files with ds9
Open python/ipython
Specifications
I will investigate the issue further