示例#1
0
    def printpage(self, preview=False, count: {'special': 'count'} = None):
        """Print the current/[count]th tab.

        Args:
            preview: Show preview instead of printing.
            count: The tab index to print, or None.
        """
        if not qtutils.check_print_compat():
            # WORKAROUND (remove this when we bump the requirements to 5.3.0)
            raise cmdexc.CommandError(
                "Printing on Qt < 5.3.0 on Windows is broken, please upgrade!")
        tab = self._cntwidget(count)
        if tab is not None:
            if preview:
                diag = QPrintPreviewDialog()
                diag.setAttribute(Qt.WA_DeleteOnClose)
                diag.setWindowFlags(diag.windowFlags()
                                    | Qt.WindowMaximizeButtonHint
                                    | Qt.WindowMinimizeButtonHint)
                diag.paintRequested.connect(tab.print)
                diag.exec_()
            else:
                diag = QPrintDialog()
                diag.setAttribute(Qt.WA_DeleteOnClose)
                diag.open(lambda: tab.print(diag.printer()))
示例#2
0
    def printpage(self, preview=False, count: {'special': 'count'}=None):
        """Print the current/[count]th tab.

        Args:
            preview: Show preview instead of printing.
            count: The tab index to print, or None.
        """
        if not qtutils.check_print_compat():
            # WORKAROUND (remove this when we bump the requirements to 5.3.0)
            raise cmdexc.CommandError(
                "Printing on Qt < 5.3.0 on Windows is broken, please upgrade!")
        tab = self._cntwidget(count)
        if tab is not None:
            if preview:
                diag = QPrintPreviewDialog()
                diag.setAttribute(Qt.WA_DeleteOnClose)
                diag.setWindowFlags(diag.windowFlags() |
                                    Qt.WindowMaximizeButtonHint |
                                    Qt.WindowMinimizeButtonHint)
                diag.paintRequested.connect(tab.print)
                diag.exec_()
            else:
                diag = QPrintDialog()
                diag.setAttribute(Qt.WA_DeleteOnClose)
                diag.open(lambda: tab.print(diag.printer()))
示例#3
0
    def print(self, preview: bool = False) -> None:
        """Print the current widget.

        **syntax:** ``:print [--preview]``

        optional arguments:
            * ``--preview``: Show preview dialog before printing.
        """
        if self._widget is None:
            raise api.commands.CommandError("No widget to print")

        logging.debug("Starting print dialog")

        def handle_print() -> None:
            # We only use handle_print in the function below, None was caught above
            self._widget = cast(PrintWidget, self._widget)
            self._widget.print(dialog.printer(), auto_apply_orientation)

        if preview:
            dialog = QPrintPreviewDialog()
            # See https://github.com/stlehmann/PyQt5-stubs/pull/7
            # TODO Remove the type: ignore once the PR was merged and a new version is
            # on PyPi
            dialog.paintRequested.connect(handle_print)  # type: ignore
            auto_apply_orientation = False
        else:
            dialog = QPrintDialog()
            auto_apply_orientation = True

        dialog.open(handle_print)