diff --git a/orangecontrib/spectroscopy/utils/__init__.py b/orangecontrib/spectroscopy/utils/__init__.py index e741a3d81..9728224a4 100644 --- a/orangecontrib/spectroscopy/utils/__init__.py +++ b/orangecontrib/spectroscopy/utils/__init__.py @@ -1,6 +1,8 @@ import numpy as np -from Orange.data import Domain, Table +from Orange.data import Domain, Table, ContinuousVariable +from Orange.widgets.utils.itemmodels import DomainModel +from orangewidget.utils.itemmodels import PyListModel MAP_X_VAR = "map_x" MAP_Y_VAR = "map_y" @@ -148,3 +150,24 @@ def split_to_size(size, interval): intervals.append(slice(pos, pos + min(size - pos, interval))) pos += min(size, interval) return intervals + + +class XYDomainModel(DomainModel): + XY = (DomainModel.METAS, PyListModel.Separator, + DomainModel.CLASSES) + + def __init__(self, order=XY, valid_types=ContinuousVariable, **kwargs): + super().__init__(order=order, valid_types=valid_types, **kwargs) + + def set_domain(self, domain): + restore_order = False + if domain is not None and self.order == self.XY: + attr_x = [domain[var] for var in domain if var.name == MAP_X_VAR] + attr_y = [domain[var] for var in domain if var.name == MAP_Y_VAR] + xy = attr_x + attr_y + if len(xy) == 2: + self.order = (xy, PyListModel.Separator) + self.order + restore_order = True + super().set_domain(domain) + if restore_order: + self.order = self.order[2:] diff --git a/orangecontrib/spectroscopy/widgets/owhyper.py b/orangecontrib/spectroscopy/widgets/owhyper.py index b462f7843..800fdd3d1 100644 --- a/orangecontrib/spectroscopy/widgets/owhyper.py +++ b/orangecontrib/spectroscopy/widgets/owhyper.py @@ -39,7 +39,7 @@ from orangewidget.utils.visual_settings_dlg import VisualSettingsDialog from orangecontrib.spectroscopy.preprocess import Integrate -from orangecontrib.spectroscopy.utils import values_to_linspace, index_values_nan, split_to_size +from orangecontrib.spectroscopy.utils import values_to_linspace, index_values_nan, split_to_size, XYDomainModel from orangecontrib.spectroscopy.widgets.owspectra import InteractiveViewBox, \ MenuFocus, CurvePlot, SELECTONE, SELECTMANY, INDIVIDUAL, AVERAGE, \ @@ -287,8 +287,7 @@ def color_palette_model(palettes, iconsize=QSize(64, 16)): class AxesSettingsMixin: def __init__(self): - self.xy_model = DomainModel(DomainModel.METAS | DomainModel.CLASSES, - valid_types=DomainModel.PRIMITIVE) + self.xy_model = XYDomainModel() def setup_axes_settings_box(self): box = gui.vBox(self)