def __init__(self): super(Moodle2PdfWindow, self).__init__() uic.loadUi(get_resource_path('moodle2pdf.ui'), self) self.siteNode = self.moodleItemsTreeWidget.topLevelItem(0) self.siteNode.setIcon(0, QtGui.QIcon(get_resource_path('res/home.svg'))) self.setWindowIcon(QtGui.QIcon(get_resource_path('res/moodle.png'))) self.setupStatusBar() self.addSlotsAndSignals() self.show()
def __init__(self): super(MoodleEditor, self).__init__() uic.loadUi(get_resource_path('moodleeditor.ui'), self) self.tempDir = tempfile.TemporaryDirectory() self.iconMap = {} self.siteNode = self.moodleItemsTreeWidget.topLevelItem(0) self.siteNode.setIcon(0, QtGui.QIcon(get_resource_path('res/home.svg'))) header = self.moodleItemsTreeWidget.header() header.setStretchLastSection(False) header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch) self.setWindowIcon(QtGui.QIcon(get_resource_path('res/moodle.png'))) self.setupStatusBar() self.addSlotsAndSignals() self.show()
def populateDatabases(self, item, course_id): self.statusBar().showMessage(self.tr('Loading all databases for course...')) databases = moodle.get_databases_by_courses(course_id) for d in databases: databaseNode = QtWidgets.QTreeWidgetItem(item) databaseNode.setText(0, d[1]) databaseNode.setData(0, QtCore.Qt.UserRole, d) databaseNode.setCheckState(0, QtCore.Qt.Unchecked) databaseNode.moodleType = 'database' databaseNode.setIcon(0, QtGui.QIcon(get_resource_path('res/database.svg'))) self.statusBar().showMessage(self.tr('All databases loaded.')) item.setExpanded(True)
def populateWikis(self, item, course_id): self.statusBar().showMessage(self.tr('Loading all wikis for course...')) wikis = moodle.get_wikis_by_courses(course_id) for w in wikis: wikiNode = QtWidgets.QTreeWidgetItem(item) wikiNode.setText(0, w[1]) wikiNode.setData(0, QtCore.Qt.UserRole, w) wikiNode.setCheckState(0, QtCore.Qt.Unchecked) wikiNode.moodleType = 'wiki' wikiNode.setIcon(0, QtGui.QIcon(get_resource_path('res/wiki.svg'))) self.statusBar().showMessage(self.tr('All wikis loaded.')) item.setExpanded(True)
def populateGlossaries(self, item, course_id): self.statusBar().showMessage(self.tr('Loading all glossaries for course...')) glossaries = moodle.get_glossaries_from_course(course_id) for g in glossaries: glossaryNode = QtWidgets.QTreeWidgetItem(item) glossaryNode.setText(0, g[1]) glossaryNode.setData(0, QtCore.Qt.UserRole, g) glossaryNode.setCheckState(0, QtCore.Qt.Unchecked) glossaryNode.moodleType = 'glossary' glossaryNode.setIcon(0, QtGui.QIcon(get_resource_path('res/glossar.svg'))) self.statusBar().showMessage(self.tr('All glossaries loaded.')) item.setExpanded(True)
def populateCourses(self): # get all courses for current user courses = moodle.get_courses_for_user() # add items for all courses self.progressBar.setValue(0) for i, c in enumerate(courses): courseNode = QtWidgets.QTreeWidgetItem(self.siteNode) courseNode.setText(0, c[1]) courseNode.setData(0, QtCore.Qt.UserRole, c) #courseNode.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) courseNode.setIcon(0, QtGui.QIcon(get_resource_path('res/course.svg'))) self.progressBar.setValue(100 / len(courses) * (i + 1)) self.siteNode.setExpanded(True)
def getIcon(self, iconPath): if iconPath in self.iconMap: return self.iconMap[iconPath] else: r = requests.get(iconPath, stream=True) if r.status_code == 200: localFile = os.path.join(self.tempDir.name, str(hash(iconPath))) with open(localFile, 'wb') as f: for chunk in r: f.write(chunk) self.iconMap[iconPath] = localFile return localFile else: return get_resource_path('res/home.svg')
def findSectionItem(self, topItem, sectionId, sectionName): for i in range(topItem.childCount()): # check all children of course node for section c = topItem.child(i) data = c.data(0, QtCore.Qt.UserRole) if data.id == sectionId and data.name == sectionName: return c # create new section node, if it does not already exists sectionNode = QtWidgets.QTreeWidgetItem(topItem) sectionNode.setText(0, '{}'.format(sectionName)) sectionNode.setIcon(0, QtGui.QIcon(get_resource_path('res/section.svg'))) sectionData = Section(sectionId, sectionName) sectionNode.setData(0, QtCore.Qt.UserRole, sectionData) sectionNode.setCheckState(1, QtCore.Qt.Checked) sectionNode.setExpanded(True) return sectionNode