def update_item(self, row, column): item = self.table.item(row, column) value, config = item.value, item.config # Set text if (config and config.format_spec != "Not specified") and \ (config.format_spec != "!s"): data_format = "%" + config.format_spec item.setText(data_format % value.rvalue) else: item.setText(str(value.rvalue)) # Set flags and state if item.writable_boolean: item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) state = QtCore.Qt.Checked if value.wvalue else QtCore.Qt.Unchecked item.setCheckState(state) else: item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) # Set background color if config.type == 5: # DevState if value.rvalue in self.STATE_COLORS: item.setBackgroundColor(QtGui.QColor(*self.STATE_COLORS[value.rvalue]))
def _draw_scale(self, w, h, fh, fw, qp): ticks = self._get_ticks() if all(t is not None for t in ticks): n = len(ticks) - 1 qp.setPen(QtGui.QColor(0, 0, 0)) qp.drawLine(Point(w, self.pad), Point(w, h + self.pad)) for i, tick in enumerate(ticks): qp.drawLine(Point(w, h - i * h / n + self.pad), Point(w + 5, h - i * h / n + self.pad)) qp.drawText( Point(w + self.pad, h - i * h / n + self.pad + fw / 2), TICK_FORMAT % tick)
def updateColumn(self, column): if not self._values: return # when does this happen? data = self._values[column] for row, value in enumerate(data.value): if not isnan(value): cfg = self._config.get(column) if cfg and cfg.format != "Not specified": item = QtGui.QTableWidgetItem(cfg.format % value) else: item = QtGui.QTableWidgetItem(str(value)) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) else: item = QtGui.QTableWidgetItem("NaN") item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) item.setBackgroundColor(QtGui.QColor(220, 220, 220)) item.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.table.setItem(row, column, item)
def draw_widget(self, qp): # TODO: clean up and complete the error handling; e.g. no limits, # non-valid qualities, etc. font = QtGui.QFont('Serif', 7, QtGui.QFont.Light) qp.setFont(font) metrics = qp.fontMetrics() ticks = self._get_ticks() fw = [metrics.width(TICK_FORMAT % s) for s in ticks if s is not None] if not fw: return # no ticks, should draw something anyway..? fw = max(fw) if len(fw) > 0 else 0 fh = metrics.height() size = self.size() w = size.width() - (self.pad + fw) h = size.height() - 2 * self.pad # draw things in the value scale with self._scale(qp): # frame qp.setPen(QtCore.Qt.transparent) qp.setBrush(QtGui.QColor(255, 255, 255)) qp.drawRect( Rect(0, self.min_value, w, self.max_value - self.min_value)) # warning if self.warn_high is not None: qp.setBrush(QtGui.QColor(255, 200, 150)) qp.drawRect( Rect(0, self.warn_high, w, self.max_value - self.warn_high)) if self.warn_low is not None: qp.setBrush(QtGui.QColor(255, 200, 150)) qp.drawRect( Rect(0, self.min_value, w, abs(self.min_value - self.warn_low))) # alarm if self.alarm_high is not None: qp.setBrush(QtGui.QColor(255, 170, 170)) qp.drawRect( Rect(0, self.alarm_high, w, self.max_value - self.alarm_high)) if self.alarm_low is not None: qp.setBrush(QtGui.QColor(255, 170, 170)) qp.drawRect( Rect(0, self.min_value, w, abs(self.min_value - self.alarm_low))) # value bar qp.setPen(QtGui.QColor(0, 200, 0)) qp.setBrush(QtGui.QColor(0, 200, 0)) qp.drawRect(Rect(10, 0, w - 2 * self.pad, self.value)) # write value line qp.setPen(QtGui.QColor(255, 0, 0)) if self.write_value: qp.drawLine(Point(0, self.write_value), Point(w, self.write_value)) # zero line qp.setPen(QtGui.QColor(0, 0, 0)) if self.min_value <= 0 <= self.max_value: qp.drawLine(0, 0, w + 5, 0) self._draw_scale(w, h, fw, fh, qp)