def analyzeFileList(files: list, item: QtWidgets.QTreeWidgetItem): if (item.childCount() > 0): for i in range(item.childCount()): files = analyzeFileList(files, item.child(i)) else: files.append(item) return files
def on_objects_listbox(self, current_index): selected = self._objects[current_index][1] self._props.clear() common_item = QTreeWidgetItem([_("Common properties")]) specific_item = QTreeWidgetItem([_("Specific properties")]) other_item = QTreeWidgetItem([ _("Other properties - they can not be searched and are not processed in any way" ) ]) common_fields = list( EntityMetadata.for_discriminator("OSMEntity").fields.keys()) selected_metadata = EntityMetadata.for_discriminator( selected.discriminator) known_fields = selected_metadata.all_fields formatted_values = {} for field_name in selected.defined_field_names(): raw_value = selected.value_of_field(field_name) if field_name not in known_fields: # By the mere fact that the other fields have no defined order, we can add them there without losing anything. other_item.addChild( QTreeWidgetItem([ "%s: %s" % (underscored_to_words(field_name), raw_value) ])) else: value_str = "%s: %s" % ( underscored_to_words(field_name), format_field_value(raw_value, known_fields[field_name].type_name)) formatted_values[field_name] = value_str for common in common_fields: del known_fields[common] common_item.addChild(QTreeWidgetItem([formatted_values[common]])) for specific in known_fields.keys( ): # Because we deleted the common ones in the loop before this, only the specific remain. if specific in formatted_values: specific_item.addChild( QTreeWidgetItem([formatted_values[specific]])) # We add the entity ID mainly for debugging purposes, and that's the reason why it is added the last and so special in the first place. common_item.addChild( QTreeWidgetItem([_("Object id: {}").format(selected.id)])) self._props.addTopLevelItem(common_item) if specific_item.childCount() > 0: self._props.addTopLevelItem(specific_item) self._props.expandItem(specific_item) #self._props.setCurrentItem(specific_item) # Breaks focus behavior slightly, but annoingly enough. if other_item.childCount() > 0: self._props.addTopLevelItem(other_item) self._object_actions.clear() for action in self._all_actions: if action.executable(selected): mi = self._object_actions.addAction(action.label) mi.triggered.connect( action_execution_handler_factory(action, selected, self))
def selectNoneSubChild(self, child: QtWidgets.QTreeWidgetItem) -> None: for i in range(child.childCount()): item = child.child(i) if (item.text(1) == ""): self.treeWidget.itemWidget( item, 2).setCheckedWithoutInternalChecking(False) self.selectNoneSubChild(item) else: self.treeWidget.itemWidget( item, 2).setCheckedWithoutInternalChecking(False)
def invertSelectionSubChild(self, child: QtWidgets.QTreeWidgetItem) -> None: for i in range(child.childCount()): item = child.child(i) if (item.text(1) == ""): self.treeWidget.itemWidget( item, 2).setCheckedWithoutInternalChecking(not ( self.treeWidget.itemWidget(item, 2).isChecked())) self.invertSelectionSubChild(item) else: self.treeWidget.itemWidget(item, 2).setChecked(not ( self.treeWidget.itemWidget(item, 2).isChecked()))
def _create_pos_action_list_items(self, xml_dict: dict, target: int): for al_name, al_dict in xml_dict.items(): al = QTreeWidgetItem([al_name]) al.setFlags(self.item_flags) for actor_name, actor_dict in al_dict.items(): actor = QTreeWidgetItem(al, [ actor_name, actor_dict.get('value'), actor_dict.get('type') ]) actor.setFlags(self.item_flags) if al.childCount(): self.add_item_queued(al, self.widgets[target])
def changeState(checkbox: CheckBoxAction, item: QtWidgets.QTreeWidgetItem): if (checkbox.avoidInternalChecking): checkbox.avoidInternalChecking = False item.setDisabled(not (checkbox.isChecked())) else: item.setDisabled(not (checkbox.isChecked())) for i in range(item.childCount()): subitem = item.child(i) subcheckbox = subitem.treeWidget().itemWidget( subitem, 2) if (subcheckbox): subitem.setDisabled(not (subcheckbox.isChecked())) subcheckbox.setChecked(checkbox.isChecked()) else: log("[ WARN ] Unable to disable/enable other checkboxes" )
def add_pak_content_to_item(self, item: QtWidgets.QTreeWidgetItem, column: int) -> None: """Adds content of pak file to treeview.""" fpath = self.get_path_for_item(item) # Add .pak file content as childs if fpath.endswith(".pak") and item.childCount() == 0: reader = PakReader(fpath) children = [] for fname in reader.filenames: child_item = QtWidgets.QTreeWidgetItem([fname]) fileinfo = QtCore.QFileInfo(os.path.join(fpath, fname)) child_item.setIcon(0, ICON_PROVIDER.icon(fileinfo)) children.append(child_item) item.addChildren(children)