Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 import os
00020
00021 from python_qt_binding.QtGui import *
00022 from python_qt_binding.QtCore import *
00023 from python_qt_binding import loadUi
00024
00025 from airbus_cobot_gui.account import Privilege
00026 from airbus_pyqt_extend.QtAgiGui import QAgiPopup
00027
00028 from airbus_cobot_gui.res import R
00029
00030 class CountryWidget(QPushButton):
00031
00032 def __init__(self, parent, country):
00033 """! The constructor."""
00034 QPushButton.__init__(self, parent)
00035
00036 self._parent = parent
00037 self._country = country
00038
00039 self.setMinimumSize(QSize(40, 40))
00040 self.setMaximumSize(QSize(60, 60))
00041 self.setStyleSheet(R.values.styles.transparent_background)
00042
00043 self.setIcon(R.getIconById(country))
00044 self.setIconSize(QSize(self.width(),self.height()))
00045
00046 def mousePressEvent(self, event):
00047 self._parent.setLanguageSelected(self._country)
00048 self._parent.close()
00049
00050
00051
00052 class ChooseCountryPopup(QAgiPopup):
00053
00054 LNGS = ['en','fr','de','es']
00055
00056 def __init__(self, parent):
00057 """! The constructor."""
00058 QAgiPopup.__init__(self, parent)
00059
00060 self._parent = parent
00061
00062 self.setRelativePosition(QAgiPopup.TopRight, QAgiPopup.BottomRight)
00063
00064
00065 loadUi(R.layouts.languages_popup, self)
00066
00067 for lng in self.LNGS:
00068 self.country_layout.addWidget(CountryWidget(self, lng))
00069
00070 self.adjustSize()
00071
00072 def setLanguageSelected(self, lng):
00073 self._parent.getContext().switchLanguage(lng)
00074
00075
00076 def closeEvent(self, event):
00077 self._parent.refresh()
00078
00079
00080
00081 class TranslatorUi(QLabel):
00082
00083 def __init__(self, context):
00084 """! The constructor."""
00085
00086 QLabel.__init__(self)
00087
00088 self._context = context
00089 self._context.addLanguageEventListner(self.onTranslate)
00090
00091 self.setMinimumSize(QSize(40, 40))
00092 self.setMaximumSize(QSize(60, 60))
00093
00094 def getContext(self):
00095 return self._context
00096
00097 def resizeEvent(self,event):
00098 """! Redefine qt methode for resize widget.
00099 @param event: qt event.
00100 @type event: QEvent.
00101 """
00102 self.refresh()
00103
00104 def refresh(self):
00105
00106 lng = self.getContext().getLanguage()
00107
00108 self.setPixmap(R.getPixmapById(lng).scaled(
00109 self.width(),
00110 self.height(),
00111 Qt.KeepAspectRatio,
00112 Qt.SmoothTransformation)
00113 )
00114
00115 def mousePressEvent(self, event):
00116 """! Redefine qt methode for resize widget.
00117 @param event: qt event.
00118 @type event: QEvent.
00119 """
00120
00121 popup = ChooseCountryPopup(self)
00122 popup.show_()
00123
00124 def onTranslate(self, lng):
00125 pass
00126
00127 def onDestroy(self):
00128 pass
00129
00130 if __name__ == "__main__":
00131
00132 import sys
00133 from airbus_cobot_gui.context import Context
00134
00135 app = QApplication(sys.argv)
00136 main = QMainWindow()
00137 main.setCentralWidget(TranslatorUi(Context(main)))
00138 main.show()
00139 app.exec_()
00140