Exemplo n.º 1
0
 def screenshot(self):
     # if we want to save whole desktop we can do:
     # QtGui.QPixmap.grabWindow(
     #   QtGui.QApplication.desktop().winId()).save(
     #       R'C:\src\me_ui\ModelEngine\bin.x64\pyqlrio\screenshot.png', 'png')
     fileName = QFileDialog.getSaveFileName(self, "Save File", ".",
                                            "Images (*.png)")
     if fileName:
         QPixmap.grabWidget(self.p).save(fileName)
Exemplo n.º 2
0
    def __print(self, printer):
        """
        Private slot to the actual printing.
        
        @param printer reference to the printer object (QPrinter)
        """
        p = QPainter(printer)
        marginX = (printer.pageRect().x() - printer.paperRect().x()) // 2
        marginY = (printer.pageRect().y() - printer.paperRect().y()) // 2

        # double the margin on bottom of page
        if printer.orientation() == QPrinter.Portrait:
            width = printer.width() - marginX * 2
            height = printer.height() - marginY * 3
        else:
            marginX *= 2
            width = printer.width() - marginX * 2
            height = printer.height() - marginY * 2
        if qVersion() >= "5.0.0":
            img = self.mainWidget.grab().toImage()
        else:
            img = QPixmap.grabWidget(self.mainWidget).toImage()
        self.__updateChildren(self.lastStyle)
        p.drawImage(
            marginX, marginY,
            img.scaled(width, height, Qt.KeepAspectRatio,
                       Qt.SmoothTransformation))
        p.end()
Exemplo n.º 3
0
    def __print(self, printer):
        """
        Private slot to the actual printing.
        
        @param printer reference to the printer object (QPrinter)
        """
        p = QPainter(printer)
        marginX = (printer.pageRect().x() - printer.paperRect().x()) // 2
        marginY = (printer.pageRect().y() - printer.paperRect().y()) // 2

        # double the margin on bottom of page
        if printer.orientation() == QPrinter.Portrait:
            width = printer.width() - marginX * 2
            height = printer.height() - marginY * 3
        else:
            marginX *= 2
            width = printer.width() - marginX * 2
            height = printer.height() - marginY * 2
        if qVersion() >= "5.0.0":
            img = self.mainWidget.grab().toImage()
        else:
            img = QPixmap.grabWidget(self.mainWidget).toImage()
        self.__updateChildren(self.lastStyle)
        p.drawImage(marginX, marginY,
                    img.scaled(width, height,
                               Qt.KeepAspectRatio, Qt.SmoothTransformation))
        p.end()
Exemplo n.º 4
0
    def mousePressEvent(self, event):
        # handle an internal move

        # start a drag event
        if event.button() == Qt.LeftButton and self.dragDropRect().contains(
                event.pos()):
            # create the pixmap
            pixmap = QPixmap.grabWidget(self, self.rect())

            # create the mimedata
            mimeData = QMimeData()
            mimeData.setText('ItemTitle::%s' % (self.title()))

            # create the drag
            drag = QDrag(self)
            drag.setMimeData(mimeData)
            drag.setPixmap(pixmap)
            drag.setHotSpot(event.pos())

            if not drag.exec_():
                self._accordianWidget.emitItemDragFailed(self)

            event.accept()

        # determine if the expand/collapse should occur
        elif event.button() == Qt.LeftButton and self.expandCollapseRect(
        ).contains(event.pos()):
            self._clicked = True
            event.accept()

        else:
            event.ignore()
Exemplo n.º 5
0
    def __copyImageToClipboard(self):
        """
        Private slot to handle the Copy Image menu action.
        """
        if self.mainWidget is None:
            E5MessageBox.critical(self, self.tr("Save Image"),
                                  self.tr("""There is no UI file loaded."""))
            return

        cb = QApplication.clipboard()
        if qVersion() >= "5.0.0":
            cb.setPixmap(self.mainWidget.grab())
        else:
            cb.setPixmap(QPixmap.grabWidget(self.mainWidget))
        self.__updateChildren(self.lastStyle)
