Skip to content

Commit

Permalink
HyperSpectra: unify visual image and vector plot controls
Browse files Browse the repository at this point in the history
Also made vector plot controls more compact.
  • Loading branch information
markotoplak committed Nov 22, 2024
1 parent a7932c9 commit 4e9ec12
Showing 1 changed file with 97 additions and 48 deletions.
145 changes: 97 additions & 48 deletions orangecontrib/spectroscopy/widgets/owhyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from AnyQt.QtWidgets import QWidget, QPushButton, \
QGridLayout, QFormLayout, QAction, QVBoxLayout, QWidgetAction, QSplitter, \
QToolTip, QGraphicsRectItem
QToolTip, QGraphicsRectItem, QLabel
from AnyQt.QtGui import QColor, QKeySequence, QPainter, QBrush, QStandardItemModel, \
QStandardItem, QLinearGradient, QPixmap, QIcon, QPen

Expand Down Expand Up @@ -1299,6 +1299,29 @@ class CurvePlotHyper(CurvePlot):
viewtype = Setting(AVERAGE) # average view by default


def create_gridbox(widget, box=False, add_space=False):
grid = QGridLayout()
grid.setColumnMinimumWidth(0, 50)
grid.setColumnStretch(1, 1)
b = gui.widgetBox(widget, box=box, orientation=grid)
if not box:
if add_space:
b.setContentsMargins(8, 4, 8, 4)
else:
b.setContentsMargins(0, 0, 0, 0)
# This must come after calling widgetBox, since widgetBox overrides it
grid.setVerticalSpacing(8)
return b


def grid_add_labelled_row(grid, label, widget):
if not isinstance(grid, QGridLayout):
grid = grid.layout()
row = grid.rowCount()
grid.addWidget(QLabel(label), row, 0)
grid.addWidget(widget, row, 1)


class OWHyper(OWWidget, SelectionOutputsMixin):
name = "HyperSpectra"

Expand Down Expand Up @@ -1420,7 +1443,6 @@ def __init__(self):
self.box_values_spectra, self, "integration_method",
items=(a.name for a in self.integration_methods),
callback=self._change_integral_type)
gui.rubber(self.controlArea)

gui.appendRadioButton(rbox, "Use feature")

Expand Down Expand Up @@ -1454,9 +1476,6 @@ def __init__(self):
contentsLength=12, searchable=True,
callback=self.update_rgb_value, model=self.rgb_value_model)

self.cb_vector = gui.checkBox(rbox, self, "show_vector_plot", label="Show vector plot",
callback=self.enable_vector)

splitter = QSplitter(self)
splitter.setOrientation(Qt.Vertical)
self.imageplot = ImagePlot(self)
Expand Down Expand Up @@ -1517,6 +1536,8 @@ def __init__(self):

self._setup_plot_parameters()

gui.rubber(self.controlArea)

