aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristiano Colangelo <colac1@bfh.ch>2020-10-24 15:16:18 +0200
committerCristiano Colangelo <colac1@bfh.ch>2020-10-24 15:16:18 +0200
commit94dcc8a678d2203b07b0c1b36e85d72f8a6176a1 (patch)
tree63764b8787deed6635d0d0d473e23b3237c78e82
parentMake PEP8 happy (diff)
downloadMuddle-94dcc8a678d2203b07b0c1b36e85d72f8a6176a1.tar.gz
Muddle-94dcc8a678d2203b07b0c1b36e85d72f8a6176a1.zip
Add double-click download/open of files
-rw-r--r--gui.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/gui.py b/gui.py
index eb5fe86..cab60aa 100644
--- a/gui.py
+++ b/gui.py
@@ -2,12 +2,15 @@
# This document *and this document only* uses the Qt naming convention instead
# of PEP because the PyQt5 bindings do not have pythonic names
#
-
+import os
+import platform
+import subprocess
import sys
import json
import enum
import html
import logging
+import tempfile
from PyQt5.QtGui import QFont
from PyQt5.Qt import QStyle
@@ -151,8 +154,19 @@ class MoodleTreeView(QTreeWidget):
def onItemDoubleClicked(self, item, col):
log.debug(f"double clicked on item with type {str(item.metadata.type)}")
if item.metadata.type == MoodleItem.Type.FILE:
- # TODO: download in a temp folder and open
- pass
+ log.debug(f"started download from {item.metadata.url}")
+ filepath = tempfile.gettempdir()+"/"+item.metadata.title
+ self.worker.apihelper.get_file(item.metadata.url, filepath)
+
+ # TODO: Maybe extract in util function
+ if platform.system() == 'Darwin': # macOS
+ subprocess.call(('open', ))
+ elif platform.system() == 'Windows': # Windows
+ os.startfile(filepath)
+ else: # linux variants
+ subprocess.call(('xdg-open', filepath))
+
+
@pyqtSlot(MoodleItem.Type, object)
def onWorkerLoadedItem(self, type, item):