def printIndex(self): widget = QApplication.focusWidget() if self.state.printer is None: self.state.printer = QPrinter(QPrinter.HighResolution) self.state.printer.setColorMode(QPrinter.GrayScale) settings = QSettings() size = PaperSizeKind( int(settings.value(Gopt.Key.PaperSize, Gopt.Default.PaperSize))) self.state.printer.setPaperSize( QPrinter.Letter if size is PaperSizeKind.LETTER else QPrinter. A4) with Lib.Qt.DisableUI(*self.window.widgets(), forModalDialog=True): form = QPrintDialog(self.state.printer, self.state.window) form.setWindowTitle("Print Index") if form.exec_(): try: with Lib.DisableUI(*self.window.widgets()): config = self.state.model.configs().copy() config.Filename = "print.$$$" config.Printer = self.state.printer Output.outputEntries(self.state.model, config, "Printing", self.window.reportProgress) say("Printed") except Output.Error as err: say("Failed to print: {}".format(err)) logging.error("printIndex failed: {}".format(err)) Lib.restoreFocus(widget)
def OnPrint(self): """""" document = self.document() printer = QPrinter() dlg = QPrintDialog(printer, self) if dlg.exec_() != QDialog.Accepted: return document.print_(printer)
def print_(self): canvas = self.mw.get_current_canvas() if not canvas: return printer = QPrinter() dlg = QPrintDialog(printer, self.mw) if dlg.exec_() == QDialog.Accepted: painter = QPainter(printer) painter.drawImage(0, 0, canvas.image) painter.end()
def actionPrint(self): """打印报告""" printer = QPrinter() printer.setOutputFormat(QPrinter.NativeFormat) printer.setOutputFileName("") printer.setOrientation(QPrinter.Landscape) printer.setPageSize(QPrinter.A4) #=======================================================# #无需选择 printDialog = QPrintDialog(printer, self) #self.print_(printer) #如果需要选择打印机 if printDialog.exec_(): self.print_(printer)
def print_(self): """ TOWRITE """ dialog = QPrintDialog(self.printer, self) if dialog.exec_() == QDialog.Accepted: painter = QPainter(self.printer) if self.mainWin.getSettingsPrintingDisableBG(): # Save current bg. brush = self.gview.backgroundBrush() # QBrush # Save ink by not printing the bg at all. self.gview.setBackgroundBrush(Qt.NoBrush) # Print, fitting the viewport contents into a full page. self.gview.render(painter) # Restore the bg. self.gview.setBackgroundBrush(brush) else: # Print, fitting the viewport contents into a full page self.gview.render(painter)
def __init__(self): """ Constructs the main window. """ super(MainWindow, self).__init__() self.setupUi(self) self.actionAboutpySUMO.triggered.connect(self._showAboutBox_) self.infolog = InfoLog() self.log = logging.getLogger('.' + __name__) self.setCentralWidget(None) callback = partial(self._addWidget_, "TextEditorWidget", self.menuTextEditorWidgets) self.actionTextEditorWidget.triggered.connect(callback) callback = partial(self._addWidget_, "DocumentationWidget", self.menuDocumentationWidgets) self.actionDocumentationWidget.triggered.connect(callback) callback = partial(self._addWidget_, "HierarchyWidget", self.menuHierarchyWidgets) self.actionHierarchyWidget.triggered.connect(callback) callback = partial(self._addWidget_, "GraphWidget", self.menuGraphWidgets) self.actionGraphWidget.triggered.connect(callback) self.newOntologyAction.triggered.connect(self._newOntology_) self.openLocalOntologyAction.triggered.connect( self._openLocalOntology_) self.openRemoteOntologyAction.triggered.connect( self._openRemoteOntology_) self.createStatusBar() self.ontologyAdded.connect(self.notifyOntologyAdded) self.clearHistoryAction.triggered.connect( self._ClearRecentOntologiesHistory_) self.widgets = list() # unique instances. self.fileChooser = QFileDialog(self) self.dialog = QPrintDialog() self.userLayout = LayoutManager(self) filepath = pysumo.CONFIG_PATH + "/settings.ini" exist = False try: with open(filepath) as f: f.close() exist = True except IOError: pass self.settings = PySumoSettings(self, filepath) if not exist: self.settings.loadDefaults() self.optionDialog = OptionDialog(self, self.settings) self.actionSettings.triggered.connect(self._showOptionDialog_) # restore and show the view. self.userLayout.restoreLayout() self.show()
def _print_(self): """ Creates a print dialog with the latest text""" dialog = QPrintDialog() if dialog.exec_() == QDialog.Accepted: doc = self.plainTextEdit.document() doc.print_(dialog.printer())