def _setup_plot_parameters(self):
parts_from_spectra = [SpectraParameterSetter.ANNOT_BOX,
SpectraParameterSetter.LABELS_BOX,
Expand All @@ -1529,7 +1550,13 @@ def _setup_plot_parameters(self):

def setup_vector_plot_controls(self):

self.vectorbox = gui.widgetBox(self.controlArea, box=True)
mainbox = gui.widgetBox(self.controlArea, box="Vector plot")

self.cb_vector = gui.checkBox(mainbox, self, "show_vector_plot",
label="Show vector plot",
callback=self.enable_vector)

self.vectorbox = gui.widgetBox(mainbox, box=False)

self.vector_opts = DomainModel(DomainModel.SEPARATED,
valid_types=DomainModel.PRIMITIVE, placeholder='None')
Expand All @@ -1546,47 +1573,65 @@ def setup_vector_plot_controls(self):
self.vcol_byval_feat = None
self.colour_opts = vector_colour

self.v_angle_select = gui.comboBox(self.vectorbox, self, 'vector_angle', searchable=True,
label="Vector Angle", model=self.vector_opts,
callback=self._update_vector_params)

self.v_mag_select = gui.comboBox(self.vectorbox, self, 'vector_magnitude', searchable=True,
label="Vector Magnitude", model=self.vector_opts,
callback=self._update_vector_params)

self.v_colour_select = gui.comboBox(self.vectorbox, self, 'vector_colour_index',
label="Vector Colour", model=self.vector_col_opts,
callback=self._update_vector)

self.v_colour_byval = gui.comboBox(self.vectorbox, self, 'vcol_byval_feat',
label="Vector Colour by Feature",
model=self.vector_cbyf_opts,
callback=self._update_cbyval)

self.v_colour_byval_select = gui.comboBox(self.vectorbox, self, 'vcol_byval_index',
label="", model = self.vector_pal_opts,
callback=self._update_cbyval)
self.v_colour_byval_select.setIconSize(QSize(64, 16))

self.v_scale_slider = gui.hSlider(self.vectorbox, self, 'vector_scale', label="Scale",
minValue=1, maxValue=1000, step=10, createLabel=False,
callback=self._update_vector)

self.v_width_slider = gui.hSlider(self.vectorbox, self, 'vector_width', label="Width",
minValue=1, maxValue=20, step=1, createLabel=False,
callback=self._update_vector)

self.v_opacity_slider = gui.hSlider(self.vectorbox, self, 'vector_opacity', label="Opacity",
minValue=0, maxValue=255, step=5, createLabel=False,
callback=self._update_vector)

self.v_bin_select = gui.comboBox(self.vectorbox, self, 'v_bin', label = "Pixel Binning",
model = self.vector_bin_opts,
callback = self._update_binsize)
gb = create_gridbox(self.vectorbox, box=False)

v_angle_select = gui.comboBox(None, self, 'vector_angle', searchable=True,
label="Vector Angle", model=self.vector_opts,
contentsLength=10,
callback=self._update_vector_params)
grid_add_labelled_row(gb, "Angle: ", v_angle_select)

v_mag_select = gui.comboBox(None, self, 'vector_magnitude', searchable=True,
label="Vector Magnitude", model=self.vector_opts,
contentsLength=10,
callback=self._update_vector_params)
grid_add_labelled_row(gb, "Magnitude: ", v_mag_select)

v_bin_select = gui.comboBox(None, self, 'v_bin', label="Pixel Binning",
model=self.vector_bin_opts,
contentsLength=10,
callback=self._update_binsize)
grid_add_labelled_row(gb, "Binning: ", v_bin_select)

v_colour_select = gui.comboBox(None, self, 'vector_colour_index',
label="Vector Colour", model=self.vector_col_opts,
contentsLength=10,
callback=self._update_vector)
grid_add_labelled_row(gb, "Color: ", v_colour_select)

v_colour_byval = gui.comboBox(None, self, 'vcol_byval_feat',
label="Vector Colour by Feature",
model=self.vector_cbyf_opts,
contentsLength=10,
callback=self._update_cbyval)
grid_add_labelled_row(gb, "Feature: ", v_colour_byval)

v_colour_byval_select = gui.comboBox(None, self, 'vcol_byval_index',
label="", model=self.vector_pal_opts,
contentsLength=5,
callback=self._update_cbyval)
v_colour_byval_select.setIconSize(QSize(64, 16))
grid_add_labelled_row(gb, "Palette: ", v_colour_byval_select)

gb = create_gridbox(self.vectorbox, box=False)

v_scale_slider = gui.hSlider(None, self, 'vector_scale', label="Scale",
minValue=1, maxValue=1000, step=10, createLabel=False,
callback=self._update_vector)
grid_add_labelled_row(gb, "Scale: ", v_scale_slider)

v_width_slider = gui.hSlider(None, self, 'vector_width', label="Width",
minValue=1, maxValue=20, step=1, createLabel=False,
callback=self._update_vector)
grid_add_labelled_row(gb, "Width: ", v_width_slider)

v_opacity_slider = gui.hSlider(None, self, 'vector_opacity', label="Opacity",
minValue=0, maxValue=255, step=5, createLabel=False,
callback=self._update_vector)
grid_add_labelled_row(gb, "Opacity: ", v_opacity_slider)

self.enable_vector()


def update_vector_plot_interface(self):
vector_params = ['vector_angle', 'vector_magnitude', 'vector_colour_index',
'vector_scale', 'vector_width', 'vector_opacity', 'v_bin']
Expand Down Expand Up @@ -1761,16 +1806,19 @@ def init_vector_plot(self, data):
self.vector_magnitude = self.vector_angle = self.vcol_byval_feat = None

def setup_visible_image_controls(self):
self.visbox = gui.widgetBox(self.controlArea, True)
self.visbox = gui.widgetBox(self.controlArea, box="Visible image")

gui.checkBox(
self.visbox, self, 'show_visible_image',
label='Show visible image',
callback=lambda: (self.update_visible_image_interface(), self.update_visible_image()))

self.visboxhide = gui.widgetBox(self.visbox, box=False)
self.visboxhide.hide()

self.visible_image_model = VisibleImageListModel()
gui.comboBox(
self.visbox, self, 'visible_image',
self.visboxhide, self, 'visible_image',
model=self.visible_image_model,
callback=self.update_visible_image)

Expand All @@ -1781,13 +1829,13 @@ def setup_visible_image_controls(self):
('Difference', QPainter.CompositionMode_Difference)
])
gui.comboBox(
self.visbox, self, 'visible_image_composition', label='Composition mode:',
self.visboxhide, self, 'visible_image_composition', label='Composition mode:',
model=PyListModel(self.visual_image_composition_modes.keys()),
callback=self.update_visible_image_composition_mode
)

gui.hSlider(
self.visbox, self, 'visible_image_opacity', label='Opacity:',
self.visboxhide, self, 'visible_image_opacity', label='Opacity:',
minValue=0, maxValue=255, step=10, createLabel=False,
callback=self.update_visible_image_opacity
)
Expand All @@ -1798,6 +1846,7 @@ def setup_visible_image_controls(self):

def update_visible_image_interface(self):
controlled = ['visible_image', 'visible_image_composition', 'visible_image_opacity']
self.visboxhide.setVisible(self.show_visible_image)
for c in controlled:
getattr(self.controls, c).setEnabled(self.show_visible_image)

Expand Down

0 comments on commit 4e9ec12

Please sign in to comment.