def selectAll(self): iterator = QTreeWidgetItemIterator(self.treeWidget) iterator += 1 while iterator.value(): item = iterator.value() item.setCheckState(0, Qt.Checked) iterator += 1
def actionClick(self, txt): if not txt: return p = ''.join((r'.*', txt, r'.*')) obj = re.compile(p) cursor = QTreeWidgetItemIterator(self.treeWidget) while cursor.value(): item = cursor.value() if item is not self.treeWidget._rootItem: item.setExpanded(False) item.setSelected(False) cursor = cursor.__iadd__(1) cursor = QTreeWidgetItemIterator(self.treeWidget) while cursor.value(): item = cursor.value() if item is self.treeWidget._rootItem: cursor = cursor.__iadd__(1) continue if item.parent() is self.treeWidget._rootItem: cursor = cursor.__iadd__(1) continue itemtext = item.text(0) if obj.match(itemtext): self.ChangeParentExpanded(item) item.setSelected(True) cursor = cursor.__iadd__(1)
def get_hierarchies(self, **kwargs): """ return selected hierarchy """ only_selected = kwargs.get('only_selected', None) sets_to_display = list() if only_selected: iterator = QTreeWidgetItemIterator(self.hierarchy_widget, QTreeWidgetItemIterator.Checked) else: iterator = QTreeWidgetItemIterator(self.hierarchy_widget) while iterator.value(): # note: if hierarchy value is not a tuple, then this is just top level qTreeWidgetItem that # holds subcategories. We don't want to display all sets from category if type(iterator.value().hierarchy) is not str: if not only_selected: sets_to_display.append(iterator.value().hierarchy) else: if not iterator.value().isDisabled(): sets_to_display.append(iterator.value().hierarchy) iterator += 1 return sets_to_display
def items(self): iterator = QTreeWidgetItemIterator(self.ui.plugins, QTreeWidgetItemIterator.All) while iterator.value(): item = iterator.value() iterator += 1 yield item
def draw_stuff(self): it = QTreeWidgetItemIterator(self.treeWidget_formula) while it.value(): item = it.value() # 标记为0的列即为未领够料的记录 if item.text(9) == '0': stuffkind = item.text(2) precision = int(item.text(7)) loss = item.text(8) # 处理产品信息的变量,去除系统变量 item.setText(4, self.reckon_expression(item.text(4), 1)) # 计划量 try: presamount = Decimal( rnd(eval(item.text(4), evalenv(self)), precision)) except SyntaxError: if stuffkind + ' 计划量' not in self.errormsg: self.errormsg.append(stuffkind + ' 计划量') presamount = 0 # 把计划量加到产品信息变量中 # self.detail['presamount'] = presamount # 实际量公式,去除系统变量 item.setText(5, self.reckon_expression(item.text(5), 1)) # 领取量公式,去除系统变量 item.setText(6, self.reckon_expression(item.text(6), 1)) # 计算领料量,返回领料情况res, 和标记:是否已经领购料 res = self.reckon_drawamount(stuffkind, presamount, precision, item.text(5), item.text(6), loss) if len(res): self.treeWidget_drawstuff_add_item(res) it += 1 self.is_drawamount_enough()
def copy_tree(self): """Copy the tree to the clipboard.""" items = [] inval_index = QModelIndex() it = QTreeWidgetItemIterator(self) prev_depth = 0 while it.value(): depth = 0 item = it.value() parent = item.parent() while parent: depth += 1 parent = parent.parent() if depth < prev_depth: items.extend([" |"*depth, "\n"]) if depth: items.extend([" |"*depth, "--", item.text(0), "\n"]) else: items.extend([item.text(0), "\n"]) prev_depth = depth it += 1 QApplication.clipboard().setText("".join(items))
def okButtonClicked(self): modules_to_process = {'delete': [], 'install': []} iterator = QTreeWidgetItemIterator(self.tree) item = iterator.value() while item is not None: if item.parent() is not None: if item.parent().parent() is not None: # handle the installed modules to delete repo_name = item.parent().parent().text(0) if repo_name == INSTALLED_MODULES: if item.checkState(0) == Qt.Unchecked: modules_to_process['delete'].append(item.text(0)) # handle the remote modules to install else: if item.checkState(0) == Qt.Checked: item_dict = { 'name': item.text(0), 'repository': repo_name, } modules_to_process['install'].append(item_dict) iterator += 1 item = iterator.value() self.installAndUninstallModules(modules_to_process)
def clearSitesToApply(self): """ unchecks all objects in site_tree_widget """ iterator = QTreeWidgetItemIterator(self.site_tree_widget, QTreeWidgetItemIterator.Checked) while iterator.value(): obj = iterator.value() obj.setCheckState(0, Qt.Unchecked) iterator += 1
def copy_tree(self): """Copy the tree to the clipboard.""" items = [] inval_index = QModelIndex() it = QTreeWidgetItemIterator(self) prev_depth = 0 while it.value(): depth = 0 item = it.value() parent = item.parent() while parent: depth += 1 parent = parent.parent() if depth < prev_depth: items.extend([" |" * depth, "\n"]) if depth: items.extend([" |" * depth, "--", item.text(0), "\n"]) else: items.extend([item.text(0), "\n"]) prev_depth = depth it += 1 QApplication.clipboard().setText("".join(items))
def findParentWidget(self, findOrder=None): '''scan the tree and find the treeviewwidget with the matching parentOrder''' # if the find id is None then this is the root so return the tree view itself if findOrder is None: return self.tvPath # find the parent tree view widget parentWidget = None # iterate through the treeview tvPathIterator = QTreeWidgetItemIterator( self.tvPath, flags=QTreeWidgetItemIterator.All) while tvPathIterator: if not tvPathIterator.value() is None: queryPathNodeItem = tvPathIterator.value() queryPathNodeDict = queryPathNodeItem.data(0, Qt.UserRole).dict() order = queryPathNodeDict.get("order", 0) # save the value for order if it's greater if order == findOrder: parentWidget = queryPathNodeItem break tvPathIterator.__iadd__(1) else: break return parentWidget
def set_state(self, value): self.tab.blockSignals(True) iterator = QTreeWidgetItemIterator(self.tab) while iterator.value(): item = iterator.value() path = [] while item is not None: path.append(str(item.text(0))) item = item.parent() path = "/".join(reversed(path)) path = path.split('/') if len(path) > 1: path = path[1:] if path[0] == value: item = iterator.value() if len(path) == 1: checked = item.checkState(0) #checked=bool(checked) if len(path) > 1: item.setCheckState(0, checked) iterator += 1 self.tab.blockSignals(False)
def get_data(self): self.pb.setValue(0) queue = Queue() self.result_queue = Queue() self.systems_list = [] self.options = {'correlation': self.corr_btn.isChecked(), 'decomposition': self.show_decomp_btn.isChecked(), 'components': [x.text() for x in [self.com_btn, self.rec_btn, self.lig_btn] if x.isChecked()], 'remove_empty_charts': self.remove_empty_charts_btn.isChecked(), 'remove_empty_terms':self.remove_empty_terms_btn.isChecked() ,'hide_toolbar': self.hide_tb_btn.isChecked()} it = QTreeWidgetItemIterator(self.f_item) while it.value(): item = it.value() if item.checkState(1) == Qt.Checked and item.info: self.systems_list.append(item.info) it += 1 self.pb.setRange(0, len(self.systems_list)) if not len(self.systems_list): m = QMessageBox.critical(self, 'Error processing systems', 'You must select at least one system.', QMessageBox.Ok) return it = QTreeWidgetItemIterator(self.f_item) while it.value(): item = it.value() if item.checkState(1) == Qt.Checked and item.info: queue.put(item.info[1]) self.systems_list.append(item.info) it += 1 self.worker.define_dat(API.load_gmxmmpbsa_info, queue, self.result_queue, self.jobs_spin.value()) self.worker.start()
def accept(self): torrentPriorities = {"Low": 0, "Normal": 127, "High": 255} filePriorities = {"Low": 1, "Normal": 4, "High": 7} it = QTreeWidgetItemIterator(self.treeView, QTreeWidgetItemIterator.NoChildren) itemsInfo = {} while it.value(): currentItem = it.value() if currentItem.checkState(0) == Qt.Unchecked: priority = 0 else: priority = filePriorities[currentItem.text(2)] itemsInfo[self.getFullPath(currentItem)] = priority it += 1 paths = [f.path for f in self.torrentInfo.files()] self.prioritiesList = [itemsInfo[p] for p in paths] comboBoxIndex = self.priorityComboBox.currentIndex() self.priority = torrentPriorities[self.priorityComboBox.itemText( comboBoxIndex)] self.hide() self.dataReady.emit(self.getData()) super().accept()
def findParentWidget(self, findID=None): '''scan the tree and find the treeviewwidget with the matching parentOrder''' # if the find id is None then this is the root so return the tree view itself if findID is None: return self.tvOutline # find the parent tree view widget parentWidget = None # iterate through the treeview tvOutlineIterator = QTreeWidgetItemIterator(self.tvOutline, flags = QTreeWidgetItemIterator.All) while tvOutlineIterator: if not tvOutlineIterator.value() is None: # get the treeview widget tvWidget = tvOutlineIterator.value() # get the form item object from the widget formItem = tvWidget.data(0, Qt.UserRole) # get the idNum of the form item object idNum = formItem.itemDict["idNum"] # check to see if this is the idNum we're looking for if idNum == findID: parentWidget = tvWidget break tvOutlineIterator.__iadd__(1) else: break return parentWidget
def func(): it = QTreeWidgetItemIterator(tree, flags=QTreeWidgetItemIterator.All) mx = tree.topLevelItemCount() c = 0 tempath = [] while it.value(): if mx > c: item = it.value() if item.isExpanded(): tempath = [item.text(0)] MX = item.childCount() C = 0 nit = QTreeWidgetItemIterator(item, flags=QTreeWidgetItemIterator.All) while nit.value(): if MX > C: global a a = nit.value().parent() if nit.value().text(0) == "jake": tempath.append("jake") MX = 0 mx = 0 break nit += 1 C += 1 else: break it += 1 c += 1 else: break
def find_checked(self): iterator = QTreeWidgetItemIterator(self.main.treeWidget) # print(iterator) while iterator.value(): item = iterator.value() if item.checkState(0): self.checked.append(item.text(0)) iterator += 1
def hilightFormatInfoTree(self, range): iterator = QTreeWidgetItemIterator(self) while iterator.value(): item = iterator.value() itemRange = item.data(0, Range.RangeRole) #item.setBackground(0, QColor("#dddddd") if itemRange is not None and itemRange.overlaps(range) else QColor("#ffffff")) #item.setProperty("class", "highlighted" if itemRange is not None and itemRange.overlaps(range) else "") iterator += 1
def GetSelectedItems(self): interator = QTreeWidgetItemIterator(self.treeWidget, QTreeWidgetItemIterator.Checked) while (interator.value()): item = interator.value() self.arrayResult.append(item.text(0)) interator += 1 self.close()
def find_parent_node(tree, parent_id): iterator = QTreeWidgetItemIterator(tree) while iterator.value(): node = iterator.value() if get_node_data(node).node_id == parent_id: return node iterator += 1 return None
def setCurrentTreeItemByData(self, data): it = QTreeWidgetItemIterator(self.ui.treeWidget) while it.value(): if it.value().data(0, Qt.UserRole) == data: self.ui.treeWidget.setCurrentItem(it.value()) return True it += 1 return False
def unselect_all(self): iterator = QTreeWidgetItemIterator(self.main.treeWidget) while iterator.value(): item = iterator.value() item.setCheckState(0, QtCore.Qt.Unchecked) iterator += 1 self.main.pushBtnSelectAll.setEnabled(True) self.main.pushBtnUnselectAll.setEnabled(False)
def on_header_sectionResized(self, p_int, p_int_1, p_int_2): try: it = QTreeWidgetItemIterator(self) while it.value(): it.value().resetText(p_int, p_int_2) it += 1 except ValueError: pass
def fetch_item_by_node(self, node): iterator = QTreeWidgetItemIterator(self) while iterator.value(): item = iterator.value() if item.node is node: return item iterator += 1 return None
def check_status(self): iterator = QTreeWidgetItemIterator(self.ui.treeWidget_select_test) item = iterator.value() while iterator.value(): if item.checkState(0): self.ui.select_all_button.setEnabled(False) self.ui.deselect_all_button.setEnabled(True) iterator += 1
def select_all_checkbox(self): iterator = QTreeWidgetItemIterator(self.ui.treeWidget_select_test) while iterator.value(): item = iterator.value() item.setCheckState(0, QtCore.Qt.Checked) iterator += 1 self.ui.select_all_button.setEnabled(False) self.ui.deselect_all_button.setEnabled(True)
def _on_tree_item_selection_changed(self): iterator = QTreeWidgetItemIterator(self) while iterator.value(): item = iterator.value() item.widget.hide() iterator += 1 for item in self.selectedItems(): item.widget.show()
def selectAllSitesToApply(self): """ checks all objects in site_tree_widget, may be useful if the user wants to select all but a few in the list""" iterator = QTreeWidgetItemIterator(self.site_tree_widget, QTreeWidgetItemIterator.NotChecked) while iterator.value(): obj = iterator.value() obj.setCheckState(0, Qt.Checked) iterator += 1
def make_puzzle(self): word_image = [] if self.tree.topLevelItemCount() == 0: self.start_download() return self.disable_buttons() if self.picture_on: iterator = QTreeWidgetItemIterator( self.tree, QTreeWidgetItemIterator.HasChildren) else: iterator = QTreeWidgetItemIterator(self.tree, QTreeWidgetItemIterator.All) if iterator.value() is None: self.c.press_set_keyword_bt.emit() q = QMessageBox(self) q.information(self, 'information', '검색어 키워드가 존재하지 않아요. 그래서 검색어 키워드 버튼을 대신 눌렀습니다~.', QMessageBox.Ok) self.enable_buttons() return while iterator.value(): item = iterator.value() word = item.data(0, 0) pic = '' if self.picture_on: pic = item.path if not os.path.exists(pic): self.c.press_set_keyword_bt.emit() self.enable_buttons() q = QMessageBox(self) q.information(self, 'information', '선택하신 이미지가 존재하지 않습니다. 다시 다운로드 눌러주세요.', QMessageBox.Ok) return if word.strip().find(' ') != -1: if self.korean: word = '가'.join(word.split()) else: word = 'a'.join(word.split()) word_image.append([word, pic]) iterator += 1 self.path = self.get_save_hwp_dir() if self.path: puzzle_worker = PuzzleWorker(wordsearch_generater.MakeWordSearch, word_image, self.width, self.height, self.diff, self.option, self.picture_on, self.korean, self.chosung_scramable, self.uppercase, self.path) puzzle_worker.signal.puzzle_complete.connect(self.puzzle_finish) puzzle_worker.signal.recursionerrormsg.connect(self.recurerrormsg) puzzle_worker.signal.valueerrormsg.connect(self.valerrormsg) self.threadpool.start(puzzle_worker) else: self.enable_buttons()
def has_checked_input_file_node_children(node): iterator = QTreeWidgetItemIterator(node) while iterator.value(): child_node = iterator.value() node_data = get_node_data(child_node) if node_data.map_selection or node_data.file: return True iterator += 1 return False
def btnHome_Click(self): CSRWidgets.changeCentralWidget(self, CSRWidgets.createDesignButtons(self,'default')) self.availableItems.clear() itSku = QTreeWidgetItemIterator(self.garmentTree) ################################################################################# while itSku.value(): if itSku.value().parent() != None: itSku.value().setExpanded(False) itSku += 1
def save_tree(tree, alias=ALIAS): db = sqlite3.connect(mm_config.CURRENT_DB_CMM_SMM_FILE_PATH) db.row_factory = sqlite3.Row c = db.cursor() iterator = QTreeWidgetItemIterator(tree) remaining_node_ids = [] while iterator.value(): node = iterator.value() data = get_node_data(node) if data.node_id: if does_node_exist(data.node_id): c.execute( "UPDATE NODES SET SELECTED = ?, DESCRIPTION = ?, ICON = ?, FILE = ?, SHAPE_ATTRIBUTE = ?, ALGORITHM_ID = ?, MAP_SELECTION = ?, BUFFER = ? WHERE NODE_ID=?", (_get_boolean_value(node.checkState(0)), node.text(0), data.icon, path2alias(data.file, alias), data.shape_attribute, _get_int_value(data.algorithm_id), data.map_selection, _get_int_value( data.buffer), _get_int_value(data.node_id))) else: c.execute( "INSERT INTO NODES (NODE_ID,TREE_ID,MAIN_NODE_ID,SELECTED,DESCRIPTION,ICON,FILE,SHAPE_ATTRIBUTE,ALGORITHM_ID,MAP_SELECTION,TYPE, ALGORITHM_SELECTION, BUFFER)" " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (data.node_id, data.tree_id, data.main_node_id, _get_boolean_value( node.checkState(0)), node.text(0), data.icon, path2alias(data.file, alias), data.shape_attribute, data.algorithm_id, data.map_selection, data.type, data.algorithm_selection, data.buffer)) else: c.execute( "INSERT INTO NODES (TREE_ID,MAIN_NODE_ID,SELECTED,DESCRIPTION,ICON,FILE,SHAPE_ATTRIBUTE,ALGORITHM_ID,MAP_SELECTION,TYPE, ALGORITHM_SELECTION, BUFFER)" " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (data.tree_id, data.main_node_id, _get_boolean_value(node.checkState(0)), node.text(0), data.icon, path2alias(data.file, alias), data.shape_attribute, data.algorithm_id, data.map_selection, data.type, data.algorithm_selection, data.buffer)) data.node_id = c.lastrowid if data.parameters: update_parameters(c, data) remaining_node_ids.append(data.node_id) iterator += 1 # remove all nodes that are not in the tree anymore (deleted) c.execute("SELECT NODE_ID FROM NODES WHERE TREE_ID = ?", (data.tree_id, )) db_node_id_rows = c.fetchall() for db_node_id_row in db_node_id_rows: db_node_id = db_node_id_row["node_id"] if db_node_id not in remaining_node_ids: c.execute("DELETE FROM PARAMETERS WHERE NODE_ID = ?", (db_node_id, )) c.execute("DELETE FROM NODES WHERE NODE_ID = ?", (db_node_id, )) db.commit() c.close() db.close()
def validate(self): if self.objectDict is None: self.objectDict = {} templateName = self.txtPathTemplateName.text() # template name if self.helper.NoTextValueError(templateName, "Must enter a Path Template Name"): self.txtPathTemplateName.setFocus() return False # find duplicate cypher variables varList = [] # iterate through the treeview tvPathIterator = QTreeWidgetItemIterator( self.tvPath, flags=QTreeWidgetItemIterator.All) returnCount = 0 while tvPathIterator: if not tvPathIterator.value() is None: queryPathNodeItem = tvPathIterator.value() thisQueryPathNode = queryPathNodeItem.data(0, Qt.UserRole) if thisQueryPathNode.type in ["Node", "Relationship"]: returnCount = returnCount + thisQueryPathNode.numReturnProps( ) if returnCount < 1: self.helper.displayErrMsg( thisQueryPathNode.templateName, "Must return at least one property.") return False if self.helper.NoTextValueError( thisQueryPathNode.templateName, "Must supply a template name."): return False if self.helper.NoTextValueError( thisQueryPathNode.cypherVar, "Must supply a cypher variable for {}.".format( thisQueryPathNode.templateName)): return False if thisQueryPathNode.cypherVar in varList: self.helper.displayErrMsg( "Validate Path", "Error - duplicate cypher variable {} defined in template: {} " .format(thisQueryPathNode.cypherVar, thisQueryPathNode.templateName)) return False if thisQueryPathNode.templateName == "No Template Selected" and thisQueryPathNode.blankTemplate == False: self.helper.displayErrMsg( "Validate Path", "Error - must select a template or set blank template to True " ) return False varList.append(thisQueryPathNode.cypherVar) tvPathIterator.__iadd__(1) else: break # passed all edits so return True return True
def vrfs_selected(self, widget): iterator = QTreeWidgetItemIterator(widget, QTreeWidgetItemIterator.Checked) selected_items = [] while iterator.value(): item = iterator.value() if item.text(0) not in selected_items: selected_items.append(item.text(0)) iterator += 1 return selected_items
def _set_dependencies(self): """ Set the dependency information. """ project = self.project editor = self._stdlib_edit required_modules, required_libraries = project.get_stdlib_requirements() blocked = editor.blockSignals(True) it = QTreeWidgetItemIterator(editor) itm = it.value() while itm is not None: external = required_modules.get(itm._name) expanded = False if external is None: state = Qt.Unchecked elif external: state = Qt.Checked expanded = True else: state = Qt.PartiallyChecked itm.setCheckState(0, state) # Make sure every explicitly checked item is visible. if expanded: parent = itm.parent() while parent is not None: parent.setExpanded(True) parent = parent.parent() it += 1 itm = it.value() editor.blockSignals(blocked) model = self._extlib_edit.model() # Note that we can't simply block the model's signals as this would # interfere with the model/view interactions. self._ignore_extlib_changes = True for extlib in external_libraries_metadata: if extlib.name in required_libraries: for idx, itm in enumerate(extlib._items): itm.setFlags( Qt.ItemIsEnabled|Qt.ItemIsEditable if idx != 0 else Qt.ItemIsEnabled) else: for itm in extlib._items: itm.setFlags(Qt.NoItemFlags) self._ignore_extlib_changes = False
def _get_items(self): """ Return an iterator over the tree widget items. """ it = QTreeWidgetItemIterator(self._package_edit) if self._show_root: it += 1 itm = it.value() while itm is not None: yield itm it += 1 itm = it.value()
def convert(self): if self.root is None: return # 遍历所有转换叶子节点 it = QTreeWidgetItemIterator(self.root) while it.value(): node = it.value() if node.childCount() == 0: if node.checkState(0) == Qt.Checked: # print("convert...", node.resData["Name"]) pass it += 1
def select_res_group(self, groups): if self.root is None: return # 遍历所有转换叶子节点 it = QTreeWidgetItemIterator(self.root) while it.value(): node = it.value() if node.childCount() == 0: if int(node.resData["BinStyles"]) in groups: node.setCheckState(0, Qt.Checked) else: node.setCheckState(0, Qt.Unchecked) it += 1
def updateOrderDetails(self): # If there is already a garment tree we want to clear out the old lists we do this to catch in an error # in case this function get's called before there is a tree build or grown, ha ha. if self.garmentTree: lstItems = [] # Open a iterator to iterate through the tree (again) and build a list of lists of items in the tree to be added to the table. itOrders = QTreeWidgetItemIterator(self.garmentTree) while itOrders.value(): if itOrders.value() != None: # Below makes sure that there are values for both the price and the quantity. if itOrders.value().text(3) != "" and itOrders.value().text(2) != "": # This makes sure that we are at the correct level in the tree so we do try to add what shouldn't be added if itOrders.value().parent().parent().parent() != None: txtItems = [] txtItems = [itOrders.value().parent().parent().parent().text(0), itOrders.value().parent().parent().text(0), itOrders.value().parent().text(0), itOrders.value().text(0), itOrders.value().text(1), str(format(float(itOrders.value().text(2)) * float(itOrders.value().text(3)), '.2f')), itOrders.value().text(3)] lstItems.append(txtItems) itOrders += 1 # A check to make sure the iterator picked up items from the list. if len(lstItems) > 0: # Build the table to hold the information from the tree. CSRWidgets.tblOrderDetails.setRowCount(len(lstItems)) CSRWidgets.tblOrderDetails.setColumnCount(7) CSRWidgets.tblOrderDetails.setAlternatingRowColors(True) lstHeader = ["Name", "Design", "Category", "Type", "Size", "Price", "Qty" ] CSRWidgets.tblOrderDetails.setHorizontalHeaderLabels(lstHeader) #CSRWidgets.tblOrderDetails.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) CSRWidgets.tblOrderDetails.setWordWrap(False) # Another check to make sure the list is there and has data, then we go through it and add data to the table. if lstItems: for i, row in enumerate(lstItems): for j, col in enumerate(row): item = QTableWidgetItem(col) item.setFlags(Qt.ItemIsEditable) CSRWidgets.tblOrderDetails.setItem(i, j, item) CSRWidgets.tblOrderDetails.resizeColumnsToContents() #self.vBox.addWidget(CSRWidgets.tblOrderDetails) CSRWidgets.tblOrderDetails.show() testBox = CSRWidgets.totalBox(self) self.winGrid.addWidget(testBox, 2, 1, 1, 1) #print("hit update orders") else: CSRWidgets.tblOrderDetails.hide()
def loadGarmentInfo(self,sku_code,garment_type,garment_name,design_name): #print(garment_type) #Query the database to get all garments available for this particular SKU. garm = mysql_db.garmentInfo(self, sku_code, garment_type) columnList = ["Design", "Size","Price", "Qty",""] #Set tree header/title stuff self.garmentTree.setHeaderLabels(columnList) self.garmentTree.setColumnCount(5) self.garmentTree.header().resizeSection(0, 280) self.garmentTree.header().resizeSection(1, 75) self.garmentTree.header().resizeSection(2, 45) self.garmentTree.header().resizeSection(3, 30) self.garmentTree.header().resizeSection(4, 10) #If there are no nodes in this tree yet, create the first one if self.garmentTree.topLevelItemCount() == 0: #print("NEW PARENT NODE") CSRWidgets.lblTotal = {} nm = QTreeWidgetItem(self.garmentTree) nm.setText(0, self.orderVars) nm.setBackground(0, QColor(180,180,180,127)) nm.setBackground(1, QColor(180,180,180,127)) nm.setBackground(2, QColor(180,180,180,127)) nm.setBackground(3, QColor(180,180,180,127)) nm.setBackground(4, QColor(180,180,180,127)) nm.setFont(0, QFont("Helvetica",16,QFont.Bold)) sku = QTreeWidgetItem(nm) sku.setText(0, sku_code) sku.setBackground(0, QColor(180,180,180,127)) sku.setBackground(1, QColor(180,180,180,127)) sku.setBackground(2, QColor(180,180,180,127)) sku.setBackground(3, QColor(180,180,180,127)) sku.setBackground(4, QColor(180,180,180,127)) sku.setFont(0, QFont("Helvetica",12,QFont.Bold)) #If the garment name does not exist we want to create a node for it. garmName = QTreeWidgetItem(sku) garmName.setText(0, garment_name) garmName.setText(3, "") garmName.setFont(0,QFont("Helvetica",10,QFont.Bold)) garmName.setFont(3,QFont("Helvetica",10,QFont.Bold)) garmName.setBackground(0, QColor(230,230,230,127)) garmName.setBackground(1, QColor(230,230,230,127)) garmName.setBackground(2, QColor(230,230,230,127)) garmName.setBackground(3, QColor(230,230,230,127)) garmName.setBackground(4, QColor(230,230,230,127)) removeName = QToolButton(self) removeName.setIcon(QIcon("Icon/close-widget.png")) removeName.setIconSize(QSize(14,14)) removeName.setAutoRaise(True) removeName.clicked.connect(lambda: CSRWidgets.remove_widget(self)) removeSku = QToolButton(self) removeSku.setIcon(QIcon("icon/close-widget.png")) removeSku.setIconSize(QSize(14, 14)) removeSku.setAutoRaise(True) removeSku.clicked.connect(lambda: CSRWidgets.remove_widget(self)) removeGarment = QToolButton(self) removeGarment.setIcon(QIcon("icon/close-widget.png")) removeGarment.setIconSize(QSize(14, 14)) removeGarment.setAutoRaise(True) removeGarment.clicked.connect(lambda: CSRWidgets.remove_widget(self)) CSRWidgets.lblTotal[str(sku_code + garment_name)] = QLabel() CSRWidgets.lblTotal[str(sku_code + garment_name)].setMaximumWidth(30) CSRWidgets.lblTotal[str(sku_code + garment_name)].setFont(QFont("Helvetica",10,QFont.Bold)) self.garmentTree.setItemWidget(nm, 4, removeName) self.garmentTree.setItemWidget(sku, 4, removeSku) self.garmentTree.setItemWidget(garmName, 4, removeGarment) self.garmentTree.setItemWidget(garmName, 3, CSRWidgets.lblTotal[str(sku_code + garment_name)]) CSRWidgets.le = {} #Create all the garment types for the first node for i in garm: kiddo = QTreeWidgetItem(garmName) kiddo.setText(0, i[1]) kiddo.setText(2, str(i[3])) kiddo.setText(1, i[2]) kiddo.setText(3,"") kiddo.setFont(3, QFont("Helvetica",10,QFont.Bold) ) kiddo.setText(4,"-") nm.setExpanded(True) sku.setExpanded(True) garmName.setExpanded(True) kiddo.setExpanded(True) #print(le.objectName()) #If items already exist in the tree, do stuff depending on what sku/garment was clicked. else: name_match = 0 sku_match = 0 itSku = QTreeWidgetItemIterator(self.garmentTree) #iterate through all tree items and see if anything matches the SKU we selected. while itSku.value(): if itSku.value().text(0) == self.orderVars: name_match = 1 #print("NAME MATCHED!!!") #If the SKU we selected exists somewhere in the tree, set variable to indicate that. if itSku.value().text(0) == sku_code and itSku.value().parent().text(0) == self.orderVars: sku_match = 1 #print("SKU MATCHED!!!") #Collapse all non-parent nodes so we can selectively open the nodes we are currently working on below. if itSku.value().parent() != None: itSku.value().setExpanded(False) itSku += 1 if name_match == 1: #print("NAME MATCHED!!!!!!!!") #if the SKU we've selected already exists in the tree, check to see if the garment we've selected exists also if sku_match == 1: #print("SKU MATCHED!!!") garm_match = 0 #print("already", sku_code) #Create an iterator to iterate through all the elements in the tree. itGarment = QTreeWidgetItemIterator(self.garmentTree) #Open up iterator while itGarment.value(): #If BOTH the SKU and garment already exist in the tree, just expand it while collapsing all other items. if itGarment.value().text(0) == garment_name and itGarment.value().parent().text(0) == sku_code and itGarment.value().parent().parent().text(0) == self.orderVars: #itGarment.value().parent().setExpanded(True) #itGarment.value().setExpanded(True) garm_match = 1 itGarment.value().parent().parent().setExpanded(True) itGarment.value().parent().setExpanded(True) itGarment.value().setExpanded(True) itGarment += 1 #If the selected garment does NOT exist in the tree for this SKU, create it. if garm_match == 0: #create tree iterator itSizes = QTreeWidgetItemIterator(self.garmentTree) while itSizes.value(): #When the iterator hits the correct SKU, create the new garment node that doesn't exist yet. if itSizes.value().text(0) == sku_code and itSizes.value().parent().text(0) == self.orderVars: #If the garment name does not exist we want to create a node for it. garmName = QTreeWidgetItem(itSizes.value()) garmName.setText(0, garment_name) garmName.setText(3, "") garmName.setFont(0,QFont("Helvetica",10,QFont.Bold)) garmName.setFont(3,QFont("Helvetica",10,QFont.Bold)) garmName.setBackground(0, QColor(230,230,230,127)) garmName.setBackground(1, QColor(230,230,230,127)) garmName.setBackground(2, QColor(230,230,230,127)) garmName.setBackground(3, QColor(230,230,230,127)) garmName.setBackground(4, QColor(230,230,230,127)) removeGarment = QToolButton(self) removeGarment.setIcon(QIcon("icon/close-widget.png")) removeGarment.setIconSize(QSize(14, 14)) removeGarment.setAutoRaise(True) removeGarment.clicked.connect(lambda: CSRWidgets.remove_widget(self)) CSRWidgets.lblTotal[str(sku_code + garment_name)] = QLabel(self.garmentTree) CSRWidgets.lblTotal[str(sku_code + garment_name)].setMaximumWidth(30) CSRWidgets.lblTotal[str(sku_code + garment_name)].setFont(QFont("Helvetica",10,QFont.Bold)) self.garmentTree.setItemWidget(garmName, 4, removeGarment) self.garmentTree.setItemWidget(garmName, 3, CSRWidgets.lblTotal[str(sku_code + garment_name)]) #Create all the garment types for the node #CSRWidgets.le = {} for i in garm: kiddo = QTreeWidgetItem(garmName) kiddo.setText(0, i[1]) kiddo.setText(2, str(i[3])) kiddo.setText(1, i[2]) kiddo.setText(3,"") kiddo.setFont(3, QFont("Helvetica",10,QFont.Bold) ) kiddo.setText(4,"-") itSizes.value().setExpanded(True) garmName.setExpanded(True) kiddo.setExpanded(True) itSizes += 1 #If the SKU does NOT exist in the tree yet, but others already do, create this particular SKU. else: #print("SAME NAME, DIFFERENT SKU!!!!! SKU = " + sku_code + " -- Name = " + self.orderVars) iterNewSku = QTreeWidgetItemIterator(self.garmentTree) while iterNewSku.value(): if iterNewSku.value().childCount() > 0: if iterNewSku.value().text(0) == self.orderVars: sku = QTreeWidgetItem(iterNewSku.value()) sku.setText(0, sku_code) sku.setBackground(0, QColor(180,180,180,127)) sku.setBackground(1, QColor(180,180,180,127)) sku.setBackground(2, QColor(180,180,180,127)) sku.setBackground(3, QColor(180,180,180,127)) sku.setBackground(4, QColor(180,180,180,127)) sku.setFont(0, QFont("Helvetica",12,QFont.Bold) ) removeSku = QToolButton(self) removeSku.setIcon(QIcon("icon/close-widget.png")) removeSku.setIconSize(QSize(14, 14)) removeSku.setAutoRaise(True) removeSku.clicked.connect(lambda: CSRWidgets.remove_widget(self)) garmName = QTreeWidgetItem(sku) garmName.setText(0, garment_name) garmName.setText(3, "") garmName.setFont(0,QFont("Helvetica",10,QFont.Bold)) garmName.setFont(3,QFont("Helvetica",10,QFont.Bold)) garmName.setBackground(0, QColor(230,230,230,127)) garmName.setBackground(1, QColor(230,230,230,127)) garmName.setBackground(2, QColor(230,230,230,127)) garmName.setBackground(3, QColor(230,230,230,127)) garmName.setBackground(4, QColor(230,230,230,127)) removeGarment = QToolButton(self) removeGarment.setIcon(QIcon("icon/close-widget.png")) removeGarment.setIconSize(QSize(14, 14)) removeGarment.setAutoRaise(True) removeGarment.clicked.connect(lambda: CSRWidgets.remove_widget(self)) CSRWidgets.lblTotal[str(sku_code + garment_name)] = QLabel(self.garmentTree) CSRWidgets.lblTotal[str(sku_code + garment_name)].setMaximumWidth(30) CSRWidgets.lblTotal[str(sku_code + garment_name)].setFont(QFont("Helvetica",10,QFont.Bold)) self.garmentTree.setItemWidget(sku, 4, removeSku) self.garmentTree.setItemWidget(garmName, 4, removeGarment) self.garmentTree.setItemWidget(garmName, 3, CSRWidgets.lblTotal[str(sku_code + garment_name)]) #CSRWidgets.le = {} #Create all the garment types for the first node for i in garm: kiddo = QTreeWidgetItem(garmName) kiddo.setText(0, i[1]) kiddo.setText(2, str(i[3])) kiddo.setText(1, i[2]) kiddo.setText(3,"") kiddo.setFont(3, QFont("Helvetica",10,QFont.Bold)) kiddo.setText(4,"-") #nm.setExpanded(True) sku.setExpanded(True) garmName.setExpanded(True) kiddo.setExpanded(True) iterNewSku += 1 else: #print("NEW NAME") CSRWidgets.lblTotal = {} nm = QTreeWidgetItem(self.garmentTree) nm.setText(0, self.orderVars) nm.setBackground(0, QColor(180,180,180,127)) nm.setBackground(1, QColor(180,180,180,127)) nm.setBackground(2, QColor(180,180,180,127)) nm.setBackground(3, QColor(180,180,180,127)) nm.setBackground(4, QColor(180,180,180,127)) nm.setFont(0, QFont("Helvetica",16,QFont.Bold)) sku = QTreeWidgetItem(nm) sku.setText(0, sku_code) sku.setBackground(0, QColor(180,180,180,127)) sku.setBackground(1, QColor(180,180,180,127)) sku.setBackground(2, QColor(180,180,180,127)) sku.setBackground(3, QColor(180,180,180,127)) sku.setBackground(4, QColor(180,180,180,127)) sku.setFont(0, QFont("Helvetica",12,QFont.Bold)) #If the garment name does not exist we want to create a node for it. garmName = QTreeWidgetItem(sku) garmName.setText(0, garment_name) garmName.setText(3, "") garmName.setFont(0,QFont("Helvetica",10,QFont.Bold)) garmName.setFont(3,QFont("Helvetica",10,QFont.Bold)) garmName.setBackground(0, QColor(230,230,230,127)) garmName.setBackground(1, QColor(230,230,230,127)) garmName.setBackground(2, QColor(230,230,230,127)) garmName.setBackground(3, QColor(230,230,230,127)) garmName.setBackground(4, QColor(230,230,230,127)) removeName = QToolButton(self) removeName.setIcon(QIcon("Icon/close-widget.png")) removeName.setIconSize(QSize(14,14)) removeName.setAutoRaise(True) removeName.clicked.connect(lambda: CSRWidgets.remove_widget(self)) removeSku = QToolButton(self) removeSku.setIcon(QIcon("icon/close-widget.png")) removeSku.setIconSize(QSize(14, 14)) removeSku.setAutoRaise(True) removeSku.clicked.connect(lambda: CSRWidgets.remove_widget(self)) removeGarment = QToolButton(self) removeGarment.setIcon(QIcon("icon/close-widget.png")) removeGarment.setIconSize(QSize(14, 14)) removeGarment.setAutoRaise(True) removeGarment.clicked.connect(lambda: CSRWidgets.remove_widget(self)) CSRWidgets.lblTotal[str(sku_code + garment_name)] = QLabel() CSRWidgets.lblTotal[str(sku_code + garment_name)].setMaximumWidth(30) CSRWidgets.lblTotal[str(sku_code + garment_name)].setFont(QFont("Helvetica",10,QFont.Bold)) self.garmentTree.setItemWidget(nm, 4, removeName) self.garmentTree.setItemWidget(sku, 4, removeSku) self.garmentTree.setItemWidget(garmName, 4, removeGarment) self.garmentTree.setItemWidget(garmName, 3, CSRWidgets.lblTotal[str(sku_code + garment_name)]) CSRWidgets.le = {} #Create all the garment types for the first node for i in garm: kiddo = QTreeWidgetItem(garmName) kiddo.setText(0, i[1]) kiddo.setText(2, str(i[3])) kiddo.setText(1, i[2]) kiddo.setText(3,"") kiddo.setFont(3, QFont("Helvetica",10,QFont.Bold) ) kiddo.setText(4,"-") nm.setExpanded(True) sku.setExpanded(True) garmName.setExpanded(True) kiddo.setExpanded(True) #print(le.objectName()) self.treeDock.show() self.viewMenu.addAction(self.treeDock.toggleViewAction()) self.treeDock.setWidget(self.garmentTree) self.addDockWidget(Qt.RightDockWidgetArea, self.treeDock)
def items(self): iterator = QTreeWidgetItemIterator(self.ui.plugins, QTreeWidgetItemIterator.All) while iterator.value(): item = iterator.value() iterator += 1 yield item