From b3f93ed4ece7236b7b5c5395606c582bdabafb81 Mon Sep 17 00:00:00 2001 From: uids6535 Date: Thu, 7 Sep 2023 13:06:08 +0300 Subject: [PATCH] Improve groups enable/disable handling. --- src/asammdf/gui/widgets/plot.py | 4 +-- src/asammdf/gui/widgets/tree.py | 43 +++++++++++++++++++++++++++------ src/asammdf/version.py | 2 +- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/asammdf/gui/widgets/plot.py b/src/asammdf/gui/widgets/plot.py index 8e9decf99..715b5bcf3 100644 --- a/src/asammdf/gui/widgets/plot.py +++ b/src/asammdf/gui/widgets/plot.py @@ -2186,6 +2186,8 @@ def add_new_items(tree, root, items, items_pool): if info["enabled"] else QtCore.Qt.Unchecked, ) + if info["disabled"]: + item.set_disabled(info["disabled"]) self.channel_selection.blockSignals(False) self.channel_selection.refresh() @@ -2464,10 +2466,8 @@ def channel_selection_item_double_clicked(self, item, button): self.channel_selection.setExpandsOnDoubleClick(False) if item.isDisabled(): item.set_disabled(False) - item.setIcon(item.NameColumn, QtGui.QIcon(":/open.png")) else: item.set_disabled(True) - item.setIcon(item.NameColumn, QtGui.QIcon(":/erase.png")) self.plot.update() else: item.setExpanded(not item.isExpanded()) diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index f2b0f854f..2fa267f24 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -367,11 +367,20 @@ class Delegate(QtWidgets.QItemDelegate): def __init__(self, *args): super().__init__(*args) - def paint(self, pinter, option, index): + def paint(self, painter, option, index): model = index.model() + item = self.parent().itemFromIndex(index) brush = model.data(index, QtCore.Qt.ForegroundRole) + # Paint disabled items - hard way + if item and item.type() == item.Channel and item.parent(): + for column in range(item.columnCount()): + if item.isDisabled(): + item.setForeground(column, QtGui.Qt.darkGray) + else: + item.setForeground(column, item.color) + if brush is not None: color = brush.color() @@ -379,7 +388,7 @@ def paint(self, pinter, option, index): option.palette.setColor(QtGui.QPalette.Highlight, color) option.palette.setColor(QtGui.QPalette.HighlightedText, complementary) - super().paint(pinter, option, index) + super().paint(painter, option, index) class ChannelsTreeFlags(IntFlag): @@ -1042,14 +1051,14 @@ def open_menu(self): # for item in self.selectedItems(): if item.type() == item.Group and item.isDisabled(): item.set_disabled(False) - item.setIcon(item.NameColumn, QtGui.QIcon(":/open.png")) self.group_activation_changed.emit() elif action_text == "Deactivate groups": - for item in self.selectedItems(): + selectedItems = self.selectedItems() + selectedItems.append(item) + for item in selectedItems: if item.type() == item.Group and not item.isDisabled(): item.set_disabled(True) - item.setIcon(item.NameColumn, QtGui.QIcon(":/erase.png")) self.group_activation_changed.emit() @@ -1699,6 +1708,9 @@ def __init__( self.setCheckState(self.NameColumn, QtCore.Qt.Unchecked) self.name = name.split("\t[")[0] + # Store Previous State (Disabled/Enabled) + self._previous_state = self.isDisabled() + elif type == self.Channel: self.signal = signal self.details = None @@ -2105,7 +2117,7 @@ def set_conversion(self, conversion): child = self.child(i) child.set_conversion(conversion) - def set_disabled(self, disabled): + def set_disabled(self, disabled, preserve_subgroup_state=True): if self.type() == self.Channel: self.setDisabled(disabled) if self.details is not None: @@ -2118,12 +2130,29 @@ def set_disabled(self, disabled): self.signal.enable = enable elif self.type() == self.Group: + # If the group is subgroup (has a parent) + if self.parent() and not self.parent().isDisabled(): + # And the action was triggered on it + if preserve_subgroup_state: + # Save current state + self._previous_state = not self.isDisabled() + # Restore state + elif not disabled: + disabled = self._previous_state + + if disabled: + self.setIcon(self.NameColumn, QtGui.QIcon(":/erase.png")) + elif not self.parent() or ( + self.parent() and not self.parent().isDisabled() + ): + self.setIcon(self.NameColumn, QtGui.QIcon(":/open.png")) + self.setDisabled(disabled) count = self.childCount() for i in range(count): child = self.child(i) - child.set_disabled(disabled) + child.set_disabled(disabled, preserve_subgroup_state=False) def set_fmt(self, fmt): if self.kind in "SUV": diff --git a/src/asammdf/version.py b/src/asammdf/version.py index 18b92c930..833c2947e 100644 --- a/src/asammdf/version.py +++ b/src/asammdf/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- """ asammdf version module """ -__version__ = "7.3.15.dev5" +__version__ = "7.3.15.dev6"