aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2020-11-09 00:42:58 +0100
committerNao Pross <np@0hm.ch>2020-11-09 00:42:58 +0100
commitea87abcb9771bbe734cfa67d373b5fc8a35cc7a6 (patch)
tree3a023f306cfbdf2c82d539f3394b8a41b36411b5
parentUpdate screenshot (diff)
downloadMuddle-ea87abcb9771bbe734cfa67d373b5fc8a35cc7a6.tar.gz
Muddle-ea87abcb9771bbe734cfa67d373b5fc8a35cc7a6.zip
Implement download path selection
-rw-r--r--gui.py58
-rw-r--r--muddle.ui33
2 files changed, 76 insertions, 15 deletions
diff --git a/gui.py b/gui.py
index b2fc552..3cb1474 100644
--- a/gui.py
+++ b/gui.py
@@ -18,6 +18,7 @@ from PyQt5.Qt import QStyle
from PyQt5.QtCore import (
Qt,
+ QDir,
QThread,
pyqtSlot,
pyqtSignal,
@@ -41,7 +42,9 @@ from PyQt5.QtWidgets import (
QLineEdit,
QProgressBar,
QTabWidget,
- QPlainTextEdit
+ QPlainTextEdit,
+ QFileSystemModel,
+ QFileDialog,
)
import moodle
@@ -179,7 +182,7 @@ class MoodleTreeWidget(QTreeWidget):
def refresh(self, instance_url, token):
if not self.worker or self.worker.isFinished():
self.setSortingEnabled(False)
- # TODO: remove elements if present
+ self.clear()
self.worker = MoodleFetcher(self, instance_url, token)
self.worker.loadedItem.connect(self.onWorkerLoadedItem)
@@ -290,6 +293,25 @@ class MuddleWindow(QMainWindow):
searchBar = self.findChild(QLineEdit, "searchBar")
searchBar.textChanged.connect(self.onSearchBarTextChanged)
+ # local filesystem view
+ self.downloadPath = QDir.homePath()
+
+ self.fileSystemModel = QFileSystemModel()
+ self.fileSystemModel.setRootPath(QDir.homePath())
+
+ localTreeView = self.findChild(QTreeView, "localTab")
+ localTreeView.setModel(self.fileSystemModel)
+ localTreeView.setRootIndex(self.fileSystemModel.index(QDir.homePath()))
+ localTreeView.setColumnWidth(0, 240)
+
+ downloadPathEdit = self.findChild(QLineEdit, "downloadPathEdit")
+ downloadPathEdit.setText(self.downloadPath)
+ downloadPathEdit.editingFinished.connect(self.onDownloadPathEditEditingFinished)
+
+ # select path
+ selectPathBtn = self.findChild(QToolButton, "selectPathBtn")
+ selectPathBtn.clicked.connect(self.onSelectPathBtnClicked)
+
self.show()
@pyqtSlot(str)
@@ -303,6 +325,38 @@ class MuddleWindow(QMainWindow):
def onNewLogMessage(self, msg):
self.findChild(QPlainTextEdit, "logsTab").appendPlainText(msg)
+ @pyqtSlot()
+ def onDownloadPathEditEditingFinished(self):
+ downloadPathEdit = self.findChild(QLineEdit, "downloadPathEdit")
+ path = downloadPathEdit.text()
+
+ if not self.updateDownloadPath(path):
+ downloadPathEdit.setText(self.downloadPath)
+
+ @pyqtSlot()
+ def onSelectPathBtnClicked(self):
+ path = QFileDialog.getExistingDirectory(
+ self, "Select Download Directory",
+ self.downloadPath, QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
+
+ if not path:
+ return
+
+ self.updateDownloadPath(path)
+
+ @pyqtSlot()
+ def updateDownloadPath(self, newpath):
+ if not self.fileSystemModel.index(newpath).isValid():
+ return False
+
+ self.downloadPath = newpath
+
+ downloadPathEdit = self.findChild(QLineEdit, "downloadPathEdit")
+ localTreeView = self.findChild(QTreeView, "localTab")
+
+ downloadPathEdit.setText(self.downloadPath)
+ localTreeView.setRootIndex(self.fileSystemModel.index(self.downloadPath))
+
def start(instance_url, token):
app = QApplication(sys.argv)
diff --git a/muddle.ui b/muddle.ui
index 9737c7a..b9b0414 100644
--- a/muddle.ui
+++ b/muddle.ui
@@ -40,7 +40,7 @@
<item row="2" column="0">
<widget class="QLineEdit" name="downloadPathEdit">
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
</property>
</widget>
</item>
@@ -87,7 +87,7 @@
<item row="2" column="1">
<widget class="QToolButton" name="selectPathBtn">
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="text">
<string>Select</string>
@@ -103,20 +103,10 @@
</item>
</layout>
</widget>
- <widget class="QTreeWidget" name="localTab">
+ <widget class="QTreeView" name="localTab">
<attribute name="title">
<string>Local</string>
</attribute>
- <column>
- <property name="text">
- <string notr="true">Name</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Size</string>
- </property>
- </column>
</widget>
<widget class="QPlainTextEdit" name="logsTab">
<property name="sizePolicy">
@@ -195,6 +185,23 @@
</property>
</widget>
</item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="defaultDownloadPathLabel">
+ <property name="text">
+ <string>Default download path</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="checkBox">
+ <property name="text">
+ <string>Always start GUI</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="defaltDownloadPathEdit"/>
+ </item>
</layout>
</widget>
</item>