From 6ce5ab5d5f8ffba09431d4e1b6897e5738a310f8 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 1 Jan 2021 17:06:13 +0100 Subject: [PATCH] [tree] emit signal upon data tree selection --- central_widget.py | 16 +++++++++++++--- communicator.py | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/central_widget.py b/central_widget.py index d76c1ad..aae7f5d 100644 --- a/central_widget.py +++ b/central_widget.py @@ -87,14 +87,24 @@ class FileView(QWidget): def dataTreeResize(self, index): self._data_tree.resizeColumnToContents(index.column()) - + + def dataTreeSelection(self, current_index, last_index): + if not current_index.isValid(): + return + item = current_index.internalPointer() + comm.communicator.item_selected.emit(item) + def update(self): data_model = TreeModel(self._file_handler, TreeType.Data) metadata_model = TreeModel(self._file_handler, TreeType.Metadata) self._data_tree.setModel(data_model) + selection_model = QItemSelectionModel(data_model) + self._data_tree.setSelectionModel(selection_model) + selection_model.currentChanged.connect(self.dataTreeSelection) self._mdata_tree.setModel(metadata_model) - self._data_tree.resizeColumnToContents(0) - self._mdata_tree.resizeColumnToContents(0) + for i in range(data_model.columnCount(None)): + self._data_tree.resizeColumnToContents(i) + self._mdata_tree.resizeColumnToContents(i) def reset(self): print("FileView ", self._file_handler.is_valid) diff --git a/communicator.py b/communicator.py index 746c90d..d2755db 100644 --- a/communicator.py +++ b/communicator.py @@ -1,3 +1,4 @@ +from tree_model import NixTreeItem from PyQt5.QtCore import QObject, pyqtSignal class Communicate(QObject): @@ -5,5 +6,7 @@ class Communicate(QObject): Small class for across app communication. Defines signals, to which other classes can connect. """ open_recent = pyqtSignal(str) + + item_selected = pyqtSignal(NixTreeItem) communicator = Communicate() \ No newline at end of file