Exemplo n.º 1
0
 def build_diff_table(self, data):
     self.comp._wi.tableWidget.clear()
     cols=7
     self.comp._wi.tableWidget.setColumnCount(cols)
     self.comp._wi.tableWidget.setHorizontalHeaderLabels(["Attribute Name", "RV1", "WV1", "RV2", "WV2", "diff1", "diff2"])
     self.comp._wi.tableWidget.setGeometry(QtCore.QRect(20, 190, 500, 400))
     if data:
         rows=len(data)
         self.comp._wi.tableWidget.setRowCount(rows)
         for row in range(0, rows):
                 for col in range(0, cols):
                     item=QtGui.QTableWidgetItem("%s" % data[row][col])
                     if (data[row][col]==None or data[row][col]=='None'):
                         item=QtGui.QTableWidgetItem("%s" %"X")
                         item.setTextColor(QtGui.QColor(255,0,0))
                     if row%2==0:
                         item.setBackgroundColor(QtGui.QColor(225,225,225))
                     if (col==5 or col==6) and (data[row][col]!=0) and (data[row][col]!='None') and (data[row][col]!=None):
                         item.setBackgroundColor(QtGui.QColor(45,150,255))
                     elif (col==1 or col==2):
                         if (data[row][col]>data[row][col+2]):
                             item.setBackgroundColor(QtGui.QColor(255,0,0))
                         elif(data[row][col]<data[row][col+2]):
                             item.setBackgroundColor(QtGui.QColor(255,255,0))
                     elif (col==3 or col==4):
                         if (data[row][col]>data[row][col-2]):
                             item.setBackgroundColor(QtGui.QColor(255,0,0))
                         elif (data[row][col]<data[row][col-2]):
                             item.setBackgroundColor(QtGui.QColor(255,255,0))
                     self.comp._wi.tableWidget.setItem(row,col,item)
     else:
         self.comp._wi.tableWidget.setRowCount(1)
         item=QtGui.QTableWidgetItem("%s" % QtCore.QString('No Data!'))
         self.comp._wi.tableWidget.setItem(0, 0, item)
     self.comp._wi.tableWidget.resizeColumnsToContents()
Exemplo n.º 2
0
 def __init__(self, parent=None, designMode=False):
     TaurusValueLineEdit.__init__(self, parent, designMode)
     self.setFocusPolicy(QtCore.Qt.WheelFocus)
     self._throttle_timer = QtCore.QTimer()
     self._throttle_timer.setInterval(200)
     self._throttle_timer.setSingleShot(True)
     self.connect(self._throttle_timer, QtCore.SIGNAL("timeout()"),
                  self._writeValue)
     self.w_value_trigger.connect(self._updateWriteValue)
 def __init__(self, parent=None):
     print('In EditTextDialog.__init__()')
     QtGui.QDialog.__init__(self, parent)
     self.setModal(1)
     self.initComponents()
     self.show()
     self.result = 0
     # Signals
     QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"),
                            self.pressOK)
     QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"),
                            self.close)
Exemplo n.º 4
0
    def build_widgets(self,
                      values,
                      show_labels=False,
                      width=240,
                      height=20,
                      value_width=120):
        widgets_matrix = []
        for row in values:
            widgets_row = []
            for cell in row:
                cell_frame = self.create_frame_with_gridlayout()
                count = 0
                for synoptic in sorted(cell):
                    self.debug("processing synoptic %s" % synoptic)
                    name = model = synoptic

                    self.debug('Creating TaurusValue with model =  %s' % model)
                    synoptic_value = TaurusValue(cell_frame)
                    self.modelsQueue.put((synoptic_value, model))
                    QtCore.QObject.connect(
                        synoptic_value, QtCore.SIGNAL("itemClicked(QString)"),
                        self.itemClicked)

                    if self.hideLabels:
                        synoptic_value.setLabelWidgetClass(None)
                    else:
                        # DO NOT DELETE THIS LINE!!!
                        synoptic_value.setLabelConfig('label')
                    cell_frame.layout().addWidget(synoptic_value, count, 0)
                    self._widgets_list.append(synoptic_value)
                    count += 1

                # Done in this way as TauValue.mousePressEvent are never called
                def mousePressEvent(event, obj):
                    # print 'In cell clicked'
                    targets = set(
                        str(child.getModelName()) for child in obj.children()
                        if hasattr(child, 'underMouse') and child.underMouse()
                        and hasattr(child, 'getModelName'))
                    [
                        obj.emit(Qt.SIGNAL("itemClicked(QString)"), t)
                        for t in targets
                    ]

                cell_frame.mousePressEvent = partial(mousePressEvent,
                                                     obj=cell_frame)
                QtCore.QObject.connect(cell_frame,
                                       QtCore.SIGNAL("itemClicked(QString)"),
                                       self.itemClicked)

                widgets_row.append(cell_frame)
            widgets_matrix.append(widgets_row)
        return widgets_matrix
