taurus-org / taurus

Moved to https://gitlab.com/taurus-org/taurus
http://taurus-scada.org
43 stars 46 forks source link

Update TaurusForm #1130

Closed hayg25 closed 3 years ago

hayg25 commented 3 years ago

Dear All, I try to update a TaurusForm using TaurusAttrListComboBox(): see the code below

        self.Combo = TaurusAttrListComboBox()
        self.Combo.addItems(["PiC","PrC","PiS","PrS","QS","PS","PhD"])

        self.Combo.currentIndexChanged.connect(self.selectionchange)
        self.Combo_current_index = 0
        self.form = TaurusForm()
                self.form.setModel(initial_Model)

    def selectionchange(self,i):
        print "Items in the list are :"

        for count in range(self.Combo.count()):
            print self.Combo.itemText(count)
        print "Current index",i,"selection changed ",self.Combo.currentText()
        # updated_Model depends on the Combo choice 
        self.form.parentModelChanged(updated_Model[i])

I tried to update it using parentModelChanged and I failed to update. I also tried resetModel same problem with additional error message : TaurusForm: Cannot handle model "State". Using default widget.

Thanks for the feedback

cpascual commented 3 years ago

Hi, can't say for sure, but it looks like you are trying to use a TaurusAttrListComboBox for something that is not its purpose. You are not suppossed to call addItems on a TaurusAttrListComboBox. Instead, a TaurusAttrListComboBox populates itself from the value of the taurus attribute it has as its model. I think that for your purposes, (assuming that the ["PiC","PrC","PiS","PrS","QS","PS","PhD"] list is not coming from a Taurus Attribute), you should use a pure Qt QComboBox instead...

Then I see another issue in your code which is your call to self.form.parentModelChanged(updated_Model[i]). As a first warning, using the "parent model API" is already discouraged... but I cannot give more specific hints because without an explanation of what updated_Model is, I cannot understand exactly what do you want to achieve. Maybe if you give us a bit of context (basically helping us understanding what do you intend to do) we could be of more help.

hayg25 commented 3 years ago

Hi @cpascual, Basically what I have HF signals from different boards ["PiC","PrC","PiS","PrS","QS","PS","PhD"]. Each element corresponds to a Device Server (7 device servers in this example). What I want, is to access to the HF signal board parameters from a TaurusForm, and switch from board to board (by changing the device server ID) by using the ComboBox.
Ok I try to use a pure Qt QComboBox. May be you have other way to display the Panel ? Like using N = 7 buttons ?

cpascual commented 3 years ago

In your situation, I see 2 main approaches

The first is the simplest and more compact and intuitive, and also is the most responsive if you change the viewed device often, because the forms are always ready. On the down side, it takes a bit more time to initialize at the beguinning and does not scale well if you have a lot of devices and/or attributes.

Note1: the first approach can be implemented without coding by simply populating a TaurusGui with the 7 forms and ordering the panels as tabs

On July 23, 2020 8:32:34 AM GMT+01:00, Guler Hayg notifications@github.com wrote:

Hi @cpascual, Basically what I have HF signals from different boards ["PiC","PrC","PiS","PrS","QS","PS","PhD"]. Each element corresponds to a Device Server (7 device servers in this example). What I want, is to access to the HF signal board parameters from a TaurusForm, and switch from board to board (by changing the device server ID) by using the ComboBox.
Ok I try to use a pure Qt QComboBox. May be you have other way to display the Panel ? Like using N = 7 buttons ?

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/taurus-org/taurus/issues/1130#issuecomment-662860809

hayg25 commented 3 years ago

Thanks @cpascual, could you please provide an example to create the 7 taurusforms from the beginning l and put them in a tab widget, I would like to put them on the side part of my plot.

cpascual commented 3 years ago

could you please provide an example

Here is a working example of what I mean (using 2 forms and dummy eval attributes for the models):

import sys
from taurus.external.qt import Qt
from taurus.qt.qtgui.panel import TaurusForm
from taurus.qt.qtgui.application import TaurusApplication

app = TaurusApplication()

d = {  # map your models for each form here
    "dev1": ["eval:11", "eval:12", "eval:13"],
    "dev2": ["eval:21", "eval:22", "eval:23"],
}

tw = Qt.QTabWidget()

for name, models in d.items():
    f = TaurusForm()
    f.setModel(models)
    tw.addTab(f, name)

tw.show()
sys.exit(app.exec_())

Does it help?

cpascual commented 3 years ago

Also note that if you just want a plot and an explorer of devices, you can use the taurus panel command and you get just that.

Or, for more flexibility, you can create a new GUI with the taurus newgui wizard and add the plot and all the forms with the wizard (without coding) and then just sort them as you wish (e.g. plot on the left and forms tabbed on the right).

hayg25 commented 3 years ago

could you please provide an example

Here is a working example of what I mean (using 2 forms and dummy eval attributes for the models):

import sys
from taurus.external.qt import Qt
from taurus.qt.qtgui.panel import TaurusForm
from taurus.qt.qtgui.application import TaurusApplication

app = TaurusApplication()

d = {  # map your models for each form here
    "dev1": ["eval:11", "eval:12", "eval:13"],
    "dev2": ["eval:21", "eval:22", "eval:23"],
}

tw = Qt.QTabWidget()

for name, models in d.items():
    f = TaurusForm()
    f.setModel(models)
    tw.addTab(f, name)

tw.show()
sys.exit(app.exec_())

Does it help?

Dear @cpascual, many thanks yes that's what I want :) Thanks a lot.