def on_category(self): """ Command launched when 'Category' tree item widget is clicked Update category settings """ selItems = self.tw_category.selectedItems() or [] #--- Update Display ---# if not selItems: self.qf_settingsWidget.setVisible(False) else: if selItems[0].itemType == 'category': self.qf_settingsWidget.setVisible(False) else: self.qf_settingsWidget.setVisible(True) #--- Reset Visibility (resize bug) ---# for item in pQt.getAllItems(self.tw_category): if hasattr(item, 'itemWidget'): if item.itemWidget is not None: item.itemWidget.setVisible(False) #--- Edit Visibility ---# for item in pQt.getAllItems(self.tw_category): if hasattr(item, 'itemWidget'): if item.itemWidget is not None: if item.itemLabel == selItems[0].itemLabel: if item.parent( ).itemLabel == selItems[0].parent().itemLabel: item.itemWidget.setVisible(True)
def on_category(self): """ Command launched when 'Category' tree item widget is clicked Update category settings """ selItems = self.tw_category.selectedItems() or [] #--- Update Display ---# if not selItems: self.qf_settingsWidget.setVisible(False) else: if selItems[0].itemType == 'category': self.qf_settingsWidget.setVisible(False) else: self.qf_settingsWidget.setVisible(True) #--- Reset Visibility (resize bug) ---# for item in pQt.getAllItems(self.tw_category): if hasattr(item, 'itemWidget'): if item.itemWidget is not None: item.itemWidget.setVisible(False) #--- Edit Visibility ---# for item in pQt.getAllItems(self.tw_category): if hasattr(item, 'itemWidget'): if item.itemWidget is not None: if item.itemLabel == selItems[0].itemLabel: if item.parent().itemLabel == selItems[0].parent().itemLabel: item.itemWidget.setVisible(True)
def on_filter(self): """ Command launched when 'Filter' QComboBox item is clicked Update use tree display """ super(Users, self).on_filter() filter = str(self.cbb_filter.currentText()) for item in pQt.getAllItems(self.tw_tree): #--- Prefix ---# if len(filter) == 1: if item.itemObj.userPrefix == filter.lower(): item.setHidden(False) else: item.setHidden(True) #--- All ---# elif filter == 'All': item.setHidden(False) #--- Added, Edited, Deleted ---# elif filter in ['Added', 'Edited', 'Deleted']: if item in self.__editedItems__[filter.lower()]: item.setHidden(False) else: item.setHidden(True) #--- Changed ---# elif filter == 'Changed': if (item in self.__editedItems__['added'] or item in self.__editedItems__['edited'] or item in self.__editedItems__['deleted']): item.setHidden(False) else: item.setHidden(True)
def result(self): """ Get dialog result :return: Dialog result :rtype: dict """ data = dict() for item in pQt.getAllItems(self.tw_prompts): data[item.itemLabel] = item.itemWidget.result() return data
def pinedProjects(self): """ Get pined projects from 'My Projects' tree :return: Pined projects :rtype: list """ projects = [] for item in pQt.getAllItems(self.tw_myProjects) or []: projects.append(item.project) return projects
def rf_editedItemStyle(self): """ Refresh catecory style """ for item in pQt.getAllItems(self.tw_category): if item.itemType == 'subCategory': if item in self.getEditedItems(): item.setFont(0, self.editedSubCategoryFont) item.setTextColor(0, QtGui.QColor(100, 150, 255)) else: item.setFont(0, QtGui.QFont()) item.setTextColor(0, QtGui.QColor(220, 220, 220))
def on_button(self, QPushButton): """ Command launched when given QPushButton is clicked Add border line to selected color index :param QPushButton: Color index button :type QPushButton: QtGui.QPushButton """ self.clearSelection() for item in pQt.getAllItems(self): for n in range(self.columnCount()): item.setBackgroundColor(n, QtGui.QColor(0, 0, 0)) QPushButton.pItem.setBackgroundColor(QPushButton.column, QtGui.QColor(255, 0, 0))
def getEditedItems(self): """ Get edited subCategory items :return: Edited subCategory items :rtype: list """ editedItems = [] for item in pQt.getAllItems(self.tw_category): if item.itemType == 'subCategory': if item.itemWidget is not None: if item.itemWidget.__edited__: editedItems.append(item) return editedItems
def getItemFromAttrValue(self, attr, value): """ Get tree item considering given attribute and value :param attr: Item attribute name :type attr: str :param value: Item attribute value :type value: str :return: Tree item :rtype: QtGui.QtreeWidgetItem """ for item in pQt.getAllItems(self.tw_tree): if hasattr(item.itemObj, attr): if getattr(item.itemObj, attr) == value: return item
def on_moveItem(self, side): """ Command launched when 'Up' or 'Down' QPushButton is clicked Move selected item :param side: 'up' or 'down' :type side: str """ if hasattr(self, 'log'): self.log.detail(">>> Launch 'Move Item': %s <<<" % side) selItems = self.tw_tree.selectedItems() or [] if selItems: movedItem = None #--- Get Current Index ---# if selItems[0].parent() is None: parent = None index = self.tw_tree.indexOfTopLevelItem(selItems[0]) else: parent = selItems[0].parent() index = parent.indexOfChild(selItems[0]) #--- Move Up ---# if side == 'up': if index > 0: if parent is None: movedItem = self.tw_tree.takeTopLevelItem( self.tw_tree.indexOfTopLevelItem(selItems[0])) self.tw_tree.insertTopLevelItem((index - 1), movedItem) else: movedItem = parent.takeChild( parent.indexOfChild(selItems[0])) parent.insertChild((index - 1), movedItem) #--- Move Down ---# else: if index < (self.tw_tree.topLevelItemCount()): if parent is None: movedItem = self.tw_tree.takeTopLevelItem( self.tw_tree.indexOfTopLevelItem(selItems[0])) self.tw_tree.insertTopLevelItem((index + 1), movedItem) else: movedItem = parent.takeChild( parent.indexOfChild(selItems[0])) parent.insertChild((index + 1), movedItem) #--- Select Moved Item ---# if movedItem is not None: self.tw_tree.clearSelection() for item in pQt.getAllItems(self.tw_tree): if item == movedItem: self.tw_tree.setItemSelected(movedItem, True)
def rf_itemStyle(self): """ refresh tree item style """ for item in pQt.getAllItems(self.tw_tree) or []: #--- Get Color ---# if item in self.__editedItems__['added']: color = (0, 255, 0) elif item in self.__editedItems__['edited']: color = (50, 150, 255) elif item in self.__editedItems__['deleted']: color = (255, 0, 0) else: color = (200, 200, 200) #--- Set Color ---# for n in range(self.tw_tree.columnCount()): item.setTextColor(n, QtGui.QColor(color[0], color[1], color[2]))
def on_moveItem(self, side): """ Command launched when 'Up' or 'Down' QPushButton is clicked Move selected item :param side: 'up' or 'down' :type side: str """ if hasattr(self, 'log'): self.log.detail(">>> Launch 'Move Item': %s <<<" % side) selItems = self.tw_tree.selectedItems() or [] if selItems: movedItem = None #--- Get Current Index ---# if selItems[0].parent() is None: parent = None index = self.tw_tree.indexOfTopLevelItem(selItems[0]) else: parent = selItems[0].parent() index = parent.indexOfChild(selItems[0]) #--- Move Up ---# if side == 'up': if index > 0: if parent is None: movedItem = self.tw_tree.takeTopLevelItem(self.tw_tree.indexOfTopLevelItem(selItems[0])) self.tw_tree.insertTopLevelItem((index - 1), movedItem) else: movedItem = parent.takeChild(parent.indexOfChild(selItems[0])) parent.insertChild((index - 1), movedItem) #--- Move Down ---# else: if index < (self.tw_tree.topLevelItemCount()): if parent is None: movedItem = self.tw_tree.takeTopLevelItem(self.tw_tree.indexOfTopLevelItem(selItems[0])) self.tw_tree.insertTopLevelItem((index + 1), movedItem) else: movedItem = parent.takeChild(parent.indexOfChild(selItems[0])) parent.insertChild((index + 1), movedItem) #--- Select Moved Item ---# if movedItem is not None: self.tw_tree.clearSelection() for item in pQt.getAllItems(self.tw_tree): if item == movedItem: self.tw_tree.setItemSelected(movedItem, True)
def getItemFromCtxtCode(self, ctxtCode, parentCode=None): """ Get item from given CtxtCode :param ctxtCode: Context entity code :type ctxtCode: str :param parentCode: Parent context entity code :type parentCode: str :return: CtxtEntity item :rtype: QtGui.QTreeWidgetItem """ for item in pQt.getAllItems(self.tw_tree): if parentCode is None: if item.itemObj.ctxtCode == ctxtCode and item.itemObj.contextType == 'mainType': return item else: if item.itemObj.ctxtCode == ctxtCode and item.itemObj.contextType == 'subType': if item.parent().itemObj.ctxtCode == parentCode: return item
def getItemFromCtxtCode(self, ctxtCode, parentCode=None): """ Get item from given CtxtCode :param ctxtCode: Context entity code :type ctxtCode: str :param parentCode: Parent context entity code :type parentCode: str :return: CtxtEntity item :rtype: QtGui.QTreeWidgetItem """ for item in pQt.getAllItems(self.tw_tree): if parentCode is None: if item.itemObj.ctxtCode == ctxtCode and item.itemObj.contextType == "mainType": return item else: if item.itemObj.ctxtCode == ctxtCode and item.itemObj.contextType == "subType": if item.parent().itemObj.ctxtCode == parentCode: return item
def selectedColorIndex(self): for item in pQt.getAllItems(self): for widget in item._widgets: if widget.isChecked(): return widget.index