コード例 #1
0
ファイル: __init__.py プロジェクト: EmDash00/python-gr
    def paintEvent(self, event):

        self._painter = QPainter()
        self._painter.begin(self)
        self._painter.fillRect(0, 0, self.width(), self.height(), self._bgColor)
        os.environ["GKSconid"] = getGKSConnectionId(self, self._painter)
        gr.clearws()
        self.draw()
        gr.updatews()
        self._painter.end()
コード例 #2
0
 def paintEvent(self, event):
     self._painter = QPainter()
     self._painter.begin(self)
     self._painter.fillRect(0, 0, self.width(), self.height(), self._bgColor)
     os.environ["GKSconid"] = getGKSConnectionId(self, self._painter)
     gr.clearws()
     self.draw()
     gr.updatews()
     self._painter.end()
コード例 #3
0
class GRWidget(QWidget):

    def __init__(self, *args, **kwargs):
        super(GRWidget, self).__init__(*args, **kwargs)
        self._sizex, self._sizey = 1., 1.
        self._dwidth, self._dheight = self.width(), self.height()
        self._mwidth = self.width() * .0254 / self.logicalDpiX()
        self._mheight = self.height() * .0254 / self.logicalDpiY()
        self._keepRatio = False
        self._bgColor = QtCore.Qt.white
        os.environ["GKS_WSTYPE"] = "381" # GKS Qt Plugin
        os.environ["GKS_DOUBLE_BUF"] = "True"

    def paintEvent(self, event):
        self._painter = QPainter()
        self._painter.begin(self)
        self._painter.fillRect(0, 0, self.width(), self.height(), self._bgColor)
        os.environ["GKSconid"] = getGKSConnectionId(self, self._painter)
        gr.clearws()
        self.draw()
        gr.updatews()
        self._painter.end()

    def resizeEvent(self, event):
        self._dwidth, self._dheight = self.width(), self.height()
        self._mwidth = self.width() * .0254 / self.logicalDpiX()
        self._mheight = self.height() * .0254 / self.logicalDpiY()
        if self._mwidth > self._mheight:
            self._sizex = 1.
            if self.keepRatio:
                self._sizey = 1.
                self._mwidth = self._mheight
                self._dwidth = self._dheight
            else:
                self._sizey = self._mheight / self._mwidth
        else:
            if self.keepRatio:
                self._sizex = 1.
                self._mheight = self._mwidth
                self._dheight = self._dwidth
            else:
                self._sizex = self._mwidth / self._mheight
            self._sizey = 1.

    def setBackground(self, qcolor):
        self._bgColor = qcolor

    @property
    def mwidth(self):
        """Get metric width of the widget excluding any window frame."""
        return self._mwidth

    @property
    def mheight(self):
        """Get metric height of the widget excluding any window frame."""
        return self._mheight

    @property
    def dwidth(self):
        """Get device width in consideration of ratio (keepRatio)."""
        return self._dwidth

    @property
    def dheight(self):
        """Get device height in consideration of ratio (keepRatio)."""
        return self._dheight

    @property
    def sizex(self):
        """..."""
        return self._sizex

    @property
    def sizey(self):
        """..."""
        return self._sizey

    @property
    def keepRatio(self):
        return self._keepRatio

    @keepRatio.setter
    def keepRatio(self, bool):
        self._keepRatio = bool
        self.resizeEvent(None)
        self.update()

    def draw(self, clear=None, update=None):
        # obsolete kwargs clear, update (unused) just kept for compatibility
        if clear is not None or update is not None:
            warnings.warn("Clear and update kwargs do not affect draw "
                          "method anymore and will be removed in future "
                          "versions. Please remove these arguments from your "
                          "draw calls. A clear and update will be done "
                          "internally for each paintEvent.", FutureWarning)

    def save(self, path):
        (p, ext) = os.path.splitext(path)
        if ext.lower()[1:] == gr.GRAPHIC_GRX:
            gr.begingraphics(path)
            self.draw()
            gr.endgraphics()
        else:
            gr.beginprint(path)
            self.draw()
            gr.endprint()
        self.repaint()

    def printDialog(self, documentName="qtgr-untitled"):
        printer = QPrinter(QPrinter.HighResolution)
        printer.setDocName(documentName)
        painter = QPainter()
        dlg = QPrintDialog(printer)
        if dlg.exec_() == QPrintDialog.Accepted:
            painter.begin(printer)
            os.environ["GKSconid"] = getGKSConnectionId(self, painter)

            # upscaling to paper size and
            # alignment (horizontal and vertical centering)
            xscale = printer.pageRect().width() / float(self.width())
            yscale = printer.pageRect().height() / float(self.height())
            scale = min(xscale, yscale)
            painter.translate(printer.paperRect().x() +
                              printer.pageRect().width() / 2,
                              printer.paperRect().y() +
                              printer.pageRect().height() / 2)
            painter.scale(scale, scale)
            painter.translate(-self.width() / 2, -self.height() / 2)
            gr.clearws()
            self.draw()
            gr.updatews()
            painter.end()

    def __del__(self):
        if gr:
            gr.emergencyclosegks()