Exemplo n.º 6
0
 def mouseMoveEvent(self, evt):
     """
     Protected method to handle mouse move events.
     
     @param evt reference to the event (QMouseEvent)
     """
     if self.__model is None:
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     if not (evt.buttons() & Qt.LeftButton):
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     manhattanLength = (evt.pos() -
                        self.__dragStartPosition).manhattanLength()
     if manhattanLength <= QApplication.startDragDistance():
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     act = self.actionAt(self.__dragStartPosition)
     if act is None:
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     idx = self.index(act)
     if not idx.isValid():
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     drag = QDrag(self)
     drag.setMimeData(self.__model.mimeData([idx]))
     actionRect = self.actionGeometry(act)
     if qVersion() >= "5.0.0":
         drag.setPixmap(self.grab(actionRect))
     else:
         drag.setPixmap(QPixmap.grabWidget(self, actionRect))
     
     if drag.exec_() == Qt.MoveAction:
         row = idx.row()
         if self.__dropIndex == idx.parent() and self.__dropRow <= row:
             row += 1
         self.__model.removeRow(row, self.__root)
         
         if not self.isAncestorOf(drag.target()):
             self.close()
         else:
             self.aboutToShow.emit()
Exemplo n.º 7
0
 def mouseMoveEvent(self, evt):
     """
     Protected method to handle mouse move events.
     
     @param evt reference to the event (QMouseEvent)
     """
     if self.__model is None:
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     if not (evt.buttons() & Qt.LeftButton):
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     manhattanLength = (evt.pos() -
                        self.__dragStartPosition).manhattanLength()
     if manhattanLength <= QApplication.startDragDistance():
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     act = self.actionAt(self.__dragStartPosition)
     if act is None:
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     idx = self.index(act)
     if not idx.isValid():
         super(E5ModelMenu, self).mouseMoveEvent(evt)
         return
     
     drag = QDrag(self)
     drag.setMimeData(self.__model.mimeData([idx]))
     actionRect = self.actionGeometry(act)
     if qVersion() >= "5.0.0":
         drag.setPixmap(self.grab(actionRect))
     else:
         drag.setPixmap(QPixmap.grabWidget(self, actionRect))
     
     if drag.exec_() == Qt.MoveAction:
         row = idx.row()
         if self.__dropIndex == idx.parent() and self.__dropRow <= row:
             row += 1
         self.__model.removeRow(row, self.__root)
         
         if not self.isAncestorOf(drag.target()):
             self.close()
         else:
             self.aboutToShow.emit()
Exemplo n.º 8
0
 def __copyImageToClipboard(self):
     """
     Private slot to handle the Copy Image menu action.
     """
     if self.mainWidget is None:
         E5MessageBox.critical(
             self,
             self.tr("Save Image"),
             self.tr("""There is no UI file loaded."""))
         return
     
     cb = QApplication.clipboard()
     if qVersion() >= "5.0.0":
         cb.setPixmap(self.mainWidget.grab())
     else:
         cb.setPixmap(QPixmap.grabWidget(self.mainWidget))
     self.__updateChildren(self.lastStyle)
Exemplo n.º 9
0
 def __saveImage(self):
     """
     Private slot to handle the Save Image menu action.
     """
     if self.mainWidget is None:
         E5MessageBox.critical(
             self,
             self.tr("Save Image"),
             self.tr("""There is no UI file loaded."""))
         return
     
     defaultExt = "PNG"
     filters = ""
     formats = QImageWriter.supportedImageFormats()
     for format in formats:
         filters = "{0}*.{1} ".format(
             filters, bytes(format).decode().lower())
     filter = self.tr("Images ({0})").format(filters[:-1])
     
     fname = E5FileDialog.getSaveFileName(
         self,
         self.tr("Save Image"),
         "",
         filter)
     if not fname:
         return
         
     ext = QFileInfo(fname).suffix().upper()
     if not ext:
         ext = defaultExt
         fname.append(".{0}".format(defaultExt.lower()))
     
     if qVersion() >= "5.0.0":
         pix = self.mainWidget.grab()
     else:
         pix = QPixmap.grabWidget(self.mainWidget)
     self.__updateChildren(self.lastStyle)
     if not pix.save(fname, str(ext)):
         E5MessageBox.critical(
             self,
             self.tr("Save Image"),
             self.tr(
                 """<p>The file <b>{0}</b> could not be saved.</p>""")
             .format(fname))