def create_table_item(column, itemname, invalid_value_count, log_size, callable, *args): item = QStandardItem() item.setEditable(False) #format if there is invalid data entries if invalid_value_count == -1: item.setData(DEEP_RED, Qt.BackgroundRole) item.setToolTip( "All of the values in the log are marked invalid, none of them are filtered." ) elif invalid_value_count > 0: saturation = 10 + (170 * (invalid_value_count / (log_size + invalid_value_count))) item.setData(QColor.fromHsv(0, saturation, 255), Qt.BackgroundRole) aux_verb = "is" if invalid_value_count == 1 else "are" item.setToolTip( f"{invalid_value_count}/{log_size+invalid_value_count} of the values in the log" f" {aux_verb} marked invalid, and {aux_verb} filtered.") try: item.setText(callable(*args)) except Exception as exc: logger.warning("Error setting column {} for log {}: {}".format( column, itemname, str(exc))) return item
def on_debug_message(self, message): msg = 'DEBUG - occurred at: [ {} ]\n{}'.format( NotificationsWidget._get_time(), NotificationsWidget._strip_new_line(message)) notification_item = QStandardItem() notification_item.setText(msg) notification_item.setIcon(QIcon.fromTheme('dialog-question')) notification_item.setEditable(False) self.all_notification_model.appendRow(notification_item)
def create_table_item(column, itemname, callable, *args): item = QStandardItem() item.setEditable(False) try: item.setText(callable(*args)) except Exception as exc: logger.warning("Error setting column {} for log {}: {}".format( column, itemname, str(exc))) return item
def on_error_message(self, message): msg = 'ERROR - occurred at: [ {} ]\n{}'.format( NotificationsWidget._get_time(), NotificationsWidget._strip_new_line(message)) LOG.debug('-----on_error_message called: {}'.format(message)) notification_item = QStandardItem() notification_item.setText(msg) notification_item.setIcon(QIcon.fromTheme('dialog-error')) notification_item.setEditable(False) self.all_notification_model.appendRow(notification_item)
def set_plot_list(self, plot_list): """ Populate the plot list from the Presenter :param plot_list: the list of plot names (list of strings) """ self.list_view.model().clear() for plot_name in plot_list: item = QStandardItem(plot_name) item.setEditable(False) self.list_view.model().appendRow(item)
def on_debug_message(self, message): timestamp = time() dt_object = datetime.fromtimestamp(timestamp) current_time = str(dt_object) msg = 'DEBUG\nTIME {}\n {}'.format(current_time, message) notification_item = QStandardItem() notification_item.setText(msg) notification_item.setIcon(QIcon.fromTheme('dialog-question')) notification_item.setEditable(False) self.all_notification_model.appendRow(notification_item)
def __init__(self, parent, info, title="Channel Properties"): super().__init__(parent) self.setWindowTitle(title) self.model = QStandardItemModel(info["nchan"], 4) self.model.setHorizontalHeaderLabels(["#", "Label", "Type", "Bad"]) for index, ch in enumerate(info["chs"]): item = QStandardItem() item.setData(index, Qt.DisplayRole) item.setFlags(item.flags() & ~Qt.ItemIsEditable) self.model.setItem(index, 0, item) self.model.setItem(index, 1, QStandardItem(ch["ch_name"])) kind = channel_type(info, index).upper() self.model.setItem(index, 2, QStandardItem(str(kind))) bad = QStandardItem() bad.setData(ch["ch_name"] in info["bads"], Qt.UserRole) bad.setCheckable(True) bad.setEditable(False) checked = ch["ch_name"] in info["bads"] bad.setCheckState(Qt.Checked if checked else Qt.Unchecked) self.model.setItem(index, 3, bad) self.model.itemChanged.connect(bad_changed) self.proxymodel = MySortFilterProxyModel() self.proxymodel.setDynamicSortFilter(False) self.proxymodel.setSourceModel(self.model) self.view = QTableView() self.view.setModel(self.proxymodel) self.view.setItemDelegateForColumn(2, ComboBoxDelegate(self.view)) self.view.setEditTriggers(QAbstractItemView.AllEditTriggers) self.view.verticalHeader().setVisible(False) self.view.horizontalHeader().setStretchLastSection(True) self.view.setShowGrid(False) self.view.setSelectionMode(QAbstractItemView.NoSelection) self.view.setSortingEnabled(True) self.view.sortByColumn(0, Qt.AscendingOrder) vbox = QVBoxLayout(self) vbox.addWidget(self.view) self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) vbox.addWidget(self.buttonbox) self.buttonbox.accepted.connect(self.accept) self.buttonbox.rejected.connect(self.reject) self.resize(475, 650) self.view.setColumnWidth(0, 70) self.view.setColumnWidth(1, 155) self.view.setColumnWidth(2, 90)
def update_list(self): self.model.clear() packages = {} # {NodePackage: [Node]} for node, node_package in self.main_window.node_packages.items(): if node_package in packages.keys(): packages[node_package].append(node) else: packages[node_package] = [node] for node_package, nodes in packages.items(): package_item = QStandardItem(node_package.name) package_item.setEditable(False) for n in nodes: node_item = NodeItem(n) # node_item.setEditable(False) # node_item.setDragEnabled(True) package_item.appendRow(node_item) self.model.appendRow(package_item)
def add_model(self, model): """ Adds a model to the internal Qt model. Parameters ---------- model : :class:`astropy.modeling.FittableModel` The model instance to add. Returns ------- :class:`qtpy.QtCore.QModelIndex` The index in the Qt model where the new model been added. """ model_name = model.name or model.__class__.name model_count = len([self.item(idx) for idx in range(self.rowCount()) if model_name in self.item(idx).text()]) model_name = model_name + "_" + str(model_count) \ if model_count > 0 else model_name model_item = QStandardItem(model_name) model_item.setData(model, Qt.UserRole + 1) for para_name in model.param_names: # Retrieve the parameter object from the model parameter = getattr(model, para_name) # Store the name value param_name = QStandardItem(parameter.name) param_name.setData(parameter.name, Qt.UserRole + 1) param_name.setEditable(False) # Store the data value of the parameter param_value = QStandardItem("{:.5g}".format(parameter.value)) param_value.setData(parameter.value, Qt.UserRole + 1) # Store the unit information # param_unit = QStandardItem("{}".format(parameter.unit)) param_unit = QStandardItem("Plot Units") param_unit.setData(parameter.unit, Qt.UserRole + 1) param_unit.setEditable(False) # Store the fixed state of the unit param_fixed = QStandardItem() param_fixed.setData(parameter.fixed, Qt.UserRole + 1) param_fixed.setCheckable(True) param_fixed.setEditable(False) model_item.appendRow([param_name, param_value, param_unit, param_fixed]) self.appendRow([model_item, None, None, None]) # Add this model to the model equation string. By default, all models # are simply added together self._equation += " + {}".format(model_name) \ if len(self._equation) > 0 else "{}".format(model_name) return model_item.index()
def add_model(self, model): model_name = model.__class__.name model_count = len([ self.item(idx) for idx in range(self.rowCount()) if model.__class__.name in self.item(idx).text() ]) model_name = model_name + str( model_count) if model_count > 0 else model_name model_item = QStandardItem(model_name) model_item.setData(model, Qt.UserRole + 1) for para_name in model.param_names: # Retrieve the parameter object from the model parameter = getattr(model, para_name) # Store the name value param_name = QStandardItem(parameter.name) param_name.setData(parameter.name, Qt.UserRole + 1) param_name.setEditable(False) # Store the data value of the parameter param_value = QStandardItem("{:.5g}".format(parameter.value)) param_value.setData(parameter.value, Qt.UserRole + 1) # Store the unit information # param_unit = QStandardItem("{}".format(parameter.unit)) param_unit = QStandardItem("Plot Units") param_unit.setData(parameter.unit, Qt.UserRole + 1) param_unit.setEditable(False) # Store the fixed state of the unit param_fixed = QStandardItem() param_fixed.setData(parameter.fixed, Qt.UserRole + 1) param_fixed.setCheckable(True) param_fixed.setEditable(False) model_item.appendRow( [param_name, param_value, param_unit, param_fixed]) self.appendRow([model_item, None, None, None]) # Add this model to the model equation string. By default, all models # are simply added together self._equation += " + {}".format(model_name) \ if len(self._equation) > 0 else "{}".format(model_name) return model_item.index()
def getItemModel(self): """Return a QModel made from the current workspace. This should be set onto a QTableView """ model = QStandardItemModel() model.setHorizontalHeaderLabels(["Name", "Type", "Value", "Units"]) model.setColumnCount(4) for key in self.get_log_names(): log = self.run.getLogData(key) name = QStandardItem() name.setText(log.name) name.setEditable(False) log_type = QStandardItem() log_type.setText(get_type(log)) log_type.setEditable(False) value = QStandardItem() value.setText(str(get_value(log))) value.setEditable(False) unit = QStandardItem() unit.setText(log.units) unit.setEditable(False) model.appendRow((name, log_type, value, unit)) model.sort(0) return model