diff options
author | Nao Pross <np@0hm.ch> | 2020-11-10 17:51:49 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2020-11-10 17:51:49 +0100 |
commit | 4dddb71229725b584898e3d8836efbc409e211b5 (patch) | |
tree | 002d6a2231c8ba0f4e008cc0de23669560499c23 | |
parent | Refractor gui.MoodleTreeWidget into MoodleTreeModel (diff) | |
download | Muddle-4dddb71229725b584898e3d8836efbc409e211b5.tar.gz Muddle-4dddb71229725b584898e3d8836efbc409e211b5.zip |
Fix double-click to download and open file
The feature was broken since the refractor to load a .ui file
Diffstat (limited to '')
-rw-r--r-- | gui.py | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -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) |