libtraduc.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 ################################################################################
3 #
4 # Copyright Airbus Group SAS 2015
5 # All rigths reserved.
6 #
7 # File Name : libtraduc.py
8 # Authors : Martin Matignon
9 #
10 # If you find any bug or if you have any question please contact
11 # Adolfo Suarez Roos <adolfo.suarez@airbus.com>
12 # Martin Matignon <martin.matignon.external@airbus.com>
13 #
14 #
15 ################################################################################
16 
17 import rospy
18 
19 from python_qt_binding import QtGui
20 from python_qt_binding import QtCore
21 
22 # Wrapping tr() and trUtf8()
23 
24 #############################################################################
25 class Traduc(QtCore.QObject):
26 
27  def __init__(self):
28  QtCore.QObject.__init__(self)
29 
30  def __call__(self, texte, context='MainWindow', disambig=None, n=-1):
31  return QtGui.QApplication.translate(context, texte, disambig,
32  QtGui.QApplication.CodecForTr, n)
33 tr = Traduc()
34 
35 #############################################################################
36 class TraducUtf8(QtCore.QObject):
37 
38  translate = QtCore.Signal()
39 
40  def __init__(self):
41 
42  QtCore.QObject.__init__(self)
43  self.translator = QtCore.QTranslator()
44  self.language = 'en'
45 
46  def load(self, lng_name, qm_file):
47 
48  self.language = lng_name
49  self.translator.load(qm_file)
50 
51  def uppercase(self, text):
52  return text[0].upper()+text[1:]
53 
54  def __call__(self,
55  text,
56  endcharacter='',
57  context='MainWindow',
58  disambig=None,
59  n=-1):
60 
61  trad = self.translator.translate(context, text, disambig,
62  QtGui.QApplication.UnicodeUTF8)
63 
64  if trad == '' or trad == '##########' or trad is None:
65  rospy.logwarn('No translation "en to %s" available for "%s"!'
66  %( self.language, text))
67 
68  text+= endcharacter
69  return text
70  else:
71  trad+= endcharacter
72  return trad
73 
74 trUtf8 = TraducUtf8()


airbus_cobot_gui
Author(s):
autogenerated on Thu Dec 17 2015 11:42:05