taurus-org / taurus

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

Changing qwt5.TaurusPlot curves legend titles? #1165

Open hayg25 opened 3 years ago

hayg25 commented 3 years ago

Dear all, I would need to modify the curves legend in my code. Thanks for the help

cpascual commented 3 years ago

Hi @hayg25 , In order to be of any help I am afraid I need a bit more info...

hayg25 commented 3 years ago

Hi @cpascual, yes it's in user interface and we use old qwt5. at the moment I used 6 signals so I put a list in the setmodel. But the list is like : Attr_names = ['/ds/path/name/Att_CH0', '..../CH1', '..../CH0', '..../CH1', etc ] so for the plots I see as label : CH0, CH1, CH0, CH1 etc So I need to modify the names to be able to recognize the curves.

Thanks

cpascual commented 3 years ago

Ok, then what you want is explained here: http://taurus-scada.org/users/ui/plot.html#customizing-the-titles-of-the-curves

I hope that helps

hayg25 commented 3 years ago

Thx for your help. I was guessing something similar to setModel() like : setCurvesTitle() to set the title or legend to each curve. because from what I see in your link, it's not done ideogrammatically.

cpascual commented 3 years ago

Oh, sorry, I understood that you wanted it in the UI. What I sent is the UI way to do it. If you want it programmatically, have a look at:

cpascual commented 3 years ago

By the way... I recommend not to waste much time learning the API of qwt5.TaurusPlot. The next taurus release will be python3-only and that means that qwt5-based widgets will only be available in the "frozen" py2 branch. So it s better to use the taurus_pyqtgraph.TaurusPlot implementation.

hayg25 commented 3 years ago

thanks for the answers. Do you believe that taurus_pyqtgraph.TaurusPlot offers more possibilities than qwt5.TaurusPlot? I indeed plan to push for taurus_pyqtgraph but would like to be sure about the benefits. thanks again for your help

cpascual commented 3 years ago

Well... taurus.qt.qtgui.qwt5.TaurusPlot (the old one) is much more stable and robust than taurus_pyqtgraph.TaurusPlot (the new one) because it has been used in production for 10 years, and has some features that are not available in the new one. But it does not work with Qt5 or python3 which means that it is not going to be possible to support in any modern environment. In fact, its development has been frozen in Taurus since at least 3 years already, and it won't be available in the future.

On the other hand, the new one also has some features not available in the old one, and it offers a lot more possibilities in terms of customization. It is actively developed and is the default in Taurus now.

At this point, from the UI point of view the new one might not seem as being as good or polished as the old one, but in terms of programming API it is way better, and in terms of maintainability it is the only option.

hayg25 commented 3 years ago

many thanks for the feedback

hayg25 commented 3 years ago

dear @cpascual , sorry to come back to this issue but I have problem using taurus.qt.qtgui.qwt5.TaurusPlot.setCurvesTitle() since in my case I put an array in setModel() (many attributes I wish to plot) but taurus.qt.qtgui.qwt5.TaurusPlot.setCurvesTitle() does not accept array ...

Thanks again

cpascual commented 3 years ago

Hi

According to the docs for setCurvesTitle it accepts 2 args: a titletext (which may contain placeholders) and the list of curves to which it applies.

If you want to use different titletext for different curves, you need to call it several times:

    def setCurvesTitle(self, titletext, curveNamesList=None):
        '''Changes the titles of current curves.

        :param titletext:      (str) string to use as title for the curves. It may
                               include placeholders as those defined in TaurusCurve.compileTitleText()
        :param curveNamesList: (sequence<str> or iterator<str>) names of the
                               curves to which the title will be changed (if None given , it will apply
                               to all the curves except the raw data ones)

        :return: (caselessDict<str,str>) dictionary with key=curvename and value=newtitle

        .. seealso:: :meth:`changeCurvesTitlesDialog`,
                     :meth:`setDefaultCurvesTitle`, :meth:`TaurusCurve.setTitleText`
        '''
hayg25 commented 3 years ago

Hi @cpascual ,

I have tried that method which works for TaurusPlot() but not for TaurusTrend() on taurus 4.4.

see that simple example :

class GraphiqueTendance(TaurusWidget):
    """
    Graphique affichant deux variables en fonction du temps.
    """
    def __init__(self, parent=None):
        # appel de l'initialisation de la classe parent 
        TaurusWidget.__init__(self, parent=parent)

        ## DEBUT ZONE MODIFIABLE
        # initialisation de l'objet avec ses proprietes
        tendance = TaurusTrend()

        # creation du modele : on peut ajouter plusieurs variables
        modelTendance = ['sys/tg_test/1/long64_scalar', 'sys/tg_test/1/long_scalar']

        # definition des abcisses comme axe du temps
        tendance.setXIsTime(True)  # to show the x values as time

        # création et application d'un cadre visuel sous forme de grille
        layout = Qt.QGridLayout()
        self.setLayout(layout)

        # association objet-device
        tendance.setModel(modelTendance)
        tendance.setCurvesTitle('Curve A', ['sys/tg_test/1/long64_scalar'])
        tendance.setCurvesTitle('Curve B', ['sys/tg_test/1/long_scalar'])
        tendance.setAxisTitle(0, 'Y title')
        tendance.setAxisTitle(2, 'X title')
        layout.addWidget(tendance)

which returns the error message :

  File "graphiqueTendance.py", line 55, in <module>
    widgetGraphiqueTendance = GraphiqueTendance()
  File "graphiqueTendance.py", line 40, in __init__
    tendance.setCurvesTitle('Curve A', ['sys/tg_test/1/long64_scalar'])
  File "/usr/local/lib/python2.7/dist-packages/taurus/qt/qtgui/plot/taurusplot.py", line 3466, in setCurvesTitle
    curve.setTitleText(titletext)
AttributeError: 'NoneType' object has no attribute 'setTitleText'
cpascual commented 3 years ago

The TaurusPlot creates a TaurusCurve for each model, but the TaurusTrend creates a TaurusTrendSet (which in turn contains one or more TaurusCurves) for each model (because TaurusTrend also accepts arrays as its model, and creates a curve for each element of the array).

Have a look at TaurusTrend.setTrendSetsTitles()

PS: note that quite probably the next taurus release won't support qwt5 anymore.