def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...): if orientation == Qt.Horizontal and role == Qt.DisplayRole: return QVariant(self.__headers[section]) return QVariant()
def _job_data(self, index: QModelIndex, node: Node, role: int): if role == Qt.BackgroundRole: return QColor( *state.REAL_STATE_TO_COLOR[node.data.get(ids.STATUS)]) if role == Qt.DisplayRole: _, data_name = COLUMNS[NodeType.STEP][index.column()] if data_name in [ids.CURRENT_MEMORY_USAGE, ids.MAX_MEMORY_USAGE]: data = node.data.get(ids.DATA) bytes = data.get(data_name) if data else None if bytes: return byte_with_unit(bytes) if data_name in [ids.STDOUT, ids.STDERR]: return "OPEN" if node.data.get(data_name) else QVariant() if data_name in [ids.START_TIME, ids.END_TIME]: _time = node.data.get(data_name) if _time is not None: return str(_time) return QVariant() return node.data.get(data_name) if role == FileRole: _, data_name = COLUMNS[NodeType.STEP][index.column()] if data_name in [ids.STDOUT, ids.STDERR]: return (node.data.get(data_name) if node.data.get(data_name) else QVariant()) if role == Qt.ToolTipRole: _, data_name = COLUMNS[NodeType.STEP][index.column()] if data_name in [ids.ERROR, ids.START_TIME, ids.END_TIME]: data = node.data.get(data_name) if data is not None: return str(data) return QVariant()
def data(self, index: QModelIndex, role: int = ...) -> typing.Any: if not index.isValid(): return QVariant() elif role != Qt.DisplayRole: return QVariant() else: return QVariant(self._measurementModel[index.row()]._name)
def data(self, index: QModelIndex, role=Qt.DisplayRole) -> QVariant: if not index.isValid(): return QVariant() if role == Qt.TextAlignmentRole: return Qt.AlignCenter if role == ProgressRole: return self._progress if role in (Qt.StatusTipRole, Qt.WhatsThisRole, Qt.ToolTipRole): return "" if role == Qt.SizeHintRole: return QSize(30, 30) if role == Qt.FontRole: return QFont() if role in (Qt.BackgroundRole, Qt.ForegroundRole, Qt.DecorationRole): return QColor() if role == Qt.DisplayRole: return "" return QVariant()
def data(self, index, role): from qtpy.QtCore import Qt, QVariant if index.isValid() and role == Qt.DisplayRole: return QVariant(self._data[index.row()]["name"]) else: return QVariant()
def headerData(self, section: int, orientation: Qt.Orientation, role: int) -> typing.Any: if role != Qt.DisplayRole: return QVariant() if orientation == Qt.Horizontal: return COLUMNS[NodeType.STEP][section][0] if orientation == Qt.Vertical: return section return QVariant()
def data(self, index: QModelIndex, role=Qt.DisplayRole) -> QVariant: if not index.isValid(): return QVariant() if role == Qt.TextAlignmentRole: return Qt.AlignCenter if role == ProgressRole: return self._progress return QVariant()
def data(self, index: QModelIndex, role: int = ...) -> typing.Any: if not index.isValid() or role != Qt.DisplayRole: return QVariant() else: if index.column() == 0: return QVariant() elif index.column() == 1: return QVariant(self.__model.row_keys[index.row()]) else: return QVariant( self.__model.is_slave(index.row(), index.column() - 2))
def get_data(self, column_name, curve): if column_name == "Y Channel": if curve.y_address is None: return QVariant() return str(curve.y_address) elif column_name == "X Channel": if curve.x_address is None: return QVariant() return str(curve.x_address) elif column_name == "Redraw Mode": return curve.redraw_mode return super(PyDMWaveformPlotCurvesModel, self).get_data(column_name, curve)
def data(self, index, role=Qt.DisplayRole): if not index.isValid(): return QVariant() if index.row() >= self.rowCount(): return QVariant() if index.column() >= self.columnCount(): return QVariant() column_name = self._column_names[index.column()] conn = self.connections[index.row()] if role == Qt.DisplayRole or role == Qt.EditRole: return str(getattr(conn, column_name)) else: return QVariant()
def data(self, index, role=None): row = index.row() column = index.column() if role == Qt.DisplayRole: # DisplayRole determines the text of each cell if self.has_data_at(row, column): return str(self.relevant_data(row)[column]) # The cell is blank return self.BLANK_CELL_STRING elif role == Qt.BackgroundRole: # BackgroundRole determines the background of each cell # Checks if the row is MASKED, if so makes it the specified color for masked # The check for masked rows should be first as a monitor row can be masked as well - and we want it to be # colored as a masked row, rather than as a monitor row. # First do the check in the cache, and only if not present go through SpectrumInfo and cache it. This logic # is repeated in the other checks below if self.checkMaskedCache(row): return self.masked_color # Checks if the row is a MONITOR, if so makes it the specified color for monitors elif self.checkMonitorCache(row): return self.monitor_color # Checks if the BIN is MASKED, if so makes it the specified color for masked elif self.checkMaskedBinCache(row, column): return self.masked_color # Checks if the cell is BLANK, if so it returns the specified color for blank cells elif self.checkBlankCache(row, column): return self.blank_cell_color elif role == Qt.ToolTipRole: tooltip = QVariant() if self.checkMaskedCache(row): if self.checkMonitorCache(row): tooltip = self.MASKED_MONITOR_ROW_TOOLTIP else: tooltip = self.MASKED_ROW_TOOLTIP elif self.checkMonitorCache(row): tooltip = self.MONITOR_ROW_TOOLTIP if self.checkMaskedBinCache(row, column): tooltip += self.MASKED_BIN_TOOLTIP elif self.checkMaskedBinCache(row, column): tooltip = self.MASKED_BIN_TOOLTIP elif self.checkBlankCache(row, column): tooltip = self.BLANK_CELL_TOOLTIP return tooltip else: return QVariant()
def data(self, index, role=Qt.DisplayRole): if not index.isValid(): return QVariant() if index.row() >= self.rowCount(): return QVariant() if index.column() >= self.columnCount(): return QVariant() column_name = self._column_names[index.column()] curve = self.plot._curves[index.row()] if role == Qt.DisplayRole or role == Qt.EditRole: return self.get_data(column_name, curve) elif role == Qt.BackgroundRole and column_name == "Color": return QBrush(curve.color) else: return QVariant()
def get_data(self, column_name, curve): if column_name == "Y Channel": if curve.y_address is None: return QVariant() return str(curve.y_address) elif column_name == "X Channel": if curve.x_address is None: return QVariant() return str(curve.x_address) elif column_name == "Redraw Mode": return curve.redraw_mode elif column_name == "Buffer Size": return curve.getBufferSize() return super(PyDMScatterPlotCurvesModel, self).get_data( column_name, curve)
def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...) -> typing.Any: if orientation == Qt.Horizontal and role == Qt.DisplayRole: if section == 0: return QVariant('') elif section == 1: return QVariant('Master') else: if section - 2 < len(self.__model.columns): return QVariant(self.__model.columns[section - 2]) else: return QVariant() return QVariant()
def _job_data(self, index: QModelIndex, node: Node, role: int): if role == Qt.BackgroundRole: assert node.parent # mypy assert node.parent.parent # mypy real = node.parent.parent return real.data[REAL_JOB_STATUS_AGGREGATED][node.id] if role == Qt.DisplayRole: _, data_name = COLUMNS[NodeType.STEP][index.column()] if data_name in [ids.CURRENT_MEMORY_USAGE, ids.MAX_MEMORY_USAGE]: data = node.data.get(ids.DATA) _bytes = data.get(data_name) if data else None if _bytes: return byte_with_unit(_bytes) if data_name in [ids.STDOUT, ids.STDERR]: return "OPEN" if node.data.get(data_name) else QVariant() if data_name in [DURATION]: start_time = node.data.get(ids.START_TIME) if start_time is None: return QVariant() delta = _estimate_duration( start_time, end_time=node.data.get(ids.END_TIME) ) # There is no method for truncating microseconds, so we remove them delta -= datetime.timedelta(microseconds=delta.microseconds) return str(delta) return node.data.get(data_name) if role == FileRole: _, data_name = COLUMNS[NodeType.STEP][index.column()] if data_name in [ids.STDOUT, ids.STDERR]: return ( node.data.get(data_name) if node.data.get(data_name) else QVariant() ) if role == Qt.ToolTipRole: _, data_name = COLUMNS[NodeType.STEP][index.column()] data = None if data_name == ids.ERROR: data = node.data.get(data_name) elif data_name == DURATION: start_time = node.data.get(ids.START_TIME) if start_time is not None: delta = _estimate_duration( start_time, end_time=node.data.get(ids.END_TIME) ) data = f"Start time: {str(start_time)}\nDuration: {str(delta)}" if data is not None: return str(data) return QVariant()
def get_data(self, column_name, curve): if column_name == "Channel": if curve.address is None: return QVariant() return str(curve.address) return super(PyDMTimePlotCurvesModel, self).get_data(column_name, curve)
def run(self): """Thread execution.""" if not self._quit_task: for i, pvn in enumerate(self._pvnames): self.currentItem.emit(pvn) value = self.get_pv(pvn).get(self._timeout) if pvn.endswith('-Cmd') and self._values is not None: self.itemRead.emit(pvn, QVariant(self._values[i])) elif value is not None: self.itemRead.emit(pvn, QVariant(value)) else: self.itemNotRead.emit(pvn) self.itemDone.emit() if self._quit_task: break self.completed.emit()
def data(self, index, role): from qtpy.QtCore import Qt, QVariant if index.isValid(): if role == Qt.DisplayRole: return QVariant(self._data[index.row()].filename) elif role == Qt.DecorationRole: from qtpy.QtWidgets import QStyle, QApplication if self.isdir(index): return QApplication.instance().style().standardIcon( QStyle.SP_DirIcon) else: return QApplication.instance().style().standardIcon( QStyle.SP_FileIcon) else: return QVariant()
def display_ranks(self): if self.ranks is None: return # https://stackoverflow.com/questions/7960505/strange-qtablewidget-behavior-not-all-cells-populated-after-sorting-followed-b self.ranks_tbl.setSortingEnabled(False) nrow, ncol = self.ranks.shape irow = 0 for index, row in self.ranks.iterrows(): pcell = QTableWidgetItem() pcell.setText(index) self.ranks_tbl.setItem(irow, 0, pcell) for icol in range(ncol): cell = QTableWidgetItem() val = row.iloc[icol] #if icol in [0, 1]: # val = str(int(val)) #else: # val = "{0:.3f}".format(val) #cell.setText(val) if icol in [0, 1]: val = int(val) else: val = "{0:.3f}".format(val) cell.setData(Qt.EditRole, QVariant(val)) self.ranks_tbl.setItem(irow, icol + 1, cell) irow += 1 self.ranks_tbl.setSortingEnabled(True)
def __init__(self, parent): super(InfoFrame, self).__init__(parent) self.widget_layout = QVBoxLayout(self) self.setLayout(self.widget_layout) self.section_label = QLabel(self) self.section_label.setText("Informations") self.widget_layout.addWidget(self.section_label) self.label = QLabel(self) self.label.setText("Select information to collect after successfull connection. Keep in mind that the more " "data you collect the more suspicious you are for antivirus software. You can " "change these settings later.") self.label.setWordWrap(True) self.widget_layout.addWidget(self.label) self.list = QListView(self) self.model = QStandardItemModel(self.list) self.widget_layout.addWidget(self.list) self.list.setModel(self.model) self.item_string = {} infos = ConfigManager.get_infos() for info in infos: self.item_string[info] = {"name": " ".join(info.capitalize().split("_"))} for string in self.item_string: item = QStandardItem(self.item_string.get(string).get("name")) item.setFlags(Qt.ItemIsEnabled) item.setData(QVariant(Qt.Checked), Qt.CheckStateRole) self.model.appendRow(item)
def data(self, index, role): if not index.isValid() or role != Qt.DisplayRole: return QVariant() row = index.row() col = index.column() if role == Qt.DisplayRole: if col == 0: return self.plot[row] elif col == 1: return self.bad[row] elif col == 2: v = self.sc.adrR[row] #print('ADR R:', v) return str(v) elif col in [3, 4]: return 'NA' return QVariant()
def headerData(self, section, orientation, role=None): if not (role == Qt.DisplayRole or role == Qt.ToolTipRole): return QVariant() if orientation == Qt.Vertical: return self._makeVerticalHeader(section, role) else: return self._makeHorizontalHeader(section, role)
def headerData(self, section, orientation, role=Qt.DisplayRole): """Set headers of the table (override).""" if role == Qt.TextAlignmentRole: pass if role != Qt.DisplayRole: return QVariant() if orientation == Qt.Horizontal: if not self._configurations[section].dirty: return QVariant(self._configurations[section].name) else: return QVariant(self._configurations[section].name + "*") elif orientation == Qt.Vertical: if role == Qt.DisplayRole: pvname = self._vertical_header[section]['name'] vheader = "{}".format(pvname) return QVariant(vheader) return QVariant(int(section + 1))
def data(self, index, role=Qt.DisplayRole): """Set data of the table (override).""" if role == Qt.DisplayRole: pvname = self._vertical_header[index.row()]['name'] pvtype = self._vertical_header[index.row()]['type'] if pvtype == float: return QVariant("{:8.5f}".format( self._configurations[index.column()].values[pvname])) else: raise NotImplementedError
def data(self, index, role=Qt.DisplayRole): if index.isValid(): if role == Qt.DisplayRole or role == Qt.EditRole: if index.column() != 0: dat = self._data.iat[index.row(), index.column()] return float(dat) elif role == Qt.CheckStateRole: if index.column() == 0: if self._data.iat[index.row(), index.column()]: return Qt.Checked else: return Qt.Unchecked return QVariant()
def _real_data(self, index: QModelIndex, node: Node, role: int): if role == RealJobColorHint: colors: List[QColor] = [] for job_id in node.parent.data[SORTED_JOB_IDS]: colors.append(node.data[REAL_JOB_STATUS_AGGREGATED][job_id]) return colors elif role == RealLabelHint: return node.id elif role == RealIens: return node.id elif role == RealStatusColorHint: return node.data[REAL_STATUS_COLOR] else: return QVariant()
def add_game_to_table(self, game): """ Append a row at bottom of the table for this game """ nrow, ncol = self.games.shape print("Add game to row {}".format(nrow)) for col in range(ncol): cell = QTableWidgetItem() val = game.iloc[0].iloc[col] if col in [1, 6, 7]: val = int(val) cell.setData(Qt.EditRole, QVariant(val)) else: val = str(val) cell.setText(val) self.games_tbl.setItem(nrow - 1, col, cell)
def data(self, index, role=None): if role != Qt.DisplayRole: return QVariant() # This is the main bottleneck for sorting. Profiling experiments # show that the main culprit is the .columns[][] accessor in the # astropy table. The index.column() and index.row() calls cause # negligible CPU load. # # return self._linelist.columns[index.column()][index.row()] # # going from an astropy table to a list of rows, the bottleneck # narrows down to the astropy code that gets a cell value from a # Row instance. return self._row_cells[index.row()][index.column()]
def get_data(self, column_name, curve): if column_name == "Label": if curve.name() is None: return QVariant() return str(curve.name()) elif column_name == "Color": return curve.color_string elif column_name == "Line Style": return self.name_for_line[curve.lineStyle] elif column_name == "Line Width": return int(curve.lineWidth) elif column_name == "Symbol": return self.name_for_symbol[curve.symbol] elif column_name == "Symbol Size": return int(curve.symbolSize)
def display_games(self): if self.games is None: return nrow, ncol = self.games.shape for row in range(nrow): for col in range(ncol): cell = QTableWidgetItem() val = self.games.iloc[row].iloc[col] if col in [1, 6, 7]: val = int(val) cell.setData(Qt.EditRole, QVariant(val)) else: val = str(val) cell.setText(val) self.games_tbl.setItem(row, col, cell)