def fillTree(self): allLessons = defaultdict(list) for lesson in lessons: allLessons[lesson.group].append(lesson) self.lessonsTree.clear() lessonIcon = QIcon(os.path.dirname(__file__) + "/lesson.gif") for group, groupLessons in allLessons.items(): groupItem = QTreeWidgetItem() groupItem.setText(0, group) groupItem.description = groups.get(group, "") for lesson in groupLessons: lessonItem = QTreeWidgetItem() lessonItem.lesson = lesson lessonItem.setText(0, lesson.name) lessonItem.setIcon(0, lessonIcon) groupItem.addChild(lessonItem) if lesson.version[0] is not None and str(lesson.version[0]) > QGis.QGIS_VERSION: lessonItem.setText(0, lesson.name + " (requires QGIS >= {})".format(lesson.version[0])) lessonItem.setDisabled(True) if lesson.version[1] is not None and str(lesson.version[1]) < QGis.QGIS_VERSION: lessonItem.setText(0, lesson.name + " (requires QGIS <= {})".format(lesson.version[1])) lessonItem.setDisabled(True) self.lessonsTree.addTopLevelItem(groupItem) self.lessonsTree.sortItems(0, 0) self.lessonsTree.expandAll()
def fillTree(self): allLessons = defaultdict(list) for lesson in lessons: allLessons[lesson.group].append(lesson) self.lessonsTree.clear() lessonIcon = QIcon(os.path.dirname(__file__) + "/lesson.gif") for group, groupLessons in list(allLessons.items()): groupItem = QTreeWidgetItem() groupItem.setText(0, group) groupItem.description = groups.get(group, "") for lesson in groupLessons: lessonItem = QTreeWidgetItem() lessonItem.lesson = lesson lessonItem.setText(0, lesson.name) lessonItem.setIcon(0, lessonIcon) groupItem.addChild(lessonItem) if lesson.version[0] is not None and str(lesson.version[0]) > QGis.QGIS_VERSION: lessonItem.setText(0, lesson.name + " (requires QGIS >= {})".format(lesson.version[0])) lessonItem.setDisabled(True) if lesson.version[1] is not None and str(lesson.version[1]) < QGis.QGIS_VERSION: lessonItem.setText(0, lesson.name + " (requires QGIS <= {})".format(lesson.version[1])) lessonItem.setDisabled(True) self.lessonsTree.addTopLevelItem(groupItem) self.lessonsTree.sortItems(0, 0) self.lessonsTree.expandAll()
def __init__(self): super(LessonSelector, self).__init__() self.setupUi(self) self.lesson = None allLessons = defaultdict(list) for lesson in lessons: allLessons[lesson.group].append(lesson) lessonIcon = QIcon(os.path.dirname(__file__) + '/lesson.gif') for group, groupLessons in allLessons.items(): groupItem = QTreeWidgetItem() groupItem.setText(0, group) groupItem.description = groups.get(group, "") for lesson in groupLessons: lessonItem = QTreeWidgetItem() lessonItem.lesson = lesson lessonItem.setText(0, lesson.name) lessonItem.setIcon(0, lessonIcon) groupItem.addChild(lessonItem) self.lessonsTree.addTopLevelItem(groupItem) self.lessonsTree.sortItems(0, 0) self.lessonsTree.expandAll() self.lessonsTree.itemDoubleClicked.connect(self.itemDoubleClicked) self.btnRunLesson.setDefault(True) self.btnRunLesson.clicked.connect(self.okPressed) self.btnRemove.clicked.connect(self.remove) self.btnClose.clicked.connect(self.close) self.btnRemove.setEnabled(False) self.lessonsTree.currentItemChanged.connect(self.currentItemChanged) self.lessonsTree.setCurrentItem( self.lessonsTree.invisibleRootItem().child(0).child(0))