translator_widget.py
Go to the documentation of this file.
1 ################################################################################
2 #
3 # Copyright Airbus Group SAS 2015
4 # All rigths reserved.
5 #
6 # File Name : translator_widget.py
7 # Authors : Martin Matignon
8 #
9 # If you find any bug or if you have any question please contact
10 # Adolfo Suarez Roos <adolfo.suarez@airbus.com>
11 # Martin Matignon <martin.matignon.external@airbus.com>
12 #
13 #
14 ################################################################################
15 
16 import rospy
17 import os
18 
19 from airbus_cobot_gui import resources_dir
20 # from airbus_cobot_gui import AccessRights
21 # from airbus_cobot_gui.security.user_account import user_connection_sender, AccessRights
22 from airbus_cobot_gui.account import Privilege, \
23  GUserAccountCommunicate
24 
25 from python_qt_binding.QtGui import *
26 from python_qt_binding.QtCore import *
27 from python_qt_binding import loadUi
28 
29 from libtraduc import trUtf8
30 from airbus_cobot_gui.python_qt_extend import QPopup
31 
32 from translate_generator import TranslateGeneratorWidget
33 
34 class CountryWidget(QPushButton):
35 
36  def __init__(self, parent, country):
37  """! The constructor."""
38  QPushButton.__init__(self, parent)
39 
40  self._parent = parent
41 
42  self.setMinimumSize(QSize(40, 40))
43  self.setMaximumSize(QSize(60, 60))
44  self.setStyleSheet('background-color:rgba(0,0,0,0);')
45 
46  self.flags_dir = resources_dir('icons', 'country_flags')
47 
48  self._country = country
49 
50  ico = QIcon(os.path.join(self.flags_dir, country+'.png'))
51 
52  self.setIconSize(QSize(self.width(),self.height()))
53 
54  self.setIcon(ico)
55 
56  def mousePressEvent(self, event):
57 
58  trans_dir = resources_dir('translations')
59  trUtf8.load(self._country, os.path.join(trans_dir,self._country+'.qm'))
60 
61  trUtf8.translate.emit()
62 
63  self._parent.close()
64 
65 
66 class TranslateGeneratorItem(QPushButton):
67 
68  def __init__(self, parent):
69  """! The constructor."""
70  QPushButton.__init__(self, parent)
71 
72  self._parent = parent
73 
74  self.setMinimumSize(QSize(40, 40))
75  self.setMaximumSize(QSize(60, 60))
76  self.setStyleSheet('background-color:rgba(0,0,0,0);')
77 
78  icon = QIcon(resources_dir('icons', 'country_flags','trad.png'))
79  self.setIconSize(QSize(self.width(),self.height()))
80  self.setIcon(icon)
81 
82  def mousePressEvent(self, event):
83 
84  trans_gene = TranslateGeneratorWidget(self)
85 
86  trans_gene.show()
87 
88  self._parent.close()
89 
90 ## @class ChooseCountryPopup
91 ## @brief User accounts popup ui.
92 class ChooseCountryPopup(QPopup):
93 
94  def __init__(self, parent, translator_hide = False):
95  """! The constructor."""
96 
97  QPopup.__init__(self, parent)
98 
99  self.set_corners_link(QPopup.TopRight, QPopup.BottomRight)
100 
101  # Extend the widget with all attributes and children from UI file
102  loadUi(resources_dir('ui','languages_popup.ui'), self)
103 
104  trans_list = TranslateGeneratorWidget.get_translate_file_list('.qm')
105 
106  for trans in trans_list:
107  lng = trans.split('.')[0]
108  self.country_layout.addWidget(CountryWidget(self, lng))
109 
110  if translator_hide:
111  self.country_layout.addWidget(TranslateGeneratorItem(self))
112 
113  self.adjustSize()
114 
115  def translate(self):
116  pass
117 
118 ## @class TranslatorGadget
119 ## @brief Translator interface by language chossen.
120 class TranslatorUi(QLabel):
121 
122  def __init__(self):
123  """! The constructor."""
124 
125  QLabel.__init__(self)
126 
127  self.setMinimumSize(QSize(30, 30))
128  self.setMaximumSize(QSize(60, 60))
129 
130  def resizeEvent(self,event):
131  """! Redefine qt methode for resize widget.
132  @param event: qt event.
133  @type event: QEvent.
134  """
135 
136  self.resize(self.width(),self.height())
137 
138  languages_ico = QPixmap(resources_dir('icons',
139  'country_flags',
140  trUtf8.language+'.png'))
141 
142  languages_ico = languages_ico.scaled(self.width(),
143  self.height(),
144  Qt.KeepAspectRatio,
145  Qt.SmoothTransformation)
146  self.setPixmap(languages_ico)
147 
148  trUtf8.translate.connect(self._update_ui)
149 
150  self._translator_hide = False
151 
152  def _update_ui(self):
153 
154  languages_ico = QPixmap(resources_dir('icons',
155  'country_flags',
156  trUtf8.language+'.png'))
157 
158  languages_ico = languages_ico.scaled(self.width(),
159  self.height(),
160  Qt.KeepAspectRatio,
161  Qt.SmoothTransformation)
162  self.setPixmap(languages_ico)
163 
164  def translator_hide(self, boolean):
165  self._translator_hide = boolean
166 
167  def mousePressEvent(self, event):
168  """! Redefine qt methode for resize widget.
169  @param event: qt event.
170  @type event: QEvent.
171  """
172 
173  popup = ChooseCountryPopup(self, self._translator_hide)
174  popup.translate()
175  popup.show_()
176 
177  def translate(self):
178  pass
179 
180 from airbus_cobot_gui.widget.widget import Widget
181 
183 
184  def __init__(self):
185  Widget.__init__(self)
186 
188 
189  self.set_widget(self.translator)
190 
191  def controlModeChangedEvent(self, mode):
192  pass
193 
194  def userChangedEvent(self, user):
195  if user.privilege < Privilege.DEVELOPER:
196  self.translator.translator_hide(False)
197  else:
198  self.translator.translator_hide(True)
199 
200  def emergencyStoppedEvent(self, state):
201  pass
202 
203  def retranslateEvent(self):
204  pass
205 
206  def shutdown(self):
207  pass
208 
209 
210 if __name__ == "__main__":
211 
212  import sys
213 
214  app = QApplication(sys.argv)
215  main = QMainWindow()
216  main.setCentralWidget(TranslatorUi())
217  main.show()
218  app.exec_()
219 
def mousePressEvent
Redefine qt methode for resize widget.
def resizeEvent
Redefine qt methode for resize widget.
Base class for create a Python widget.
Definition: widget.py:40


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