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

strange special characters into TaurusLabel #633

Closed
PhilLAL opened this issue Nov 23, 2017 · 2 comments
Closed

strange special characters into TaurusLabel #633

PhilLAL opened this issue Nov 23, 2017 · 2 comments
Labels

Comments

@PhilLAL
Copy link

PhilLAL commented Nov 23, 2017

Hello,
I have any issue probably linked to utf-8. Also I am pretty sure this is not specific to Taurus, but I probably am tired since I do not find whate is the cause

When I try to print a string with a special character like "°C", it is printed with a first special character before the string "°C".
My file type is "utf-8" :

file accents.py 
accents.py: Python script, UTF-8 Unicode text executable

To give a complete example, here is a test program :

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys

from taurus.external.qt import Qt
from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.container import TaurusWidget


from taurus.qt.qtgui.display import TaurusLabel, TaurusLed
from taurus.qt.qtgui.input import TaurusValueLineEdit, TaurusValueSpinBox, TaurusWheelEdit

class TestAccents(TaurusWidget):
    """
    Label to check accents works.
    """
    def __init__(self, parent=None):
        TaurusWidget.__init__(self, parent=parent)

        waterLabel = TaurusLabel()
        waterRead = TaurusLabel()
        waterUnit = TaurusLabel()

        waterString = 'Water temperature'
#        waterString.decode('utf-8')
        waterLabel.setText(waterString)
        waterRead.setModel('sys/tg_test/1/double_scalar#rvalue.magnitude')

        waterUnitString = '°C'
        waterUnitString.decode('utf-8')
        waterUnit.setText(waterUnitString)

        layout = Qt.QGridLayout()
        self.setLayout(layout)

        layout.addWidget(waterLabel, 0, 0)
        layout.addWidget(waterRead, 0, 1)
        layout.addWidget(waterUnit, 0, 2)


if __name__ == "__main__":
    appTestAccents = TaurusApplication(sys.argv)
    widgetTestAccents = TestAccents()
    widgetTestAccents.show()
    sys.exit(appTestAccents.exec_())

And a
screenshot

@cpascual
Copy link
Member

As you suspected, it is not a Taurus issue but a PyQt4+python2 issue.

In python2 str and utf are different and therefore you should explicitly declare your string as utf:

#!/usr/bin/python
# -*- coding: utf8 -*-
import sys
from PyQt4 import QtGui
app = QtGui.QApplication([])
t = u'°C'  # <-- NOTE THE EXPLICIT UTF declaration using the `u` prefix!
w = QtGui.QLabel()
w.setText(t)
w.show()
sys.exit(app.exec_())

Other comments:

  • In your example, do not use the str.decode('utf-8') call (not needed)
  • In your example you are using TaurusLabels for static text (not associated with a model). I suggest that you use pure QLabels for that instead
  • Also note that in your code you are essentially imitating the work of a TaurusForm. Consider using it. (it will automatically use the unit defined for the attribute)
  • Regarding the support for the "degree" symbol in taurus (pint) units, see this

@PhilLAL
Copy link
Author

PhilLAL commented Nov 24, 2017

Works perfectly.
Sorry for this off-topic question and thank you ! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants