Tools/TRPreviewer.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
21 import UI.Config 21 import UI.Config
22 22
23 23
24 noTranslationName = QApplication.translate("TRPreviewer", "<No translation>") 24 noTranslationName = QApplication.translate("TRPreviewer", "<No translation>")
25 25
26
26 class TRPreviewer(QMainWindow): 27 class TRPreviewer(QMainWindow):
27 """ 28 """
28 Class implementing the UI Previewer main window. 29 Class implementing the UI Previewer main window.
29 """ 30 """
30 def __init__(self, filenames = [], parent = None, name = None): 31 def __init__(self, filenames=[], parent=None, name=None):
31 """ 32 """
32 Constructor 33 Constructor
33 34
34 @param filenames filenames of form and/or translation files to load 35 @param filenames filenames of form and/or translation files to load
35 @param parent parent widget of this window (QWidget) 36 @param parent parent widget of this window (QWidget)
118 first = True 119 first = True
119 for fn in filenames: 120 for fn in filenames:
120 fi = QFileInfo(fn) 121 fi = QFileInfo(fn)
121 if fi.suffix().lower() == 'ui': 122 if fi.suffix().lower() == 'ui':
122 self.preview.loadWidget(fn) 123 self.preview.loadWidget(fn)
123 elif fi.suffix().lower()== 'qm': 124 elif fi.suffix().lower() == 'qm':
124 self.translations.add(fn, first) 125 self.translations.add(fn, first)
125 first = False 126 first = False
126 127
127 self.__updateActions() 128 self.__updateActions()
128 129
139 140
140 def __initActions(self): 141 def __initActions(self):
141 """ 142 """
142 Private method to define the user interface actions. 143 Private method to define the user interface actions.
143 """ 144 """
144 self.openUIAct = QAction(UI.PixmapCache.getIcon("openUI.png"), 145 self.openUIAct = QAction(UI.PixmapCache.getIcon("openUI.png"),
145 self.trUtf8('&Open UI Files...'), self) 146 self.trUtf8('&Open UI Files...'), self)
146 self.openUIAct.setStatusTip(self.trUtf8('Open UI files for display')) 147 self.openUIAct.setStatusTip(self.trUtf8('Open UI files for display'))
147 self.openUIAct.setWhatsThis(self.trUtf8( 148 self.openUIAct.setWhatsThis(self.trUtf8(
148 """<b>Open UI Files</b>""" 149 """<b>Open UI Files</b>"""
149 """<p>This opens some UI files for display.</p>""" 150 """<p>This opens some UI files for display.</p>"""
150 )) 151 ))
151 self.openUIAct.triggered[()].connect(self.__openWidget) 152 self.openUIAct.triggered[()].connect(self.__openWidget)
152 153
153 self.openQMAct = QAction(UI.PixmapCache.getIcon("openQM.png"), 154 self.openQMAct = QAction(UI.PixmapCache.getIcon("openQM.png"),
154 self.trUtf8('Open &Translation Files...'), self) 155 self.trUtf8('Open &Translation Files...'), self)
155 self.openQMAct.setStatusTip(self.trUtf8('Open Translation files for display')) 156 self.openQMAct.setStatusTip(self.trUtf8('Open Translation files for display'))
156 self.openQMAct.setWhatsThis(self.trUtf8( 157 self.openQMAct.setWhatsThis(self.trUtf8(
157 """<b>Open Translation Files</b>""" 158 """<b>Open Translation Files</b>"""
158 """<p>This opens some translation files for display.</p>""" 159 """<p>This opens some translation files for display.</p>"""
159 )) 160 ))
160 self.openQMAct.triggered[()].connect(self.__openTranslation) 161 self.openQMAct.triggered[()].connect(self.__openTranslation)
161 162
162 self.reloadAct = QAction(UI.PixmapCache.getIcon("reload.png"), 163 self.reloadAct = QAction(UI.PixmapCache.getIcon("reload.png"),
163 self.trUtf8('&Reload Translations'), self) 164 self.trUtf8('&Reload Translations'), self)
164 self.reloadAct.setStatusTip(self.trUtf8('Reload the loaded translations')) 165 self.reloadAct.setStatusTip(self.trUtf8('Reload the loaded translations'))
165 self.reloadAct.setWhatsThis(self.trUtf8( 166 self.reloadAct.setWhatsThis(self.trUtf8(
166 """<b>Reload Translations</b>""" 167 """<b>Reload Translations</b>"""
167 """<p>This reloads the translations for the loaded languages.</p>""" 168 """<p>This reloads the translations for the loaded languages.</p>"""
168 )) 169 ))
169 self.reloadAct.triggered[()].connect(self.translations.reload) 170 self.reloadAct.triggered[()].connect(self.translations.reload)
170 171
171 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"), 172 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"),
172 self.trUtf8('&Quit'), self) 173 self.trUtf8('&Quit'), self)
173 self.exitAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+Q","File|Quit"))) 174 self.exitAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+Q", "File|Quit")))
174 self.exitAct.setStatusTip(self.trUtf8('Quit the application')) 175 self.exitAct.setStatusTip(self.trUtf8('Quit the application'))
175 self.exitAct.setWhatsThis(self.trUtf8( 176 self.exitAct.setWhatsThis(self.trUtf8(
176 """<b>Quit</b>""" 177 """<b>Quit</b>"""
177 """<p>Quit the application.</p>""" 178 """<p>Quit the application.</p>"""
178 )) 179 ))
225 )) 226 ))
226 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows) 227 self.cascadeAct.triggered[()].connect(self.preview.cascadeSubWindows)
227 228
228 self.closeAct = QAction(UI.PixmapCache.getIcon("close.png"), 229 self.closeAct = QAction(UI.PixmapCache.getIcon("close.png"),
229 self.trUtf8('&Close'), self) 230 self.trUtf8('&Close'), self)
230 self.closeAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+W","File|Close"))) 231 self.closeAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+W", "File|Close")))
231 self.closeAct.setStatusTip(self.trUtf8('Close the current window')) 232 self.closeAct.setStatusTip(self.trUtf8('Close the current window'))
232 self.closeAct.setWhatsThis(self.trUtf8( 233 self.closeAct.setWhatsThis(self.trUtf8(
233 """<b>Close Window</b>""" 234 """<b>Close Window</b>"""
234 """<p>Close the current window.</p>""" 235 """<p>Close the current window.</p>"""
235 )) 236 ))
389 """ 390 """
390 Public slot to reload all translations. 391 Public slot to reload all translations.
391 """ 392 """
392 self.translations.reload() 393 self.translations.reload()
393 394
395
394 class Translation(object): 396 class Translation(object):
395 """ 397 """
396 Class to store the properties of a translation 398 Class to store the properties of a translation
397 """ 399 """
398 def __init__(self): 400 def __init__(self):
401 """ 403 """
402 self.fileName = None 404 self.fileName = None
403 self.name = None 405 self.name = None
404 self.translator = None 406 self.translator = None
405 407
408
406 class TranslationsDict(QObject): 409 class TranslationsDict(QObject):
407 """ 410 """
408 Class to store all loaded translations. 411 Class to store all loaded translations.
409 412
410 @signal translationChanged() emit after a translator was set 413 @signal translationChanged() emit after a translator was set
422 QObject.__init__(self, parent) 425 QObject.__init__(self, parent)
423 426
424 self.selector = selector 427 self.selector = selector
425 self.currentTranslator = None 428 self.currentTranslator = None
426 self.selector.addItem(noTranslationName) 429 self.selector.addItem(noTranslationName)
427 self.translations = [] # list of Translation objects 430 self.translations = [] # list of Translation objects
428 431
429 def add(self, fileName, setTranslation = True): 432 def add(self, fileName, setTranslation=True):
430 """ 433 """
431 Public method to add a translation to the list. 434 Public method to add a translation to the list.
432 435
433 If the translation file (*.qm) has not been loaded yet, it will 436 If the translation file (*.qm) has not been loaded yet, it will
434 be loaded automatically. 437 be loaded automatically.
622 625
623 @return flag signaling if any translation was loaded (boolean) 626 @return flag signaling if any translation was loaded (boolean)
624 """ 627 """
625 return len(self.translations) > 0 628 return len(self.translations) > 0
626 629
630
627 class WidgetView(QWidget): 631 class WidgetView(QWidget):
628 """ 632 """
629 Class to show a dynamically loaded widget (or dialog). 633 Class to show a dynamically loaded widget (or dialog).
630 """ 634 """
631 def __init__(self, uiFileName, parent = None, name = None): 635 def __init__(self, uiFileName, parent=None, name=None):
632 """ 636 """
633 Constructor 637 Constructor
634 638
635 @param uiFileName name of the UI file to load (string) 639 @param uiFileName name of the UI file to load (string)
636 @param parent parent widget (QWidget) 640 @param parent parent widget (QWidget)
701 """ 705 """
702 Private method to schedule a rebuild of the widget. 706 Private method to schedule a rebuild of the widget.
703 """ 707 """
704 self.__timer.start(0) 708 self.__timer.start(0)
705 709
710
706 class WidgetArea(QMdiArea): 711 class WidgetArea(QMdiArea):
707 """ 712 """
708 Specialized MDI area to show the loaded widgets. 713 Specialized MDI area to show the loaded widgets.
709 714
710 @signal lastWidgetClosed() emitted after last widget was closed 715 @signal lastWidgetClosed() emitted after last widget was closed
711 """ 716 """
712 lastWidgetClosed = pyqtSignal() 717 lastWidgetClosed = pyqtSignal()
713 rebuildWidgets = pyqtSignal() 718 rebuildWidgets = pyqtSignal()
714 719
715 def __init__(self, parent = None): 720 def __init__(self, parent=None):
716 """ 721 """
717 Constructor 722 Constructor
718 723
719 @param parent parent widget (QWidget) 724 @param parent parent widget (QWidget)
720 """ 725 """

eric ide

mercurial