Exemplo n.º 1
0
def test_form_cwidget_bck_compat(qtbot):
    """check that the cusomWidgetMap bck-compat works"""

    w = TaurusForm()
    qtbot.addWidget(w)

    # check that custom widget map is empty by default
    assert w.getCustomWidgetMap() == {}

    w.setItemFactories(include=())

    try:
        # check that an explicit call to setCustomWidgetMap works
        dummy = ("taurus.qt.qtgui.panel.test.test_taurusform._DummyTV", (), {})
        w.setCustomWidgetMap({"DataBase": dummy})
        w.setModel(["tango:sys/database/2", "tango:sys/tg_test/1"])
        qtbot.wait_until(lambda: len(w) == 2, timeout=3200)
        assert type(w[0]) == _DummyTV
        assert type(w[1]) == TaurusValue
        assert w.getCustomWidgetMap() == {"DataBase": dummy}

        # check that the custom widget map can be restored
        w.setCustomWidgetMap({})
        w.setModel(["tango:sys/database/2", "tango:sys/tg_test/1"])
        qtbot.wait_until(lambda: len(w) == 2, timeout=3200)
        assert type(w[0]) == TaurusValue
        assert type(w[1]) == TaurusValue
        assert w.getCustomWidgetMap() == {}
    finally:
        # set model to None as an attempt to avoid problems in atexit()
        w.setModel(None)
        qtbot.wait_until(lambda: len(w) == 0, timeout=3200)
Exemplo n.º 2
0
def test_form():
    from taurus.qt.qtgui.panel import TaurusForm
    tgclass_map = {'IORegister': PoolIORegisterTV}
    form = TaurusForm()
    form.setCustomWidgetMap(tgclass_map)
    model = 'tango://controls02:10000/ioregister/gc_tgiorctrl/1'
    if len(sys.argv) > 1:
        model = sys.argv[1]

    form.setModel([model])
    form.show()
Exemplo n.º 3
0
def test_form():
    from taurus.qt.qtgui.panel import TaurusForm
    tgclass_map = {'IORegister': PoolIORegisterTV}
    form = TaurusForm()
    form.setCustomWidgetMap(tgclass_map)
    model = 'tango://controls02:10000/ioregister/gc_tgiorctrl/1'
    if len(sys.argv) > 1:
        model = sys.argv[1]

    form.setModel([model])
    form.show()
Exemplo n.º 4
0
    def _updateTaurusValue(self):
        m = self.getModelName()
        self._TaurusValue.setModel("%s/value" % m)
        self._devButton.setModel(m)


if __name__ == "__main__":
    import sys
    argv = sys.argv
    if len(argv) > 0:
        models = argv[1:]
    app = Qt.QApplication(sys.argv)

    form_tv = TaurusForm()
    form_tv.setModifiableByUser(True)
    tv_widget_class = "sardana.taurus.qt.qtgui.extra_pool.PoolChannelTV"
    tv_class_map = {
        "CTExpChannel": (tv_widget_class, (), {}),
        "OneDExpChannel": (tv_widget_class, (), {}),
        "TwoDExpChannel": (tv_widget_class, (), {})
    }
    form_tv.setCustomWidgetMap(tv_class_map)
    form_tv.setModel(models)

    w = Qt.QWidget()
    w.setLayout(Qt.QVBoxLayout())
    w.layout().addWidget(form_tv)

    w.show()
    sys.exit(app.exec_())