Exemplo n.º 5
0
    def diffSetupUi(self, Form):
        Form.setObjectName("Form")
        self.diffGridLayout = QtGui.QGridLayout(Form)
        self.diffGridLayout.setObjectName("diffGridLayout")
        self.diffSnapLabel = QtGui.QLabel(Form)
        self.diffSnapLabel.setObjectName("diffSnapLabel")
        self.diffGridLayout.addWidget(self.diffSnapLabel, 0, 0, 1, 1)

        self.diffComboBox = QtGui.QComboBox(Form)
        self.diffComboBox.setObjectName("diffComboBox")
        self.diffComboBox.setToolTip(
            QtGui.QApplication.translate("Form", "Choose Second Snapshot",
                                         None, QtGui.QApplication.UnicodeUTF8))
        self.diffGridLayout.addWidget(self.diffComboBox, 0, 1, 1, 6)

        self.diffButtonCompare = QtGui.QPushButton(Form)
        self.diffButtonCompare.setObjectName("diffButtonCompare")
        self.diffGridLayout.addWidget(self.diffButtonCompare, 0, 7, 1, 1)

        self.tableWidget = QtGui.QTableWidget(Form)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(0)
        self.tableWidget.setRowCount(0)
        self.diffGridLayout.addWidget(self.tableWidget, 2, 0, 1, 8)

        self.lowerHorizontalLayout = QtGui.QHBoxLayout()
        self.lowerHorizontalLayout.setObjectName("lowerHorizontalLayout")
        self.minLabel = QtGui.QLabel(Form)
        self.minLabel.setObjectName("minLabel")
        self.minLabel.setMaximumSize(QtCore.QSize(40, 30))
        self.lowerHorizontalLayout.addWidget(self.minLabel)
        self.minLogo = QtGui.QLabel(Form)
        self.minLogo.setObjectName("minLogo")
        self.lowerHorizontalLayout.addWidget(self.minLogo)
        self.maxLabel = QtGui.QLabel(Form)
        self.maxLabel.setObjectName("maxnLabel")
        self.maxLabel.setMaximumSize(QtCore.QSize(40, 30))
        self.lowerHorizontalLayout.addWidget(self.maxLabel)
        self.maxLogo = QtGui.QLabel(Form)
        self.maxLogo.setObjectName("maxLogo")
        self.lowerHorizontalLayout.addWidget(self.maxLogo)
        self.diffLabel = QtGui.QLabel(Form)
        self.diffLabel.setObjectName("diffLabel")
        self.diffLabel.setMaximumSize(QtCore.QSize(40, 30))
        self.lowerHorizontalLayout.addWidget(self.diffLabel)
        self.diffLogo = QtGui.QLabel(Form)
        self.diffLogo.setObjectName("diffLogo")
        self.lowerHorizontalLayout.addWidget(self.diffLogo)
        self.diffGridLayout.addLayout(self.lowerHorizontalLayout, 3, 0, 1, 8)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
Exemplo n.º 6
0
    def __init__(self, parent=None, designMode=False):
        QtGui.QWidget.__init__(self, parent)
        self._command = ""
        self._fontSize = 7
        layout = QtGui.QVBoxLayout(self)

        self._proc = None
        if not designMode:
            self._proc = QtCore.QProcess(self)
            QtCore.QObject.connect(
                self._proc,
                QtCore.SIGNAL("finished(int, QProcess::ExitStatus)"),
                self._commandFinished)
