From ea87abcb9771bbe734cfa67d373b5fc8a35cc7a6 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 9 Nov 2020 00:42:58 +0100 Subject: Implement download path selection --- gui.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- muddle.ui | 33 ++++++++++++++++++++------------- 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 @@ - false + true @@ -87,7 +87,7 @@ - false + true Select @@ -103,20 +103,10 @@ - + Local - - - Name - - - - - Size - - @@ -195,6 +185,23 @@ + + + + Default download path + + + + + + + Always start GUI + + + + + + -- cgit v1.2.1