示例#1
0
 def initStyle(self,show=False):
     print 'In AlarmFormula.initStyle(%s)' %(self.obj or self.formula)
     try:
         self.org_formula = self.formula
         self.setChildrenCollapsible(False)
         self.setOrientation(Qt.Qt.Vertical)
         ###################################################################
         upperPanel = Qt.QFrame() #self
         upperPanel.setLayout(Qt.QGridLayout())
         self.insertWidget(0,upperPanel)
         self.editcb = Qt.QCheckBox('Edit')
         self.undobt = Qt.QPushButton()
         self.savebt = Qt.QPushButton()
         l = Qt.QLabel('Formula:')
         l.setFont(get_bold_font())
         self.tf = fandango.qt.QDropTextEdit() #Qt.QTextBrowser()
         self.tf.setMinimumHeight(100)
         if self.obj is not None:
             self.tf.setClickHook(self.onEdit)#@todo setClickHook stop working for unknown reasons !?!?!
             self.tf.setReadOnly(True)
             self.tf.setEnabled(False)
             self.connect(self.editcb,Qt.SIGNAL('toggled(bool)'),self.onEdit)
             upperPanel.layout().addWidget(self.editcb,0,4,1,1)
             self.undobt.setIcon(getThemeIcon('edit-undo'))
             self.undobt.setToolTip('Undo changes in formula')
             self.undobt.setEnabled(True)
             self.connect(self.undobt,Qt.SIGNAL('pressed()'),self.undoEdit)
             upperPanel.layout().addWidget(self.undobt,0,5,1,1)
             self.savebt.setIcon(getThemeIcon('media-floppy'))
             self.savebt.setToolTip('Save Alarm Formula')
             self.savebt.setEnabled(False)
             upperPanel.layout().addWidget(self.savebt,0,6,1,1)
             self.connect(self.savebt,Qt.SIGNAL('pressed()'),self.onSave)
         upperPanel.layout().addWidget(l,0,0,1,1)
         upperPanel.layout().addWidget(self.tf,1,0,1,7)
         ###################################################################
         lowerPanel,row = Qt.QFrame(),0 #self,2
         lowerPanel.setLayout(Qt.QGridLayout())
         self.insertWidget(1,lowerPanel)
         l = Qt.QLabel('Result:')
         l.setFont(get_bold_font())
         lowerPanel.layout().addWidget(l,row,0,1,1)
         self.tb = Qt.QTextEdit()
         #tb.setPlainText('Formula:\n\t%s\n\nOutput:\n\t%s'%(test.source,result))
         self.tb.setMinimumHeight(50)
         self.tb.setReadOnly(True)
         self.redobt = Qt.QPushButton()
         self.redobt.setIcon(getThemeIcon('view-refresh'))
         self.redobt.setToolTip('Update result')
         self.connect(self.redobt,Qt.SIGNAL('pressed()'),self.updateResult)
         lowerPanel.layout().addWidget(self.redobt,row,6,1,1)
         lowerPanel.layout().addWidget(self.tb,row+1,0,1,7)
         ###################################################################
         #Refresh from formula:
         if self.formula: self.updateFormula(self.formula)
         if show: self.show()
         print 'AlarmFormula.initStyle(%s) finished.'%self.formula
     except:
         print traceback.format_exc()
         print 'Unable to show AlarmFormula(%s)'%self.formula
    def setupUi(self, USE_SCROLL=False, SHOW_OPTIONS=False, USE_TREND=False):
        self.setWindowTitle('Tango Finder : Search Attributes and Archiving')
        self.setLayout(Qt.QVBoxLayout())
        self.setMinimumWidth(950)  #550)
        #self.setMinimumHeight(700)

        self.layout().setAlignment(Qt.Qt.AlignTop)
        self.browser = Qt.QFrame()
        self.browser.setLayout(Qt.QVBoxLayout())

        self.chooser = Qt.QTabWidget()
        self.chooser.setTabPosition(
            self.chooser.West if SHOW_OPTIONS else self.chooser.North)
        #self.combo = Qt.QComboBox() # Combo used for domains, currently disabled

        self.searchbar = Qt.QFrame()
        self.searchbar.setLayout(Qt.QGridLayout())

        #self.label = Qt.QLabel('Type a part of device name and a part of attribute name, use "*" or " " as wildcards:')
        #self.layout().addWidget(self.label)

        self.ServerFilter = Qt.QLineEdit()
        self.ServerFilter.setMaximumWidth(250)
        self.DeviceFilter = fandango.qt.Dropable(Qt.QLineEdit)()
        self.DeviceFilter.setSupportedMimeTypes(
            fandango.qt.TAURUS_DEV_MIME_TYPE)
        self.AttributeFilter = fandango.qt.Dropable(Qt.QLineEdit)()
        self.AttributeFilter.setSupportedMimeTypes(
            [fandango.qt.TAURUS_ATTR_MIME_TYPE, fandango.qt.TEXT_MIME_TYPE])
        self.update = Qt.QPushButton('Update')
        self.archivecheck = Qt.QCheckBox("Show archived attributes only")
        self.archivecheck.setChecked(True)

        self.searchbar.layout().addWidget(
            Qt.QLabel(
                'Enter Device and Attribute filters using wildcards '
                '(e.g. li/ct/plc[0-9]+ / ^stat*$ & !status ) and push Update'),
            0, 0, 3, 13)

        [
            self.searchbar.layout().addWidget(o, x, y, h, w)
            for o, x, y, h, w in (
                (Qt.QLabel("Device or Alias:"), 4, 0, 1, 1),
                (self.DeviceFilter, 4, 1, 1, 4),
                (Qt.QLabel("Attribute:"), 4, 5, 1, 1),
                (self.AttributeFilter, 4, 6, 1, 4),
                (self.update, 4, 10, 1, 1),
                (self.archivecheck, 4, 11, 1, 2),
            )
        ]

        if SHOW_OPTIONS:
            self.options = Qt.QWidget()  #self.searchbar
            self.options.setLayout(Qt.QGridLayout())
            separator = lambda x: Qt.QLabel(' ' * x)
            row = 1
            [
                self.options.layout().addWidget(o, x, y, h, w)
                for o, x, y, h, w in (
                    #separator(120),Qt.QLabel("Options: "),separator(5),
                    (Qt.QLabel("Server: "), row, 0, 1, 1),
                    (self.ServerFilter, row, 1, 1, 4),
                    (Qt.QLabel(''), row, 2, 1, 11))
            ]
            #self.panel = generate_table(load_all_thermocouples('SR14')[-1])
            self.optiontab = Qt.QTabWidget()
            self.optiontab.addTab(self.searchbar, 'Filters')
            self.optiontab.addTab(self.options, 'Options')
            self.optiontab.setMaximumHeight(100)
            self.optiontab.setTabPosition(self.optiontab.North)
            self.browser.layout().addWidget(self.optiontab)

        else:
            self.browser.layout().addWidget(self.searchbar)

        self.toppan = Qt.QWidget(self)
        self.toppan.setLayout(Qt.QVBoxLayout())

        if USE_SCROLL:
            print '*' * 30 + ' USE_SCROLL=True ' + '*' * 30
            ## TO USE SCROLL, HEADER HAS BEEN SET AS A SEPARATE WIDGET
            #self.header = QGridTable(self.toppan)
            #self.header.setHorizontalHeaderLabels(self.LABELS)
            #self.header.setColumnWidth(0,350)
            self.headers = []
            self.header = Qt.QWidget(self.toppan)
            self.header.setLayout(Qt.QHBoxLayout())
            for l, s in zip(self.LABELS, self.SIZES):
                ql = Qt.QLabel(l)
                self.headers.append(ql)
                #if s is not None:
                #ql.setFixedWidth(s)
                #else:
                #ql.setSizePolicy(Qt.QSizePolicy.MinimumExpanding,Qt.QSizePolicy.Fixed)
                self.header.layout().addWidget(ql)

            self.toppan.layout().addWidget(self.header)

            self._scroll = MyScrollArea(self.toppan)  #Qt.QScrollArea(self)
            self._background = AttributesPanel(
                self._scroll
            )  #At least a panel should be kept (never deleted) in background to not crash the worker!
            self.panel = None
            self._scroll.setChildrenPanel(self.panel)
            self._scroll.setWidget(self.panel)
            self._scroll.setMaximumHeight(700)
            self.toppan.layout().addWidget(self._scroll)
            self.attrpanel = self._background
        else:
            self.panel = AttributesPanel(self.toppan)
            self.toppan.layout().addWidget(self.panel)
            self.attrpanel = self.panel

        self.toppan.layout().addWidget(
            Qt.QLabel(
                'Drag any attribute from the first column into the trend or any taurus widget you want:'
            ))

        self.browser.layout().addWidget(self.toppan)
        self.chooser.addTab(self.browser, 'Search ...')

        if USE_TREND:
            self.split = Qt.QSplitter(Qt.Qt.Vertical)
            self.split.setHandleWidth(25)
            self.split.addWidget(self.chooser)

            from taurus.qt.qtgui.plot import TaurusTrend
            from PyTangoArchiving.widget.trend import ArchivingTrend, ArchivingTrendWidget
            self.trend = ArchivingTrendWidget()  #TaurusArchivingTrend()
            self.trend.setUseArchiving(True)
            self.trend.showLegend(True)
            self.attrpanel.trend = self.trend

            if TaurusModelChooser is not None:
                self.treemodel = TaurusModelChooser(parent=self.chooser)
                self.chooser.addTab(self.treemodel, 'Tree')
                self.treemodel.updateModels.connect(self.trend.addModels)
                #self.treemodel.connect(self.treemodel,Qt.SIGNAL('updateModels'),self.trend.addModels)
            else:
                tracer('TaurusModelChooser not available!')

            self.split.addWidget(self.trend)
            self.layout().addWidget(self.split)
        else:
            self.layout().addWidget(self.chooser)
        type(self)._persistent_ = self
    def generateTable(self, values):

        #thermocouples = thermocouples if thermocouples is not None else self.thermocouples
        self.setRowCount(len(values))
        self.setColumnCount(5)
        #self.vheaders = []
        self.offset = 0
        self.widgetbuffer = []

        for i, tc in enumerate(sorted(values)):
            #print 'setTableRow(%s,%s)'%(i,tc)
            model, device, attribute, alias, archived, ok = tc
            model, device, attribute, alias = map(
                str.upper, (model, device, attribute, alias))

            #self.vheaders.append(model)
            def ITEM(m, model='', size=0):
                q = fandango.qt.Draggable(Qt.QLabel)(m)
                if size is not 0:
                    q.setMinimumWidth(size)  #(.7*950/5.)
                q._model = model
                q._archived = archived
                q.setDragEventCallback(lambda s=q: s._model)
                return q

            ###################################################################
            qf = Qt.QFrame()
            qf.setLayout(Qt.QGridLayout())
            qf.setMinimumWidth(self.SIZES[0])
            qf.setSizePolicy(Qt.QSizePolicy.Expanding, Qt.QSizePolicy.Fixed)
            #Order changed, it is not clear if it has to be done before or after adding TaurusValue selfect
            self.setCellWidget(i + self.offset, 0, qf)

            #print('Adding item: %s, %s, %s, %s, %s' % (model,device,attribute,alias,archived))
            if ok:
                tv = TaurusValue()  #TaurusValueLabel()
                qf.layout().addWidget(tv, 0, 0)
                tv.setParent(qf)
            else:
                self.setItem(i + self.offset, 0, ITEM(model, model))

            devlabel = ITEM(device, model, self.SIZES[1])
            self.setItem(i + self.offset, 1, devlabel)
            self.setItem(i + self.offset, 2,
                         ITEM(attribute, model, self.SIZES[2]))
            self.setItem(i + self.offset, 3, ITEM(alias, model, self.SIZES[3]))

            from PyTangoArchiving.widget.panel import showArchivingModes, show_history
            if archived:
                active = self.reader.is_attribute_archived(model, active=True)
                txt = '/'.join(a.upper() if a in active else a
                               for a in archived)
            else:
                txt = '...'
            q = Qt.QPushButton(txt)
            q.setFixedWidth(self.SIZES[-2])
            q.setToolTip("""%s<br><br><pre>
              'HDB' : Archived and updated, push to export values
              'hdb' : Archiving stopped, push to export values
              '...' : Not archived
              </pre>""" % txt)
            self.connect(q,
                         Qt.SIGNAL("pressed ()"),
                         lambda a=self.reader.get_attribute_alias(
                             model), o=q: setattr(q, 'w', show_history(a))
                         )  #showArchivingModes(a,parent=self)))
            self.setItem(i + self.offset, 4, q)

            qc = Qt.QCheckBox()
            qc.setFixedWidth(self.SIZES[-1])
            self.setItem(i + self.offset, 5, qc, 1, 1, Qt.Qt.AlignCenter,
                         model)

            if ok:
                #print('Setting Model %s'%model)
                #ADDING WIDGETS IN BACKGROUND DIDN'T WORKED, I JUST CAN SET MODELS FROM THE WORKER
                try:
                    if self.worker:
                        self.worker.put([(lambda w=tv, m=model: w.setModel(m))
                                         ])
                        #print 'worker,put,%s'%str(model)
                    else:
                        tv.setModel(model)
                except:
                    print traceback.format_exc()
                self.models.append(tv)

            #self.widgetbuffer.extend([qf,self.itemAt(i+self.offset,1),self.itemAt(i+self.offset,2),self.itemAt(i+self.offset,3),self.itemAt(i+self.offset,4)])
            fandango.threads.Event().wait(.02)

        if len(values):

            def setup(o=self):
                [o.setRowHeight(i, 20) for i in range(o.rowCount())]
                #o.setColumnWidth(0,350)
                o.update()
                o.repaint()
                #print o.rowCount()
                o.show()

            setup(self)

        if self.worker:
            print('%s.next()' % (self.worker))
            self.worker.next()

        #threading.Event().wait(10.)
        tracer('Out of generateTable()')
 def setupUi(self,USE_SCROLL=False,SHOW_OPTIONS=True,USE_TREND=False):
     self.setWindowTitle('Tango Finder : Search Attributes and Archiving')
     self.setLayout(Qt.QVBoxLayout())
     self.setMinimumWidth(950)#550)
     #self.setMinimumHeight(700)
     self.layout().setAlignment(Qt.Qt.AlignTop)
     self.chooser = Qt.QFrame()
     self.chooser.setLayout(Qt.QHBoxLayout())
     self.combo = Qt.QComboBox() #(self)
     #self.chooser.layout().addWidget(Qt.QLabel('Choose a domain to see temperatures status:'))
     #self.chooser.layout().addWidget(self.combo)
     #self.layout().addWidget(self.chooser)
     if True:
         self.searchbar = Qt.QFrame()
         self.searchbar.setLayout(Qt.QGridLayout()) 
         self.label = Qt.QLabel('Type a part of device name and a part of attribute name, use "*" or " " as wildcards:')
         #self.search = Qt.QLineEdit()
         self.ServerFilter = Qt.QLineEdit()
         self.ServerFilter.setMaximumWidth(250)
         self.DeviceFilter = fandango.qt.Dropable(Qt.QLineEdit)()
         self.DeviceFilter.setSupportedMimeTypes(fandango.qt.TAURUS_DEV_MIME_TYPE)
         self.AttributeFilter = fandango.qt.Dropable(Qt.QLineEdit)()
         self.AttributeFilter.setSupportedMimeTypes([fandango.qt.TAURUS_ATTR_MIME_TYPE,fandango.qt.TEXT_MIME_TYPE])
         self.update = Qt.QPushButton('Update')
         self.archivecheck = Qt.QCheckBox("Show archived attributes only")
         self.archivecheck.setChecked(False)
         self.layout().addWidget(self.label)
         [self.searchbar.layout().addWidget(o,x,y,h,w) for o,x,y,h,w in (
             (Qt.QLabel("Device or Alias:"),0,0,1,1),(self.DeviceFilter,0,1,1,4),
             (Qt.QLabel("Attribute:"),0,5,1,1),(self.AttributeFilter,0,6,1,4),
             (self.update,0,10,1,1),(self.archivecheck,0,11,1,2),
             )]
         self.searchbar.layout().addWidget(Qt.QLabel('Enter Device and Attribute filters using wildcards (e.g. li/ct/plc[0-9]+ / ^stat*$ & !status ) and push Update'),1,0,4,13)
         if SHOW_OPTIONS:
             self.options = Qt.QWidget() #self.searchbar
             self.options.setLayout(Qt.QGridLayout())
             separator = lambda x:Qt.QLabel(' '*x)
             row = 1
             [self.options.layout().addWidget(o,x,y,h,w) for o,x,y,h,w in (
                 #separator(120),Qt.QLabel("Options: "),separator(5),
                 (Qt.QLabel("Server: "),row,0,1,1),(self.ServerFilter,row,1,1,4),(Qt.QLabel(''),row,2,1,11)
                 )]
             #self.panel = generate_table(load_all_thermocouples('SR14')[-1])
             self.optiontab = Qt.QTabWidget()
             self.optiontab.addTab(self.searchbar,'Filters')
             self.optiontab.addTab(self.options,'Options')
             self.optiontab.setMaximumHeight(100)
             self.optiontab.setTabPosition(self.optiontab.North)
             self.layout().addWidget(self.optiontab)
         else: self.layout().addWidget(self.searchbar)
         
     self.toppan = Qt.QWidget(self)
     self.toppan.setLayout(Qt.QVBoxLayout())
     if True:
         self.header = QGridTable(self.toppan)
         self.header.setHorizontalHeaderLabels('Label/Value Device Attribute Alias Archiving'.split())
         self.header.setColumnWidth(0,350)
         self.toppan.layout().addWidget(self.header)
     
     if USE_SCROLL:
         print '*'*30 + ' USE_SCROLL=True '+'*'*30
         self._scroll = MyScrollArea(self.toppan)#Qt.QScrollArea(self)
         self._background = AttributesPanel(self._scroll) #At least a panel should be kept (never deleted) in background to not crash the worker!
         self.panel = None
         self._scroll.setChildrenPanel(self.panel)
         self._scroll.setWidget(self.panel)
         self._scroll.setMaximumHeight(700)
         self.toppan.layout().addWidget(self._scroll)
     else:
         self.panel = AttributesPanel(self.toppan)
         self.toppan.layout().addWidget(self.panel)
         
     self.toppan.layout().addWidget(Qt.QLabel('Drag any attribute from the first column into the trend or any taurus widget you want:'))
     
     if USE_TREND:
         self.split = Qt.QSplitter(Qt.Qt.Vertical)
         self.split.setHandleWidth(10)
         self.split.addWidget(self.toppan)
         
         from taurus.qt.qtgui.plot import TaurusTrend
         from PyTangoArchiving.widget.trend import ArchivingTrend,ArchivingTrendWidget
         self.trend = ArchivingTrendWidget() #TaurusArchivingTrend()
         self.trend.setUseArchiving(True)
         self.trend.showLegend(True)
         self.split.addWidget(self.trend)
         self.layout().addWidget(self.split)
     else:
         self.layout().addWidget(self.toppan)
     type(self)._persistent_ = self