def Add(self, edit=None): """Add expressions""" self.exampleRow = MyRow() self.firstList(self.exampleRow) QtCore.QObject.connect(self.exampleRow._wi.removeButton, QtCore.SIGNAL("clicked()"), self.Rm) self._ui.scrollAreaWidgetContents.layout().addWidget(self.exampleRow) if edit: self.exampleRow._wi.variableCombo.addItem(QtCore.QString(edit[0])) self.exampleRow._wi.valueCombo.setItemText(0, edit[1]) self.exampleRow._wi.operatorCombo.addItem(QtCore.QString(edit[2])) self.connect(self.exampleRow, QtCore.SIGNAL('textChanged(QString)'), self.UpdateText)
def setDevCombo(self, device=None): self.deviceCombo.clear() devList = self.api.devices [self.deviceCombo.addItem(QtCore.QString(d)) for d in self.api.devices] self.deviceCombo.model().sort(0, Qt.Qt.AscendingOrder) print 'setDevCombo(%s)' % device if device in self.api.devices: i = self.deviceCombo.findText(device) print '\t%s at %s' % (device, i) self.deviceCombo.setCurrentIndex(i) else: print '\t%s not in AlarmsAPI!' % device
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 __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.gridLayout = QtGui.QGridLayout(self) self.gridLayout.setObjectName("gridLayout") self.comboBox = QtGui.QComboBox(self) self.comboBox.setObjectName("comboBox") self.comboBox.addItem(QtCore.QString("")) self.comboBox.addItem(QtCore.QString("(")) self.comboBox.addItem(QtCore.QString(")")) self.comboBox.addItem(QtCore.QString("OR")) self.comboBox.addItem(QtCore.QString("AND")) self.comboBox.addItem(QtCore.QString("XOR")) self.comboBox.addItem(QtCore.QString("NOT")) self.gridLayout.addWidget(self.comboBox, 0, 0, 1, 1) self.pushButton = QtGui.QPushButton(self) self.pushButton.setObjectName("pushButton") self.pushButton.setIcon(getThemeIcon("go-up")) self.gridLayout.addWidget(self.pushButton, 0, 2, 1, 1) self.pushButton_2 = QtGui.QPushButton(self) self.pushButton_2.setObjectName("pushButton_2") self.pushButton_2.setIcon(getThemeIcon("go-down")) self.gridLayout.addWidget(self.pushButton_2, 0, 3, 1, 1) self.pushButton_3 = QtGui.QPushButton(self) self.pushButton_3.setObjectName("pushButton_3") self.pushButton_3.setIcon(getThemeIcon("list-remove")) self.gridLayout.addWidget(self.pushButton_3, 0, 5, 1, 1) self.spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout.addItem(self.spacerItem, 0, 1, 1, 1) self.spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout.addItem(self.spacerItem1, 0, 4, 1, 1) QtCore.QObject.connect(self.comboBox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.CreateText)
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, row_widget): self.row_widget = row_widget row_widget.setObjectName("row_widget") row_widget.resize(382, 31) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( row_widget.sizePolicy().hasHeightForWidth()) row_widget.setSizePolicy(sizePolicy) self.gridLayout = QtGui.QGridLayout(row_widget) self.gridLayout.setMargin(0) self.gridLayout.setObjectName("gridLayout") self.valueCombo = QtGui.QComboBox(row_widget) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.valueCombo.sizePolicy().hasHeightForWidth()) self.valueCombo.setSizePolicy(sizePolicy) self.valueCombo.setObjectName("valueCombo") self.valueCombo.addItem(QtCore.QString()) self.valueCombo.setItemText(0, "") self.valueCombo.addItem(QtCore.QString("<")) self.valueCombo.addItem(QtCore.QString("<=")) self.valueCombo.addItem(QtCore.QString("==")) self.valueCombo.addItem(QtCore.QString(">")) self.valueCombo.addItem(QtCore.QString(">=")) self.valueCombo.addItem(QtCore.QString("!=")) self.gridLayout.addWidget(self.valueCombo, 1, 1, 1, 1) self.operatorCombo = QtGui.QComboBox(row_widget) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.operatorCombo.sizePolicy().hasHeightForWidth()) self.operatorCombo.setSizePolicy(sizePolicy) self.operatorCombo.setEditable(True) self.operatorCombo.setFrame(True) self.operatorCombo.setObjectName("operatorCombo") self.gridLayout.addWidget(self.operatorCombo, 1, 2, 1, 1) self.variableCombo = QtGui.QComboBox(row_widget) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.variableCombo.sizePolicy().hasHeightForWidth()) self.variableCombo.setSizePolicy(sizePolicy) self.variableCombo.setEditable(True) self.variableCombo.setObjectName("variableCombo") self.gridLayout.addWidget(self.variableCombo, 1, 0, 1, 1) self.removeButton = QtGui.QPushButton(row_widget) self.removeButton.setObjectName("removeButton") self.removeButton.setIcon(getThemeIcon("list-remove")) self.gridLayout.addWidget(self.removeButton, 1, 3, 1, 1) self.retranslateUi(row_widget) QtCore.QObject.connect(self.variableCombo, QtCore.SIGNAL("editTextChanged(QString)"), self.row_widget.CreateText) QtCore.QObject.connect(self.operatorCombo, QtCore.SIGNAL("editTextChanged(QString)"), self.row_widget.CreateText) QtCore.QObject.connect(self.valueCombo, QtCore.SIGNAL("currentIndexChanged(QString)"), self.row_widget.CreateText) QtCore.QMetaObject.connectSlotsByName(row_widget)
def setComboBox(self, comboBox, values, sort=False): # print "setRecData" comboBox.clear() [comboBox.addItem(QtCore.QString(i)) for i in values] if sort: comboBox.model().sort(0, Qt.Qt.AscendingOrder)