Tools/TRPreviewer.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2847
1843ef6e2656
parent 2997
7f0ef975da9e
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
11 11
12 import os 12 import os
13 13
14 from PyQt4.QtCore import QDir, QTimer, QFileInfo, pyqtSignal, QEvent, QSize, \ 14 from PyQt4.QtCore import QDir, QTimer, QFileInfo, pyqtSignal, QEvent, QSize, \
15 QTranslator, QObject, Qt 15 QTranslator, QObject, Qt
16 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QKeySequence, \ 16 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, \
17 QWhatsThis, QMdiArea, qApp, QApplication, QComboBox, QVBoxLayout, QAction, QLabel 17 QKeySequence, QWhatsThis, QMdiArea, qApp, QApplication, QComboBox, \
18 QVBoxLayout, QAction, QLabel
18 from PyQt4 import uic 19 from PyQt4 import uic
19 20
20 from E5Gui import E5MessageBox, E5FileDialog 21 from E5Gui import E5MessageBox, E5FileDialog
21 from E5Gui.E5MainWindow import E5MainWindow 22 from E5Gui.E5MainWindow import E5MainWindow
22 23
48 if not name: 49 if not name:
49 self.setObjectName("TRPreviewer") 50 self.setObjectName("TRPreviewer")
50 else: 51 else:
51 self.setObjectName(name) 52 self.setObjectName(name)
52 53
53 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) 54 self.setStyle(Preferences.getUI("Style"),
55 Preferences.getUI("StyleSheet"))
54 56
55 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint())) 57 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint()))
56 self.setAttribute(Qt.WA_DeleteOnClose) 58 self.setAttribute(Qt.WA_DeleteOnClose)
57 self.statusBar() 59 self.statusBar()
58 60
70 self.languageLayout = QHBoxLayout() 72 self.languageLayout = QHBoxLayout()
71 self.languageLayout.setContentsMargins(0, 0, 0, 0) 73 self.languageLayout.setContentsMargins(0, 0, 0, 0)
72 self.languageLayout.setSpacing(6) 74 self.languageLayout.setSpacing(6)
73 self.languageLayout.setObjectName("languageLayout") 75 self.languageLayout.setObjectName("languageLayout")
74 76
75 self.languageLabel = QLabel(self.trUtf8("Select language file"), self.cw) 77 self.languageLabel = QLabel(
78 self.trUtf8("Select language file"), self.cw)
76 self.languageLabel.setObjectName("languageLabel") 79 self.languageLabel.setObjectName("languageLabel")
77 self.languageLayout.addWidget(self.languageLabel) 80 self.languageLayout.addWidget(self.languageLabel)
78 81
79 self.languageCombo = QComboBox(self.cw) 82 self.languageCombo = QComboBox(self.cw)
80 self.languageCombo.setObjectName("languageCombo") 83 self.languageCombo.setObjectName("languageCombo")
81 self.languageCombo.setEditable(False) 84 self.languageCombo.setEditable(False)
82 self.languageCombo.setToolTip(self.trUtf8("Select language file")) 85 self.languageCombo.setToolTip(self.trUtf8("Select language file"))
83 self.languageCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) 86 self.languageCombo.setSizePolicy(
87 QSizePolicy.Expanding, QSizePolicy.Preferred)
84 self.languageLayout.addWidget(self.languageCombo) 88 self.languageLayout.addWidget(self.languageCombo)
85 89
86 languageSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) 90 languageSpacer = QSpacerItem(
91 40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
87 self.languageLayout.addItem(languageSpacer) 92 self.languageLayout.addItem(languageSpacer)
88 self.TRPreviewerLayout.addLayout(self.languageLayout) 93 self.TRPreviewerLayout.addLayout(self.languageLayout)
89 94
90 self.preview = WidgetArea(self.cw) 95 self.preview = WidgetArea(self.cw)
91 self.preview.setObjectName("preview") 96 self.preview.setObjectName("preview")
95 self.setCentralWidget(self.cw) 100 self.setCentralWidget(self.cw)
96 101
97 self.languageCombo.activated[str].connect(self.setTranslation) 102 self.languageCombo.activated[str].connect(self.setTranslation)
98 103
99 self.translations = TranslationsDict(self.languageCombo, self) 104 self.translations = TranslationsDict(self.languageCombo, self)
100 self.translations.translationChanged.connect(self.preview.rebuildWidgets) 105 self.translations.translationChanged.connect(
106 self.preview.rebuildWidgets)
101 107
102 self.__initActions() 108 self.__initActions()
103 self.__initMenus() 109 self.__initMenus()
104 self.__initToolbars() 110 self.__initToolbars()
105 111
160 )) 166 ))
161 self.openUIAct.triggered[()].connect(self.__openWidget) 167 self.openUIAct.triggered[()].connect(self.__openWidget)
162 168
163 self.openQMAct = QAction(UI.PixmapCache.getIcon("openQM.png"), 169 self.openQMAct = QAction(UI.PixmapCache.getIcon("openQM.png"),
164 self.trUtf8('Open &Translation Files...'), self) 170 self.trUtf8('Open &Translation Files...'), self)
165 self.openQMAct.setStatusTip(self.trUtf8('Open Translation files for display')) 171 self.openQMAct.setStatusTip(self.trUtf8(
172 'Open Translation files for display'))
166 self.openQMAct.setWhatsThis(self.trUtf8( 173 self.openQMAct.setWhatsThis(self.trUtf8(
167 """<b>Open Translation Files</b>""" 174 """<b>Open Translation Files</b>"""
168 """<p>This opens some translation files for display.</p>""" 175 """<p>This opens some translation files for display.</p>"""
169 )) 176 ))
170 self.openQMAct.triggered[()].connect(self.__openTranslation) 177 self.openQMAct.triggered[()].connect(self.__openTranslation)
171 178
172 self.reloadAct = QAction(UI.PixmapCache.getIcon("reload.png"), 179 self.reloadAct = QAction(UI.PixmapCache.getIcon("reload.png"),
173 self.trUtf8('&Reload Translations'), self) 180 self.trUtf8('&Reload Translations'), self)
174 self.reloadAct.setStatusTip(self.trUtf8('Reload the loaded translations')) 181 self.reloadAct.setStatusTip(self.trUtf8(
182 'Reload the loaded translations'))
175 self.reloadAct.setWhatsThis(self.trUtf8( 183 self.reloadAct.setWhatsThis(self.trUtf8(
176 """<b>Reload Translations</b>""" 184 """<b>Reload Translations</b>"""
177 """<p>This reloads the translations for the loaded languages.</p>""" 185 """<p>This reloads the translations for the loaded"""
186 """ languages.</p>"""
178 )) 187 ))
179 self.reloadAct.triggered[()].connect(self.translations.reload) 188 self.reloadAct.triggered[()].connect(self.translations.reload)
180 189
181 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"), 190 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"),
182 self.trUtf8('&Quit'), self) 191 self.trUtf8('&Quit'), self)
183 self.exitAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+Q", "File|Quit"))) 192 self.exitAct.setShortcut(QKeySequence(
193 self.trUtf8("Ctrl+Q", "File|Quit")))
184 self.exitAct.setStatusTip(self.trUtf8('Quit the application')) 194 self.exitAct.setStatusTip(self.trUtf8('Quit the application'))
185 self.exitAct.setWhatsThis(self.trUtf8( 195 self.exitAct.setWhatsThis(self.trUtf8(
186 """<b>Quit</b>""" 196 """<b>Quit</b>"""
187 """<p>Quit the application.</p>""" 197 """<p>Quit the application.</p>"""
188 )) 198 ))
191 self.whatsThisAct = QAction(UI.PixmapCache.getIcon("whatsThis.png"), 201 self.whatsThisAct = QAction(UI.PixmapCache.getIcon("whatsThis.png"),
192 self.trUtf8('&What\'s This?'), self) 202 self.trUtf8('&What\'s This?'), self)
193 self.whatsThisAct.setShortcut(QKeySequence(self.trUtf8("Shift+F1"))) 203 self.whatsThisAct.setShortcut(QKeySequence(self.trUtf8("Shift+F1")))
194 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help')) 204 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help'))
195 self.whatsThisAct.setWhatsThis(self.trUtf8( 205 self.whatsThisAct.setWhatsThis(self.trUtf8(
196 """<b>Display context sensitive help</b>""" 206 """<b>Display context sensitive help</b>"""
197 """<p>In What's This? mode, the mouse cursor shows an arrow with a""" 207 """<p>In What's This? mode, the mouse cursor shows an arrow"""
198 """ question mark, and you can click on the interface elements to get""" 208 """ with a question mark, and you can click on the interface"""
199 """ a short description of what they do and how to use them. In""" 209 """ elements to get a short description of what they do and"""
200 """ dialogs, this feature can be accessed using the context help""" 210 """ how to use them. In dialogs, this feature can be accessed"""
201 """ button in the titlebar.</p>""" 211 """ using the context help button in the titlebar.</p>"""
202 )) 212 ))
203 self.whatsThisAct.triggered[()].connect(self.__whatsThis) 213 self.whatsThisAct.triggered[()].connect(self.__whatsThis)
204 214
205 self.aboutAct = QAction(self.trUtf8('&About'), self) 215 self.aboutAct = QAction(self.trUtf8('&About'), self)
206 self.aboutAct.setStatusTip(self.trUtf8('Display information about this software')) 216 self.aboutAct.setStatusTip(self.trUtf8(
217 'Display information about this software'))
207 self.aboutAct.setWhatsThis(self.trUtf8( 218 self.aboutAct.setWhatsThis(self.trUtf8(
208 """<b>About</b>""" 219 """<b>About</b>"""
209 """<p>Display some information about this software.</p>""" 220 """<p>Display some information about this software.</p>"""
210 )) 221 ))
211 self.aboutAct.triggered[()].connect(self.__about) 222 self.aboutAct.triggered[()].connect(self.__about)
220 self.aboutQtAct.triggered[()].connect(self.__aboutQt) 231 self.aboutQtAct.triggered[()].connect(self.__aboutQt)
221 232
222 self.tileAct = QAction(self.trUtf8('&Tile'), self) 233 self.tileAct = QAction(self.trUtf8('&Tile'), self)
223 self.tileAct.setStatusTip(self.trUtf8('Tile the windows')) 234 self.tileAct.setStatusTip(self.trUtf8('Tile the windows'))
224 self.tileAct.setWhatsThis(self.trUtf8( 235 self.tileAct.setWhatsThis(self.trUtf8(
225 """<b>Tile the windows</b>""" 236 """<b>Tile the windows</b>"""
226 """<p>Rearrange and resize the windows so that they are tiled.</p>""" 237 """<p>Rearrange and resize the windows so that they are"""
238 """ tiled.</p>"""
227 )) 239 ))
228 self.tileAct.triggered[()].connect(self.preview.tileSubWindows) 240 self.tileAct.triggered[()].connect(self.preview.tileSubWindows)
229 241
230 self.cascadeAct = QAction(self.trUtf8('&Cascade'), self) 242 self.cascadeAct = QAction(self.trUtf8('&Cascade'), self)
231 self.cascadeAct.setStatusTip(self.trUtf8('Cascade the windows')) 243 self.cascadeAct.setStatusTip(self.trUtf8('Cascade the windows'))
232 self.cascadeAct.setWhatsThis(self.trUtf8( 244 self.cascadeAct.setWhatsThis(self.trUtf8(
233 """<b>Cascade the windows</b>""" 245 """<b>Cascade the windows</b>"""
234 """<p>Rearrange and resize the windows so that they are cascaded.</p>""" 246 """<p>Rearrange and resize the windows so that they are"""
247 """ cascaded.</p>"""
235 )) 248 ))
236 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows) 249 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows)
237 250
238 self.closeAct = QAction(UI.PixmapCache.getIcon("close.png"), 251 self.closeAct = QAction(UI.PixmapCache.getIcon("close.png"),
239 self.trUtf8('&Close'), self) 252 self.trUtf8('&Close'), self)
240 self.closeAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+W", "File|Close"))) 253 self.closeAct.setShortcut(QKeySequence(self.trUtf8(
254 "Ctrl+W", "File|Close")))
241 self.closeAct.setStatusTip(self.trUtf8('Close the current window')) 255 self.closeAct.setStatusTip(self.trUtf8('Close the current window'))
242 self.closeAct.setWhatsThis(self.trUtf8( 256 self.closeAct.setWhatsThis(self.trUtf8(
243 """<b>Close Window</b>""" 257 """<b>Close Window</b>"""
244 """<p>Close the current window.</p>""" 258 """<p>Close the current window.</p>"""
245 )) 259 ))
332 """ 346 """
333 Private slot to show the about information. 347 Private slot to show the about information.
334 """ 348 """
335 E5MessageBox.about(self, self.trUtf8("TR Previewer"), self.trUtf8( 349 E5MessageBox.about(self, self.trUtf8("TR Previewer"), self.trUtf8(
336 """<h3> About TR Previewer </h3>""" 350 """<h3> About TR Previewer </h3>"""
337 """<p>The TR Previewer loads and displays Qt User-Interface files""" 351 """<p>The TR Previewer loads and displays Qt User-Interface"""
338 """ and translation files and shows dialogs for a selected language.</p>""" 352 """ files and translation files and shows dialogs for a"""
353 """ selected language.</p>"""
339 )) 354 ))
340 355
341 def __aboutQt(self): 356 def __aboutQt(self):
342 """ 357 """
343 Private slot to show info about Qt. 358 Private slot to show info about Qt.
402 self.translations.reload() 417 self.translations.reload()
403 418
404 419
405 class Translation(object): 420 class Translation(object):
406 """ 421 """
407 Class to store the properties of a translation 422 Class to store the properties of a translation.
408 """ 423 """
409 def __init__(self): 424 def __init__(self):
410 """ 425 """
411 Constructor 426 Constructor
412 """ 427 """
444 459
445 If the translation file (*.qm) has not been loaded yet, it will 460 If the translation file (*.qm) has not been loaded yet, it will
446 be loaded automatically. 461 be loaded automatically.
447 462
448 @param fileName name of the translation file to be added (string) 463 @param fileName name of the translation file to be added (string)
449 @param setTranslation flag indicating, if this should be set as the active 464 @param setTranslation flag indicating, if this should be set as
450 translation (boolean) 465 the active translation (boolean)
451 """ 466 """
452 if not self.__haveFileName(fileName): 467 if not self.__haveFileName(fileName):
453 ntr = Translation() 468 ntr = Translation()
454 ntr.fileName = fileName 469 ntr.fileName = fileName
455 ntr.name = self.__uniqueName(fileName) 470 ntr.name = self.__uniqueName(fileName)
482 if name != noTranslationName: 497 if name != noTranslationName:
483 trans = self.__findName(name) 498 trans = self.__findName(name)
484 if trans is None: 499 if trans is None:
485 E5MessageBox.warning(self.parent(), 500 E5MessageBox.warning(self.parent(),
486 self.trUtf8("Set Translator"), 501 self.trUtf8("Set Translator"),
487 self.trUtf8("""<p>The translator <b>{0}</b> is not known.</p>""")\ 502 self.trUtf8(
503 """<p>The translator <b>{0}</b> is not known.</p>""")\
488 .format(name)) 504 .format(name))
489 return 505 return
490 506
491 nTranslator = trans.translator 507 nTranslator = trans.translator
492 508
592 608
593 return uname 609 return uname
594 610
595 def __del(self, name): 611 def __del(self, name):
596 """ 612 """
597 Private method to delete a translator from the list of available translators. 613 Private method to delete a translator from the list of available
614 translators.
598 615
599 @param name name of the translator to delete (string) 616 @param name name of the translator to delete (string)
600 """ 617 """
601 if name == noTranslationName: 618 if name == noTranslationName:
602 return 619 return
695 pass 712 pass
696 713
697 if not self.__widget: 714 if not self.__widget:
698 E5MessageBox.warning(self, 715 E5MessageBox.warning(self,
699 self.trUtf8("Load UI File"), 716 self.trUtf8("Load UI File"),
700 self.trUtf8("""<p>The file <b>{0}</b> could not be loaded.</p>""")\ 717 self.trUtf8(
718 """<p>The file <b>{0}</b> could not be loaded.</p>""")\
701 .format(self.__uiFileName)) 719 .format(self.__uiFileName))
702 self.__valid = False 720 self.__valid = False
703 return 721 return
704 722
705 self.__widget.setParent(self) 723 self.__widget.setParent(self)
749 if wview is None: 767 if wview is None:
750 name = os.path.basename(uiFileName) 768 name = os.path.basename(uiFileName)
751 if not name: 769 if not name:
752 E5MessageBox.warning(self, 770 E5MessageBox.warning(self,
753 self.trUtf8("Load UI File"), 771 self.trUtf8("Load UI File"),
754 self.trUtf8("""<p>The file <b>{0}</b> could not be loaded.</p>""")\ 772 self.trUtf8(
773 """<p>The file <b>{0}</b> could not be loaded.</p>""")\
755 .format(uiFileName)) 774 .format(uiFileName))
756 return 775 return
757 776
758 uname = name 777 uname = name
759 cnt = 1 778 cnt = 1
778 797
779 def eventFilter(self, obj, ev): 798 def eventFilter(self, obj, ev):
780 """ 799 """
781 Protected method called to filter an event. 800 Protected method called to filter an event.
782 801
783 @param object object, that generated the event (QObject) 802 @param obj object, that generated the event (QObject)
784 @param event the event, that was generated by object (QEvent) 803 @param ev the event, that was generated by object (QEvent)
785 @return flag indicating if event was filtered out 804 @return flag indicating if event was filtered out
786 """ 805 """
787 if obj in self.widgets and ev.type() == QEvent.Close: 806 if obj in self.widgets and ev.type() == QEvent.Close:
788 try: 807 try:
789 self.widgets.remove(obj) 808 self.widgets.remove(obj)

eric ide

mercurial