Tools/TRPreviewer.py

changeset 3190
a9a94491c4fd
parent 3160
209a07d7e401
child 3201
0f115f6db6cb
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
55 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint())) 55 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint()))
56 self.setAttribute(Qt.WA_DeleteOnClose) 56 self.setAttribute(Qt.WA_DeleteOnClose)
57 self.statusBar() 57 self.statusBar()
58 58
59 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) 59 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png"))
60 self.setWindowTitle(self.trUtf8("Translations Previewer")) 60 self.setWindowTitle(self.tr("Translations Previewer"))
61 61
62 self.cw = QWidget(self) 62 self.cw = QWidget(self)
63 self.cw.setObjectName("qt_central_widget") 63 self.cw.setObjectName("qt_central_widget")
64 64
65 self.TRPreviewerLayout = QVBoxLayout(self.cw) 65 self.TRPreviewerLayout = QVBoxLayout(self.cw)
71 self.languageLayout.setContentsMargins(0, 0, 0, 0) 71 self.languageLayout.setContentsMargins(0, 0, 0, 0)
72 self.languageLayout.setSpacing(6) 72 self.languageLayout.setSpacing(6)
73 self.languageLayout.setObjectName("languageLayout") 73 self.languageLayout.setObjectName("languageLayout")
74 74
75 self.languageLabel = QLabel( 75 self.languageLabel = QLabel(
76 self.trUtf8("Select language file"), self.cw) 76 self.tr("Select language file"), self.cw)
77 self.languageLabel.setObjectName("languageLabel") 77 self.languageLabel.setObjectName("languageLabel")
78 self.languageLayout.addWidget(self.languageLabel) 78 self.languageLayout.addWidget(self.languageLabel)
79 79
80 self.languageCombo = QComboBox(self.cw) 80 self.languageCombo = QComboBox(self.cw)
81 self.languageCombo.setObjectName("languageCombo") 81 self.languageCombo.setObjectName("languageCombo")
82 self.languageCombo.setEditable(False) 82 self.languageCombo.setEditable(False)
83 self.languageCombo.setToolTip(self.trUtf8("Select language file")) 83 self.languageCombo.setToolTip(self.tr("Select language file"))
84 self.languageCombo.setSizePolicy( 84 self.languageCombo.setSizePolicy(
85 QSizePolicy.Expanding, QSizePolicy.Preferred) 85 QSizePolicy.Expanding, QSizePolicy.Preferred)
86 self.languageLayout.addWidget(self.languageCombo) 86 self.languageLayout.addWidget(self.languageCombo)
87 87
88 languageSpacer = QSpacerItem( 88 languageSpacer = QSpacerItem(
155 """ 155 """
156 Private method to define the user interface actions. 156 Private method to define the user interface actions.
157 """ 157 """
158 self.openUIAct = QAction( 158 self.openUIAct = QAction(
159 UI.PixmapCache.getIcon("openUI.png"), 159 UI.PixmapCache.getIcon("openUI.png"),
160 self.trUtf8('&Open UI Files...'), self) 160 self.tr('&Open UI Files...'), self)
161 self.openUIAct.setStatusTip(self.trUtf8('Open UI files for display')) 161 self.openUIAct.setStatusTip(self.tr('Open UI files for display'))
162 self.openUIAct.setWhatsThis(self.trUtf8( 162 self.openUIAct.setWhatsThis(self.tr(
163 """<b>Open UI Files</b>""" 163 """<b>Open UI Files</b>"""
164 """<p>This opens some UI files for display.</p>""" 164 """<p>This opens some UI files for display.</p>"""
165 )) 165 ))
166 self.openUIAct.triggered[()].connect(self.__openWidget) 166 self.openUIAct.triggered[()].connect(self.__openWidget)
167 167
168 self.openQMAct = QAction( 168 self.openQMAct = QAction(
169 UI.PixmapCache.getIcon("openQM.png"), 169 UI.PixmapCache.getIcon("openQM.png"),
170 self.trUtf8('Open &Translation Files...'), self) 170 self.tr('Open &Translation Files...'), self)
171 self.openQMAct.setStatusTip(self.trUtf8( 171 self.openQMAct.setStatusTip(self.tr(
172 'Open Translation files for display')) 172 'Open Translation files for display'))
173 self.openQMAct.setWhatsThis(self.trUtf8( 173 self.openQMAct.setWhatsThis(self.tr(
174 """<b>Open Translation Files</b>""" 174 """<b>Open Translation Files</b>"""
175 """<p>This opens some translation files for display.</p>""" 175 """<p>This opens some translation files for display.</p>"""
176 )) 176 ))
177 self.openQMAct.triggered[()].connect(self.__openTranslation) 177 self.openQMAct.triggered[()].connect(self.__openTranslation)
178 178
179 self.reloadAct = QAction( 179 self.reloadAct = QAction(
180 UI.PixmapCache.getIcon("reload.png"), 180 UI.PixmapCache.getIcon("reload.png"),
181 self.trUtf8('&Reload Translations'), self) 181 self.tr('&Reload Translations'), self)
182 self.reloadAct.setStatusTip(self.trUtf8( 182 self.reloadAct.setStatusTip(self.tr(
183 'Reload the loaded translations')) 183 'Reload the loaded translations'))
184 self.reloadAct.setWhatsThis(self.trUtf8( 184 self.reloadAct.setWhatsThis(self.tr(
185 """<b>Reload Translations</b>""" 185 """<b>Reload Translations</b>"""
186 """<p>This reloads the translations for the loaded""" 186 """<p>This reloads the translations for the loaded"""
187 """ languages.</p>""" 187 """ languages.</p>"""
188 )) 188 ))
189 self.reloadAct.triggered[()].connect(self.translations.reload) 189 self.reloadAct.triggered[()].connect(self.translations.reload)
190 190
191 self.exitAct = QAction( 191 self.exitAct = QAction(
192 UI.PixmapCache.getIcon("exit.png"), self.trUtf8('&Quit'), self) 192 UI.PixmapCache.getIcon("exit.png"), self.tr('&Quit'), self)
193 self.exitAct.setShortcut(QKeySequence( 193 self.exitAct.setShortcut(QKeySequence(
194 self.trUtf8("Ctrl+Q", "File|Quit"))) 194 self.tr("Ctrl+Q", "File|Quit")))
195 self.exitAct.setStatusTip(self.trUtf8('Quit the application')) 195 self.exitAct.setStatusTip(self.tr('Quit the application'))
196 self.exitAct.setWhatsThis(self.trUtf8( 196 self.exitAct.setWhatsThis(self.tr(
197 """<b>Quit</b>""" 197 """<b>Quit</b>"""
198 """<p>Quit the application.</p>""" 198 """<p>Quit the application.</p>"""
199 )) 199 ))
200 self.exitAct.triggered[()].connect(qApp.closeAllWindows) 200 self.exitAct.triggered[()].connect(qApp.closeAllWindows)
201 201
202 self.whatsThisAct = QAction( 202 self.whatsThisAct = QAction(
203 UI.PixmapCache.getIcon("whatsThis.png"), 203 UI.PixmapCache.getIcon("whatsThis.png"),
204 self.trUtf8('&What\'s This?'), self) 204 self.tr('&What\'s This?'), self)
205 self.whatsThisAct.setShortcut(QKeySequence(self.trUtf8("Shift+F1"))) 205 self.whatsThisAct.setShortcut(QKeySequence(self.tr("Shift+F1")))
206 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help')) 206 self.whatsThisAct.setStatusTip(self.tr('Context sensitive help'))
207 self.whatsThisAct.setWhatsThis(self.trUtf8( 207 self.whatsThisAct.setWhatsThis(self.tr(
208 """<b>Display context sensitive help</b>""" 208 """<b>Display context sensitive help</b>"""
209 """<p>In What's This? mode, the mouse cursor shows an arrow""" 209 """<p>In What's This? mode, the mouse cursor shows an arrow"""
210 """ with a question mark, and you can click on the interface""" 210 """ with a question mark, and you can click on the interface"""
211 """ elements to get a short description of what they do and""" 211 """ elements to get a short description of what they do and"""
212 """ how to use them. In dialogs, this feature can be accessed""" 212 """ how to use them. In dialogs, this feature can be accessed"""
213 """ using the context help button in the titlebar.</p>""" 213 """ using the context help button in the titlebar.</p>"""
214 )) 214 ))
215 self.whatsThisAct.triggered[()].connect(self.__whatsThis) 215 self.whatsThisAct.triggered[()].connect(self.__whatsThis)
216 216
217 self.aboutAct = QAction(self.trUtf8('&About'), self) 217 self.aboutAct = QAction(self.tr('&About'), self)
218 self.aboutAct.setStatusTip(self.trUtf8( 218 self.aboutAct.setStatusTip(self.tr(
219 'Display information about this software')) 219 'Display information about this software'))
220 self.aboutAct.setWhatsThis(self.trUtf8( 220 self.aboutAct.setWhatsThis(self.tr(
221 """<b>About</b>""" 221 """<b>About</b>"""
222 """<p>Display some information about this software.</p>""" 222 """<p>Display some information about this software.</p>"""
223 )) 223 ))
224 self.aboutAct.triggered[()].connect(self.__about) 224 self.aboutAct.triggered[()].connect(self.__about)
225 225
226 self.aboutQtAct = QAction(self.trUtf8('About &Qt'), self) 226 self.aboutQtAct = QAction(self.tr('About &Qt'), self)
227 self.aboutQtAct.setStatusTip( 227 self.aboutQtAct.setStatusTip(
228 self.trUtf8('Display information about the Qt toolkit')) 228 self.tr('Display information about the Qt toolkit'))
229 self.aboutQtAct.setWhatsThis(self.trUtf8( 229 self.aboutQtAct.setWhatsThis(self.tr(
230 """<b>About Qt</b>""" 230 """<b>About Qt</b>"""
231 """<p>Display some information about the Qt toolkit.</p>""" 231 """<p>Display some information about the Qt toolkit.</p>"""
232 )) 232 ))
233 self.aboutQtAct.triggered[()].connect(self.__aboutQt) 233 self.aboutQtAct.triggered[()].connect(self.__aboutQt)
234 234
235 self.tileAct = QAction(self.trUtf8('&Tile'), self) 235 self.tileAct = QAction(self.tr('&Tile'), self)
236 self.tileAct.setStatusTip(self.trUtf8('Tile the windows')) 236 self.tileAct.setStatusTip(self.tr('Tile the windows'))
237 self.tileAct.setWhatsThis(self.trUtf8( 237 self.tileAct.setWhatsThis(self.tr(
238 """<b>Tile the windows</b>""" 238 """<b>Tile the windows</b>"""
239 """<p>Rearrange and resize the windows so that they are""" 239 """<p>Rearrange and resize the windows so that they are"""
240 """ tiled.</p>""" 240 """ tiled.</p>"""
241 )) 241 ))
242 self.tileAct.triggered[()].connect(self.preview.tileSubWindows) 242 self.tileAct.triggered[()].connect(self.preview.tileSubWindows)
243 243
244 self.cascadeAct = QAction(self.trUtf8('&Cascade'), self) 244 self.cascadeAct = QAction(self.tr('&Cascade'), self)
245 self.cascadeAct.setStatusTip(self.trUtf8('Cascade the windows')) 245 self.cascadeAct.setStatusTip(self.tr('Cascade the windows'))
246 self.cascadeAct.setWhatsThis(self.trUtf8( 246 self.cascadeAct.setWhatsThis(self.tr(
247 """<b>Cascade the windows</b>""" 247 """<b>Cascade the windows</b>"""
248 """<p>Rearrange and resize the windows so that they are""" 248 """<p>Rearrange and resize the windows so that they are"""
249 """ cascaded.</p>""" 249 """ cascaded.</p>"""
250 )) 250 ))
251 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows) 251 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows)
252 252
253 self.closeAct = QAction( 253 self.closeAct = QAction(
254 UI.PixmapCache.getIcon("close.png"), self.trUtf8('&Close'), self) 254 UI.PixmapCache.getIcon("close.png"), self.tr('&Close'), self)
255 self.closeAct.setShortcut(QKeySequence(self.trUtf8( 255 self.closeAct.setShortcut(QKeySequence(self.tr(
256 "Ctrl+W", "File|Close"))) 256 "Ctrl+W", "File|Close")))
257 self.closeAct.setStatusTip(self.trUtf8('Close the current window')) 257 self.closeAct.setStatusTip(self.tr('Close the current window'))
258 self.closeAct.setWhatsThis(self.trUtf8( 258 self.closeAct.setWhatsThis(self.tr(
259 """<b>Close Window</b>""" 259 """<b>Close Window</b>"""
260 """<p>Close the current window.</p>""" 260 """<p>Close the current window.</p>"""
261 )) 261 ))
262 self.closeAct.triggered[()].connect(self.preview.closeWidget) 262 self.closeAct.triggered[()].connect(self.preview.closeWidget)
263 263
264 self.closeAllAct = QAction(self.trUtf8('Clos&e All'), self) 264 self.closeAllAct = QAction(self.tr('Clos&e All'), self)
265 self.closeAllAct.setStatusTip(self.trUtf8('Close all windows')) 265 self.closeAllAct.setStatusTip(self.tr('Close all windows'))
266 self.closeAllAct.setWhatsThis(self.trUtf8( 266 self.closeAllAct.setWhatsThis(self.tr(
267 """<b>Close All Windows</b>""" 267 """<b>Close All Windows</b>"""
268 """<p>Close all windows.</p>""" 268 """<p>Close all windows.</p>"""
269 )) 269 ))
270 self.closeAllAct.triggered[()].connect(self.preview.closeAllWidgets) 270 self.closeAllAct.triggered[()].connect(self.preview.closeAllWidgets)
271 271
273 """ 273 """
274 Private method to create the menus. 274 Private method to create the menus.
275 """ 275 """
276 mb = self.menuBar() 276 mb = self.menuBar()
277 277
278 menu = mb.addMenu(self.trUtf8('&File')) 278 menu = mb.addMenu(self.tr('&File'))
279 menu.setTearOffEnabled(True) 279 menu.setTearOffEnabled(True)
280 menu.addAction(self.openUIAct) 280 menu.addAction(self.openUIAct)
281 menu.addAction(self.openQMAct) 281 menu.addAction(self.openQMAct)
282 menu.addAction(self.reloadAct) 282 menu.addAction(self.reloadAct)
283 menu.addSeparator() 283 menu.addSeparator()
284 menu.addAction(self.closeAct) 284 menu.addAction(self.closeAct)
285 menu.addAction(self.closeAllAct) 285 menu.addAction(self.closeAllAct)
286 menu.addSeparator() 286 menu.addSeparator()
287 menu.addAction(self.exitAct) 287 menu.addAction(self.exitAct)
288 288
289 self.windowMenu = mb.addMenu(self.trUtf8('&Window')) 289 self.windowMenu = mb.addMenu(self.tr('&Window'))
290 self.windowMenu.setTearOffEnabled(True) 290 self.windowMenu.setTearOffEnabled(True)
291 self.windowMenu.aboutToShow.connect(self.__showWindowMenu) 291 self.windowMenu.aboutToShow.connect(self.__showWindowMenu)
292 self.windowMenu.triggered.connect(self.preview.toggleSelectedWidget) 292 self.windowMenu.triggered.connect(self.preview.toggleSelectedWidget)
293 293
294 mb.addSeparator() 294 mb.addSeparator()
295 295
296 menu = mb.addMenu(self.trUtf8('&Help')) 296 menu = mb.addMenu(self.tr('&Help'))
297 menu.setTearOffEnabled(True) 297 menu.setTearOffEnabled(True)
298 menu.addAction(self.aboutAct) 298 menu.addAction(self.aboutAct)
299 menu.addAction(self.aboutQtAct) 299 menu.addAction(self.aboutQtAct)
300 menu.addSeparator() 300 menu.addSeparator()
301 menu.addAction(self.whatsThisAct) 301 menu.addAction(self.whatsThisAct)
302 302
303 def __initToolbars(self): 303 def __initToolbars(self):
304 """ 304 """
305 Private method to create the toolbars. 305 Private method to create the toolbars.
306 """ 306 """
307 filetb = self.addToolBar(self.trUtf8("File")) 307 filetb = self.addToolBar(self.tr("File"))
308 filetb.setIconSize(UI.Config.ToolBarIconSize) 308 filetb.setIconSize(UI.Config.ToolBarIconSize)
309 filetb.addAction(self.openUIAct) 309 filetb.addAction(self.openUIAct)
310 filetb.addAction(self.openQMAct) 310 filetb.addAction(self.openQMAct)
311 filetb.addAction(self.reloadAct) 311 filetb.addAction(self.reloadAct)
312 filetb.addSeparator() 312 filetb.addSeparator()
313 filetb.addAction(self.closeAct) 313 filetb.addAction(self.closeAct)
314 filetb.addSeparator() 314 filetb.addSeparator()
315 filetb.addAction(self.exitAct) 315 filetb.addAction(self.exitAct)
316 316
317 helptb = self.addToolBar(self.trUtf8("Help")) 317 helptb = self.addToolBar(self.tr("Help"))
318 helptb.setIconSize(UI.Config.ToolBarIconSize) 318 helptb.setIconSize(UI.Config.ToolBarIconSize)
319 helptb.addAction(self.whatsThisAct) 319 helptb.addAction(self.whatsThisAct)
320 320
321 def __whatsThis(self): 321 def __whatsThis(self):
322 """ 322 """
348 """ 348 """
349 Private slot to show the about information. 349 Private slot to show the about information.
350 """ 350 """
351 E5MessageBox.about( 351 E5MessageBox.about(
352 self, 352 self,
353 self.trUtf8("TR Previewer"), 353 self.tr("TR Previewer"),
354 self.trUtf8( 354 self.tr(
355 """<h3> About TR Previewer </h3>""" 355 """<h3> About TR Previewer </h3>"""
356 """<p>The TR Previewer loads and displays Qt User-Interface""" 356 """<p>The TR Previewer loads and displays Qt User-Interface"""
357 """ files and translation files and shows dialogs for a""" 357 """ files and translation files and shows dialogs for a"""
358 """ selected language.</p>""" 358 """ selected language.</p>"""
359 ) 359 )
361 361
362 def __aboutQt(self): 362 def __aboutQt(self):
363 """ 363 """
364 Private slot to show info about Qt. 364 Private slot to show info about Qt.
365 """ 365 """
366 E5MessageBox.aboutQt(self, self.trUtf8("TR Previewer")) 366 E5MessageBox.aboutQt(self, self.tr("TR Previewer"))
367 367
368 def __openWidget(self): 368 def __openWidget(self):
369 """ 369 """
370 Private slot to handle the Open Dialog action. 370 Private slot to handle the Open Dialog action.
371 """ 371 """
372 fileNameList = E5FileDialog.getOpenFileNames( 372 fileNameList = E5FileDialog.getOpenFileNames(
373 None, 373 None,
374 self.trUtf8("Select UI files"), 374 self.tr("Select UI files"),
375 "", 375 "",
376 self.trUtf8("Qt User-Interface Files (*.ui)")) 376 self.tr("Qt User-Interface Files (*.ui)"))
377 377
378 for fileName in fileNameList: 378 for fileName in fileNameList:
379 self.preview.loadWidget(fileName) 379 self.preview.loadWidget(fileName)
380 380
381 self.__updateActions() 381 self.__updateActions()
384 """ 384 """
385 Private slot to handle the Open Translation action. 385 Private slot to handle the Open Translation action.
386 """ 386 """
387 fileNameList = E5FileDialog.getOpenFileNames( 387 fileNameList = E5FileDialog.getOpenFileNames(
388 None, 388 None,
389 self.trUtf8("Select translation files"), 389 self.tr("Select translation files"),
390 "", 390 "",
391 self.trUtf8("Qt Translation Files (*.qm)")) 391 self.tr("Qt Translation Files (*.qm)"))
392 392
393 first = True 393 first = True
394 for fileName in fileNameList: 394 for fileName in fileNameList:
395 self.translations.add(fileName, first) 395 self.translations.add(fileName, first)
396 first = False 396 first = False
475 ntr.fileName = fileName 475 ntr.fileName = fileName
476 ntr.name = self.__uniqueName(fileName) 476 ntr.name = self.__uniqueName(fileName)
477 if ntr.name is None: 477 if ntr.name is None:
478 E5MessageBox.warning( 478 E5MessageBox.warning(
479 self.parent(), 479 self.parent(),
480 self.trUtf8("Set Translator"), 480 self.tr("Set Translator"),
481 self.trUtf8( 481 self.tr(
482 """<p>The translation filename <b>{0}</b>""" 482 """<p>The translation filename <b>{0}</b>"""
483 """ is invalid.</p>""").format(fileName)) 483 """ is invalid.</p>""").format(fileName))
484 return 484 return
485 485
486 ntr.translator = self.loadTransFile(fileName) 486 ntr.translator = self.loadTransFile(fileName)
505 if name != noTranslationName: 505 if name != noTranslationName:
506 trans = self.__findName(name) 506 trans = self.__findName(name)
507 if trans is None: 507 if trans is None:
508 E5MessageBox.warning( 508 E5MessageBox.warning(
509 self.parent(), 509 self.parent(),
510 self.trUtf8("Set Translator"), 510 self.tr("Set Translator"),
511 self.trUtf8( 511 self.tr(
512 """<p>The translator <b>{0}</b> is not known.</p>""") 512 """<p>The translator <b>{0}</b> is not known.</p>""")
513 .format(name)) 513 .format(name))
514 return 514 return
515 515
516 nTranslator = trans.translator 516 nTranslator = trans.translator
648 if tr.load(transFileName): 648 if tr.load(transFileName):
649 return tr 649 return tr
650 650
651 E5MessageBox.warning( 651 E5MessageBox.warning(
652 self.parent(), 652 self.parent(),
653 self.trUtf8("Load Translator"), 653 self.tr("Load Translator"),
654 self.trUtf8("""<p>The translation file <b>{0}</b> could""" 654 self.tr("""<p>The translation file <b>{0}</b> could"""
655 """ not be loaded.</p>""").format(transFileName)) 655 """ not be loaded.</p>""").format(transFileName))
656 return None 656 return None
657 657
658 def hasTranslations(self): 658 def hasTranslations(self):
659 """ 659 """
660 Public method to check for loaded translations. 660 Public method to check for loaded translations.
722 pass 722 pass
723 723
724 if not self.__widget: 724 if not self.__widget:
725 E5MessageBox.warning( 725 E5MessageBox.warning(
726 self, 726 self,
727 self.trUtf8("Load UI File"), 727 self.tr("Load UI File"),
728 self.trUtf8( 728 self.tr(
729 """<p>The file <b>{0}</b> could not be loaded.</p>""") 729 """<p>The file <b>{0}</b> could not be loaded.</p>""")
730 .format(self.__uiFileName)) 730 .format(self.__uiFileName))
731 self.__valid = False 731 self.__valid = False
732 return 732 return
733 733
778 if wview is None: 778 if wview is None:
779 name = os.path.basename(uiFileName) 779 name = os.path.basename(uiFileName)
780 if not name: 780 if not name:
781 E5MessageBox.warning( 781 E5MessageBox.warning(
782 self, 782 self,
783 self.trUtf8("Load UI File"), 783 self.tr("Load UI File"),
784 self.trUtf8( 784 self.tr(
785 """<p>The file <b>{0}</b> could not be loaded.</p>""") 785 """<p>The file <b>{0}</b> could not be loaded.</p>""")
786 .format(uiFileName)) 786 .format(uiFileName))
787 return 787 return
788 788
789 uname = name 789 uname = name

eric ide

mercurial