Exemplo n.º 7
0
    def __init__(self, parent=None, designMode=False):
        TaurusWidget.__init__(self, parent, designMode=designMode)
        self._setup_ui()

        self._throttle_timer = QtCore.QTimer()
        self._throttle_timer.setInterval(200)
        self._throttle_timer.setSingleShot(True)
        self.connect(self._throttle_timer, QtCore.SIGNAL("timeout()"),
                     self._writeValue)

        self._value = None

        self._acc_value = 0  # accumulate fast wheel events
        self._last_wheel = 0  # time of last wheel event
Exemplo n.º 8
0
    def retranslateUi(self, Form):
        if Form.ctxID:
            Form.setWindowTitle(
                QtGui.QApplication.translate("Form", "Modify Context", None,
                                             QtGui.QApplication.UnicodeUTF8))
            self.pushButtonCreate.setText(
                QtGui.QApplication.translate("Form", "Modify", None,
                                             QtGui.QApplication.UnicodeUTF8))
            self.pushButtonCreate.setToolTip(
                QtGui.QApplication.translate("Form", "Modify Context", None,
                                             QtGui.QApplication.UnicodeUTF8))
        else:
            Form.setWindowTitle(
                QtGui.QApplication.translate("Form", "Create Context", None,
                                             QtGui.QApplication.UnicodeUTF8))
            self.pushButtonCreate.setText(
                QtGui.QApplication.translate("Form", "Create", None,
                                             QtGui.QApplication.UnicodeUTF8))
            self.pushButtonCreate.setToolTip(
                QtGui.QApplication.translate("Form", "Create Context", None,
                                             QtGui.QApplication.UnicodeUTF8))
        self.pushButtonCancel.setText(
            QtGui.QApplication.translate("Form", "Cancel", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.pushButtonCancel.setToolTip(
            QtGui.QApplication.translate("Form", "Cancel", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.label_name.setText(
            QtGui.QApplication.translate("Form", "Name:", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.label_author.setText(
            QtGui.QApplication.translate("Form", "Author:", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.label_reason.setText(
            QtGui.QApplication.translate("Form", "Reason:", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.label_description.setText(
            QtGui.QApplication.translate("Form", "Description:", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.att_label.setText(
            QtGui.QApplication.translate("Form", "Add / remove attributes:",
                                         None, QtGui.QApplication.UnicodeUTF8))

        QtCore.QObject.connect(self.pushButtonCreate,
                               QtCore.SIGNAL("pressed()"),
                               Form.onCreatePressed)
        QtCore.QObject.connect(self.pushButtonCancel,
                               QtCore.SIGNAL("pressed()"),
                               Form.onCancelPressed)
Exemplo n.º 9
0
 def onEditPressed(self):
     cid = self.getCurrentContext()
     self.CtxEditForm = ContextEditWidget(ctxID=cid)
     QtCore.QObject.connect(self.CtxEditForm,
                            QtCore.SIGNAL("ContextModified(int)"),
                            self.refresh)
     self.CtxEditForm.show()
Exemplo n.º 10
0
    def defineStyle(self):
        """ Defines the initial style for the widget """
        self.setWindowTitle('Properties')
        self.setColumnCount(2)
        self.setRowCount(0)
        self.setGeometry(QtCore.QRect(0, 0, 400, 500))

        self.setColumnWidth(0, 124)
        self.setColumnWidth(1, 254)

        headerItem = QtGui.QTableWidgetItem()
        headerItem.setText(
            QtGui.QApplication.translate("PLCTabWidget", "Property Name", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.setHorizontalHeaderItem(0, headerItem)

        headerItem1 = QtGui.QTableWidgetItem()
        headerItem1.setText(
            QtGui.QApplication.translate("PLCTabWidget", "Value", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.setHorizontalHeaderItem(1, headerItem1)
        hh = self.horizontalHeader()
        if hh.length() > 0:
            try:
                hh.setSectionResizeMode(hh.ResizeToContents)
            except AttributeError:  # PyQt4
                hh.setResizeMode(hh.ResizeToContents)
Exemplo n.º 11
0
 def modifyContext(self, cid):
     print 'In modifyContext(%s)'%cid
     try:
         attributes=[]
         for i in range(self.ui.final_List.count()):
             attributes.append(str(self.ui.final_List.item(i).text()))
         #self.snapapi = SnapAPI()
         self.ctx.name=str(self.ui.line_name.text())
         self.ctx.author=str(self.ui.line_author.text())
         self.ctx.reason=str(self.ui.line_reason.text())
         self.ctx.description=str(self.ui.line_description.text())
         #self.snapapi.db.update_context(self.ctx)
         #self.snapapi.db.update_context_attributes(cid, attributes)
         self.snapapi.modify_context(cid,self.ctx.author,self.ctx.name,
             self.ctx.reason,self.ctx.description,attributes)
     except Exception:
         print traceback.format_exc()
         Qt.QMessageBox.critical(self,"Tango Archiving Problem",
                                 "Could not modify context.<br>" + \
                                 "Was not possible to talk with SnapManager DS.<br>" + \
                                 "Please check if DS is running.")
         return
     Qt.QMessageBox.information(self,"Context","Context modified succesfully!")
     self.emit(QtCore.SIGNAL("ContextModified(int)"), cid)
     self.onCancelPressed()
Exemplo n.º 12
0
 def createNewContext(self):
     try:
         self.snapapi = SnapAPI()
         attributes = []
         for i in range(self.ui.final_List.count()):
             attributes.append(str(self.ui.final_List.item(i).text()))
         self.snapapi.create_context(str(self.ui.line_author.text()),
                                     str(self.ui.line_name.text()),
                                     str(self.ui.line_reason.text()),
                                     str(self.ui.line_description.text()),
                                     attributes)
     except Exception:
         print traceback.format_exc()
         Qt.QMessageBox.critical(self,"Tango Archiving Problem",
                                 "Could not create new context.<br>" + \
                                 "Was not possible to talk with SnapManager DS.<br>" + \
                                 "Please check if DS is running.")
         return
     self.newID = self.snapapi.contexts.keys()[
         len(self.snapapi.contexts.items()) - 1]
     print('un contexte nou: %d' % self.newID)
     self.emit(QtCore.SIGNAL("NewContextCreated(int)"), self.newID)
     self.onCancelPressed()
     Qt.QMessageBox.information(self, "Context",
                                "Context created succesfully!")
 def contextMenuEvent(self, event):
     ''' This function is called when right clicking on qwt plot area. A pop up menu will be
     shown with the available options. '''
     self.info('TaurusPropTable.contextMenuEvent()')
     menu = Qt.QMenu(self)
     configDialogAction = menu.addAction("Add new property")
     self.connect(configDialogAction, QtCore.SIGNAL("triggered()"),
                  self.addProperty)
     configDialogAction = menu.addAction("Delete property")
     self.connect(configDialogAction, QtCore.SIGNAL("triggered()"),
                  self.deleteProperty)
     configDialogAction = menu.addAction("Edit property")
     self.connect(configDialogAction, QtCore.SIGNAL("triggered()"),
                  self.editProperty)
     menu.addSeparator()
     menu.exec_(event.globalPos())
     del menu
Exemplo n.º 14
0
    def __init__(self, parent=None):
        QtGui.QToolBar.__init__(self, parent)
        self.setIconSize(Qt.QSize(30, 30))
        self.SnapApp = snapWidget()
        self.att_table = []
        self.factory = taurus.Factory()
        self.refresh()
        self.refreshTimer = QtCore.QTimer()
        QtCore.QObject.connect(self.refreshTimer, QtCore.SIGNAL("timeout()"),
                               self.refresh)
        self.refreshTimer.start(5000)

        snap = self.SnapApp.show
        self.addAction(Qt.QIcon(":/devices/camera-photo.svg"),
                       "Snapshot Widget", snap)
        self.setMovable(True)
        self.setFloatable(True)
        self.setToolTip("Snapshot Toolbar")
Exemplo n.º 15
0
    def setData(self, data):
        '''
        sets the data object and emits a "dataChanged" signal with the data as the parameter

        :param data: (object) the new value for the Model's data
        '''
        self.__data = data
        self.__isDataSet = True
        self.emit(QtCore.SIGNAL("dataChanged"), self.__data)
Exemplo n.º 16
0
    def disconnectReader(self, slot):
        '''
        unregister a reader

        :param slot: (callable) the slot to which this was connected

        .. seealso:: :meth:`SharedDataManager.disconnectReader`, :meth:`getData`
        '''
        ok = self.disconnect(self, QtCore.SIGNAL("dataChanged"), slot)
        self.__readerSlots.remove((weakref.ref(slot.__self__), slot.__name__))
Exemplo n.º 17
0
    def disconnectWriter(self, writer, signalname):
        '''unregister a writer from this data model

        :param writer: (QObject) object to unregister
        :param signalname: (str) the signal that was registered

        .. seealso:: :meth:`SharedDataManager.disconnectWriter`
        '''
        ok = self.disconnect(writer, QtCore.SIGNAL(signalname), self.setData)
        self.__writerSignals.remove((weakref.ref(writer), signalname))
Exemplo n.º 18
0
 def __init__(self, contextid=None, useInputForComment=False, parent=None):
     QtGui.QPushButton.__init__(self, parent)
     self.setIconSize(Qt.QSize(30, 30))
     self.setIcon(Qt.QIcon(":/devices/camera-photo.svg"))
     self.snapapi = SnapAPI()
     self.contextid = contextid
     self.comment = "AutoSnap"
     self.useInputForComment = useInputForComment
     QtCore.QObject.connect(self, QtCore.SIGNAL("clicked()"), self.snap)
     self.setToolTip("Snapshot for contextid " + str(self.contextid))
Exemplo n.º 19
0
 def __init__(self, parent=None):
     QtGui.QAction.__init__(self, "Fixed range scale", parent)
     self.setCheckable(True)
     self.toggled.connect(self._onToggled)
     self._timer = QtCore.QTimer()
     self._timer.timeout.connect(self.updateRange)
     self._originalXAutoRange = None
     self._viewBox = None
     self._XactionMenu = None
     self._scrollStep = 0.2
Exemplo n.º 20
0
    def connectWriter(self, writer, signalname):
        '''
        Registers the given writer object as a writer of the data. The writer is
        then expected to emit a `QtCore.SIGNAL(signalname)` with the new data as the
        first parameter.

        :param writer: (QObject) object that will change the data
        :param signalname: (str) the signal name that will notify changes
                           of the data

        .. seealso:: :meth:`connectReader`, :meth:`setData`
        '''
        self.connect(writer, QtCore.SIGNAL(signalname), self.setData)
        self.__writerSignals.append((weakref.ref(writer), signalname))
Exemplo n.º 21
0
 def _getWarningWidget(self):
     w = Qt.QWidget()
     layout = QtGui.QHBoxLayout()
     w.setLayout(layout)
     icon = QtGui.QIcon.fromTheme('dialog-warning')
     pixmap = QtGui.QPixmap(icon.pixmap(QtCore.QSize(32, 32)))
     label_icon = QtGui.QLabel()
     label_icon.setPixmap(pixmap)
     label = QtGui.QLabel('This experiment configuration dialog '
                          'updates automatically on external changes!')
     layout.addWidget(label_icon)
     layout.addWidget(label)
     layout.addStretch(1)
     return w
Exemplo n.º 22
0
    def __init__(self, parent=None, designMode=False):
        TaurusWidget.__init__(self, parent=None, designMode=designMode)

        self.loadUi(filename="selectsignal.ui")

        self.signalComboBox = SignalComboBox(self)
        self.signalComboBox.setGeometry(QtCore.QRect(70, 50, 161, 27))
        self.signalComboBox.setObjectName("SignalcomboBox")

        self.signalComboBox.currentIndexChanged['QString'].connect(
            self.onSignalChanged)

        self.doorName = None
        self.door_device = None

        registerExtensions()
Exemplo n.º 23
0
 def buildSnap2Box(self, sid):
     cid = self.getCurrentContext()
     self.comp._wi.diffComboBox.clear()
     try:
         snaps = self.snapapi.db.get_context_snapshots(cid)
     except:
         QtCore.QMessageBox.critical(
             self, "Tango Archiving Problem",
             "Could not talk with SnapManager DS.<br>Please check if DS is running."
         )
     self.comp._wi.diffComboBox.addItem("Actual values")
     for snapshot in snaps:
         if snapshot[0] != sid:
             self.comp._wi.diffComboBox.addItem(
                 "%s : \"%s\"" % (snapshot[1], snapshot[2].split('\n')[0]),
                 QtCore.QVariant(snapshot[0]))
Exemplo n.º 24
0
class StatusArea(TaurusWidget):

    """A (scrolling) text area that displays device status, or any other
    string attribute."""

    statusTrigger = QtCore.pyqtSignal(str)

    def __init__(self, parent=None, down_command=None, up_command=None, state=None):
        TaurusWidget.__init__(self, parent)
        self._setup_ui()

    def _setup_ui(self):

        hbox = QtGui.QVBoxLayout(self)
        self.setLayout(hbox)

        self.status_label = QtGui.QLabel("(No status has been read.)")
        self.status_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
        self.status_label.setWordWrap(True)
        self.status_label.setAlignment(QtCore.Qt.AlignTop)
        status_scroll_area = QtGui.QScrollArea()
        status_scroll_area.setMaximumSize(QtCore.QSize(100000, 100))
        status_scroll_area.setWidgetResizable(True)
        status_scroll_area.setWidget(self.status_label)
        hbox.addWidget(status_scroll_area)
        self.status = None

        self.statusTrigger.connect(self.updateStatus)

    def setModel(self, model):
        if model:
            split_model = model.split("/")
            if len(split_model) < 4:
                self.status = Attribute("%s/Status" % model)
            else:
                self.status = Attribute(model)
            self.status.addListener(self.onStatusChange)
        else:
            self.status and self.status.removeListener(self.onStatusChange)

    def onStatusChange(self, evt_src, evt_type, evt_value):
        if evt_type in [PyTango.EventType.CHANGE_EVENT,
                        PyTango.EventType.PERIODIC_EVENT]:
            self.statusTrigger.emit(evt_value.value)

    def updateStatus(self, status):
        self.status_label.setText(status)
Exemplo n.º 25
0
    def _setup_ui(self):

        hbox = QtGui.QVBoxLayout(self)
        self.setLayout(hbox)

        self.status_label = QtGui.QLabel("(No status has been read.)")
        self.status_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
        self.status_label.setWordWrap(True)
        self.status_label.setAlignment(QtCore.Qt.AlignTop)
        status_scroll_area = QtGui.QScrollArea()
        status_scroll_area.setMaximumSize(QtCore.QSize(100000, 100))
        status_scroll_area.setWidgetResizable(True)
        status_scroll_area.setWidget(self.status_label)
        hbox.addWidget(status_scroll_area)
        self.status = None

        self.statusTrigger.connect(self.updateStatus)
Exemplo n.º 26
0
 def __init__(self,
              useInputForComment=False,
              useWizardForContext=False,
              parent=None):
     QtGui.QPushButton.__init__(self, parent)
     self.setIconSize(Qt.QSize(30, 30))
     self.setIcon(Qt.QIcon(":/devices/camera-photo.svg"))
     self.snapapi = SnapAPI()
     self.contextid = None
     self.model = ""
     self.author = self.getUserName()
     self.name = "AutoSnap_" + time.strftime("%Y_%m_%d_%H%M%S")
     self.reason = "Always a good reason to create an AutoSnap"
     self.description = "Snap for all attributes of " + self.model
     self.comment = "AutoSnap"
     self.useInputForComment = useInputForComment
     self.useWizardForContext = useWizardForContext
     QtCore.QObject.connect(self, QtCore.SIGNAL("clicked()"), self.snap)
     self.setToolTip("Snapshot for device " + self.model)
Exemplo n.º 27
0
    def connectReader(self, slot, readOnConnect=True):
        '''
        Registers the given slot method to receive notifications whenever the
        data is changed.

        :param slot: (callable) a method that will be called when the data changes.
                     This slot will be the receiver of a signal which has the
                     data as its first argument.
        :param readOnConnect: (bool) if True (default) the slot will be called
                              immediately with the current value of the data
                              if the data has been already initialized

        .. seealso:: :meth:`connectWriter`, :meth:`getData`
        '''
        self.connect(self, QtCore.SIGNAL("dataChanged"), slot)
        if readOnConnect and self.__isDataSet:
            slot(self.__data)
        obj = getattr(slot, '__self__', slot)
        self.__readerSlots.append((weakref.ref(obj), slot.__name__))
    def setTable(self, dev_name):
        """
        Fills the table with the names of properties and their values for the
        given device.
        """
        if dev_name is None:
            return  # TODO: the table should be cleaned

        elif self.db is None:
            self.warning('Model must be set before calling setTable')
            return
        QtCore.QObject.disconnect(self, QtCore.SIGNAL("cellChanged(int, int)"),
                                  self.valueChanged)
        dev_name = str(dev_name)
        self.list_prop = list(self.db.get_device_property_list(dev_name, '*'))
        self.setRowCount(len(self.list_prop))
        for i in range(0, len(self.list_prop)):
            elem = self.list_prop[i]
            self.setText(elem, i, 0)
            self.dictionary = self.db.get_device_property(
                dev_name, self.list_prop)
            self.debug('Getting %s properties: %s -> %s', dev_name,
                       self.list_prop, self.dictionary)
            value = self.dictionary[elem]
            self.debug('TaurusPropsTable: property %s is type %s', elem,
                       type(value))
            USE_TABLES = False
            if USE_TABLES:
                self.setPropertyValue(value, i, 1)
            else:
                if not isinstance(value, str):  # not something like an string
                    # adding new lines in between elements in the list
                    value = '\n'.join(str(v) for v in value)
                self.setText(str(value), i, 1)

        self.updateStyle()
        self.dev_name = dev_name
        self.setWindowTitle('%s Properties' % dev_name)
        self.resizeColumnsToContents()
        self.resizeRowsToContents()
Exemplo n.º 29
0
    def defineStyle(self):
        """ Defines the initial style for the widget """
        self.setWindowTitle('Properties')
        self.setColumnCount(2)
        self.setRowCount(0)
        self.setGeometry(QtCore.QRect(0, 0, 400, 500))

        self.setColumnWidth(0, 124)
        self.setColumnWidth(1, 254)

        headerItem = QtGui.QTableWidgetItem()
        headerItem.setText(
            QtGui.QApplication.translate("PLCTabWidget", "Property Name", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.setHorizontalHeaderItem(0, headerItem)

        headerItem1 = QtGui.QTableWidgetItem()
        headerItem1.setText(
            QtGui.QApplication.translate("PLCTabWidget", "Value", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.setHorizontalHeaderItem(1, headerItem1)
        self.horizontalHeader().setResizeMode(
            QtGui.QHeaderView.ResizeToContents)  # .Stretch)
Exemplo n.º 30
0
class ForcedReadTool(QtGui.QAction, BaseConfigurableClass):
    """
    This tool provides a menu option to control the "Forced Read" period of
    Plot data items that implement a `setForcedReadPeriod` method
    (see, e.g. :meth:`TaurusTrendSet.setForcedReadPeriod`).

    The force-read feature consists on forcing periodic attribute reads for
    those attributes being plotted with a :class:`TaurusTrendSet` object.
    This allows to force plotting periodical updates even for attributes
    for which the taurus polling is not enabled.
    Note that this is done at the widget level and therefore does not affect
    the rate of arrival of events for other widgets connected to the same
    attributes

    This tool inserts an action with a spinbox and emits a `valueChanged`
    signal whenever the value is changed.

    The connection between the data items and this tool can be done manually
    (by connecting to the `valueChanged` signal or automatically, if
    :meth:`autoconnect()` is `True` (default). The autoconnection feature works
    by discovering the compliant data items that share associated to the
    plot_item.

    This tool is implemented as an Action, and provides a method to attach it
    to a :class:`pyqtgraph.PlotItem`
    """

    valueChanged = QtCore.pyqtSignal(int)

    def __init__(
        self,
        parent=None,
        period=0,
        text="Change forced read period...",
        autoconnect=True,
    ):
        BaseConfigurableClass.__init__(self)
        QtGui.QAction.__init__(self, text, parent)
        tt = "Period between forced readings.\nSet to 0 to disable"
        self.setToolTip(tt)
        self._period = period
        self._autoconnect = autoconnect

        # register config properties
        self.registerConfigProperty(self.period, self.setPeriod, "period")
        self.registerConfigProperty(
            self.autoconnect, self.setAutoconnect, "autoconnect"
        )

        # internal conections
        self.triggered.connect(self._onTriggered)

    def _onTriggered(self):
        period = self.period()
        period, ok = QtGui.QInputDialog.getInt(
            self.parentWidget(),
            "New read period",
            "Period (in ms) between forced readings.\nSet to 0 to disable",
            period,
            0,
            604800000,
            500,
        )
        if ok:
            self.setPeriod(period)

    def attachToPlotItem(self, plot_item):
        """Use this method to add this tool to a plot

        :param plot_item: (PlotItem)
        """
        menu = plot_item.getViewBox().menu
        menu.addAction(self)
        self.plot_item = plot_item
        # force an update of period for connected trendsets
        self.setPeriod(self.period())
        if self.autoconnect():
            # enable the forced reading also for trendsets added in the future
            try:  # requires https://github.com/pyqtgraph/pyqtgraph/pull/1388
                plot_item.scene().sigItemAdded.connect(self._onAddedItem)
            except AttributeError:
                pass

    def _onAddedItem(self, item):
        if hasattr(item, "setForcedReadPeriod"):
            item.setForcedReadPeriod(self.period())

    def autoconnect(self):
        """Returns autoconnect state

        :return: (bool)
        """
        return self._autoconnect

    def setAutoconnect(self, autoconnect):
        """Set autoconnect state. If True, the tool will autodetect trendsets
        associated to the plot item and will call setForcedReadPeriod
        on each of them for each change. If False, it will only emit a
        valueChanged signal and only those connected to it will be notified
        of changes

        :param autoconnect: (bool)
        """
        self._autoconnect = autoconnect

    def period(self):
        """Returns the current period value (in ms)

        :return: (int)
        """
        return self._period

    def setPeriod(self, period):
        """Change the period value. Use 0 for disabling

        :param period: (int) period in ms
        """
        self._period = period
        # update existing items
        if self.autoconnect() and self.plot_item is not None:
            for item in self.plot_item.listDataItems():
                if hasattr(item, "setForcedReadPeriod"):
                    item.setForcedReadPeriod(period)
        # emit valueChanged
        self.valueChanged.emit(period)
Exemplo n.º 31
0
        return TaurusDevice

    @classmethod
    def getQtDesignerPluginInfo(cls):
        ret = TaurusBaseWidget.getQtDesignerPluginInfo()
        ret['module'] = 'taurus.qt.qtgui.table'
        ret['group'] = 'Taurus Views'
        ret['icon'] = "designer:table.png"
        return ret

    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
    # QT properties
    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

    model = QtCore.pyqtProperty("QString", TaurusBaseWidget.getModel,
                                setModel,
                                TaurusBaseWidget.resetModel)

    useParentModel = QtCore.pyqtProperty("bool",
                                         TaurusBaseWidget.getUseParentModel,
                                         TaurusBaseWidget.setUseParentModel,
                                         TaurusBaseWidget.resetUseParentModel)

    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
    # My methods
    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

    @QtCore.pyqtSlot('QString')
    def setTable(self, dev_name):
        """
        Fills the table with the names of properties and their values for the
Exemplo n.º 32
0
            try:
                if tv and tv.unitsWidget:
                    if boolean:
                        tv.unitsWidget().show()
                    else:
                        tv.unitsWidget().hide()
            except:
                pass
        return self._show_attr_units

    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
    # QT properties
    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

    model = QtCore.pyqtProperty("QStringList", getModel,
                                setModel,
                                resetModel)

    rowlabels = QtCore.pyqtProperty("QString", getRowLabels,
                                    setRowLabels,
                                    resetRowLabels)

    columnlabels = QtCore.pyqtProperty("QString", getColumnLabels,
                                       setColumnLabels,
                                       resetColumnLabels)

    useParentModel = QtCore.pyqtProperty("bool",
                                         TaurusBaseWidget.getUseParentModel,
                                         TaurusBaseWidget.setUseParentModel,
                                         TaurusBaseWidget.resetUseParentModel)