示例#1
0
文件: gui.py 项目: S2Innovation/PANIC
 def setViewMenu(self, action=None):
     print 'In AlarmGUI.setViewMenu(%s)' % action
     self.mainwindow.viewMenu.clear()
     windows = WindowManager.getWindowsNames()
     for w in windows:
         self.mainwindow.viewMenu.addAction(
             w, lambda x=w: WindowManager.putOnTop(x))
     self.mainwindow.viewMenu.addAction('Close All',
                                        lambda: WindowManager.closeAll())
     return
示例#2
0
文件: gui.py 项目: S2Innovation/PANIC
 def showNewAlarmPanel(s=self, a=alarmApp):
     i = len([
         w for w in WindowManager.getWindowsNames()
         if w.startswith('panel')
     ])
     name = 'panel%d' % i
     a.tools[name] = WindowManager.addWindow(
         panic.gui.panel.QAlarmPanel())
     a.tools[name].setModel(s.view)
     a.tools[name].show()
示例#3
0
 def onEdit(self,edit=True):
     alarm = self.getCurrentAlarm()
     print "AlarmGUI.onEdit(%s)"%alarm
     forms = [f for f in WindowManager.WINDOWS 
         if isinstance(f,AlarmForm) and f.getCurrentAlarm().tag==alarm.tag] 
     
     if forms: #Bring existing forms to focus
         form = forms[0]
         form.enableEditForm(edit)
         form.hide()
         form.show()
     else: #Create a new form
         form = WindowManager.addWindow(AlarmForm(self.parent()))
         #form.connect(form,Qt.SIGNAL('valueChanged'),self.hurry)
         if edit: form.onEdit(alarm)
         else: form.setAlarmData(alarm)
     form.show()
     return form
