예제 #1
0
파일: gui.py 프로젝트: S2Innovation/PANIC
 def onItemSelected(self):
     try:
         items = self.getSelectedItems(extend=False)
         if len(items) == 1:
             a = self.view.get_alarm_from_text(items[0])
             tags = a.tag.split('_')
             self.emit(Qt.SIGNAL('alarmSelected'), a.tag)
             models = self.api.parse_attributes(a.formula)
             devices = sorted(
                 set(
                     fn.tango.parse_tango_model(m)['device']
                     for m in models))
             print('onItemSelected(%s) devices: %s' %
                   (a, shortstr(devices)))
             self.emit(Qt.SIGNAL('devicesSelected'),
                       '|'.join(devices + tags))
     except:
         traceback.print_exc()
예제 #2
0
파일: gui.py 프로젝트: S2Innovation/PANIC
    def setFontsAndColors(item, alarm):

        state, severity = alarm.get_state(), alarm.severity
        severity = severity or panic.DEFAULT_SEVERITY
        color = Qt.QColor("black")
        background = Qt.QColor("white")
        bold = False
        icon = ""

        if state in ('OOSRV', ):
            color = Qt.QColor("grey").light()
            background = Qt.QColor("white")

        elif state in ('ERROR', ):
            color = Qt.QColor("red")
            background = Qt.QColor("white")

        elif state in ACTIVE_STATES:

            if severity in ('ERROR', ):
                color = Qt.QColor("white")
                background = Qt.QColor("red").lighter()

            elif severity in ('ALARM', ):
                background = Qt.QColor("red").lighter()

            elif severity == 'WARNING':
                background = Qt.QColor("orange").lighter()

            elif severity in ('INFO', 'DEBUG'):
                background = Qt.QColor("yellow").lighter()

        elif state in ('DSUPR', 'SHLVD'):
            color = Qt.QColor("grey").light()
            background = Qt.QColor("white")

        elif state == 'NORM':
            color = Qt.QColor("green").lighter()
            background = Qt.QColor("white")

        else:
            raise Exception('UnknownState:%s' % state)

        icon = getIconForAlarm(alarm)

        if (fandango.now() - alarm.get_time()) < 60:
            bold = True

        alarmicon = getThemeIcon(icon) if icon else None
        #tracer('setFontsAndColors(%s,%s,%s,%s,%s)'
        #%(alarm.tag,state,icon,background,bold))
        item.setIcon(alarmicon or Qt.QIcon())
        item.setTextColor(color)
        item.setBackgroundColor(background)
        f = item.font()
        f.setFixedPitch(True)
        f.setBold(bold)
        item.setFont(f)

        status = [
            'Severity: ' + alarm.severity,
            'Formula: ' + alarm.formula,
            'Description: %s' % alarm.description,
            'Alarm Device: %s' % alarm.device,
            'Archived: %s' % ('Yes' if 'SNAP' in alarm.receivers else 'No'),
        ]
        for t in ('last_error', 'acknowledged', 'disabled', 'sortkey'):
            v = getattr(alarm, t, None)
            if v:
                status.append('%s%s: %s' % (t[0].upper(), t[1:], shortstr(v)))

        item.setToolTip('\n'.join(status))

        try:
            forms = []
            for f in WindowManager.WINDOWS:
                if isinstance(f, AlarmForm):
                    tag = f.getCurrentAlarm().tag
                    if tag == alarm.tag:
                        forms.append(f)
            if forms:
                #@TODO: these checks will be not needed after full update
                tracer("\tupdating %d %s forms" % (len(forms), alarm))
                [f.valueChanged(forced=True) for f in forms]
            else:
                pass  #tracer("no forms open?")
        except:
            tracer(traceback.format_exc())

        return item