diff --git a/snub/gui/icons/x.png b/snub/gui/icons/x.png new file mode 100644 index 0000000..9f527b7 Binary files /dev/null and b/snub/gui/icons/x.png differ diff --git a/snub/gui/stacks/panel.py b/snub/gui/stacks/panel.py index 202787d..84548b1 100644 --- a/snub/gui/stacks/panel.py +++ b/snub/gui/stacks/panel.py @@ -27,6 +27,9 @@ def __init__(self, config, selected_intervals): panel = ROIPanel(config, **props) self.widgets.append(panel) + for w in self.widgets: + w.closed.connect(self.widget_closed) + self.initUI() def initUI(self): @@ -60,3 +63,7 @@ def change_layout_mode(self, layout_mode): {"columns": Qt.Vertical, "rows": Qt.Horizontal}[layout_mode] ) super().change_layout_mode(layout_mode) + + def widget_closed(self): + if not any([w.isVisible() for w in self.widgets]): + self.hide() diff --git a/snub/gui/stacks/track.py b/snub/gui/stacks/track.py index bc3fc79..271c521 100644 --- a/snub/gui/stacks/track.py +++ b/snub/gui/stacks/track.py @@ -158,7 +158,6 @@ def update_current_range(self, new_range=None): child.update_current_range(self.current_range) def update_current_time(self, t): - pass for w in self.widgets + self.overlays: w.update_current_time(t) self.current_time_marker.set_timepoint(t) diff --git a/snub/gui/utils/widgets.py b/snub/gui/utils/widgets.py index 2b8af34..717dfab 100644 --- a/snub/gui/utils/widgets.py +++ b/snub/gui/utils/widgets.py @@ -42,6 +42,8 @@ def accept_range(self): class HeaderMixin: + closed = pyqtSignal() + def initUI( self, name="", @@ -59,6 +61,8 @@ def initUI( self.header_height = header_height self.toggle_button = QPushButton() self.toggle_button.clicked.connect(self.toggle_visiblity) + self.close_button = QPushButton() + self.close_button.clicked.connect(self.hide_widget) self.title = VerticalLabel(name, orientation="horizontal") self.header = QWidget(objectName="trackGroup_header") @@ -67,6 +71,7 @@ def initUI( self.header_layout.addWidget(self.title) self.header_layout.addStretch(0) self.header_layout.addWidget(self.toggle_button) + self.header_layout.addWidget(self.close_button) self.layout = QVBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) @@ -86,8 +91,17 @@ def initUI( ) ) ) + self.x_icon = QIcon( + QPixmap( + os.path.join( + os.path.dirname(os.path.realpath(__file__)), "../icons", "x.png" + ) + ) + ) self.toggle_button.setIcon(self.plus_icon) self.toggle_button.setIconSize(QSize(12, 12)) + self.close_button.setIcon(self.x_icon) + self.close_button.setIconSize(QSize(12, 12)) self.setStyleSheet( "QWidget#trackGroup_header { background-color: rgb(30,30,30); }" @@ -105,6 +119,10 @@ def toggle_visiblity(self, *args): self.is_visible = True self.update_layout() + def hide_widget(self): + self.hide() + self.closed.emit() + def set_header_orientation(self, orientation): self.setMaximumSize(10000, 10000) self.setMinimumSize(0, 0)