Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Changing qwt5.TaurusPlot curves legend titles? #1165

Open
hayg25 opened this issue Dec 3, 2020 · 13 comments
Open

Changing qwt5.TaurusPlot curves legend titles? #1165

hayg25 opened this issue Dec 3, 2020 · 13 comments
Labels
py2 This issue affects especifically to python2 support PyQt4 this issue is specific of PyQt4 support question

Comments

@hayg25
Copy link

hayg25 commented Dec 3, 2020

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

@cpascual
Copy link
Member

cpascual commented Dec 3, 2020

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

  • you want to do it from the user interface or programmatically? (Iguess programmatically, because you say "in my code")
  • what widget are you using (the old qwt5 implementation or the new taurus_pyqtgraph one) ?
  • what kind of modification you have in mind (move it around, altering the appearance, changing curve names,...)?

@hayg25
Copy link
Author

hayg25 commented Dec 3, 2020

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
Copy link
Member

cpascual commented Dec 3, 2020

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
Copy link
Author

hayg25 commented Dec 3, 2020

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
Copy link
Member

cpascual commented Dec 4, 2020

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:

  • taurus.qt.qtgui.qwt5.TaurusPlot.setCurvesTitle()
  • taurus.qt.qtgui.qwt5.TaurusPlot.setDefaultCurvesTitle()
  • taurus.qt.qtgui.qwt5.TaurusCurve.setTitleText()
  • taurus.qt.qtgui.qwt5.TaurusPlot.changeCurvesTitlesDialog

@cpascual cpascual changed the title TaurosPlot curves legend TaurusPlot curves legend Dec 4, 2020
@cpascual cpascual changed the title TaurusPlot curves legend Changing qwt5.TaurusPlot curves legend titles? Dec 4, 2020
@cpascual
Copy link
Member

cpascual commented Dec 4, 2020

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.

@cpascual cpascual added py2 This issue affects especifically to python2 support PyQt4 this issue is specific of PyQt4 support labels Dec 4, 2020
@hayg25
Copy link
Author

hayg25 commented Dec 4, 2020

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
Copy link
Member

cpascual commented Dec 4, 2020

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
Copy link
Author

hayg25 commented Dec 4, 2020

many thanks for the feedback

@hayg25 hayg25 closed this as completed Dec 4, 2020
@hayg25
Copy link
Author

hayg25 commented Dec 15, 2020

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

@hayg25 hayg25 reopened this Dec 15, 2020
@cpascual
Copy link
Member

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
Copy link
Author

hayg25 commented Feb 2, 2021

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
Copy link
Member

cpascual commented Feb 3, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
py2 This issue affects especifically to python2 support PyQt4 this issue is specific of PyQt4 support question
Projects
None yet
Development

No branches or pull requests

2 participants