def __init__(self,parent=None,devices=None):
     #print '~'*80
     #print 'In AttributesPanel()'
     PARENT_KLASS.__init__(self,parent)
     self.setSizePolicy(Qt.QSizePolicy(Qt.QSizePolicy.Ignored,Qt.QSizePolicy.Ignored))
     self.worker = SingletonWorker(parent=self,cursor=True,sleep=50.,start=True)
     #self.worker.log.setLogLevel(self.worker.log.Debug)
     self.filters=('','','') #server/device/attribute
     self.devices=devices or []
     self.setValues(None)
     self.models = []
     self.current_item = None
     #self.connect(self, Qt.SIGNAL('customContextMenuRequested(const QPoint&)'), self.onContextMenu)
     self.popMenu = Qt.QMenu(self)
     self.actions = {
         'TestDevice': self.popMenu.addAction(Qt.QIcon(),"Test Device",self.onTestDevice),
         'ShowDeviceInfo': self.popMenu.addAction(Qt.QIcon(),"Show Device Info",self.onShowInfo),
         #'ShowDevicePanel': self.popMenu.addAction(Qt.QIcon(),"Show Info",self.onShowPanel),
         'ShowArchivingInfo': self.popMenu.addAction(Qt.QIcon(),"Show Archiving Info",self.onShowArchivingModes),
         #'Test Device': self.popMenu.addAction(Qt.QIcon(),"Test Device",self.onTestDevice)
         }
     #if hasattr(self,'setFrameStyle'):
         #self.setFrameStyle(self.Box)
     try:
         import PyTangoArchiving
         self.reader = PyTangoArchiving.Reader('*')
         #self.hreader = self.reader.configs['hdb']
         #self.treader = self.reader.configs.get('tdb',self.hreader)
     except:
         traceback.print_exc()
예제 #2
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