Skip to content

Commit

Permalink
wip: chest and drawers classes draft
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Nov 10, 2023
1 parent edfc529 commit e2ebf8e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
27 changes: 27 additions & 0 deletions brainglobe_utils/qtpy/chest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QGroupBox, QVBoxLayout


class Chest(QGroupBox):
def __init__(self):
super().__init__()
self.setLayout(QVBoxLayout())

self.layout().setAlignment(Qt.AlignTop)
self.layout().setSpacing(0)
self.layout().setContentsMargins(0, 0, 0, 0)
self.drawers = []

def add_drawer(self, drawer):
self.drawers.append(drawer)
self.layout().addWidget(drawer, 0, Qt.AlignTop)
drawer.toggled_signal.connect(self._update_drawers)

def _update_drawers(self, signalling_drawer, state):
if state:
for drawer in self.drawers:
if (
drawer is not signalling_drawer
and drawer.currently_expanded
):
drawer.toggle_expansion()
41 changes: 41 additions & 0 deletions brainglobe_utils/qtpy/drawer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from qtpy.QtCore import Qt, Signal
from qtpy.QtWidgets import QPushButton, QVBoxLayout, QWidget


class Drawer(QWidget):
"""
LayerList class which acts as collapsable list.
"""

toggled_signal = Signal(QWidget, bool)

def __init__(self, name, expand=False):
super().__init__()
self.currently_expanded = expand
self.main_layout = QVBoxLayout()

self.expand_button = QPushButton(name)
self.expand_button.setToolTip(f"{name}")

# self.expand_button.setIcon \
# (QIcon(os.path.join(PATH, 'LayersList_Up.png')))

self.main_layout.addWidget(self.expand_button, 0, Qt.AlignTop)

self.expand_button.clicked.connect(self._on_expand_toggle)
self.setLayout(self.main_layout)

def _on_expand_toggle(self):
self.toggle_expansion()
self.toggled_signal.emit(self, self.currently_expanded)

def toggle_expansion(self):
self.currently_expanded = not self.currently_expanded
for i in range(1, self.layout().count()):
self.layout().itemAt(i).widget().setVisible(
self.currently_expanded
)

def add(self, widget: QWidget):
widget.setVisible(False)
self.layout().addWidget(widget)
22 changes: 22 additions & 0 deletions tests/tests/test_unit/test_qtpy/test_drawer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from qtpy.QtWidgets import QLabel

from brainglobe_utils.qtpy.chest import Chest
from brainglobe_utils.qtpy.drawer import Drawer


def test_layers_list(qtbot):
chest = Chest()
drawer = Drawer("test")
drawer_2 = Drawer("test2")
drawer.add(QLabel("test"))
drawer.add(QLabel("test2"))
drawer_2.add(QLabel("test"))
drawer_2.add(QLabel("test2"))

chest.add_drawer(drawer)
chest.add_drawer(drawer_2)
qtbot.addWidget(chest)

chest.window().show()

qtbot.wait(100000)

0 comments on commit e2ebf8e

Please sign in to comment.