Tools/UIPreviewer.py

branch
5_3_x
changeset 2468
957f6e1d97e1
parent 2302
f29e9405c851
child 2525
8b507a9a2d40
child 2824
858412c29c34
equal deleted inserted replaced
2466:6739502248ef 2468:957f6e1d97e1
5 5
6 """ 6 """
7 Module implementing the UI Previewer main window. 7 Module implementing the UI Previewer main window.
8 """ 8 """
9 9
10 from PyQt4.QtCore import QDir, QFileInfo, QEvent, QSize, Qt 10 from PyQt4.QtCore import qVersion, QDir, QFileInfo, QEvent, QSize, Qt
11 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QCursor, \ 11 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QCursor, \
12 QPrinter, QKeySequence, QPrintDialog, QWhatsThis, QPixmap, QImageWriter, QPainter, \ 12 QPrinter, QKeySequence, QPrintDialog, QWhatsThis, QPixmap, QImageWriter, QPainter, \
13 QDialog, QScrollArea, qApp, QApplication, QStyleFactory, QFrame, QMainWindow, \ 13 QDialog, QScrollArea, qApp, QApplication, QStyleFactory, QFrame, QMainWindow, \
14 QComboBox, QVBoxLayout, QAction, QLabel 14 QComboBox, QVBoxLayout, QAction, QLabel
15 from PyQt4 import uic 15 from PyQt4 import uic
445 ext = QFileInfo(fname).suffix().upper() 445 ext = QFileInfo(fname).suffix().upper()
446 if not ext: 446 if not ext:
447 ext = defaultExt 447 ext = defaultExt
448 fname.append(".{0}".format(defaultExt.lower())) 448 fname.append(".{0}".format(defaultExt.lower()))
449 449
450 pix = QPixmap.grabWidget(self.mainWidget) 450 if qVersion() >= "5.0.0":
451 pix = self.mainWidget.grab()
452 else:
453 pix = QPixmap.grabWidget(self.mainWidget)
451 self.__updateChildren(self.lastStyle) 454 self.__updateChildren(self.lastStyle)
452 if not pix.save(fname, str(ext)): 455 if not pix.save(fname, str(ext)):
453 E5MessageBox.critical(self, 456 E5MessageBox.critical(self,
454 self.trUtf8("Save Image"), 457 self.trUtf8("Save Image"),
455 self.trUtf8("""<p>The file <b>{0}</b> could not be saved.</p>""") 458 self.trUtf8("""<p>The file <b>{0}</b> could not be saved.</p>""")
464 self.trUtf8("Save Image"), 467 self.trUtf8("Save Image"),
465 self.trUtf8("""There is no UI file loaded.""")) 468 self.trUtf8("""There is no UI file loaded."""))
466 return 469 return
467 470
468 cb = QApplication.clipboard() 471 cb = QApplication.clipboard()
469 cb.setPixmap(QPixmap.grabWidget(self.mainWidget)) 472 if qVersion() >= "5.0.0":
473 cb.setPixmap(self.mainWidget.grab())
474 else:
475 cb.setPixmap(QPixmap.grabWidget(self.mainWidget))
470 self.__updateChildren(self.lastStyle) 476 self.__updateChildren(self.lastStyle)
471 477
472 def __printImage(self): 478 def __printImage(self):
473 """ 479 """
474 Private slot to handle the Print Image menu action. 480 Private slot to handle the Print Image menu action.
552 height = printer.height() - marginY * 3 558 height = printer.height() - marginY * 3
553 else: 559 else:
554 marginX *= 2 560 marginX *= 2
555 width = printer.width() - marginX * 2 561 width = printer.width() - marginX * 2
556 height = printer.height() - marginY * 2 562 height = printer.height() - marginY * 2
557 img = QPixmap.grabWidget(self.mainWidget).toImage() 563 if qVersion() >= "5.0.0":
564 img = self.mainWidget.grab().toImage()
565 else:
566 img = QPixmap.grabWidget(self.mainWidget).toImage()
558 self.__updateChildren(self.lastStyle) 567 self.__updateChildren(self.lastStyle)
559 p.drawImage(marginX, marginY, 568 p.drawImage(marginX, marginY,
560 img.scaled(width, height, 569 img.scaled(width, height,
561 Qt.KeepAspectRatio, Qt.SmoothTransformation)) 570 Qt.KeepAspectRatio, Qt.SmoothTransformation))
562 p.end() 571 p.end()

eric ide

mercurial