示例#4
0
文件: gui.py 项目: S2Innovation/PANIC
    def init_mw(self, tmw=None):
        """ 
        Method to initialize main window (menus and frames) 
        """
        t0 = time.time()
        alarmApp = self
        tmw = tmw if isinstance(tmw, Qt.QMainWindow) else CleanMainWindow()
        tmw.setWindowTitle('PANIC')
        tmw.menuBar = Qt.QMenuBar(tmw)
        tmw.toolsMenu = Qt.QMenu('Tools', tmw.menuBar)
        tmw.fileMenu = Qt.QMenu('File', tmw.menuBar)
        tmw.viewMenu = Qt.QMenu('View', tmw.menuBar)
        tmw.helpMenu = Qt.QMenu('Help', tmw.menuBar)

        tmw.setMenuBar(tmw.menuBar)
        [
            tmw.menuBar.addAction(a.menuAction())
            for a in (tmw.fileMenu, tmw.toolsMenu, tmw.helpMenu, tmw.viewMenu)
        ]
        toolbar = Qt.QToolBar(tmw)
        toolbar.setIconSize(Qt.QSize(20, 20))

        tmw.helpMenu.addAction(getThemeIcon("applications-system"), "Webpage",
                               lambda: os.system('konqueror %s &' % PANIC_URL))
        tmw.toolsMenu.addAction(getThemeIcon("applications-system"), "Jive",
                                lambda: os.system('jive &'))
        tmw.toolsMenu.addAction(getThemeIcon("applications-system"), "Astor",
                                lambda: os.system('astor &'))
        tmw.fileMenu.addAction(getThemeIcon(":/designer/back.png"),
                               "Export to CSV file", alarmApp.saveToFile)
        tmw.fileMenu.addAction(getThemeIcon(":/designer/forward.png"),
                               "Import from CSV file", alarmApp.loadFromFile)
        tmw.fileMenu.addAction(getThemeIcon(":/designer/filereader.png"),
                               "Use external editor", alarmApp.editFile)
        tmw.fileMenu.addAction(getThemeIcon("applications-system"), "Exit",
                               tmw.close)
        tmw.viewMenu.connect(tmw.viewMenu, Qt.SIGNAL('aboutToShow()'),
                             alarmApp.setViewMenu)

        from phonebook import PhoneBook
        alarmApp.tools['bookApp'] = WindowManager.addWindow(
            PhoneBook(container=tmw))
        tmw.toolsMenu.addAction(getThemeIcon("x-office-address-book"),
                                "PhoneBook", alarmApp.tools['bookApp'].show)
        toolbar.addAction(getThemeIcon("x-office-address-book"), "PhoneBook",
                          alarmApp.tools['bookApp'].show)

        trend_action = (getThemeIcon(":/designer/qwtplot.png"), 'Trend',
                        lambda: WindowManager.addWindow(
                            widgets.get_archive_trend(show=True)))
        tmw.toolsMenu.addAction(*trend_action)
        toolbar.addAction(*trend_action)

        alarmApp.tools['config'] = WindowManager.addWindow(
            dacWidget(container=tmw))
        tmw.toolsMenu.addAction(getThemeIcon("applications-system"),
                                "Advanced Configuration",
                                alarmApp.tools['config'].show)
        toolbar.addAction(getThemeIcon("applications-system"),
                          "Advanced Configuration",
                          alarmApp.tools['config'].show)

        toolbar.setMovable(False)
        toolbar.setFloatable(False)
        tmw.addToolBar(toolbar)

        if SNAP_ALLOWED:
            alarmApp.tools['history'] = WindowManager.addWindow(
                ahWidget(container=tmw))
            tmw.toolsMenu.addAction(getThemeIcon("office-calendar"),
                                    "Alarm History Viewer",
                                    alarmApp.tools['history'].show)
            toolbar.addAction(getThemeIcon("office-calendar"),
                              "Alarm History Viewer",
                              alarmApp.tools['history'].show)
        else:
            trace("Unable to load SNAP", 'History Viewer Disabled!')

        alarm_preview_action = (getThemeIcon("accessories-calculator"),
                                "Alarm Calculator",
                                lambda g=alarmApp: WindowManager.addWindow(
                                    AlarmPreview.showEmptyAlarmPreview(g)))
        [o.addAction(*alarm_preview_action) for o in (tmw.toolsMenu, toolbar)]

        try:
            import PyTangoArchiving.widget.ArchivingBrowser
            MSW = PyTangoArchiving.widget.ArchivingBrowser.ModelSearchWidget
            alarmApp.tools['finder'] = WindowManager.addWindow(MSW())
            tmw.toolsMenu.addAction(getThemeIcon("system-search"),
                                    "Attribute Finder",
                                    alarmApp.tools['finder'].show)
            toolbar.addAction(getThemeIcon("system-search"),
                              "Attribute Finder",
                              alarmApp.tools['finder'].show)
        except:
            print('PyTangoArchiving not available')
            #traceback.print_exc()

        import panic.gui.panel

        def showNewAlarmPanel(s=self, a=alarmApp):
            i = len([
                w for w in WindowManager.getWindowsNames()
                if w.startswith('panel')
            ])
            name = 'panel%d' % i
            a.tools[name] = WindowManager.addWindow(
                panic.gui.panel.QAlarmPanel())
            a.tools[name].setModel(s.view)
            a.tools[name].show()

        url = os.path.dirname(panic.__file__) + '/gui/icon/panel-view.png'
        panel_icon = Qt.QIcon(Qt.QPixmap(url))
        alarm_panel_action = (panel_icon, "Alarm Panel", showNewAlarmPanel)
        [o.addAction(*alarm_panel_action) for o in (tmw.toolsMenu, toolbar)]

        import panic.gui.views
        alarmApp.tools['rawview'] = WindowManager.addWindow(
            panic.gui.views.ViewRawBrowser())
        #url = os.path.dirname(panic.__file__)+'/gui/icon/panel-view.png'
        #panel_icon = Qt.QIcon(Qt.QPixmap(url))
        alarm_panel_action = (
            getThemeIcon('actions:leftjust.svg'), "RawView",
            lambda s=self: alarmApp.tools['rawview'].setModel(self))
        [o.addAction(*alarm_panel_action) for o in (tmw.toolsMenu, )]

        print('Toolbars created after %s seconds' % (time.time() - t0))
        tmw.setCentralWidget(alarmApp)
        tmw.show()
        return tmw
