Skip to content

Commit

Permalink
Merge pull request #968 from astrofrog/fix-default-viewer
Browse files Browse the repository at this point in the history
Fix the selection of the default viewer based on the data shape
  • Loading branch information
astrofrog committed May 3, 2016
1 parent 2dde1a7 commit 2ed0b43
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ v0.7.3 (unreleased)
* Add missing find_spec for import hook, to avoid issues when trying to set
colormap. [#930]

* Fix the selection of the default viewer based on the data shape. [#968]

* Ignore extra dimensions in WCS (for instance, if the data is 3D and the
header is 4D, ignore the 4th dimension in the WCS).

Expand Down
6 changes: 3 additions & 3 deletions glue/app/qt/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ def choose_new_data_viewer(self, data=None):
from glue.config import qt_client

if data and data.ndim == 1 and ScatterWidget in qt_client.members:
default = qt_client.members.index(ScatterWidget)
default = ScatterWidget
elif data and data.ndim > 1 and ImageWidget in qt_client.members:
default = qt_client.members.index(ImageWidget)
default = ImageWidget
else:
default = 0
default = None

client = pick_class(list(qt_client.members), title='Data Viewer',
label="Choose a new data viewer",
Expand Down
4 changes: 2 additions & 2 deletions glue/app/qt/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ def test_new_data_defaults(self):

self.app.choose_new_data_viewer(data=d1)
args, kwargs = pc.call_args
assert qt_client.members[kwargs['default']] == ScatterWidget
assert kwargs['default'] is ScatterWidget

self.app.choose_new_data_viewer(data=d2)
args, kwargs = pc.call_args
assert qt_client.members[kwargs['default']] == ImageWidget
assert kwargs['default'] is ImageWidget

def test_drop_load_data(self):
m = QtCore.QMimeData()
Expand Down
14 changes: 10 additions & 4 deletions glue/utils/qt/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def pick_item(items, labels, title="Pick an item", label="Pick an item",
default=0):
default=None):
""" Prompt the user to choose an item
:param items: List of items to choose
Expand All @@ -18,8 +18,14 @@ def pick_item(items, labels, title="Pick an item", label="Pick an item",
Returns the selected item, or None
"""

if default in items:
current = items.index(default)
else:
current = 0

choice, isok = QtGui.QInputDialog.getItem(None, title, label,
labels, current=default,
labels, current=current,
editable=False)
if isok:
index = labels.index(str(choice))
Expand All @@ -40,7 +46,7 @@ def _label(c):
return c.LABEL
except AttributeError:
return c.__name__

if sort:
classes = sorted(classes, key=lambda x: _label(x))
choices = [_label(c) for c in classes]
Expand All @@ -57,4 +63,4 @@ def get_text(title='Enter a label'):
"""
result, isok = QtGui.QInputDialog.getText(None, title, title)
if isok:
return str(result)
return str(result)
4 changes: 2 additions & 2 deletions glue/utils/qt/tests/test_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Bar:
Bar.LABEL = 'Baz'

with mock.patch('glue.utils.qt.dialogs.pick_item') as d:
pick_class([Foo, Bar])
d.assert_called_once_with([Foo, Bar], ['Foo', 'Baz'])
pick_class([Foo, Bar], default=Foo)
d.assert_called_once_with([Foo, Bar], ['Foo', 'Baz'], default=Foo)

with mock.patch('glue.utils.qt.dialogs.pick_item') as d:
pick_class([Foo, Bar], sort=True)
Expand Down

0 comments on commit 2ed0b43

Please sign in to comment.