From 8c1c5ff998aa0021d68d0b04ffacad40c67f3839 Mon Sep 17 00:00:00 2001 From: danielhrisca Date: Wed, 6 Mar 2024 10:25:34 +0200 Subject: [PATCH] fix searching for channels in the modify & export views --- src/asammdf/gui/dialogs/advanced_search.py | 5 +- src/asammdf/gui/widgets/batch.py | 35 ++++++------- src/asammdf/gui/widgets/file.py | 61 ++++++++-------------- src/asammdf/gui/widgets/mdi_area.py | 3 +- src/asammdf/gui/widgets/tree.py | 3 +- 5 files changed, 40 insertions(+), 67 deletions(-) diff --git a/src/asammdf/gui/dialogs/advanced_search.py b/src/asammdf/gui/dialogs/advanced_search.py index e611d402f..80bea1f1c 100644 --- a/src/asammdf/gui/dialogs/advanced_search.py +++ b/src/asammdf/gui/dialogs/advanced_search.py @@ -392,10 +392,7 @@ def _match_double_clicked(self, item): new_item = item iterator = QtWidgets.QTreeWidgetItemIterator(self.selection) - while iterator.value(): - item = iterator.value() - if item is None: - break + while item := iterator.value(): data = tuple(item.text(i) for i in range(self.columns)) selection.add(data) diff --git a/src/asammdf/gui/widgets/batch.py b/src/asammdf/gui/widgets/batch.py index 73f2ac3e2..4536b5821 100644 --- a/src/asammdf/gui/widgets/batch.py +++ b/src/asammdf/gui/widgets/batch.py @@ -902,8 +902,7 @@ def _get_filtered_channels(self): total = 0 if self.filter_view.currentText() == "Internal file structure": - while iterator.value(): - item = iterator.value() + while item := iterator.value(): group, index = item.entry if index != 0xFFFFFFFFFFFFFFFF: @@ -916,8 +915,7 @@ def _get_filtered_channels(self): iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: group, index = item.entry @@ -955,7 +953,7 @@ def raster_search(self, event): name = list(result)[0] self.raster_channel.setCurrentText(name) - def filter_changed(self, item, column): + def filter_changed(self, item, column=0): name = item.text(0) if item.checkState(0) == QtCore.Qt.CheckState.Checked: self._selected_filter.add(name) @@ -1015,8 +1013,6 @@ def search(self, event=None): if (dg_cntr, ch_cntr) in result: item.setCheckState(0, QtCore.Qt.CheckState.Checked) - else: - item.setCheckState(0, QtCore.Qt.CheckState.Unchecked) iterator += 1 ch_cntr += 1 @@ -1025,8 +1021,7 @@ def search(self, event=None): iterator = QtWidgets.QTreeWidgetItemIterator(widget) signals = set() - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: signals.add(item.entry) @@ -1036,28 +1031,32 @@ def search(self, event=None): signals = signals | set(result) widget.clear() + self._selected_filter.clear() + + uuid = os.urandom(6).hex() items = [] for entry in signals: gp_index, ch_index = entry ch = mdf.groups[gp_index].channels[ch_index] - channel = MinimalTreeItem(entry, ch.name, strings=[ch.name], origin_uuid=self.uuid) + channel = MinimalTreeItem(entry, ch.name, strings=[ch.name], origin_uuid=uuid) channel.setCheckState(0, QtCore.Qt.CheckState.Checked) items.append(channel) + self._selected_filter.add(ch.name) if len(items) < 30000: items = natsorted(items, key=lambda x: x.name) else: items.sort(key=lambda x: x.name) + widget.addTopLevelItems(items) + self.update_selected_filter_channels() else: iterator = QtWidgets.QTreeWidgetItemIterator(widget) while item := iterator.value(): if item.entry in result: item.setCheckState(0, QtCore.Qt.CheckState.Checked) - else: - item.setCheckState(0, QtCore.Qt.CheckState.Unchecked) iterator += 1 except: @@ -1074,8 +1073,6 @@ def update_channel_tree(self, *args): if not count: self.filter_tree.clear() return - elif self.filter_tree.topLevelItemCount(): - return else: uuid = os.urandom(6).hex() @@ -1102,8 +1099,7 @@ def update_channel_tree(self, *args): iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: signals.add(item.entry) @@ -1850,8 +1846,7 @@ def load_filter_list(self, event=None, file_name=None): iterator = QtWidgets.QTreeWidgetItemIterator(self.filter_tree) if self.filter_view.currentText() == "Internal file structure": - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.parent() is None: iterator += 1 continue @@ -1864,9 +1859,9 @@ def load_filter_list(self, event=None, file_name=None): item.setCheckState(0, QtCore.Qt.CheckState.Unchecked) iterator += 1 + elif self.filter_view.currentText() == "Natural sort": - while iterator.value(): - item = iterator.value() + while item := iterator.value(): channel_name = item.text(0) if channel_name in channels: diff --git a/src/asammdf/gui/widgets/file.py b/src/asammdf/gui/widgets/file.py index e0abf1107..0a4fac32c 100644 --- a/src/asammdf/gui/widgets/file.py +++ b/src/asammdf/gui/widgets/file.py @@ -565,8 +565,7 @@ def _update_channel_tree(self, index=None, widget=None, force=False): signals = set() if widget.mode == "Internal file structure": - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.entry[1] != 0xFFFFFFFFFFFFFFFF: if item.checkState(0) == QtCore.Qt.CheckState.Checked: @@ -574,8 +573,7 @@ def _update_channel_tree(self, index=None, widget=None, force=False): iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: signals.add(item.entry) @@ -820,8 +818,7 @@ def search(self, event=None): dg_cntr = -1 ch_cntr = 0 - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.parent() is None: iterator += 1 dg_cntr += 1 @@ -841,8 +838,7 @@ def search(self, event=None): iterator = QtWidgets.QTreeWidgetItemIterator(widget) signals = set() - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: signals.add((item.text(0), *item.entry)) @@ -854,6 +850,7 @@ def search(self, event=None): signals = signals | names widget.clear() + self._selected_filter = {e[0] for e in signals} items = [] for name, gp_index, ch_index in signals: @@ -868,13 +865,12 @@ def search(self, event=None): else: items.sort(key=lambda x: x.name) widget.addTopLevelItems(items) - for item in items: - self.filter_changed(item) + + self.update_selected_filter_channels() else: iterator = QtWidgets.QTreeWidgetItemIterator(widget) - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.entry in result: item.setCheckState(0, QtCore.Qt.CheckState.Checked) @@ -952,8 +948,7 @@ def to_config(self): signals = [] if self.channel_view.currentText() == "Internal file structure": - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.parent() is None: iterator += 1 continue @@ -963,8 +958,7 @@ def to_config(self): iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: signals.append(item.text(0)) @@ -1235,8 +1229,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False): iterator = QtWidgets.QTreeWidgetItemIterator(self.channels_tree) if self.channel_view.currentText() == "Internal file structure": - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.parent() is None: iterator += 1 continue @@ -1250,8 +1243,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False): iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): channel_name = item.text(0) if channel_name in channels: @@ -1546,8 +1538,7 @@ def show_info(self, item, column): def clear_filter(self): iterator = QtWidgets.QTreeWidgetItemIterator(self.filter_tree) - while iterator.value(): - item = iterator.value() + while item := iterator.value(): item.setCheckState(0, QtCore.Qt.CheckState.Unchecked) if item.parent() is None: @@ -1559,16 +1550,14 @@ def clear_channels(self): iterator = QtWidgets.QTreeWidgetItemIterator(self.channels_tree) if self.channel_view.currentIndex() == 1: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.parent() is None: item.setExpanded(False) else: item.setCheckState(0, QtCore.Qt.CheckState.Unchecked) iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): item.setCheckState(0, QtCore.Qt.CheckState.Unchecked) iterator += 1 @@ -1576,16 +1565,14 @@ def select_all_channels(self): iterator = QtWidgets.QTreeWidgetItemIterator(self.channels_tree) if self.channel_view.currentIndex() == 1: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.parent() is None: item.setExpanded(False) else: item.setCheckState(0, QtCore.Qt.CheckState.Checked) iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): item.setCheckState(0, QtCore.Qt.CheckState.Checked) iterator += 1 @@ -1692,8 +1679,7 @@ def _create_window(self, event=None, window_type=None): signals = [] if self.channel_view.currentIndex() == 1: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.parent() is None: iterator += 1 continue @@ -1717,8 +1703,7 @@ def _create_window(self, event=None, window_type=None): iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: group, index = item.entry @@ -2606,8 +2591,7 @@ def _get_filtered_channels(self): channels = [] if self.filter_view.currentText() == "Internal file structure": - while iterator.value(): - item = iterator.value() + while item := iterator.value(): group, index = item.entry @@ -2617,8 +2601,7 @@ def _get_filtered_channels(self): iterator += 1 else: - while iterator.value(): - item = iterator.value() + while item := iterator.value(): if item.checkState(0) == QtCore.Qt.CheckState.Checked: group, index = item.entry @@ -2993,7 +2976,7 @@ def raster_search(self, event): name = list(result)[0] self.raster_channel.setCurrentText(name) - def filter_changed(self, item, column): + def filter_changed(self, item, column=0): name = item.text(0) if self.filter_view.currentText() == "Internal file structure": if item.checkState(0) == QtCore.Qt.CheckState.Checked and item.parent() is not None: diff --git a/src/asammdf/gui/widgets/mdi_area.py b/src/asammdf/gui/widgets/mdi_area.py index 286d6180e..3d338d02b 100644 --- a/src/asammdf/gui/widgets/mdi_area.py +++ b/src/asammdf/gui/widgets/mdi_area.py @@ -3480,8 +3480,7 @@ def _load_plot_window(self, window_info): plot.cursor_info.set_precision(window_info["configuration"]["cursor_precision"]) iterator = QtWidgets.QTreeWidgetItemIterator(plot.channel_selection) - while iterator.value(): - item = iterator.value() + while item := iterator.value(): iterator += 1 if item.type() == item.Group: diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index 55cf977d8..47b724743 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -875,8 +875,7 @@ def open_menu(self): count = 0 enabled = 0 iterator = QtWidgets.QTreeWidgetItemIterator(self) - while iterator.value(): - cur_item = iterator.value() + while cur_item := iterator.value(): if cur_item.type() == ChannelsTreeItem.Channel: count += 1 if cur_item.checkState(self.NameColumn) == QtCore.Qt.CheckState.Checked: