src/eric7/WebBrowser/Tools/PrintToPdfDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
22 class PrintToPdfDialog(QDialog, Ui_PrintToPdfDialog): 22 class PrintToPdfDialog(QDialog, Ui_PrintToPdfDialog):
23 """ 23 """
24 Class implementing a dialog to enter the data for printing a web page to 24 Class implementing a dialog to enter the data for printing a web page to
25 PDF. 25 PDF.
26 """ 26 """
27
27 def __init__(self, filePath, parent=None): 28 def __init__(self, filePath, parent=None):
28 """ 29 """
29 Constructor 30 Constructor
30 31
31 @param filePath path of the file to write into 32 @param filePath path of the file to write into
32 @type str 33 @type str
33 @param parent reference to the parent widget 34 @param parent reference to the parent widget
34 @type QWidget 35 @type QWidget
35 """ 36 """
36 super().__init__(parent) 37 super().__init__(parent)
37 self.setupUi(self) 38 self.setupUi(self)
38 39
39 self.pdfFilePicker.setMode( 40 self.pdfFilePicker.setMode(EricPathPickerModes.SAVE_FILE_OVERWRITE_MODE)
40 EricPathPickerModes.SAVE_FILE_OVERWRITE_MODE) 41 self.pdfFilePicker.setFilters(self.tr("PDF Files (*.pdf);;" "All Files (*)"))
41 self.pdfFilePicker.setFilters(self.tr(
42 "PDF Files (*.pdf);;"
43 "All Files (*)"))
44 if not os.path.isabs(filePath): 42 if not os.path.isabs(filePath):
45 documentsPath = QStandardPaths.writableLocation( 43 documentsPath = QStandardPaths.writableLocation(
46 QStandardPaths.StandardLocation.DocumentsLocation) 44 QStandardPaths.StandardLocation.DocumentsLocation
45 )
47 if documentsPath: 46 if documentsPath:
48 filePath = os.path.join(documentsPath, filePath) 47 filePath = os.path.join(documentsPath, filePath)
49 else: 48 else:
50 filePath = os.path.abspath(filePath) 49 filePath = os.path.abspath(filePath)
51 self.pdfFilePicker.setText(filePath, toNative=True) 50 self.pdfFilePicker.setText(filePath, toNative=True)
52 51
53 self.__currentPageLayout = QPageLayout( 52 self.__currentPageLayout = QPageLayout(
54 QPageSize(QPageSize.PageSizeId.A4), 53 QPageSize(QPageSize.PageSizeId.A4),
55 QPageLayout.Orientation.Portrait, 54 QPageLayout.Orientation.Portrait,
56 QMarginsF(0.0, 0.0, 0.0, 0.0)) 55 QMarginsF(0.0, 0.0, 0.0, 0.0),
57 56 )
57
58 self.__updatePageLayoutLabel() 58 self.__updatePageLayoutLabel()
59 59
60 @pyqtSlot() 60 @pyqtSlot()
61 def on_pageLayoutButton_clicked(self): 61 def on_pageLayoutButton_clicked(self):
62 """ 62 """
63 Private slot to define the page layout. 63 Private slot to define the page layout.
64 """ 64 """
65 printer = QPrinter() 65 printer = QPrinter()
66 printer.setPageLayout(self.__currentPageLayout) 66 printer.setPageLayout(self.__currentPageLayout)
67 67
68 dlg = QPageSetupDialog(printer, self) 68 dlg = QPageSetupDialog(printer, self)
69 if dlg.exec() == QDialog.DialogCode.Accepted: 69 if dlg.exec() == QDialog.DialogCode.Accepted:
70 self.__currentPageLayout = printer.pageLayout() 70 self.__currentPageLayout = printer.pageLayout()
71 self.__updatePageLayoutLabel() 71 self.__updatePageLayoutLabel()
72 72
73 def __updatePageLayoutLabel(self): 73 def __updatePageLayoutLabel(self):
74 """ 74 """
75 Private method to update the page layout label. 75 Private method to update the page layout label.
76 """ 76 """
77 orientation = ( 77 orientation = (
78 self.tr("Portrait") 78 self.tr("Portrait")
79 if (self.__currentPageLayout.orientation() == 79 if (
80 QPageLayout.Orientation.Portrait) else 80 self.__currentPageLayout.orientation()
81 self.tr("Landscape") 81 == QPageLayout.Orientation.Portrait
82 )
83 else self.tr("Landscape")
82 ) 84 )
83 self.pageLayoutLabel.setText( 85 self.pageLayoutLabel.setText(
84 self.tr("{0}, {1}", "page size, page orientation").format( 86 self.tr("{0}, {1}", "page size, page orientation").format(
85 self.__currentPageLayout.pageSize().name(), 87 self.__currentPageLayout.pageSize().name(), orientation
86 orientation)) 88 )
87 89 )
90
88 def getData(self): 91 def getData(self):
89 """ 92 """
90 Public method to get the dialog data. 93 Public method to get the dialog data.
91 94
92 @return tuple containing the file path and the page layout 95 @return tuple containing the file path and the page layout
93 @rtype tuple of str and QPageLayout 96 @rtype tuple of str and QPageLayout
94 """ 97 """
95 return ( 98 return (
96 self.pdfFilePicker.text(toNative=True), 99 self.pdfFilePicker.text(toNative=True),

eric ide

mercurial