aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2020-11-10 17:51:49 +0100
committerNao Pross <np@0hm.ch>2020-11-10 17:51:49 +0100
commit4dddb71229725b584898e3d8836efbc409e211b5 (patch)
tree002d6a2231c8ba0f4e008cc0de23669560499c23
parentRefractor gui.MoodleTreeWidget into MoodleTreeModel (diff)
downloadMuddle-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
-rw-r--r--gui.py21
1 files changed, 20 insertions, 1 deletions
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)