def buildList(self, device=None): self.tableWidget.blockSignals(True) index = -1 if device is None else self.deviceCombo.findText(device) if index < 0: device = str(self.deviceCombo.currentText()) else: self.deviceCombo.setCurrentIndex(index) device = str(device) if self.api.devices: data = self.api.devices[device].get_config( True ) #get_config() already manages extraction and default values replacement else: data = {} print '%s properties: %s' % (device, data) rows = len(data) self.tableWidget.setColumnCount(2) self.tableWidget.setRowCount(rows) self.tableWidget.setHorizontalHeaderLabels( ["Attribute Name", "Attribute Value"]) for row, prop in enumerate(sorted(panic.ALARM_CONFIG)): for col in (0, 1): if not col: item = QtGui.QTableWidgetItem("%s" % prop) item.setFlags(QtCore.Qt.ItemIsEnabled) else: item = QtGui.QTableWidgetItem("%s" % data[prop]) if row % 2 == 0: item.setBackgroundColor(QtGui.QColor(225, 225, 225)) self.tableWidget.setItem(row, col, item) self.tableWidget.resizeColumnsToContents() self.tableWidget.blockSignals(False)
def buildList(self): data = self.api.get_phonebook() self.tableWidget.setColumnCount(2) self.tableWidget.setRowCount(len(data)) #self.tableWidget.setHorizontalHeaderLabels(["",""]) #print data i = 0 for name, value in sorted(data.items()): for k in (name, value): item = QtGui.QTableWidgetItem(k) #if k.split('#')[0].strip(): #item.setFlags(QtCore.Qt.ItemIsEnabled) if not (i / 2) % 2: item.setBackgroundColor(QtGui.QColor(225, 225, 225)) self.tableWidget.setItem(int(i / 2), i % 2, item) i += 1 self.tableWidget.resizeColumnsToContents()
def updateStyle(self, event=False, error=False): #trace('%s -> AlarmRow(%s).updateStyle(event=%s)'%(time.ctime(),self.alarm.tag,event),clean=True) if getattr(self.qtparent, '_attributesSignalsBlocked', False): #print '\tupdateStyle(): blocked!' return if event: try: self.font = QtGui.QFont(QtCore.QString("Courier")) self.font.setPointSize(10) if error: if self.errors >= self.MAX_ERRORS and not self.errors % self.MAX_ERRORS: self.was_ok = self.alarm.active or self.alarm.recovered self.alarm.active, self.alarm.recovered, self.alarm.counter = 0, 0, 0 self.qtparent.emit(QtCore.SIGNAL('setfontsandcolors'), self.tag, None, False, QtGui.QColor("grey").light(), QtGui.QColor("white")) if self.was_ok: self.font.setBold(False) error_text = clean_str(error if isinstance( error, basestring) else 'disabled').split( '=', 1)[-1].strip()[:40] self.setText(' ' + ' - '.join((self.get_tag_text(), error_text))) self.status = 'Exception received, check device %s' % self.alarm.device elif self.alarm.active is None: #trace('updateStyle(%s): value not received yet' %(self.alarm.tag),clean=True) pass else: trace('AlarmRow.updateStyle: %s = %s (%s)' % (self.alarm.tag, self.alarm.active, self.quality), clean=True) if self.alarm.active and not self.alarmDisabled: if self.quality == PyTango.AttrQuality.ATTR_ALARM: trace('alarm') if self.alarmAcknowledged: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "media-playback-pause", False, QtGui.QColor("black"), QtGui.QColor("red").lighter()) else: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "software-update-urgent", False, QtGui.QColor("black"), QtGui.QColor("red").lighter()) elif self.quality == PyTango.AttrQuality.ATTR_WARNING: trace('warning') if self.alarmAcknowledged: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "media-playback-pause", False, QtGui.QColor("black"), QtGui.QColor("orange").lighter()) else: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "emblem-important", False, QtGui.QColor("black"), QtGui.QColor("orange").lighter()) elif self.quality == PyTango.AttrQuality.ATTR_VALID: trace('debug') if self.alarmAcknowledged: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "media-playback-pause", False, QtGui.QColor("black"), QtGui.QColor("yellow").lighter()) else: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "applications-development", False, QtGui.QColor("black"), QtGui.QColor("yellow").lighter()) else: print '\tUnknown event quality?!? %s' % self.quality if self.alarm.counter < 2: self.font.setBold(True) self.alarm.recovered, self.alarm.counter = 0, 2 #else: self.font.SetBold(False) #Good to keep it, to see what changed self.status = 'Alarm Acknowledged, no more messages will be sent' if self.alarmAcknowledged else 'Alarm is ACTIVE' self.setText(' | '.join( (self.get_tag_text(), self.get_alarm_date(), self.alarm.description))) #self.setText('%45s | %30s'%(str(self.alarm.tag)[:45], self.get_alarm_date(), self.alarm.description)) elif self.alarm.active in (False, 0) and not self.alarmDisabled: if self.alarmAcknowledged: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "media-playback-pause", False, QtGui.QColor("green").lighter(), QtGui.QColor("white")) else: self.qtparent.emit( QtCore.SIGNAL('setfontsandcolors'), self.tag, "emblem-system", False, QtGui.QColor("green").lighter(), QtGui.QColor("white")) if not self.alarm.recovered: #trace('\teventReceived(%s): %s => %s' %(self.alarm.tag,self.alarm.active,self.value),clean=True) if self.alarm.counter > 1: self.font.setBold(True) self.alarm.active, self.alarm.recovered, self.alarm.counter = 0, time.time( ), 1 #else: self.font.SetBold(False) #Good to keep it, to see what changed self.status = 'Alarm has NOT been triggered' self.setText(' - '.join( (self.get_tag_text(), 'Not triggered'))) else: #AlarmDisabled or value = None self.status = 'Alarm is Disabled, status will not be updated' self.qtparent.emit(QtCore.SIGNAL('setfontsandcolors'), self.tag, "dialog-error", False, QtGui.QColor("black"), QtGui.QColor("grey").lighter()) #if self.qtparent.USE_EVENT_REFRESH: self.setToolTip('\n'.join([ self.status, '', 'Severity: ' + self.alarm.severity, 'Formula: ' + self.alarm.formula, 'Description: %s' % self.alarm.description, 'Alarm Device: %s' % self.alarm.device, 'Archived: %s' % ('Yes' if 'SNAP' in self.alarm.receivers else 'No'), ])) self.setFont(self.font) except: print 'Exception in updateStyle(%s,...): \n%s' % ( self.alarm.tag, traceback.format_exc()) else: for klass in type(self).__bases__: try: if hasattr(klass, 'updateStyle'): klass.updateStyle(self) except: pass pass