Exemplo n.º 5
0
class IORUserPanel(TaurusWidget):

    """Widget to use the IOR"""

    def __init__(self, parent=None):
        TaurusWidget.__init__(self, parent)
        self._setup_ui()
        self.ior_model = None
        self.mot_model = None
        self.options = []
        self.dict =  {}

    def updateBoxes(self,arg):
        """ If receive signal to update the options, adjust the model"""
        if self.ior_model is not None and self.mot_model is not None : #only do it once initialised
            self.setModel(self.ior_model, self.mot_model,firstcall=False,updateIOR=True)

    def _setup_ui(self):

        self.gridLayout = QtGui.QGridLayout(self)
        self.taurusForm = TaurusForm(self)


        #form for the standard IOR widget
        self.taurusForm.setWithButtons(False)
        self.gridLayout.addWidget(self.taurusForm, 0, 0, 1, 2)

        #form for the standard motor widget
        self.taurusForm2 = TaurusForm(self)
        self.taurusForm2.setWithButtons(False)
        self.gridLayout.addWidget(self.taurusForm2, 1, 0, 1, 2)

        #form with a custom combo box - can replace the standard IOR widget
        #self.comboBox = TaurusValueComboBox(self)
        #self.comboBox.setAutoApply(True)
        #self.gridLayout.addWidget(self.comboBox, 2, 0, 1, 2)

        #self.label = TaurusLabel(self)
        #self.gridLayout.addWidget(self.label, 0, 1, 1, 1)

    def setModel(self, ior, mot, firstcall=False,updateIOR=False):

        self.ior_model = ior
        self.mot_model = mot
        self.updateIOR = updateIOR
        self.firstcall = firstcall

        #If we triggered a change, have the labels really changed, if so set model
        updated = False
        if self.firstcall or self.updateIOR:

            options = [(option.split(":")[0], option.split(":")[1])
                       for option in (taurus.Attribute(ior+"/Labels").read().value).split()]

            if options != self.options:
                updated = True
                self.options = options
                for opt in self.options:
                    self.dict[opt[0]] = opt[1]
                    #self.comboBox.setValueNames(self.options)

            #set the IOR widget
            try:
                self.taurusForm.setCustomWidgetMap(getattr(tauruscustomsettings,'T_FORM_CUSTOM_WIDGET_MAP',{}))
            except NameError:
                self.taurusForm.setCustomWidgetMap(getattr(TaurusCustomSettings,'T_FORM_CUSTOM_WIDGET_MAP',{}))
            self.taurusForm.setModel([self.ior_model])

            #set the motor widget
            try:
                self.taurusForm2.setCustomWidgetMap(getattr(tauruscustomsettings,'T_FORM_CUSTOM_WIDGET_MAP',{}))
            except NameError:
                self.taurusForm2.setCustomWidgetMap(getattr(TaurusCustomSettings,'T_FORM_CUSTOM_WIDGET_MAP',{}))
            self.taurusForm2.setModel([self.mot_model])

            if self.firstcall:

                #make ior widget auto apply settings
                for widget in self.taurusForm:
                    widget.writeWidget().setAutoApply(True)

                #connect combo box changes to method below
                #self.connect(self.comboBox, QtCore.SIGNAL('currentIndexChanged(const int &)'), self.indexChanged)

                #fill label
                #self.label.setModel(taurus.Attribute(ior+"/Value"))
                #get taurus attribute which is value and also motor pos
                self.position_ior = taurus.Attribute(ior+"/Value")
Exemplo n.º 6
0
def taurusFormMain():
    """A launcher for TaurusForm."""

    from taurus.qt.qtgui.panel import TaurusForm
    from taurus.external.qt import Qt
    from functools import partial

    parser = argparse.get_taurus_parser()
    parser.set_usage("%prog [options] [model1 [model2 ...]]")
    parser.set_description("the taurus form panel application")
    parser.add_option("--window-name",
                      dest="window_name",
                      default="TaurusForm",
                      help="Name of the window")
    parser.add_option("--config",
                      "--config-file",
                      dest="config_file",
                      default=None,
                      help="use the given config file for initialization")
    app = TaurusApplication(cmd_line_parser=parser,
                            app_name="taurusform",
                            app_version=Release.version)
    args = app.get_command_line_args()
    options = app.get_command_line_options()

    dialog = TaurusForm()
    dialog.setModifiableByUser(True)
    dialog.setModelInConfig(True)
    dialog.setWindowTitle(options.window_name)

    # Make sure the window size and position are restored
    dialog.registerConfigProperty(dialog.saveGeometry, dialog.restoreGeometry,
                                  'MainWindowGeometry')

    quitApplicationAction = Qt.QAction(Qt.QIcon.fromTheme("process-stop"),
                                       'Close Form', dialog)
    quitApplicationAction.triggered.connect(dialog.close)

    saveConfigAction = Qt.QAction("Save current settings...", dialog)
    saveConfigAction.setShortcut(Qt.QKeySequence.Save)
    saveConfigAction.triggered.connect(
        partial(dialog.saveConfigFile, ofile=None))
    loadConfigAction = Qt.QAction("&Retrieve saved settings...", dialog)
    loadConfigAction.setShortcut(Qt.QKeySequence.Open)
    loadConfigAction.triggered.connect(
        partial(dialog.loadConfigFile, ifile=None))

    dialog.addActions(
        (saveConfigAction, loadConfigAction, quitApplicationAction))

    # set the default map for this installation
    from taurus import tauruscustomsettings
    dialog.setCustomWidgetMap(
        getattr(tauruscustomsettings, 'T_FORM_CUSTOM_WIDGET_MAP', {}))

    # set a model list from the command line or launch the chooser
    if options.config_file is not None:
        dialog.loadConfigFile(options.config_file)
    elif len(args) > 0:
        models = args
        dialog.setModel(models)
    else:
        dialog.chooseModels()

    dialog.show()

    sys.exit(app.exec_())