From 47d8b712d49d115bf8cc95431258061225fc210b Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Sun, 15 Apr 2018 19:40:58 +0100 Subject: [PATCH] Further fixes to tests --- glue/external/echo/qt/connect.py | 2 +- glue/utils/qt/widget_properties.py | 17 +++-------------- glue/viewers/custom/qt/custom_viewer.py | 3 ++- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/glue/external/echo/qt/connect.py b/glue/external/echo/qt/connect.py index c47485551..aa52e9326 100644 --- a/glue/external/echo/qt/connect.py +++ b/glue/external/echo/qt/connect.py @@ -292,7 +292,7 @@ def _find_combo_data(widget, value): # Here we check that the result is True, because some classes may overload # == and return other kinds of objects whether true or false. for idx in range(widget.count()): - if widget.itemData(idx).data is value or (widget.itemData(idx).data == value) is True: + if widget.itemData(idx) is not None and (widget.itemData(idx).data is value or (widget.itemData(idx).data == value) is True): return idx else: raise ValueError("%s not found in combo box" % (value,)) diff --git a/glue/utils/qt/widget_properties.py b/glue/utils/qt/widget_properties.py index 3e59d564f..bb57773ec 100644 --- a/glue/utils/qt/widget_properties.py +++ b/glue/utils/qt/widget_properties.py @@ -25,6 +25,8 @@ def __init__(self): from glue.external.six.moves import reduce from glue.utils.array import pretty_number +from glue.external.echo.qt.connect import _find_combo_data + # Backward-compatibility from glue.external.echo.qt import (connect_checkable_button as connect_bool_button, connect_combo_data as connect_current_combo, @@ -98,7 +100,7 @@ def getter(self, widget): if widget.currentIndex() == -1: return None else: - return widget.itemData(widget.currentIndex()) + return widget.itemData(widget.currentIndex()).data def setter(self, widget, value): """ @@ -264,16 +266,3 @@ def setter(self, widget, val): vmin, vmax = self.value_range val = (val - vmin) / (vmax - vmin) * (imax - imin) + imin widget.setValue(val) - - -def _find_combo_data(widget, value): - """ - Returns the index in a combo box where itemData == value - - Raises a ValueError if data is not found - """ - i = widget.findData(value) - if i == -1: - raise ValueError("{0} not found in combo box".format(value)) - else: - return i diff --git a/glue/viewers/custom/qt/custom_viewer.py b/glue/viewers/custom/qt/custom_viewer.py index 440a08362..29436a1ef 100644 --- a/glue/viewers/custom/qt/custom_viewer.py +++ b/glue/viewers/custom/qt/custom_viewer.py @@ -89,6 +89,7 @@ from glue.core.edit_subset_mode import EditSubsetMode from glue.utils import nonpartial, as_list, all_artists, new_artists, remove_artists from glue import core +from glue.external.echo.qt.connect import UserDataWrapper from glue.viewers.common.viz_client import GenericMplClient @@ -1397,7 +1398,7 @@ def _update_components(self): comps = self._list_components() for c in comps: - combo.addItem(c.label, userData=c) + combo.addItem(c.label, userData=UserDataWrapper(c)) try: combo.setCurrentIndex(comps.index(old))