コード例 #4
0
    def printDialog(self, documentName="qtgr-untitled"):
        printer = QPrinter(QPrinter.HighResolution)
        printer.setDocName(documentName)
        painter = QPainter()
        dlg = QPrintDialog(printer)
        if dlg.exec_() == QPrintDialog.Accepted:
            painter.begin(printer)
            os.environ["GKSconid"] = getGKSConnectionId(self, painter)

            # upscaling to paper size and
            # alignment (horizontal and vertical centering)
            xscale = printer.pageRect().width() / float(self.width())
            yscale = printer.pageRect().height() / float(self.height())
            scale = min(xscale, yscale)
            painter.translate(printer.paperRect().x() +
                              printer.pageRect().width() / 2,
                              printer.paperRect().y() +
                              printer.pageRect().height() / 2)
            painter.scale(scale, scale)
            painter.translate(-self.width() / 2, -self.height() / 2)
            gr.clearws()
            self.draw()
            gr.updatews()
            painter.end()
コード例 #5
0
ファイル: __init__.py プロジェクト: EmDash00/python-gr
class GRWidget(QWidget):

    def __init__(self, *args, **kwargs):
        super(GRWidget, self).__init__(*args, **kwargs)

        self._sizex, self._sizey = 1., 1.
        self._dwidth, self._dheight = self.width(), self.height()
        self._mwidth = self._dwidth * 2.54 / self.physicalDpiX() / 100.
        self._mheight = self._dheight * 2.54 / self.physicalDpiY() / 100.
        self._keepRatio = False
        self._bgColor = QtCore.Qt.white
        os.environ["GKS_WSTYPE"] = "381" # GKS Qt Plugin
        os.environ["GKS_DOUBLE_BUF"] = "True"

    def paintEvent(self, event):

        self._painter = QPainter()
        self._painter.begin(self)
        self._painter.fillRect(0, 0, self.width(), self.height(), self._bgColor)
        os.environ["GKSconid"] = getGKSConnectionId(self, self._painter)
        gr.clearws()
        self.draw()
        gr.updatews()
        self._painter.end()

    def resizeEvent(self, event):
        self._dwidth, self._dheight = self.width(), self.height()
        self._mwidth = self._dwidth * 2.54 / self.physicalDpiX() / 100.
        self._mheight = self._dheight * 2.54 / self.physicalDpiY() / 100.
        if self._mwidth > self._mheight:
            self._sizex = 1.
            if self.keepRatio:
                self._sizey = 1.
                self._mwidth = self._mheight
                self._dwidth = self._dheight
            elif self._mwidth > 0:
                self._sizey = self._mheight / self._mwidth
            else:
                self._sizey = 1.
        else:
            if self.keepRatio:
                self._sizex = 1.
                self._mheight = self._mwidth
                self._dheight = self._dwidth
            elif self._mheight > 0:
                self._sizex = self._mwidth / self._mheight
            else:
                self._sizex = 1.
            self._sizey = 1.

    def screenChangedEvent(self, event):
        gr.configurews()
        self.update()

    def setBackground(self, qcolor):
        self._bgColor = qcolor

    @property
    def mwidth(self):
        """Get metric width of the widget excluding any window frame."""
        return self._mwidth

    @property
    def mheight(self):
        """Get metric height of the widget excluding any window frame."""
        return self._mheight

    @property
    def dwidth(self):
        """Get device width in consideration of ratio (keepRatio)."""
        return self._dwidth

    @property
    def dheight(self):
        """Get device height in consideration of ratio (keepRatio)."""
        return self._dheight

    @property
    def sizex(self):
        """..."""
        return self._sizex

    @property
    def sizey(self):
        """..."""
        return self._sizey

    @property
    def keepRatio(self):
        return self._keepRatio

    @keepRatio.setter
    def keepRatio(self, bool):
        self._keepRatio = bool
        self.resizeEvent(None)
        self.update()

    def draw(self, clear=None, update=None):
        # obsolete kwargs clear, update (unused) just kept for compatibility
        if clear is not None or update is not None:
            warnings.warn("Clear and update kwargs do not affect draw "
                          "method anymore and will be removed in future "
                          "versions. Please remove these arguments from your "
                          "draw calls. A clear and update will be done "
                          "internally for each paintEvent.", FutureWarning)

    def save(self, path):
        (p, ext) = os.path.splitext(path)
        if ext.lower()[1:] == gr.GRAPHIC_GRX:
            gr.begingraphics(path)
            self.draw()
            gr.endgraphics()
        else:
            gr.beginprint(path)
            self.draw()
            gr.endprint()
        self.repaint()

    def printDialog(self, documentName="qtgr-untitled"):
        printer = QPrinter(QPrinter.HighResolution)
        printer.setDocName(documentName)
        painter = QPainter()
        dlg = QPrintDialog(printer)
        if dlg.exec_() == QPrintDialog.Accepted:
            painter.begin(printer)
            os.environ["GKSconid"] = getGKSConnectionId(self, painter)

            # upscaling to paper size and
            # alignment (horizontal and vertical centering)
            xscale = printer.pageRect().width() / float(self.width())
            yscale = printer.pageRect().height() / float(self.height())
            scale = min(xscale, yscale)
            painter.translate(printer.paperRect().x() +
                              printer.pageRect().width() / 2,
                              printer.paperRect().y() +
                              printer.pageRect().height() / 2)
            painter.scale(scale, scale)
            painter.translate(-self.width() / 2, -self.height() / 2)
            gr.clearws()
            self.draw()
            gr.updatews()
            painter.end()
コード例 #6
0
ファイル: __init__.py プロジェクト: EmDash00/python-gr
    def printDialog(self, documentName="qtgr-untitled"):
        printer = QPrinter(QPrinter.HighResolution)
        printer.setDocName(documentName)
        painter = QPainter()
        dlg = QPrintDialog(printer)
        if dlg.exec_() == QPrintDialog.Accepted:
            painter.begin(printer)
            os.environ["GKSconid"] = getGKSConnectionId(self, painter)

            # upscaling to paper size and
            # alignment (horizontal and vertical centering)
            xscale = printer.pageRect().width() / float(self.width())
            yscale = printer.pageRect().height() / float(self.height())
            scale = min(xscale, yscale)
            painter.translate(printer.paperRect().x() +
                              printer.pageRect().width() / 2,
                              printer.paperRect().y() +
                              printer.pageRect().height() / 2)
            painter.scale(scale, scale)
            painter.translate(-self.width() / 2, -self.height() / 2)
            gr.clearws()
            self.draw()
            gr.updatews()
            painter.end()