Tools/UIPreviewer.py

changeset 945
8cd4d08fa9f6
parent 897
3dcaa3195a64
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
14 from E5Gui import E5MessageBox, E5FileDialog 14 from E5Gui import E5MessageBox, E5FileDialog
15 15
16 import Preferences 16 import Preferences
17 import UI.PixmapCache 17 import UI.PixmapCache
18 import UI.Config 18 import UI.Config
19
19 20
20 class UIPreviewer(QMainWindow): 21 class UIPreviewer(QMainWindow):
21 """ 22 """
22 Class implementing the UI Previewer main window. 23 Class implementing the UI Previewer main window.
23 """ 24 """
24 def __init__(self, filename = None, parent = None, name = None): 25 def __init__(self, filename=None, parent=None, name=None):
25 """ 26 """
26 Constructor 27 Constructor
27 28
28 @param filename name of a UI file to load 29 @param filename name of a UI file to load
29 @param parent parent widget of this window (QWidget) 30 @param parent parent widget of this window (QWidget)
110 111
111 def __initActions(self): 112 def __initActions(self):
112 """ 113 """
113 Private method to define the user interface actions. 114 Private method to define the user interface actions.
114 """ 115 """
115 self.openAct = QAction(UI.PixmapCache.getIcon("openUI.png"), 116 self.openAct = QAction(UI.PixmapCache.getIcon("openUI.png"),
116 self.trUtf8('&Open File'), self) 117 self.trUtf8('&Open File'), self)
117 self.openAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+O", "File|Open"))) 118 self.openAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+O", "File|Open")))
118 self.openAct.setStatusTip(self.trUtf8('Open a UI file for display')) 119 self.openAct.setStatusTip(self.trUtf8('Open a UI file for display'))
119 self.openAct.setWhatsThis(self.trUtf8( 120 self.openAct.setWhatsThis(self.trUtf8(
120 """<b>Open File</b>""" 121 """<b>Open File</b>"""
121 """<p>This opens a new UI file for display.</p>""" 122 """<p>This opens a new UI file for display.</p>"""
122 )) 123 ))
123 self.openAct.triggered[()].connect(self.__openFile) 124 self.openAct.triggered[()].connect(self.__openFile)
124 125
125 self.printAct = QAction(UI.PixmapCache.getIcon("print.png"), 126 self.printAct = QAction(UI.PixmapCache.getIcon("print.png"),
126 self.trUtf8('&Print'), self) 127 self.trUtf8('&Print'), self)
127 self.printAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+P", "File|Print"))) 128 self.printAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+P", "File|Print")))
128 self.printAct.setStatusTip(self.trUtf8('Print a screen capture')) 129 self.printAct.setStatusTip(self.trUtf8('Print a screen capture'))
129 self.printAct.setWhatsThis(self.trUtf8( 130 self.printAct.setWhatsThis(self.trUtf8(
130 """<b>Print</b>""" 131 """<b>Print</b>"""
131 """<p>Print a screen capture.</p>""" 132 """<p>Print a screen capture.</p>"""
132 )) 133 ))
133 self.printAct.triggered[()].connect(self.__printImage) 134 self.printAct.triggered[()].connect(self.__printImage)
134 135
135 self.printPreviewAct = QAction(UI.PixmapCache.getIcon("printPreview.png"), 136 self.printPreviewAct = QAction(UI.PixmapCache.getIcon("printPreview.png"),
136 self.trUtf8('Print Preview'), self) 137 self.trUtf8('Print Preview'), self)
137 self.printPreviewAct.setStatusTip(self.trUtf8( 138 self.printPreviewAct.setStatusTip(self.trUtf8(
138 'Print preview a screen capture')) 139 'Print preview a screen capture'))
139 self.printPreviewAct.setWhatsThis(self.trUtf8( 140 self.printPreviewAct.setWhatsThis(self.trUtf8(
140 """<b>Print Preview</b>""" 141 """<b>Print Preview</b>"""
141 """<p>Print preview a screen capture.</p>""" 142 """<p>Print preview a screen capture.</p>"""
142 )) 143 ))
143 self.printPreviewAct.triggered[()].connect(self.__printPreviewImage) 144 self.printPreviewAct.triggered[()].connect(self.__printPreviewImage)
144 145
145 self.imageAct = QAction(UI.PixmapCache.getIcon("screenCapture.png"), 146 self.imageAct = QAction(UI.PixmapCache.getIcon("screenCapture.png"),
146 self.trUtf8('&Screen Capture'), self) 147 self.trUtf8('&Screen Capture'), self)
147 self.imageAct.setShortcut( 148 self.imageAct.setShortcut(
148 QKeySequence(self.trUtf8("Ctrl+S", "File|Screen Capture"))) 149 QKeySequence(self.trUtf8("Ctrl+S", "File|Screen Capture")))
149 self.imageAct.setStatusTip(self.trUtf8('Save a screen capture to an image file')) 150 self.imageAct.setStatusTip(self.trUtf8('Save a screen capture to an image file'))
150 self.imageAct.setWhatsThis(self.trUtf8( 151 self.imageAct.setWhatsThis(self.trUtf8(
151 """<b>Screen Capture</b>""" 152 """<b>Screen Capture</b>"""
152 """<p>Save a screen capture to an image file.</p>""" 153 """<p>Save a screen capture to an image file.</p>"""
153 )) 154 ))
154 self.imageAct.triggered[()].connect(self.__saveImage) 155 self.imageAct.triggered[()].connect(self.__saveImage)
155 156
156 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"), 157 self.exitAct = QAction(UI.PixmapCache.getIcon("exit.png"),
157 self.trUtf8('&Quit'), self) 158 self.trUtf8('&Quit'), self)
158 self.exitAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+Q", "File|Quit"))) 159 self.exitAct.setShortcut(QKeySequence(self.trUtf8("Ctrl+Q", "File|Quit")))
159 self.exitAct.setStatusTip(self.trUtf8('Quit the application')) 160 self.exitAct.setStatusTip(self.trUtf8('Quit the application'))
160 self.exitAct.setWhatsThis(self.trUtf8( 161 self.exitAct.setWhatsThis(self.trUtf8(
161 """<b>Quit</b>""" 162 """<b>Quit</b>"""
289 def __openFile(self): 290 def __openFile(self):
290 """ 291 """
291 Private slot to load a new file. 292 Private slot to load a new file.
292 """ 293 """
293 fn = E5FileDialog.getOpenFileName( 294 fn = E5FileDialog.getOpenFileName(
294 self, 295 self,
295 self.trUtf8("Select UI file"), 296 self.trUtf8("Select UI file"),
296 self.currentFile, 297 self.currentFile,
297 self.trUtf8("Qt User-Interface Files (*.ui)")) 298 self.trUtf8("Qt User-Interface Files (*.ui)"))
298 if fn: 299 if fn:
299 self.__loadFile(fn) 300 self.__loadFile(fn)
354 self.mainWidget.hide() 355 self.mainWidget.hide()
355 self.mainWidget.show() 356 self.mainWidget.show()
356 357
357 self.lastQStyle = qstyle 358 self.lastQStyle = qstyle
358 self.lastStyle = sstyle 359 self.lastStyle = sstyle
359 Preferences.Prefs.settings.setValue('UIPreviewer/style', 360 Preferences.Prefs.settings.setValue('UIPreviewer/style',
360 self.styleCombo.currentIndex()) 361 self.styleCombo.currentIndex())
361 QApplication.restoreOverrideCursor() 362 QApplication.restoreOverrideCursor()
362 363
363 def __updateActions(self): 364 def __updateActions(self):
364 """ 365 """
546 marginX *= 2 547 marginX *= 2
547 width = printer.width() - marginX * 2 548 width = printer.width() - marginX * 2
548 height = printer.height() - marginY * 2 549 height = printer.height() - marginY * 2
549 img = QPixmap.grabWidget(self.mainWidget).toImage() 550 img = QPixmap.grabWidget(self.mainWidget).toImage()
550 self.__updateChildren(self.lastStyle) 551 self.__updateChildren(self.lastStyle)
551 p.drawImage(marginX, marginY, 552 p.drawImage(marginX, marginY,
552 img.scaled(width, height, 553 img.scaled(width, height,
553 Qt.KeepAspectRatio, Qt.SmoothTransformation)) 554 Qt.KeepAspectRatio, Qt.SmoothTransformation))
554 p.end() 555 p.end()

eric ide

mercurial