Tools/UIPreviewer.py

branch
Py2 comp.
changeset 3058
0a02c433f52d
parent 3057
10516539f238
parent 3030
4a0a82ddd9d2
child 3060
5883ce99ee12
equal deleted inserted replaced
3057:10516539f238 3058:0a02c433f52d
124 124
125 def __initActions(self): 125 def __initActions(self):
126 """ 126 """
127 Private method to define the user interface actions. 127 Private method to define the user interface actions.
128 """ 128 """
129 self.openAct = QAction(UI.PixmapCache.getIcon("openUI.png"), 129 self.openAct = QAction(
130 self.trUtf8('&Open File'), self) 130 UI.PixmapCache.getIcon("openUI.png"),
131 self.trUtf8('&Open File'), self)
131 self.openAct.setShortcut( 132 self.openAct.setShortcut(
132 QKeySequence(self.trUtf8("Ctrl+O", "File|Open"))) 133 QKeySequence(self.trUtf8("Ctrl+O", "File|Open")))
133 self.openAct.setStatusTip(self.trUtf8('Open a UI file for display')) 134 self.openAct.setStatusTip(self.trUtf8('Open a UI file for display'))
134 self.openAct.setWhatsThis(self.trUtf8( 135 self.openAct.setWhatsThis(self.trUtf8(
135 """<b>Open File</b>""" 136 """<b>Open File</b>"""
136 """<p>This opens a new UI file for display.</p>""" 137 """<p>This opens a new UI file for display.</p>"""
137 )) 138 ))
138 self.openAct.triggered[()].connect(self.__openFile) 139 self.openAct.triggered[()].connect(self.__openFile)
139 140
140 self.printAct = QAction(UI.PixmapCache.getIcon("print.png"), 141 self.printAct = QAction(
141 self.trUtf8('&Print'), self) 142 UI.PixmapCache.getIcon("print.png"),
143 self.trUtf8('&Print'), self)
142 self.printAct.setShortcut( 144 self.printAct.setShortcut(
143 QKeySequence(self.trUtf8("Ctrl+P", "File|Print"))) 145 QKeySequence(self.trUtf8("Ctrl+P", "File|Print")))
144 self.printAct.setStatusTip(self.trUtf8('Print a screen capture')) 146 self.printAct.setStatusTip(self.trUtf8('Print a screen capture'))
145 self.printAct.setWhatsThis(self.trUtf8( 147 self.printAct.setWhatsThis(self.trUtf8(
146 """<b>Print</b>""" 148 """<b>Print</b>"""
157 """<b>Print Preview</b>""" 159 """<b>Print Preview</b>"""
158 """<p>Print preview a screen capture.</p>""" 160 """<p>Print preview a screen capture.</p>"""
159 )) 161 ))
160 self.printPreviewAct.triggered[()].connect(self.__printPreviewImage) 162 self.printPreviewAct.triggered[()].connect(self.__printPreviewImage)
161 163
162 self.imageAct = QAction(UI.PixmapCache.getIcon("screenCapture.png"), 164 self.imageAct = QAction(
163 self.trUtf8('&Screen Capture'), self) 165 UI.PixmapCache.getIcon("screenCapture.png"),
166 self.trUtf8('&Screen Capture'), self)
164 self.imageAct.setShortcut( 167 self.imageAct.setShortcut(
165 QKeySequence(self.trUtf8("Ctrl+S", "File|Screen Capture"))) 168 QKeySequence(self.trUtf8("Ctrl+S", "File|Screen Capture")))
166 self.imageAct.setStatusTip(self.trUtf8( 169 self.imageAct.setStatusTip(self.trUtf8(
167 'Save a screen capture to an image file')) 170 'Save a screen capture to an image file'))
168 self.imageAct.setWhatsThis(self.trUtf8( 171 self.imageAct.setWhatsThis(self.trUtf8(
169 """<b>Screen Capture</b>""" 172 """<b>Screen Capture</b>"""
170 """<p>Save a screen capture to an image file.</p>""" 173 """<p>Save a screen capture to an image file.</p>"""
171 )) 174 ))
172 self.imageAct.triggered[()].connect(self.__saveImage) 175 self.imageAct.triggered[()].connect(self.__saveImage)
173 176
174 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"), 177 self.exitAct = QAction(
175 self.trUtf8('&Quit'), self) 178 UI.PixmapCache.getIcon("exit.png"), self.trUtf8('&Quit'), self)
176 self.exitAct.setShortcut( 179 self.exitAct.setShortcut(
177 QKeySequence(self.trUtf8("Ctrl+Q", "File|Quit"))) 180 QKeySequence(self.trUtf8("Ctrl+Q", "File|Quit")))
178 self.exitAct.setStatusTip(self.trUtf8('Quit the application')) 181 self.exitAct.setStatusTip(self.trUtf8('Quit the application'))
179 self.exitAct.setWhatsThis(self.trUtf8( 182 self.exitAct.setWhatsThis(self.trUtf8(
180 """<b>Quit</b>""" 183 """<b>Quit</b>"""
181 """<p>Quit the application.</p>""" 184 """<p>Quit the application.</p>"""
182 )) 185 ))
183 self.exitAct.triggered[()].connect(qApp.closeAllWindows) 186 self.exitAct.triggered[()].connect(qApp.closeAllWindows)
184 187
185 self.copyAct = QAction(UI.PixmapCache.getIcon("editCopy.png"), 188 self.copyAct = QAction(
186 self.trUtf8('&Copy'), self) 189 UI.PixmapCache.getIcon("editCopy.png"), self.trUtf8('&Copy'), self)
187 self.copyAct.setShortcut( 190 self.copyAct.setShortcut(
188 QKeySequence(self.trUtf8("Ctrl+C", "Edit|Copy"))) 191 QKeySequence(self.trUtf8("Ctrl+C", "Edit|Copy")))
189 self.copyAct.setStatusTip( 192 self.copyAct.setStatusTip(
190 self.trUtf8('Copy screen capture to clipboard')) 193 self.trUtf8('Copy screen capture to clipboard'))
191 self.copyAct.setWhatsThis(self.trUtf8( 194 self.copyAct.setWhatsThis(self.trUtf8(
192 """<b>Copy</b>""" 195 """<b>Copy</b>"""
193 """<p>Copy screen capture to clipboard.</p>""" 196 """<p>Copy screen capture to clipboard.</p>"""
194 )) 197 ))
195 self.copyAct.triggered[()].connect(self.__copyImageToClipboard) 198 self.copyAct.triggered[()].connect(self.__copyImageToClipboard)
196 199
197 self.whatsThisAct = QAction(UI.PixmapCache.getIcon("whatsThis.png"), 200 self.whatsThisAct = QAction(
198 self.trUtf8('&What\'s This?'), self) 201 UI.PixmapCache.getIcon("whatsThis.png"),
202 self.trUtf8('&What\'s This?'), self)
199 self.whatsThisAct.setShortcut(QKeySequence(self.trUtf8("Shift+F1"))) 203 self.whatsThisAct.setShortcut(QKeySequence(self.trUtf8("Shift+F1")))
200 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help')) 204 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help'))
201 self.whatsThisAct.setWhatsThis(self.trUtf8( 205 self.whatsThisAct.setWhatsThis(self.trUtf8(
202 """<b>Display context sensitive help</b>""" 206 """<b>Display context sensitive help</b>"""
203 """<p>In What's This? mode, the mouse cursor shows an arrow""" 207 """<p>In What's This? mode, the mouse cursor shows an arrow"""
294 298
295 def __about(self): 299 def __about(self):
296 """ 300 """
297 Private slot to show the about information. 301 Private slot to show the about information.
298 """ 302 """
299 E5MessageBox.about(self, self.trUtf8("UI Previewer"), self.trUtf8( 303 E5MessageBox.about(
300 """<h3> About UI Previewer </h3>""" 304 self,
301 """<p>The UI Previewer loads and displays Qt User-Interface""" 305 self.trUtf8("UI Previewer"),
302 """ files with various styles, which are selectable via a""" 306 self.trUtf8(
303 """ selection list.</p>""" 307 """<h3> About UI Previewer </h3>"""
304 )) 308 """<p>The UI Previewer loads and displays Qt User-Interface"""
309 """ files with various styles, which are selectable via a"""
310 """ selection list.</p>"""
311 )
312 )
305 313
306 def __aboutQt(self): 314 def __aboutQt(self):
307 """ 315 """
308 Private slot to show info about Qt. 316 Private slot to show info about Qt.
309 """ 317 """
348 self.mainWidget.installEventFilter(self) 356 self.mainWidget.installEventFilter(self)
349 else: 357 else:
350 self.previewSV.setWidget(self.mainWidget) 358 self.previewSV.setWidget(self.mainWidget)
351 self.mainWidget.show() 359 self.mainWidget.show()
352 else: 360 else:
353 E5MessageBox.warning(self, 361 E5MessageBox.warning(
362 self,
354 self.trUtf8("Load UI File"), 363 self.trUtf8("Load UI File"),
355 self.trUtf8( 364 self.trUtf8(
356 """<p>The file <b>{0}</b> could not be loaded.</p>""")\ 365 """<p>The file <b>{0}</b> could not be loaded.</p>""")\
357 .format(fn)) 366 .format(fn))
358 self.__updateActions() 367 self.__updateActions()
378 self.mainWidget.hide() 387 self.mainWidget.hide()
379 self.mainWidget.show() 388 self.mainWidget.show()
380 389
381 self.lastQStyle = qstyle 390 self.lastQStyle = qstyle
382 self.lastStyle = sstyle 391 self.lastStyle = sstyle
383 Preferences.Prefs.settings.setValue('UIPreviewer/style', 392 Preferences.Prefs.settings.setValue(
384 self.styleCombo.currentIndex()) 393 'UIPreviewer/style', self.styleCombo.currentIndex())
385 QApplication.restoreOverrideCursor() 394 QApplication.restoreOverrideCursor()
386 395
387 def __updateActions(self): 396 def __updateActions(self):
388 """ 397 """
389 Private slot to update the actions state. 398 Private slot to update the actions state.
436 def __saveImage(self): 445 def __saveImage(self):
437 """ 446 """
438 Private slot to handle the Save Image menu action. 447 Private slot to handle the Save Image menu action.
439 """ 448 """
440 if self.mainWidget is None: 449 if self.mainWidget is None:
441 E5MessageBox.critical(self, 450 E5MessageBox.critical(
451 self,
442 self.trUtf8("Save Image"), 452 self.trUtf8("Save Image"),
443 self.trUtf8("""There is no UI file loaded.""")) 453 self.trUtf8("""There is no UI file loaded."""))
444 return 454 return
445 455
446 defaultExt = "PNG" 456 defaultExt = "PNG"
468 pix = self.mainWidget.grab() 478 pix = self.mainWidget.grab()
469 else: 479 else:
470 pix = QPixmap.grabWidget(self.mainWidget) 480 pix = QPixmap.grabWidget(self.mainWidget)
471 self.__updateChildren(self.lastStyle) 481 self.__updateChildren(self.lastStyle)
472 if not pix.save(fname, str(ext)): 482 if not pix.save(fname, str(ext)):
473 E5MessageBox.critical(self, 483 E5MessageBox.critical(
484 self,
474 self.trUtf8("Save Image"), 485 self.trUtf8("Save Image"),
475 self.trUtf8( 486 self.trUtf8(
476 """<p>The file <b>{0}</b> could not be saved.</p>""") 487 """<p>The file <b>{0}</b> could not be saved.</p>""")
477 .format(fname)) 488 .format(fname))
478 489
479 def __copyImageToClipboard(self): 490 def __copyImageToClipboard(self):
480 """ 491 """
481 Private slot to handle the Copy Image menu action. 492 Private slot to handle the Copy Image menu action.
482 """ 493 """
483 if self.mainWidget is None: 494 if self.mainWidget is None:
484 E5MessageBox.critical(self, 495 E5MessageBox.critical(
496 self,
485 self.trUtf8("Save Image"), 497 self.trUtf8("Save Image"),
486 self.trUtf8("""There is no UI file loaded.""")) 498 self.trUtf8("""There is no UI file loaded."""))
487 return 499 return
488 500
489 cb = QApplication.clipboard() 501 cb = QApplication.clipboard()
496 def __printImage(self): 508 def __printImage(self):
497 """ 509 """
498 Private slot to handle the Print Image menu action. 510 Private slot to handle the Print Image menu action.
499 """ 511 """
500 if self.mainWidget is None: 512 if self.mainWidget is None:
501 E5MessageBox.critical(self, 513 E5MessageBox.critical(
514 self,
502 self.trUtf8("Print Image"), 515 self.trUtf8("Print Image"),
503 self.trUtf8("""There is no UI file loaded.""")) 516 self.trUtf8("""There is no UI file loaded."""))
504 return 517 return
505 518
506 settings = Preferences.Prefs.settings 519 settings = Preferences.Prefs.settings
536 Private slot to handle the Print Preview menu action. 549 Private slot to handle the Print Preview menu action.
537 """ 550 """
538 from PyQt4.QtGui import QPrintPreviewDialog 551 from PyQt4.QtGui import QPrintPreviewDialog
539 552
540 if self.mainWidget is None: 553 if self.mainWidget is None:
541 E5MessageBox.critical(self, 554 E5MessageBox.critical(
555 self,
542 self.trUtf8("Print Preview"), 556 self.trUtf8("Print Preview"),
543 self.trUtf8("""There is no UI file loaded.""")) 557 self.trUtf8("""There is no UI file loaded."""))
544 return 558 return
545 559
546 settings = Preferences.Prefs.settings 560 settings = Preferences.Prefs.settings

eric ide

mercurial