示例#5
0
    def onContextMenu(self, point):
        self.popMenu = QtGui.QMenu(self)
        view = getattr(self,'view')
        items = self.getSelectedAlarms(extend=False)
        print('In onContextMenu(%s)'%str([a.tag for a in items]))
        alarm = self.getCurrentAlarm()
        #self.popMenu.addAction(getThemeIcon("face-glasses"), 
        # "Preview Attr. Values",self.onSelectAll)

        act = self.popMenu.addAction(getThemeIcon("face-glasses"),
                                     "See Alarm Details",self.onView) 
        act.setEnabled(len(items)==1)
        act = self.popMenu.addAction(getThemeIcon("accessories-calculator"),
                                     "Preview Formula/Values",
            lambda s=self:WindowManager.addWindow(s.showAlarmPreview()))
        act.setEnabled(len(items)==1)
        #self.popMenu.addAction(getThemeIcon("view-refresh"), 
                               #"Sort/Update List",self.onSevFilter)

        act = self.popMenu.addAction(getThemeIcon("office-calendar"), 
                                     "View History",self.viewHistory)
        act.setEnabled(SNAP_ALLOWED and len(items)==1) 
            # and row.get_alarm_tag() in self.ctx_names)
            
        sevMenu = self.popMenu.addMenu('Change Priority')
        for S in SEVERITIES:
            action = sevMenu.addAction(S)
            self.connect(action, QtCore.SIGNAL("triggered()"), 
                lambda ks=items,sev=S,o=self:
                  ChangeSeverity(parent=o,severity=sev))
        
        # Reset / Acknowledge options
        act = self.popMenu.addAction(getThemeIcon("edit-undo"), 
                        "Reset Alarm(s)",lambda s=self:ResetAlarm(s))    
        act.setEnabled(any(i.active for i in items))

        #if len([i.acknowledged for i in items]) in (len(items),0):
        if len(items)==1:
            self.popMenu.addAction(getThemeIcon("media-playback-pause"), 
                "Acknowledge/Renounce Alarm(s)",
                lambda s=self:AcknowledgeAlarm(s))

        #if len([i.disabled for i in items]) in (len(items),0):
        if len(items)==1:
            self.popMenu.addAction(getThemeIcon("dialog-error"), 
                "Disable/Enable Alarm(s)",
                lambda s=self:ChangeDisabled(s))
            
        # Edit options
        if getattr(self,'expert',None):
            
            self.popMenu.addSeparator()
            act = self.popMenu.addAction(
                getThemeIcon("accessories-text-editor"), 
                "Edit Alarm",self.onEdit)
            act.setEnabled(len(items)==1)
            act = self.popMenu.addAction(getThemeIcon("edit-copy"), 
                                         "Clone Alarm",self.onClone)
            act.setEnabled(len(items)==1)
            act = self.popMenu.addAction(getThemeIcon("edit-clear"), 
                                         "Delete Alarm",self.onDelete)
            act.setEnabled(len(items)==1)
            self.popMenu.addAction(getThemeIcon("applications-system"), 
                            "Advanced Config",lambda s=self:ShowConfig(s))
            self.popMenu.addSeparator()
            act = self.popMenu.addAction(
                getThemeIcon("accessories-text-editor"), "TestDevice",
                lambda d=alarm.device:testDevice(d))
            
            act.setEnabled(len(items)==1)
            
        #self.popMenu.addSeparator()
        #self.popMenu.addAction(getThemeIcon("process-stop"), "close App",self.close)

        if getattr(self,'_manager',None):
            self.popMenu.exec_(self._manager.mapToGlobal(point))
        else:
            self.popMenu.exec_(point)
示例#6
0
def ShowConfig(parent=None):
    dac = dacWidget(device=parent.getCurrentAlarm().device)
    WindowManager.addWindow(dac)
    dac.show()