From 9f46bb62adb3b0f47715de86ef4b376190dcf516 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 18 Oct 2020 13:18:14 +0200 Subject: Make item selection tristate, cleaup icon code --- gui.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'gui.py') diff --git a/gui.py b/gui.py index f644c49..cf57a1e 100644 --- a/gui.py +++ b/gui.py @@ -56,19 +56,22 @@ class MoodleItem(QTreeWidgetItem): self.setFont(0, font) icons = { - MoodleItem.Type.COURSE : QApplication.style().standardIcon(QStyle.SP_DriveNetIcon), - MoodleItem.Type.FOLDER : QApplication.style().standardIcon(QStyle.SP_DirIcon), - MoodleItem.Type.FILE : QApplication.style().standardIcon(QStyle.SP_FileIcon), - MoodleItem.Type.URL : QApplication.style().standardIcon(QStyle.SP_FileLinkIcon), + MoodleItem.Type.COURSE : QStyle.SP_DriveNetIcon, + MoodleItem.Type.FOLDER : QStyle.SP_DirIcon, + MoodleItem.Type.RESOURCE : QStyle.SP_DirLinkIcon, + MoodleItem.Type.FILE : QStyle.SP_FileIcon, + MoodleItem.Type.URL : QStyle.SP_FileLinkIcon, } if icons.get(self.metadata.type): - self.setIcon(0, icons[self.metadata.type]) + self.setIcon(0, QApplication.style().standardIcon(icons[self.metadata.type])) - if self.metadata.type == MoodleItem.Type.FILE: - flags = self.flags() - self.setFlags(flags | Qt.ItemIsUserCheckable) + flags = self.flags() + if self.metadata.type in [ MoodleItem.Type.FILE, MoodleItem.Type.FOLDER, MoodleItem.Type.RESOURCE ]: + self.setFlags(flags | Qt.ItemIsUserCheckable | Qt.ItemIsAutoTristate) self.setCheckState(0, Qt.Unchecked) + else: + self.setFlags(flags & ~Qt.ItemIsUserCheckable) self.setChildIndicatorPolicy(QTreeWidgetItem.DontShowIndicatorWhenChildless) self.setText(0, html.unescape(self.metadata.title)) @@ -151,9 +154,10 @@ class MoodleTreeView(QTreeWidget): def onItemDoubleClicked(self, item, col): log.debug(f"double clicked on item with type {str(item.metadata.type)}") if item.type == MoodleItem.Type.FILE: + # TODO: download in a temp folder and open pass - # @pyqtSlot() + @pyqtSlot(MoodleItem.Type, object) def onWorkerLoadedItem(self, type, item): # Assume that the items arrive in order moodleItem = None -- cgit v1.2.1