From 4dddb71229725b584898e3d8836efbc409e211b5 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 10 Nov 2020 17:51:49 +0100 Subject: Fix double-click to download and open file The feature was broken since the refractor to load a .ui file --- gui.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/gui.py b/gui.py index cf6c884..2471a30 100644 --- a/gui.py +++ b/gui.py @@ -24,6 +24,7 @@ from PyQt5.QtCore import ( pyqtSignal, QObject, QRegularExpression, + QModelIndex, QSortFilterProxyModel, ) @@ -248,7 +249,6 @@ class MoodleTreeModel(QStandardItemModel): parent.insertRow(0, moodleItem) self.lastInsertedItem = moodleItem - log.debug(f"inserted item of type {moodleItem.metadata.type}") @pyqtSlot() def onWorkerDone(self): @@ -292,6 +292,7 @@ class MuddleWindow(QMainWindow): moodleTreeView.sortByColumn(0, Qt.AscendingOrder) # TODO: change with minimumSize (?) moodleTreeView.header().setSectionResizeMode(0, QHeaderView.ResizeToContents) + moodleTreeView.doubleClicked.connect(self.onMoodleTreeViewDoubleClicked) # refresh moodle treeview refreshBtn = self.findChild(QToolButton, "refreshBtn") @@ -373,6 +374,24 @@ class MuddleWindow(QMainWindow): downloadPathEdit.setText(self.downloadPath) localTreeView.setRootIndex(self.fileSystemModel.index(self.downloadPath)) + @pyqtSlot(QModelIndex) + def onMoodleTreeViewDoubleClicked(self, index): + realIndex = self.filterModel.mapToSource(index) + item = self.moodleTreeModel.itemFromIndex(realIndex) + + if item.metadata.type == MoodleItem.Type.FILE: + log.debug(f"started download from {item.metadata.url}") + + filepath = tempfile.gettempdir()+"/"+item.metadata.title + self.moodleTreeModel.worker.apihelper.get_file(item.metadata.url, filepath) + + if platform.system() == 'Darwin': # macOS + subprocess.Popen(('open', filepath)) + elif platform.system() == 'Windows': # Windows + os.startfile(filepath) + else: # linux variants + subprocess.Popen(('xdg-open', filepath)) + def start(instance_url, token): app = QApplication(sys.argv) -- cgit v1.2.1