def log_error(self, msg, log_text_color=QColor(Qt.red)): """Showing error message bar.""" if self.list_view is not None: item = QStandardItem(msg) item.setForeground(QBrush(log_text_color)) self.model.appendRow([item]) else: print(msg)
def populate_trv(self, trv_widget, result, expand=False): model = QStandardItemModel() trv_widget.setModel(model) trv_widget.setUniformRowHeights(False) main_parent = QStandardItem('{}'.format('Giswater')) font = main_parent.font() font.setPointSize(8) main_parent.setFont(font) self.icon_folder = self.plugin_dir + os.sep + 'icons' path_icon_blue = self.icon_folder + os.sep + '36.png' path_icon_red = self.icon_folder + os.sep + '100.png' if os.path.exists(path_icon_blue): icon = QIcon(path_icon_blue) main_parent.setIcon(icon) for group, functions in result['fields'].items(): parent1 = QStandardItem( f'{group} [{len(functions)} Giswater algorithm]') self.no_clickable_items.append( f'{group} [{len(functions)} Giswater algorithm]') functions.sort(key=self.sort_list, reverse=False) for function in functions: func_name = QStandardItem(str(function['functionname'])) label = QStandardItem(str(function['alias'])) font = label.font() font.setPointSize(8) label.setFont(font) row = self.controller.check_function(function['functionname']) if not row: if os.path.exists(path_icon_red): icon = QIcon(path_icon_red) label.setIcon(icon) label.setForeground(QColor(255, 0, 0)) msg = f"Function {function['functionname']}" \ f" configured on the table config_toolbox, but not found in the database" label.setToolTip(msg) self.no_clickable_items.append(str(function['alias'])) else: if os.path.exists(path_icon_blue): icon = QIcon(path_icon_blue) label.setIcon(icon) label.setToolTip(function['functionname']) enable_run = QStandardItem("True") if function['input_params'] is not None: if 'btnRunEnabled' in function['input_params']: bool_dict = {True: "True", False: "False"} enable_run = QStandardItem(bool_dict[ function['input_params']['btnRunEnabled']]) parent1.appendRow([label, func_name, enable_run]) main_parent.appendRow(parent1) model.appendRow(main_parent) index = model.indexFromItem(main_parent) trv_widget.expand(index) if expand: trv_widget.expandAll()
def bar_error(self, msg, dur=5, log_text_color=QColor(Qt.black)): """Showing error message bar.""" if self.iface is not None: self.message_bar.pushMessage(self.context, msg, level=Qgis.Critical, duration=dur) if self.list_view: item = QStandardItem(msg) item.setForeground(QBrush(log_text_color)) self.model.appendRow([item]) else: print(msg)
def log_result_row(self, row, log_level): """Show row data with proper log level styling.""" text_color = self.levels_colors[log_level] if self.tree_view is not None: items = [] for value in row: item = QStandardItem(str(value)) item.setForeground(QBrush(text_color)) items.append(item) self.model.appendRow(items) for i in range(len(self.header)): self.tree_view.resizeColumnToContents(i) else: print(row)
def _populate_trv(self, trv_widget, result, expand=False): model = QStandardItemModel() trv_widget.setModel(model) trv_widget.setUniformRowHeights(False) icon_folder = self.plugin_dir + os.sep + 'icons' + os.sep + 'dialogs' + os.sep + '20x20' + os.sep path_icon_blue = icon_folder + os.sep + '36.png' path_icon_red = icon_folder + os.sep + '100.png' # Section Processes section_processes = QStandardItem('{}'.format('Processes')) for group, functions in result['processes']['fields'].items(): parent1 = QStandardItem(f'{group} [{len(functions)} Giswater algorithm]') self.no_clickable_items.append(f'{group} [{len(functions)} Giswater algorithm]') functions.sort(key=self._sort_list, reverse=False) for function in functions: func_name = QStandardItem(str(function['functionname'])) label = QStandardItem(str(function['alias'])) font = label.font() font.setPointSize(8) label.setFont(font) row = tools_db.check_function(function['functionname']) if not row: if os.path.exists(path_icon_red): icon = QIcon(path_icon_red) label.setIcon(icon) label.setForeground(QColor(255, 0, 0)) msg = f"Function {function['functionname']}" \ f" configured on the table config_toolbox, but not found in the database" label.setToolTip(msg) self.no_clickable_items.append(str(function['alias'])) else: if os.path.exists(path_icon_blue): icon = QIcon(path_icon_blue) label.setIcon(icon) label.setToolTip(function['functionname']) parent1.appendRow([label, func_name]) section_processes.appendRow(parent1) # Section Reports reports_processes = QStandardItem('{}'.format('Reports')) for group, functions in result['reports']['fields'].items(): parent1 = QStandardItem(f'{group} [{len(functions)} Reports functions]') self.no_clickable_items.append(f'{group} [{len(functions)} Reports functions]') functions.sort(key=self._sort_list, reverse=False) for function in functions: func_name = QStandardItem(str(function['listname'])) label = QStandardItem(str(function['alias'])) font = label.font() font.setPointSize(8) label.setFont(font) parent1.appendRow([label, func_name]) if os.path.exists(path_icon_blue): icon = QIcon(path_icon_blue) label.setIcon(icon) reports_processes.appendRow(parent1) if os.path.exists(path_icon_blue): icon = QIcon(path_icon_blue) section_processes.setIcon(icon) reports_processes.setIcon(icon) model.appendRow(section_processes) model.appendRow(reports_processes) section_index = model.indexFromItem(section_processes) reports_index = model.indexFromItem(reports_processes) trv_widget.expand(section_index) trv_widget.expand(reports_index) if expand: trv_widget.expandAll()