14 from PyQt6.QtWidgets import ( |
14 from PyQt6.QtWidgets import ( |
15 QWidget, QHBoxLayout, QMenu, QToolButton, QDialog |
15 QWidget, QHBoxLayout, QMenu, QToolButton, QDialog |
16 ) |
16 ) |
17 from PyQt6.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog |
17 from PyQt6.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog |
18 |
18 |
19 from E5Gui.E5TabWidget import E5TabWidget |
19 from E5Gui.EricTabWidget import EricTabWidget |
20 from E5Gui import E5MessageBox |
20 from E5Gui import EricMessageBox |
21 from E5Gui.E5Application import e5App |
21 from E5Gui.EricApplication import ericApp |
22 from E5Gui.E5OverrideCursor import E5OverrideCursor |
22 from E5Gui.EricOverrideCursor import EricOverrideCursor |
23 |
23 |
24 from .WebBrowserView import WebBrowserView |
24 from .WebBrowserView import WebBrowserView |
25 from .WebBrowserPage import WebBrowserPage |
25 from .WebBrowserPage import WebBrowserPage |
26 from .Tools import WebBrowserTools |
26 from .Tools import WebBrowserTools |
27 from . import WebInspector |
27 from . import WebInspector |
48 return testPrinter.supportsMultipleCopies() |
48 return testPrinter.supportsMultipleCopies() |
49 else: |
49 else: |
50 return False |
50 return False |
51 |
51 |
52 |
52 |
53 class WebBrowserTabWidget(E5TabWidget): |
53 class WebBrowserTabWidget(EricTabWidget): |
54 """ |
54 """ |
55 Class implementing the central widget showing the web pages. |
55 Class implementing the central widget showing the web pages. |
56 |
56 |
57 @signal sourceChanged(WebBrowserView, QUrl) emitted after the URL of a |
57 @signal sourceChanged(WebBrowserView, QUrl) emitted after the URL of a |
58 browser has changed |
58 browser has changed |
701 dlg = PrintToPdfDialog(name, self) |
701 dlg = PrintToPdfDialog(name, self) |
702 if dlg.exec() == QDialog.DialogCode.Accepted: |
702 if dlg.exec() == QDialog.DialogCode.Accepted: |
703 filePath, pageLayout = dlg.getData() |
703 filePath, pageLayout = dlg.getData() |
704 if filePath: |
704 if filePath: |
705 if os.path.exists(filePath): |
705 if os.path.exists(filePath): |
706 res = E5MessageBox.warning( |
706 res = EricMessageBox.warning( |
707 self, |
707 self, |
708 self.tr("Print to PDF"), |
708 self.tr("Print to PDF"), |
709 self.tr("""<p>The file <b>{0}</b> exists""" |
709 self.tr("""<p>The file <b>{0}</b> exists""" |
710 """ already. Shall it be""" |
710 """ already. Shall it be""" |
711 """ overwritten?</p>""").format(filePath), |
711 """ overwritten?</p>""").format(filePath), |
712 E5MessageBox.No | E5MessageBox.Yes, |
712 EricMessageBox.No | EricMessageBox.Yes, |
713 E5MessageBox.No) |
713 EricMessageBox.No) |
714 if res == E5MessageBox.No: |
714 if res == EricMessageBox.No: |
715 return |
715 return |
716 browser.page().printToPdf( |
716 browser.page().printToPdf( |
717 lambda pdf: self.__pdfGeneratedForSave(filePath, pdf), |
717 lambda pdf: self.__pdfGeneratedForSave(filePath, pdf), |
718 pageLayout) |
718 pageLayout) |
719 elif Globals.isLinuxPlatform(): |
719 elif Globals.isLinuxPlatform(): |
749 pdfFile = QFile(filePath) |
749 pdfFile = QFile(filePath) |
750 if pdfFile.open(QFile.WriteOnly): |
750 if pdfFile.open(QFile.WriteOnly): |
751 pdfFile.write(pdfData) |
751 pdfFile.write(pdfData) |
752 pdfFile.close() |
752 pdfFile.close() |
753 if pdfFile.error() != QFileDevice.FileError.NoError: |
753 if pdfFile.error() != QFileDevice.FileError.NoError: |
754 E5MessageBox.critical( |
754 EricMessageBox.critical( |
755 self, |
755 self, |
756 self.tr("Print to PDF"), |
756 self.tr("Print to PDF"), |
757 self.tr("""<p>The PDF could not be written to file <b>{0}""" |
757 self.tr("""<p>The PDF could not be written to file <b>{0}""" |
758 """</b>.</p><p><b>Error:</b> {1}</p>""").format( |
758 """</b>.</p><p><b>Error:</b> {1}</p>""").format( |
759 filePath, pdfFile.errorString()), |
759 filePath, pdfFile.errorString()), |
760 E5MessageBox.Ok) |
760 EricMessageBox.Ok) |
761 |
761 |
762 @pyqtSlot() |
762 @pyqtSlot() |
763 def printPreviewBrowser(self, browser=None): |
763 def printPreviewBrowser(self, browser=None): |
764 """ |
764 """ |
765 Public slot called to show a print preview of the displayed file. |
765 Public slot called to show a print preview of the displayed file. |
805 @param printer reference to the printer object |
805 @param printer reference to the printer object |
806 @type QPrinter |
806 @type QPrinter |
807 @param browser reference to the browser to be printed |
807 @param browser reference to the browser to be printed |
808 @type WebBrowserView |
808 @type WebBrowserView |
809 """ |
809 """ |
810 with E5OverrideCursor(): |
810 with EricOverrideCursor(): |
811 browser.page().execPrintPage(printer, 10 * 1000) |
811 browser.page().execPrintPage(printer, 10 * 1000) |
812 |
812 |
813 def __sourceChanged(self, url, browser): |
813 def __sourceChanged(self, url, browser): |
814 """ |
814 """ |
815 Private slot to handle a change of a browsers source. |
815 Private slot to handle a change of a browsers source. |
957 |
957 |
958 @return flag indicating a shut down (boolean) |
958 @return flag indicating a shut down (boolean) |
959 """ |
959 """ |
960 if self.count() > 1 and Preferences.getWebBrowser( |
960 if self.count() > 1 and Preferences.getWebBrowser( |
961 "WarnOnMultipleClose"): |
961 "WarnOnMultipleClose"): |
962 mb = E5MessageBox.E5MessageBox( |
962 mb = EricMessageBox.EricMessageBox( |
963 E5MessageBox.Information, |
963 EricMessageBox.Information, |
964 self.tr("Are you sure you want to close the window?"), |
964 self.tr("Are you sure you want to close the window?"), |
965 self.tr("""Are you sure you want to close the window?\n""" |
965 self.tr("""Are you sure you want to close the window?\n""" |
966 """You have %n tab(s) open.""", "", self.count()), |
966 """You have %n tab(s) open.""", "", self.count()), |
967 modal=True, |
967 modal=True, |
968 parent=self) |
968 parent=self) |
969 quitButton = mb.addButton( |
969 quitButton = mb.addButton( |
970 self.tr("&Quit"), E5MessageBox.AcceptRole) |
970 self.tr("&Quit"), EricMessageBox.AcceptRole) |
971 quitButton.setIcon(UI.PixmapCache.getIcon("exit")) |
971 quitButton.setIcon(UI.PixmapCache.getIcon("exit")) |
972 closeTabButton = mb.addButton( |
972 closeTabButton = mb.addButton( |
973 self.tr("C&lose Current Tab"), E5MessageBox.AcceptRole) |
973 self.tr("C&lose Current Tab"), EricMessageBox.AcceptRole) |
974 closeTabButton.setIcon(UI.PixmapCache.getIcon("tabClose")) |
974 closeTabButton.setIcon(UI.PixmapCache.getIcon("tabClose")) |
975 mb.addButton(E5MessageBox.Cancel) |
975 mb.addButton(EricMessageBox.Cancel) |
976 mb.exec() |
976 mb.exec() |
977 if mb.clickedButton() == quitButton: |
977 if mb.clickedButton() == quitButton: |
978 return True |
978 return True |
979 else: |
979 else: |
980 if mb.clickedButton() == closeTabButton: |
980 if mb.clickedButton() == closeTabButton: |
1021 |
1021 |
1022 @param edit reference to the line edit |
1022 @param edit reference to the line edit |
1023 @type UrlBar |
1023 @type UrlBar |
1024 """ |
1024 """ |
1025 url = self.__guessUrlFromPath(edit.text()) |
1025 url = self.__guessUrlFromPath(edit.text()) |
1026 if e5App().keyboardModifiers() == Qt.KeyboardModifier.AltModifier: |
1026 if ericApp().keyboardModifiers() == Qt.KeyboardModifier.AltModifier: |
1027 self.newBrowser(url) |
1027 self.newBrowser(url) |
1028 else: |
1028 else: |
1029 self.currentBrowser().setSource(url) |
1029 self.currentBrowser().setSource(url) |
1030 self.currentBrowser().setFocus() |
1030 self.currentBrowser().setFocus() |
1031 |
1031 |