Skip to content

Commit

Permalink
fix(interactive.imagetool): fix broken binning controls on loading fr…
Browse files Browse the repository at this point in the history
…on GUI
  • Loading branch information
kmnhan committed Jul 4, 2024
1 parent 8a744b0 commit 0ca5437
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/erlab/interactive/imagetool/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,24 @@ def changeEvent(self, evt: QtCore.QEvent | None): # handles dark mode


def clear_layout(layout: QtWidgets.QLayout | None) -> None:
"""Clear the given layout by removing all its child widgets and layouts recursively.
Parameters
----------
layout
The layout to be cleared.
"""
if layout is None:
return
while layout.count():
child = layout.takeAt(0)
if child is not None:
w = child.widget()
if w is not None:
w.deleteLater()
wi, lo = child.widget(), child.layout()
if wi:
wi.deleteLater()
elif lo:
clear_layout(lo)
lo.deleteLater()


class ItoolControlsBase(QtWidgets.QWidget):
Expand Down Expand Up @@ -680,11 +690,8 @@ class ItoolBinningControls(ItoolControlsBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def initialize_layout(self):
layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(3)

def initialize_widgets(self):
super().initialize_widgets()
self.gridlayout = QtWidgets.QGridLayout()
self.gridlayout.setContentsMargins(0, 0, 0, 0)
self.gridlayout.setSpacing(3)
Expand All @@ -693,12 +700,9 @@ def initialize_layout(self):
self.buttonslayout.setContentsMargins(0, 0, 0, 0)
self.buttonslayout.setSpacing(3)

layout.addLayout(self.gridlayout)
layout.addLayout(self.buttonslayout)
self.setLayout(layout)
self.layout().addLayout(self.gridlayout)
self.layout().addLayout(self.buttonslayout)

def initialize_widgets(self):
super().initialize_widgets()
self.labels = tuple(QtWidgets.QLabel() for _ in range(self.data.ndim))
self.val_labels = tuple(QtWidgets.QLabel() for _ in range(self.data.ndim))
self.spins = tuple(
Expand Down Expand Up @@ -779,7 +783,7 @@ def update(self):

for i in range(self.data.ndim):
self.spins[i].blockSignals(True)
self.labels[i].setText(f"{self.data.dims[i]!s}")
self.labels[i].setText(str(self.data.dims[i]))
self.spins[i].setRange(1, self.data.shape[i] - 1)
self.spins[i].setValue(bin_numbers[i])
if bin_values[i] is None:
Expand Down

0 comments on commit 0ca5437

Please sign in to comment.