-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: chest and drawers classes draft
- Loading branch information
1 parent
edfc529
commit e2ebf8e
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |