def __init__(self, api, qtparent, tauparent=None): QtGui.QListWidgetItem.__init__(self) TaurusBaseComponent.__init__(self, tauparent) self.api = api self.qtparent = qtparent self.alarm = None self.alarmDisabled = None self.alarmAcknowledged = None self.font = QtGui.QFont(QtCore.QString("Courier")) self.font.setPointSize(10) self.setFont(self.font) self.errors = 0 self.status = '' self.changed = False #This flag should be kept until updateStyle is called!!! self.quality = None self.setTextAlignment(Qt.Qt.AlignLeft)
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
def setupUi(self, Form): self.Form = Form Form.setObjectName("Form") Form.resize(346, 219) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) self.verticalLayout_2 = QtGui.QVBoxLayout(Form) self.verticalLayout_2.setObjectName("verticalLayout_2") self.formulaLineEdit = QtGui.QLineEdit(Form) self.formulaLineEdit.setEnabled(True) self.formulaLineEdit.setFrame(False) self.formulaLineEdit.setReadOnly(True) self.formulaLineEdit.setObjectName("formulaLineEdit") self.verticalLayout_2.addWidget(self.formulaLineEdit) self.scrollArea = QtGui.QScrollArea(Form) self.scrollArea.setMinimumSize(QtCore.QSize(0, 130)) self.scrollArea.setWidgetResizable(True) self.scrollArea.setObjectName("scrollArea") self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea) self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 332, 124)) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.scrollAreaWidgetContents.sizePolicy().hasHeightForWidth()) self.scrollAreaWidgetContents.setSizePolicy(sizePolicy) self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self.verticalLayout = QtGui.QVBoxLayout(self.scrollAreaWidgetContents) self.verticalLayout.setObjectName("verticalLayout") self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.verticalLayout_2.addWidget(self.scrollArea) self.gridLayout = QtGui.QGridLayout() self.gridLayout.setSizeConstraint(QtGui.QLayout.SetNoConstraint) self.gridLayout.setObjectName("gridLayout") self.addExpressionButton = QtGui.QPushButton(Form) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.addExpressionButton.sizePolicy().hasHeightForWidth()) self.addExpressionButton.setSizePolicy(sizePolicy) self.font = QtGui.QFont() self.font.setPointSize(8) self.addExpressionButton.setFont(self.font) self.addExpressionButton.setIconSize(QtCore.QSize(14, 14)) self.addExpressionButton.setObjectName("addExpressionButton") self.gridLayout.addWidget(self.addExpressionButton, 0, 0, 1, 1) self.spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout.addItem(self.spacerItem, 0, 1, 1, 1) self.addRelationButton = QtGui.QPushButton(Form) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.addRelationButton.sizePolicy().hasHeightForWidth()) self.addRelationButton.setSizePolicy(sizePolicy) self.font = QtGui.QFont() self.font.setPointSize(8) self.addRelationButton.setFont(self.font) self.addRelationButton.setObjectName("addRelationButton") self.gridLayout.addWidget(self.addRelationButton, 1, 0, 1, 1) self.spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout.addItem(self.spacerItem1, 1, 1, 1, 1) self.clearButton = QtGui.QPushButton(Form) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.clearButton.sizePolicy().hasHeightForWidth()) self.clearButton.setSizePolicy(sizePolicy) self.font = QtGui.QFont() self.font.setPointSize(8) self.font.setItalic(False) self.font.setUnderline(True) self.clearButton.setFont(self.font) self.clearButton.setObjectName("clearButton") self.gridLayout.addWidget(self.clearButton, 1, 2, 1, 1) self.rowEditButton = QtGui.QPushButton(Form) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.rowEditButton.sizePolicy().hasHeightForWidth()) self.rowEditButton.setSizePolicy(sizePolicy) self.font = QtGui.QFont() self.font.setPointSize(8) self.font.setWeight(75) self.font.setBold(True) self.rowEditButton.setFont(self.font) self.rowEditButton.setObjectName("rowEditButton") self.gridLayout.addWidget(self.rowEditButton, 0, 2, 1, 1) self.verticalLayout_2.addLayout(self.gridLayout) self.retranslateUi(Form) QtCore.QObject.connect(self.rowEditButton, QtCore.SIGNAL("clicked(bool)"), self.formulaLineEdit.setDisabled) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, Data): self.Data = Data Data.setObjectName("Data") Data.resize(349, 275) self.verticalLayout_3 = QtGui.QVBoxLayout(Data) self.verticalLayout_3.setObjectName("verticalLayout_3") self.gridLayout = QtGui.QGridLayout() self.gridLayout.setObjectName("gridLayout") self.font = QtGui.QFont() self.font.setBold(True) self.nameLabel = QtGui.QLabel(Data) self.nameLabel.setObjectName("nameLabel") self.nameLabel.setFont(self.font) self.gridLayout.addWidget(self.nameLabel, 0, 0, 1, 1) self.nameLineEdit = clickableQLineEdit(Data) self.nameLineEdit.setReadOnly(True) self.nameLineEdit.setObjectName("nameLineEdit") self.nameLineEdit.setFont(self.font) self.gridLayout.addWidget(self.nameLineEdit, 0, 1, 1, 3) self.statusLabel = QtGui.QLabel(Data) self.statusLabel.setObjectName("statusLabel") self.gridLayout.addWidget(self.statusLabel, 1, 0, 1, 1) self.horizontalLane = QtGui.QHBoxLayout() self.horizontalLane.setObjectName("horizontalLayout") self.gridLayout.addLayout(self.horizontalLane, 1, 1, 1, 3) self.disableLabel = QtGui.QLabel(Data) self.disableLabel.setObjectName("disableLabel") self.gridLayout.addWidget(self.disableLabel, 2, 0, 1, 1) self.disabledCheckBox = QtGui.QCheckBox(Data) self.disabledCheckBox.setObjectName("disabledCheckBox") self.gridLayout.addWidget(self.disabledCheckBox, 2, 1, 1, 1) self.disabledCheckBox.setEnabled(False) self.ackLabel = QtGui.QLabel(Data) self.ackLabel.setObjectName("ackLabel") self.gridLayout.addWidget(self.ackLabel, 3, 0, 1, 1) self.ackCheckBox = QtGui.QCheckBox(Data) self.ackCheckBox.setObjectName("ackCheckBox") self.gridLayout.addWidget(self.ackCheckBox, 3, 1, 1, 1) self.ackCheckBox.setEnabled(False) self.deviceLabel = QtGui.QLabel(Data) self.deviceLabel.setObjectName("deviceLabel") self.gridLayout.addWidget(self.deviceLabel, 4, 0, 1, 1) self.deviceStackedLayout = QtGui.QStackedLayout() self.deviceStackedLayout.setObjectName("deviceStackedLayout") self.deviceCombo = QtGui.QComboBox(Data) self.deviceCombo.setObjectName("deviceCombo") self.deviceStackedLayout.addWidget(self.deviceCombo) self.deviceLineEdit = clickableQLineEdit(Data) self.deviceLineEdit.setReadOnly(True) self.deviceLineEdit.setObjectName("deviceLineEdit") self.deviceStackedLayout.addWidget(self.deviceLineEdit) self.deviceStackedLayout.setCurrentIndex(1) self.gridLayout.addLayout(self.deviceStackedLayout, 4, 1, 1, 2) self.deviceConfig = QtGui.QPushButton(Data) self.deviceConfig.setIcon(getThemeIcon("applications-system")) self.gridLayout.addWidget(self.deviceConfig, 4, 3, 1, 1) self.severityLabel = QtGui.QLabel(Data) self.severityLabel.setObjectName("severityLabel") self.gridLayout.addWidget(self.severityLabel, 5, 0, 1, 1) self.severityStackedLayout = QtGui.QStackedLayout() self.severityStackedLayout.setObjectName("severityStackedLayout") self.severityCombo = QtGui.QComboBox(Data) self.severityCombo.setObjectName("severityCombo") #self.severityCombo.connect(self.severityCombo,Q.textChanged,self.severityLineEdit.setText) self.severityStackedLayout.addWidget(self.severityCombo) self.severityLineEdit = clickableQLineEdit(Data) self.severityLineEdit.setReadOnly(True) self.severityLineEdit.setObjectName("severityLineEdit") self.severityStackedLayout.addWidget(self.severityLineEdit) self.severityStackedLayout.setCurrentIndex(1) self.gridLayout.addLayout(self.severityStackedLayout, 5, 1, 1, 3) self.descriptionLabel = QtGui.QLabel(Data) self.descriptionLabel.setObjectName("descriptionLabel") self.descriptionLabel.setMinimumWidth(70) self.gridLayout.addWidget(self.descriptionLabel, 6, 0, 1, 1) self.descriptionTextEdit = clickableQTextEdit(Data) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.descriptionTextEdit.sizePolicy().hasHeightForWidth()) self.descriptionTextEdit.setSizePolicy(sizePolicy) self.descriptionTextEdit.setMinimumSize(QtCore.QSize(0, 25)) self.descriptionTextEdit.setReadOnly(True) self.descriptionTextEdit.setObjectName("descriptionTextEdit") self.gridLayout.addWidget(self.descriptionTextEdit, 6, 1, 1, 3) self.receiversLabel = QtGui.QLabel(Data) self.receiversLabel.setObjectName("receiversLabel") self.gridLayout.addWidget(self.receiversLabel, 7, 0, 1, 1) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.receiversStackedLayout = QtGui.QStackedLayout() self.receiversStackedLayout.setObjectName("receiversStackedLayout") self.receiversLineEdit = clickableQLineEdit(Data) self.receiversLineEdit.setReadOnly(True) self.receiversLineEdit.setObjectName("receiversLineEdit") self.receiversLineEdit.setSizePolicy(sizePolicy) self.receiversStackedLayout.addWidget(self.receiversLineEdit) self.receiversWidget = QtGui.QWidget(Data) self.receiversWidget.setObjectName("receiversWidget") # self.receiversStackedLayout.addWidget(self.receiversWidget) self.receiversStackedLayout.setCurrentIndex(0) self.horizontalLayout.addLayout(self.receiversStackedLayout) self.addReceiversButton = QtGui.QPushButton(Data) self.addReceiversButton.setObjectName("addReceiversButton") self.addReceiversButton.setIcon(getThemeIcon("list-add")) self.horizontalLayout.addWidget(self.addReceiversButton) self.addReceiversButton.setEnabled(False) self.gridLayout.addLayout(self.horizontalLayout, 7, 1, 1, 1) self.verticalLayout_3.addLayout(self.gridLayout) self.frame = QtGui.QFrame(Data) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName("frame") self.formulaStacked = QtGui.QStackedLayout(self.frame) self.formulaStacked.setObjectName("stackedLayout") self.formulaWidget = QtGui.QWidget(self.frame) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.formulaWidget.sizePolicy().hasHeightForWidth()) self.formulaWidget.setSizePolicy(sizePolicy) self.formulaWidget.setObjectName("formulaWidget") self.formulaStacked.addWidget( self.formulaWidget) # ad widget to stacked self.verticalLayout_2 = QtGui.QVBoxLayout(self.formulaWidget) self.verticalLayout_2.setObjectName("verticalLayout_2") self.formulaLabel = QtGui.QLabel() #self.formulaWidget) #self.font = QtGui.QFont() #self.font.setPointSize(8) #self.font.setWeight(75) #self.font.setBold(True) #self.formulaLabel.setFont(self.font) #self.formulaLabel.setObjectName("formulaLabel") #self.verticalLayout_2.addWidget(self.formulaLabel) from widgets import AlarmFormula self.formulaTextEdit = AlarmFormula( ) #clickableQTextEdit(self.formulaWidget) self.formulaTextEdit.setReadOnly(True) self.formulaTextEdit.setObjectName("formulaTextEdit") self.verticalLayout_2.addWidget(self.formulaTextEdit) self.verticalLayout_3.addWidget(self.frame) self.gridLayout_2 = QtGui.QGridLayout() self.gridLayout_2.setObjectName("gridLayout_2") self.spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_2.addItem(self.spacerItem, 0, 2, 1, 1) self.editButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.editButton.setFont(self.font) self.editButton.setObjectName("editButton") self.editButton.setIcon(getThemeIcon("accessories-text-editor")) self.gridLayout_2.addWidget(self.editButton, 0, 0, 1, 1) self.previewButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.previewButton.setFont(self.font) self.previewButton.setObjectName("previewButton") self.previewButton.setIcon(getThemeIcon("face-glasses")) self.gridLayout_2.addWidget(self.previewButton, 0, 1, 1, 1) self.cancelButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.cancelButton.setFont(self.font) self.cancelButton.setObjectName("cancelButton") self.cancelButton.setIcon(getThemeIcon("edit-delete")) self.gridLayout_2.addWidget(self.cancelButton, 0, 4, 1, 1) self.saveButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.saveButton.setFont(self.font) self.saveButton.setObjectName("saveButton") self.saveButton.setIcon(getThemeIcon("document-save")) self.gridLayout_2.addWidget(self.saveButton, 0, 3, 1, 1) self.verticalLayout_3.addLayout(self.gridLayout_2) self.retranslateUi(Data) QtCore.QMetaObject.connectSlotsByName(Data)