def model_loaded(self, model: KnechtModel, file: Path): LOGGER.debug('Restoring: %s', file.name) # Update progress view = self.ui.view_mgr.current_view() view.progress_msg.hide_progress() clean_state = True # Restore original save path if file.name in self.restore_files_storage.store: if isinstance(self.restore_files_storage.store[file.name], dict): file = Path(self.restore_files_storage.store[file.name].get('file') or '') clean_state = self.restore_files_storage.store[file.name].get('clean_state') else: file = Path(self.restore_files_storage.store[file.name]) if file.name == 'Variants_Tree.xml': # Update Variants Tree update_model = UpdateModel(self.ui.variantTree) update_model.update(model) new_view = self.ui.variantTree else: # Create a new view inside a new tab or load into current view if view model is empty new_view = self.ui.view_mgr.create_view(model, file) # Refresh model data new_view.model().sourceModel().initial_item_id_connection() new_view.model().sourceModel().refreshData() # Mark document non-clean if isinstance(clean_state, bool): if not clean_state: new_view.undo_stack.resetClean() self._load_next()
def _build_material_tree(self, use_config: bool = False): material_root_item = KnechtItem(data=('', 'Material Name', 'PR-Tags', 'Desc')) for idx, (name, target) in enumerate(self.plmxml.look_lib.materials.items()): child_idx = material_root_item.childCount() material_root_item.insertChildren(child_idx, 1, (f'{idx:03d}', name, '', '')) target_item = material_root_item.child(child_idx) KnechtItemStyle.style_column(target_item, 'fakom_option') # -- Create Material Variants for c_idx, v in enumerate(target.variants): # -- Skip invisible variants in Config Display if use_config: if v != target.visible_variant: continue target_child_idx = target_item.childCount() target_item.insertChildren( target_child_idx, 1, (f'{c_idx:03d}', v.name, v.pr_tags, v.desc)) if use_config: variant_item = target_item.child(target_child_idx) variant_item.style_bg_green() update_material_tree = UpdateModel(self.material_tree) update_material_tree.update(KnechtModel(material_root_item))
def _build_scene_tree(self, use_config: bool): scene_root_item = KnechtItem(data=('', 'Name', 'PR-Tags', 'Trigger Rules')) for idx, node in enumerate(self.plmxml.iterate_root_nodes()): self._iterate_scene_children(idx, node, scene_root_item, use_config) update_scene_tree = UpdateModel(self.scene_tree) update_scene_tree.update(KnechtModel(scene_root_item))
def read_finished(self, data: KnData): if self._abort: return self.data = data models = self.models_root_item.copy() pr_fam = self.pr_root_item.copy() # Populate models tree for idx, t in enumerate(self.data.models): models.insertChildren( models.childCount(), 1, (f'{idx:01d}', t.model, t.market, t.model_text, '', '', t.gearbox), fixed_userType=Kg.dialog_item ) # Populate PR Family tree for idx, p in enumerate(self.data.pr_families): pr_fam.insertChildren( pr_fam.childCount(), 1, (f'{idx:01d}', p.name, p.desc), fixed_userType=Kg.dialog_item ) # Update View Models update_models = UpdateModel(self.treeView_Models) update_models.finished.connect(self._data_ready) update_models.update(KnechtModel(models, checkable_columns=[self.ModelColumn.code])) update_pr = UpdateModel(self.treeView_PrFam) update_pr.finished.connect(self._data_ready) update_pr.update(KnechtModel(pr_fam, checkable_columns=[self.PrColumn.code]))
def _init_tree_view(self, tree_view: QTreeView) -> KnechtTreeView: """ Replace the UI Designer placeholder tree views """ parent = tree_view.parent() new_view = KnechtTreeView(parent, None) replace_widget(tree_view, new_view) # DeltaGenResult wizard specific new_view.setEditTriggers(QTreeView.NoEditTriggers) new_view.setDragDropMode(QTreeView.NoDragDrop) new_view.supports_drag_move = False new_view.supports_drop = False # Setup filter widget new_view.filter_text_widget = self.filter_edit # Setup keyboard shortcuts new_view.shortcuts = KnechtTreeViewShortcuts(new_view) # Override Edit Shotcuts new_view.shortcut_overrides = PresetTreeViewShortcutOverrides(new_view) # Update with placeholder Model to avoid access to unset attributes UpdateModel(new_view).update(KnechtModel()) for column in (Kg.VALUE, Kg.TYPE, Kg.REF, Kg.ID): new_view.hideColumn(column) return new_view
def replace_view(self, old_view): """ Replace an existing placeholder view """ replace_widget(old_view, self) # Update with placeholder Model to avoid access to unset attributes UpdateModel(self).update(KnechtModel()) # most Dialogs do not require a column description self.setHeaderHidden(True)
def _update_existing_page(self, new_model, file: Path): current_view = self.current_view() if not current_view.undo_stack.isClean(): return False if not current_view.model().sourceModel().rowCount(): if new_model: update_model = UpdateModel(current_view) update_model.update(new_model) self.update_tab_title(self.tab.currentIndex(), file) current_view.setObjectName(file.name) current_view.undo_stack.clear() setup_header_layout(current_view) return True return False
def update_project_view(self, projects: dict): """ (Name, ModelYear, 'JobNo) """ if not projects: return root_item = KnechtItem( None, ('', _('Bezeichnung'), _('Modelljahr'), _('Job'), '', _('Id'))) for num_idx, (_id, project_data) in enumerate(projects.items()): data = (f'{num_idx:03d}', *project_data, '', str(_id)) p_item = KnechtItem(root_item, data) KnechtItemStyle.style_column(p_item, 'render_preset', column=Kg.NAME) root_item.append_item_child(p_item) update_model = UpdateModel(self.project_view) update_model.update(KnechtModel(root_item)) self.toggle_view_columns(self.details_btn.isChecked()) self.project_view.setHeaderHidden(False)
def setup_tree_view(self, tree_view: KnechtTreeView, model: Union[KnechtModel, None] = None, file: Path = Path('New_Document.xml'), filter_widget: QLineEdit = None): # Setup TreeView model if not model: # Use empty model if none provided model = KnechtModel() # Setup model update_model = UpdateModel(tree_view) update_model.update(model) tree_view.progress.hide() # Setup keyboard shortcuts shortcuts = KnechtTreeViewShortcuts(tree_view) tree_view.shortcuts = shortcuts # Setup filter text widget if filter_widget: tree_view.filter_text_widget = filter_widget # Set Tree object name tree_view.setObjectName(file.name) # Set focus to the just created view # otherwise menus may try to access already deleted views tree_view.setFocus(Qt.OtherFocusReason) # Connect view clean status change tree_view.clean_changed.connect(self.view_clean_changed) LOGGER.debug('View manager basic tree setup for %s %s', tree_view.objectName(), file.name) self.view_updated.emit(tree_view) self.additional_tree_setup(tree_view)
def update_image_view(self, images: dict): if not images: return root_item = KnechtItem(None, ('', _('Name'), _('Priorität'), _('Erstellt'), '', _('wagenbauteil Id'))) for num_idx, (img_id, image_data) in enumerate(images.items()): """ (name, priority, created, pr_string, opt_id, produced_image_id) """ name, priority, created, pr_string, opt_id, produced_image_id = image_data img_item = KnechtItem( root_item, (f'{num_idx:03d}', name, priority, created, '', str(opt_id))) KnechtItemStyle.style_column(img_item, 'preset', Kg.NAME) root_item.append_item_child(img_item) update_model = UpdateModel(self.image_view) update_model.update( KnechtModel(root_item, checkable_columns=[self.check_column])) self.toggle_view_columns(self.details_btn.isChecked()) self.image_view.setHeaderHidden(False) self.image_view.check_items([], Kg.NAME, check_all=True)
def initializePage(self): data = self.wizard.session.data.import_data item_creator = KnechtDataToModel(data) # -- Populate Preset Tree -- for trim in data.models: if trim.model not in data.selected_models: continue item_data = (f'{item_creator.root_item.childCount():03d}', trim.model_text, trim.model, 'trim_setup') trim_item = KnechtItem(item_creator.root_item, item_data) trim_item.fixed_userType = Kg.group_item item_creator.create_fakom(trim, is_preset_wizard=True, parent_item=trim_item) item_creator.root_item.append_item_child(trim_item) fakom_model = KnechtModel(item_creator.root_item) for column in (Kg.VALUE, Kg.DESC, Kg.TYPE, Kg.REF, Kg.ID): self.fakom_tree.hideColumn(column) UpdateModel(self.fakom_tree).update(fakom_model) QTimer.singleShot(50, self.load_fakom_selection) LOGGER.info('FaKom Wizard Page initialized.')
def _init_tree_view(self, tree_view: QTreeView, item_model: KnechtModel) -> KnechtTreeView: """ Replace the UI Designer placeholder tree views """ parent = tree_view.parent() new_view = KnechtTreeView(parent, self.wizard.ui.app.undo_grp) replace_widget(tree_view, new_view) # Preset wizard specific new_view.setEditTriggers(QTreeView.NoEditTriggers) new_view.supports_drag_move = False new_view.supports_drop = False # Setup filter widget new_view.filter_text_widget = self.line_edit_preset # Setup keyboard shortcuts new_view.shortcuts = KnechtTreeViewShortcuts(new_view) # Update with placeholder Model to avoid access to unset attributes UpdateModel(new_view).update(item_model or KnechtModel()) for column in self.hidden_columns_a: new_view.hideColumn(column) return new_view
def _init_tree_view(self, tree_view: QTreeView) -> KnechtTreeView: """ Replace the UI Designer placeholder tree views """ parent = tree_view.parent() new_view = KnechtTreeView(parent, None) replace_widget(tree_view, new_view) # Fakom wizard specific new_view.setSelectionMode(QTreeView.NoSelection) new_view.setSelectionBehavior(QTreeView.SelectRows) new_view.setEditTriggers(QTreeView.NoEditTriggers) new_view.setDragDropMode(QTreeView.NoDragDrop) new_view.supports_drag_move = False new_view.setIndentation(15) # Setup filter widget new_view.filter_text_widget = self.filter_edit # Setup keyboard shortcuts new_view.shortcuts = KnechtTreeViewShortcuts(new_view) # Update with placeholder Model to avoid access to unset attributes UpdateModel(new_view).update(KnechtModel()) new_view.clicked.connect(self._fakom_item_pressed) return new_view
def _reset_view(self): UpdateModel(self.search_view).update(KnechtModel())
def load_model(self, item_model: KnechtModel): UpdateModel(self.preset_tree).update(item_model)
def collect_result(self): kn_data = self.session.data.import_data converter = KnechtDataToModel(kn_data) trim_items = dict() # --- Create Trim Setups --- for model_code in self.session.data.fakom_selection.keys(): trim = self._get_trim_from_models(kn_data.models, model_code) trim_items[model_code] = dict() trim_item = converter.create_trim(trim) trim_item.refresh_id_data() trim_items[model_code]['trim_setup'] = trim_item trim_items[model_code][ 'trim_option'] = converter.create_trim_options( trim, kn_data.options_text_filter) trim_items[model_code]['packages'] = list() trim_items[model_code]['fakom'] = dict() # -- Create FaKom Items -- for preset_page in self.session.iterate_preset_pages(): fakom_ls = preset_page.fakom.split('-') if len(fakom_ls) < 4: continue trim = self._get_trim_from_models(kn_data.models, preset_page.model) # Create lists of List[KnPr] for SIB/VOS/LUM families sib_pr_ls = [ pr for pr in trim.iterate_available_pr() if pr.family.casefold() == 'sib' ] lum_pr_ls = [ pr for pr in trim.iterate_available_pr() if pr.family.casefold() == 'lum' ] vos_pr_ls = [ pr for pr in trim.iterate_available_pr() if pr.family.casefold() == 'vos' ] fa, sib, vos, lum = fakom_ls LOGGER.debug('Creating Fakom Item %s %s %s %s', fa, sib, vos, lum) sib_pr = self._get_pr_from_list(sib_pr_ls, sib) vos_pr = self._get_pr_from_list(vos_pr_ls, vos) lum_pr = self._get_pr_from_list(lum_pr_ls, lum) fakom_type = 'fakom_option' if not {sib_pr.value, vos_pr.value, lum_pr.value}.difference('L'): fakom_type = 'fakom_setup' fa_item = converter.create_fakom_item(None, trim.model, trim.model_text, fa, sib, vos, lum, sib_pr.desc, vos_pr.desc, lum_pr.desc, fakom_type, False) fa_item.refresh_id_data() trim_items[preset_page.model]['fakom'][preset_page.fakom] = fa_item # --- Prepare presets --- preset_items = list() for preset_page in self.session.iterate_preset_pages(): # -- Create Preset item -- preset_item = KnechtItem( None, ('000', preset_page.subTitle(), '', Kg.type_keys[Kg.preset], '', Kid.create_id())) # -- Add reference to trim setup -- trim_ref = trim_items[preset_page.model]['trim_setup'].copy( copy_children=False) trim_ref.convert_to_reference() trim_ref.setData(0, '000') preset_item.append_item_child(trim_ref) # -- Add reference to fakom item -- fa_ref = trim_items[preset_page.model]['fakom'][ preset_page.fakom].copy(copy_children=False) fa_ref.convert_to_reference() fa_ref.setData(0, '001') preset_item.append_item_child(fa_ref) # -- Collect preset content -- for _, pr_item in preset_page.preset_tree.editor.iterator.iterate_view( ): if pr_item.userType == Kg.variant: # --- Add PR-option --- pr_item_copy = pr_item.copy() pr_item_copy.setData(0, f'{preset_item.childCount():03d}') preset_item.append_item_child(pr_item_copy) else: # --- Add package reference --- pkg_ref = pr_item.copy(copy_children=False) pkg_ref.convert_to_reference() pkg_ref.setData(0, f'{preset_item.childCount():03d}') preset_item.append_item_child(pkg_ref) # --- Add package --- trim_items[preset_page.model]['packages'].append( pr_item.copy()) preset_items.append(preset_item) # --- Create trim, package and fakom items --- root_item = KnechtItem() for model_code in self.session.data.fakom_selection.keys(): # -- Add trim setup -- trim_item = trim_items[model_code]['trim_setup'] trim_item.setData(Kg.ORDER, f'{root_item.childCount():03d}') root_item.append_item_child(trim_item) # -- Add trim options -- trim_options = trim_items[model_code]['trim_option'] trim_options.setData(Kg.ORDER, f'{root_item.childCount():03d}') root_item.append_item_child(trim_options) # -- Add Packages -- for pkg_item in trim_items[model_code]['packages']: pkg_item.setData(Kg.ORDER, f'{root_item.childCount():03d}') root_item.append_item_child(pkg_item) # -- Add FaKom Items -- for fa_item in trim_items[model_code]['fakom'].values(): fa_item.setData(Kg.ORDER, f'{root_item.childCount():03d}') root_item.append_item_child(fa_item) # -- Add separator -- root_item.append_item_child( KnechtItem( None, (f'{root_item.childCount():03d}', '', '', 'separator'))) # -- Create default Reset -- reset_item = create_reset_item(root_item.childCount()) root_item.append_item_child(reset_item) # -- Add separator -- root_item.append_item_child( KnechtItem(None, (f'{root_item.childCount():03d}', '', '', 'separator'))) # --- Create Preset items --- for preset_item in preset_items: preset_item.setData(Kg.ORDER, f'{root_item.childCount():03d}') root_item.append_item_child(preset_item) UpdateModel(self.result_tree).update(KnechtModel(root_item))
def new_empty_model(view): empty_model = KnechtModel() update_model = UpdateModel(view) update_model.update(empty_model)