Esempio n. 1
0
class CyclePanel(TaurusWidget):
    "Panel for controlling the cycling functionality"

    trend_trigger = QtCore.pyqtSignal(bool)

    attrs = [
        "CyclingTimePlateau", "CyclingIterations", "CyclingSteps",
        "CyclingRampTime", "NominalSetPoint"
    ]
    scale_factor = 1.1

    def __init__(self, parent=None):
        TaurusWidget.__init__(self, parent)
        self._setup_ui()
        print('CyclePanel juste avant setmodel')

    #    self.setModel('sys/tg_test/1')

    def scaleSize(self):
        size = self.form.scrollArea.widget().frameSize()
        return QtCore.QSize(size.width(), size.height() * self.scale_factor)

    def _setup_ui(self):
        vbox = QtGui.QVBoxLayout(self)
        self.setLayout(vbox)

        grid = QtGui.QGridLayout()
        self.form = MAXForm(withButtons=False)

        grid.addWidget(self.form, 0, 0, 2, 1)
        # rescale taurus form methode
        self.form.scrollArea.sizeHint = self.scaleSize
        self.status_label = StatusArea()
        grid.addWidget(self.status_label, 0, 1, 1, 1)

        commandbox = QtGui.QVBoxLayout(self)
        self.start_button = TaurusCommandButton(command="StartCycle")
        self.start_button.setUseParentModel(True)
        self.stop_button = TaurusCommandButton(command="StopCycle")
        self.stop_button.setUseParentModel(True)
        commandbox.addWidget(self.start_button)
        commandbox.addWidget(self.stop_button)
        grid.addLayout(commandbox, 1, 1, 1, 1)

        vbox.addLayout(grid)

        self.trend = TaurusTrend()
        vbox.addWidget(self.trend, stretch=1)
        self.trend_trigger.connect(self.set_trend_paused)

        self.cyclingState = None

    def setModel(self, device):
        print self.__class__.__name__, "setModel", device
        TaurusWidget.setModel(self, device)
        # self.state_button.setModel(device)
        if device:
            self.form.setModel(
                ["%s/%s" % (device, attribute) for attribute in self.attrs])

            self.status_label.setModel("%s/cyclingStatus" % device)

            ps = str(PyTango.Database().get_device_property(
                device, "PowerSupplyProxy")["PowerSupplyProxy"][0])

            self.trend.setPaused()
            self.trend.setModel(["%s/Current" % ps])
            self.trend.setForcedReadingPeriod(0.2)
            self.trend.showLegend(True)

            # let's pause the trend when not cycling
            self.cyclingState = self.getModelObj().getAttribute("cyclingState")
            self.cyclingState.addListener(self.handle_cycling_state)
        else:
            if self.cyclingState:
                self.cyclingState.removeListener(self.handle_cycling_state)
            self.trend.setModel(None)
            self.status_label.setModel(None)

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

    def set_trend_paused(self, value):
        self.trend.setForcedReadingPeriod(0.2 if value else -1)
        self.trend.setPaused(not value)