9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import QDir, QTimer, QFileInfo, pyqtSignal, QEvent, QSize, \ |
12 from PyQt4.QtCore import QDir, QTimer, QFileInfo, pyqtSignal, QEvent, QSize, \ |
13 QTranslator, QObject, Qt |
13 QTranslator, QObject, Qt |
14 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QKeySequence, \ |
14 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, \ |
15 QWhatsThis, QMdiArea, qApp, QApplication, QComboBox, QVBoxLayout, QAction, QLabel |
15 QKeySequence, QWhatsThis, QMdiArea, qApp, QApplication, QComboBox, \ |
|
16 QVBoxLayout, QAction, QLabel |
16 from PyQt4 import uic |
17 from PyQt4 import uic |
17 |
18 |
18 from E5Gui import E5MessageBox, E5FileDialog |
19 from E5Gui import E5MessageBox, E5FileDialog |
19 from E5Gui.E5MainWindow import E5MainWindow |
20 from E5Gui.E5MainWindow import E5MainWindow |
20 |
21 |
46 if not name: |
47 if not name: |
47 self.setObjectName("TRPreviewer") |
48 self.setObjectName("TRPreviewer") |
48 else: |
49 else: |
49 self.setObjectName(name) |
50 self.setObjectName(name) |
50 |
51 |
51 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) |
52 self.setStyle(Preferences.getUI("Style"), |
|
53 Preferences.getUI("StyleSheet")) |
52 |
54 |
53 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint())) |
55 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint())) |
54 self.setAttribute(Qt.WA_DeleteOnClose) |
56 self.setAttribute(Qt.WA_DeleteOnClose) |
55 self.statusBar() |
57 self.statusBar() |
56 |
58 |
68 self.languageLayout = QHBoxLayout() |
70 self.languageLayout = QHBoxLayout() |
69 self.languageLayout.setContentsMargins(0, 0, 0, 0) |
71 self.languageLayout.setContentsMargins(0, 0, 0, 0) |
70 self.languageLayout.setSpacing(6) |
72 self.languageLayout.setSpacing(6) |
71 self.languageLayout.setObjectName("languageLayout") |
73 self.languageLayout.setObjectName("languageLayout") |
72 |
74 |
73 self.languageLabel = QLabel(self.trUtf8("Select language file"), self.cw) |
75 self.languageLabel = QLabel( |
|
76 self.trUtf8("Select language file"), self.cw) |
74 self.languageLabel.setObjectName("languageLabel") |
77 self.languageLabel.setObjectName("languageLabel") |
75 self.languageLayout.addWidget(self.languageLabel) |
78 self.languageLayout.addWidget(self.languageLabel) |
76 |
79 |
77 self.languageCombo = QComboBox(self.cw) |
80 self.languageCombo = QComboBox(self.cw) |
78 self.languageCombo.setObjectName("languageCombo") |
81 self.languageCombo.setObjectName("languageCombo") |
79 self.languageCombo.setEditable(False) |
82 self.languageCombo.setEditable(False) |
80 self.languageCombo.setToolTip(self.trUtf8("Select language file")) |
83 self.languageCombo.setToolTip(self.trUtf8("Select language file")) |
81 self.languageCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
84 self.languageCombo.setSizePolicy( |
|
85 QSizePolicy.Expanding, QSizePolicy.Preferred) |
82 self.languageLayout.addWidget(self.languageCombo) |
86 self.languageLayout.addWidget(self.languageCombo) |
83 |
87 |
84 languageSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) |
88 languageSpacer = QSpacerItem( |
|
89 40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) |
85 self.languageLayout.addItem(languageSpacer) |
90 self.languageLayout.addItem(languageSpacer) |
86 self.TRPreviewerLayout.addLayout(self.languageLayout) |
91 self.TRPreviewerLayout.addLayout(self.languageLayout) |
87 |
92 |
88 self.preview = WidgetArea(self.cw) |
93 self.preview = WidgetArea(self.cw) |
89 self.preview.setObjectName("preview") |
94 self.preview.setObjectName("preview") |
93 self.setCentralWidget(self.cw) |
98 self.setCentralWidget(self.cw) |
94 |
99 |
95 self.languageCombo.activated[str].connect(self.setTranslation) |
100 self.languageCombo.activated[str].connect(self.setTranslation) |
96 |
101 |
97 self.translations = TranslationsDict(self.languageCombo, self) |
102 self.translations = TranslationsDict(self.languageCombo, self) |
98 self.translations.translationChanged.connect(self.preview.rebuildWidgets) |
103 self.translations.translationChanged.connect( |
|
104 self.preview.rebuildWidgets) |
99 |
105 |
100 self.__initActions() |
106 self.__initActions() |
101 self.__initMenus() |
107 self.__initMenus() |
102 self.__initToolbars() |
108 self.__initToolbars() |
103 |
109 |
158 )) |
164 )) |
159 self.openUIAct.triggered[()].connect(self.__openWidget) |
165 self.openUIAct.triggered[()].connect(self.__openWidget) |
160 |
166 |
161 self.openQMAct = QAction(UI.PixmapCache.getIcon("openQM.png"), |
167 self.openQMAct = QAction(UI.PixmapCache.getIcon("openQM.png"), |
162 self.trUtf8('Open &Translation Files...'), self) |
168 self.trUtf8('Open &Translation Files...'), self) |
163 self.openQMAct.setStatusTip(self.trUtf8('Open Translation files for display')) |
169 self.openQMAct.setStatusTip(self.trUtf8( |
|
170 'Open Translation files for display')) |
164 self.openQMAct.setWhatsThis(self.trUtf8( |
171 self.openQMAct.setWhatsThis(self.trUtf8( |
165 """<b>Open Translation Files</b>""" |
172 """<b>Open Translation Files</b>""" |
166 """<p>This opens some translation files for display.</p>""" |
173 """<p>This opens some translation files for display.</p>""" |
167 )) |
174 )) |
168 self.openQMAct.triggered[()].connect(self.__openTranslation) |
175 self.openQMAct.triggered[()].connect(self.__openTranslation) |
169 |
176 |
170 self.reloadAct = QAction(UI.PixmapCache.getIcon("reload.png"), |
177 self.reloadAct = QAction(UI.PixmapCache.getIcon("reload.png"), |
171 self.trUtf8('&Reload Translations'), self) |
178 self.trUtf8('&Reload Translations'), self) |
172 self.reloadAct.setStatusTip(self.trUtf8('Reload the loaded translations')) |
179 self.reloadAct.setStatusTip(self.trUtf8( |
|
180 'Reload the loaded translations')) |
173 self.reloadAct.setWhatsThis(self.trUtf8( |
181 self.reloadAct.setWhatsThis(self.trUtf8( |
174 """<b>Reload Translations</b>""" |
182 """<b>Reload Translations</b>""" |
175 """<p>This reloads the translations for the loaded languages.</p>""" |
183 """<p>This reloads the translations for the loaded""" |
|
184 """ languages.</p>""" |
176 )) |
185 )) |
177 self.reloadAct.triggered[()].connect(self.translations.reload) |
186 self.reloadAct.triggered[()].connect(self.translations.reload) |
178 |
187 |
179 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"), |
188 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"), |
180 self.trUtf8('&Quit'), self) |
189 self.trUtf8('&Quit'), self) |
181 self.exitAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+Q", "File|Quit"))) |
190 self.exitAct.setShortcut(QKeySequence( |
|
191 self.trUtf8("Ctrl+Q", "File|Quit"))) |
182 self.exitAct.setStatusTip(self.trUtf8('Quit the application')) |
192 self.exitAct.setStatusTip(self.trUtf8('Quit the application')) |
183 self.exitAct.setWhatsThis(self.trUtf8( |
193 self.exitAct.setWhatsThis(self.trUtf8( |
184 """<b>Quit</b>""" |
194 """<b>Quit</b>""" |
185 """<p>Quit the application.</p>""" |
195 """<p>Quit the application.</p>""" |
186 )) |
196 )) |
189 self.whatsThisAct = QAction(UI.PixmapCache.getIcon("whatsThis.png"), |
199 self.whatsThisAct = QAction(UI.PixmapCache.getIcon("whatsThis.png"), |
190 self.trUtf8('&What\'s This?'), self) |
200 self.trUtf8('&What\'s This?'), self) |
191 self.whatsThisAct.setShortcut(QKeySequence(self.trUtf8("Shift+F1"))) |
201 self.whatsThisAct.setShortcut(QKeySequence(self.trUtf8("Shift+F1"))) |
192 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help')) |
202 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help')) |
193 self.whatsThisAct.setWhatsThis(self.trUtf8( |
203 self.whatsThisAct.setWhatsThis(self.trUtf8( |
194 """<b>Display context sensitive help</b>""" |
204 """<b>Display context sensitive help</b>""" |
195 """<p>In What's This? mode, the mouse cursor shows an arrow with a""" |
205 """<p>In What's This? mode, the mouse cursor shows an arrow""" |
196 """ question mark, and you can click on the interface elements to get""" |
206 """ with a question mark, and you can click on the interface""" |
197 """ a short description of what they do and how to use them. In""" |
207 """ elements to get a short description of what they do and""" |
198 """ dialogs, this feature can be accessed using the context help""" |
208 """ how to use them. In dialogs, this feature can be accessed""" |
199 """ button in the titlebar.</p>""" |
209 """ using the context help button in the titlebar.</p>""" |
200 )) |
210 )) |
201 self.whatsThisAct.triggered[()].connect(self.__whatsThis) |
211 self.whatsThisAct.triggered[()].connect(self.__whatsThis) |
202 |
212 |
203 self.aboutAct = QAction(self.trUtf8('&About'), self) |
213 self.aboutAct = QAction(self.trUtf8('&About'), self) |
204 self.aboutAct.setStatusTip(self.trUtf8('Display information about this software')) |
214 self.aboutAct.setStatusTip(self.trUtf8( |
|
215 'Display information about this software')) |
205 self.aboutAct.setWhatsThis(self.trUtf8( |
216 self.aboutAct.setWhatsThis(self.trUtf8( |
206 """<b>About</b>""" |
217 """<b>About</b>""" |
207 """<p>Display some information about this software.</p>""" |
218 """<p>Display some information about this software.</p>""" |
208 )) |
219 )) |
209 self.aboutAct.triggered[()].connect(self.__about) |
220 self.aboutAct.triggered[()].connect(self.__about) |
218 self.aboutQtAct.triggered[()].connect(self.__aboutQt) |
229 self.aboutQtAct.triggered[()].connect(self.__aboutQt) |
219 |
230 |
220 self.tileAct = QAction(self.trUtf8('&Tile'), self) |
231 self.tileAct = QAction(self.trUtf8('&Tile'), self) |
221 self.tileAct.setStatusTip(self.trUtf8('Tile the windows')) |
232 self.tileAct.setStatusTip(self.trUtf8('Tile the windows')) |
222 self.tileAct.setWhatsThis(self.trUtf8( |
233 self.tileAct.setWhatsThis(self.trUtf8( |
223 """<b>Tile the windows</b>""" |
234 """<b>Tile the windows</b>""" |
224 """<p>Rearrange and resize the windows so that they are tiled.</p>""" |
235 """<p>Rearrange and resize the windows so that they are""" |
|
236 """ tiled.</p>""" |
225 )) |
237 )) |
226 self.tileAct.triggered[()].connect(self.preview.tileSubWindows) |
238 self.tileAct.triggered[()].connect(self.preview.tileSubWindows) |
227 |
239 |
228 self.cascadeAct = QAction(self.trUtf8('&Cascade'), self) |
240 self.cascadeAct = QAction(self.trUtf8('&Cascade'), self) |
229 self.cascadeAct.setStatusTip(self.trUtf8('Cascade the windows')) |
241 self.cascadeAct.setStatusTip(self.trUtf8('Cascade the windows')) |
230 self.cascadeAct.setWhatsThis(self.trUtf8( |
242 self.cascadeAct.setWhatsThis(self.trUtf8( |
231 """<b>Cascade the windows</b>""" |
243 """<b>Cascade the windows</b>""" |
232 """<p>Rearrange and resize the windows so that they are cascaded.</p>""" |
244 """<p>Rearrange and resize the windows so that they are""" |
|
245 """ cascaded.</p>""" |
233 )) |
246 )) |
234 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows) |
247 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows) |
235 |
248 |
236 self.closeAct = QAction(UI.PixmapCache.getIcon("close.png"), |
249 self.closeAct = QAction(UI.PixmapCache.getIcon("close.png"), |
237 self.trUtf8('&Close'), self) |
250 self.trUtf8('&Close'), self) |
238 self.closeAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+W", "File|Close"))) |
251 self.closeAct.setShortcut(QKeySequence(self.trUtf8( |
|
252 "Ctrl+W", "File|Close"))) |
239 self.closeAct.setStatusTip(self.trUtf8('Close the current window')) |
253 self.closeAct.setStatusTip(self.trUtf8('Close the current window')) |
240 self.closeAct.setWhatsThis(self.trUtf8( |
254 self.closeAct.setWhatsThis(self.trUtf8( |
241 """<b>Close Window</b>""" |
255 """<b>Close Window</b>""" |
242 """<p>Close the current window.</p>""" |
256 """<p>Close the current window.</p>""" |
243 )) |
257 )) |
330 """ |
344 """ |
331 Private slot to show the about information. |
345 Private slot to show the about information. |
332 """ |
346 """ |
333 E5MessageBox.about(self, self.trUtf8("TR Previewer"), self.trUtf8( |
347 E5MessageBox.about(self, self.trUtf8("TR Previewer"), self.trUtf8( |
334 """<h3> About TR Previewer </h3>""" |
348 """<h3> About TR Previewer </h3>""" |
335 """<p>The TR Previewer loads and displays Qt User-Interface files""" |
349 """<p>The TR Previewer loads and displays Qt User-Interface""" |
336 """ and translation files and shows dialogs for a selected language.</p>""" |
350 """ files and translation files and shows dialogs for a""" |
|
351 """ selected language.</p>""" |
337 )) |
352 )) |
338 |
353 |
339 def __aboutQt(self): |
354 def __aboutQt(self): |
340 """ |
355 """ |
341 Private slot to show info about Qt. |
356 Private slot to show info about Qt. |
442 |
457 |
443 If the translation file (*.qm) has not been loaded yet, it will |
458 If the translation file (*.qm) has not been loaded yet, it will |
444 be loaded automatically. |
459 be loaded automatically. |
445 |
460 |
446 @param fileName name of the translation file to be added (string) |
461 @param fileName name of the translation file to be added (string) |
447 @param setTranslation flag indicating, if this should be set as the active |
462 @param setTranslation flag indicating, if this should be set as |
448 translation (boolean) |
463 the active translation (boolean) |
449 """ |
464 """ |
450 if not self.__haveFileName(fileName): |
465 if not self.__haveFileName(fileName): |
451 ntr = Translation() |
466 ntr = Translation() |
452 ntr.fileName = fileName |
467 ntr.fileName = fileName |
453 ntr.name = self.__uniqueName(fileName) |
468 ntr.name = self.__uniqueName(fileName) |
480 if name != noTranslationName: |
495 if name != noTranslationName: |
481 trans = self.__findName(name) |
496 trans = self.__findName(name) |
482 if trans is None: |
497 if trans is None: |
483 E5MessageBox.warning(self.parent(), |
498 E5MessageBox.warning(self.parent(), |
484 self.trUtf8("Set Translator"), |
499 self.trUtf8("Set Translator"), |
485 self.trUtf8("""<p>The translator <b>{0}</b> is not known.</p>""")\ |
500 self.trUtf8( |
|
501 """<p>The translator <b>{0}</b> is not known.</p>""")\ |
486 .format(name)) |
502 .format(name)) |
487 return |
503 return |
488 |
504 |
489 nTranslator = trans.translator |
505 nTranslator = trans.translator |
490 |
506 |
693 pass |
710 pass |
694 |
711 |
695 if not self.__widget: |
712 if not self.__widget: |
696 E5MessageBox.warning(self, |
713 E5MessageBox.warning(self, |
697 self.trUtf8("Load UI File"), |
714 self.trUtf8("Load UI File"), |
698 self.trUtf8("""<p>The file <b>{0}</b> could not be loaded.</p>""")\ |
715 self.trUtf8( |
|
716 """<p>The file <b>{0}</b> could not be loaded.</p>""")\ |
699 .format(self.__uiFileName)) |
717 .format(self.__uiFileName)) |
700 self.__valid = False |
718 self.__valid = False |
701 return |
719 return |
702 |
720 |
703 self.__widget.setParent(self) |
721 self.__widget.setParent(self) |