Helpviewer/HelpTabWidget.py

Thu, 03 Apr 2014 23:05:31 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Thu, 03 Apr 2014 23:05:31 +0200
branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3345
071afe8be2a1
child 3656
441956d8fce5
permissions
-rw-r--r--

Merge with default branch.

638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3158
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the central widget showing the web pages.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3080
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
11
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
14 from PyQt4.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt4.QtGui import QWidget, QHBoxLayout, QMenu, QToolButton, QPrinter, \
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 QPrintDialog, QDialog, QIcon
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1781
diff changeset
17 from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from E5Gui.E5TabWidget import E5TabWidget
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from E5Gui import E5MessageBox
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
21 from E5Gui.E5Application import e5App
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 from .HelpBrowserWV import HelpBrowser
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
24
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 import UI.PixmapCache
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
27 import Utilities
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 import Preferences
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 from eric5config import getConfig
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
32
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 class HelpTabWidget(E5TabWidget):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 Class implementing the central widget showing the web pages.
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
36
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
37 @signal sourceChanged(HelpBrowser, QUrl) emitted after the URL of a browser
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
38 has changed
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
39 @signal titleChanged(HelpBrowser, str) emitted after the title of a browser
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
40 has changed
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
41 @signal showMessage(str) emitted to show a message in the main window
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
42 status bar
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
43 @signal browserClosed(QWidget) emitted after a browser was closed
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
44 @signal browserZoomValueChanged(int) emitted to signal a change of the
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
45 current browser's zoom level
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
47 sourceChanged = pyqtSignal(HelpBrowser, QUrl)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
48 titleChanged = pyqtSignal(HelpBrowser, str)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 showMessage = pyqtSignal(str)
1196
77da430b4080 Added an action to preview the file in the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1155
diff changeset
50 browserClosed = pyqtSignal(QWidget)
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
51 browserZoomValueChanged = pyqtSignal(int)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def __init__(self, parent):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Constructor
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param parent reference to the parent widget (QWidget)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
59 E5TabWidget.__init__(self, parent, dnd=True)
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
60
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
61 from .HelpTabBar import HelpTabBar
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
62 self.__tabBar = HelpTabBar(self)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
63 self.setCustomTabBar(True, self.__tabBar)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.__mainWindow = parent
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
1422
47f1dffa398e Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1232
diff changeset
67 self.setUsesScrollButtons(True)
47f1dffa398e Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1232
diff changeset
68 self.setDocumentMode(True)
47f1dffa398e Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1232
diff changeset
69 self.setElideMode(Qt.ElideNone)
47f1dffa398e Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1232
diff changeset
70
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
71 from .ClosedTabsManager import ClosedTabsManager
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
72 self.__closedTabsManager = ClosedTabsManager(self)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
73 self.__closedTabsManager.closedTabAvailable.connect(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
74 self.__closedTabAvailable)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
75
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
76 from .UrlBar.StackedUrlBar import StackedUrlBar
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
77 self.__stackedUrlBar = StackedUrlBar(self)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
78 self.__tabBar.tabMoved.connect(self.__stackedUrlBar.moveBar)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
79
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.__tabContextMenuIndex = -1
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
81 self.currentChanged[int].connect(self.__currentChanged)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.setTabContextMenuPolicy(Qt.CustomContextMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.customTabContextMenuRequested.connect(self.__showContextMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__rightCornerWidget = QWidget(self)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__rightCornerWidgetLayout = QHBoxLayout(self.__rightCornerWidget)
2824
858412c29c34 Replaced the obsoleted method setMargin() with setContentsMargins().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
87 self.__rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.__rightCornerWidgetLayout.setSpacing(0)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.__navigationMenu = QMenu(self)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.__navigationButton = QToolButton(self)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
95 self.__navigationButton.setIcon(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
96 UI.PixmapCache.getIcon("1downarrow.png"))
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
97 self.__navigationButton.setToolTip(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
98 self.tr("Show a navigation menu"))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.__navigationButton.setPopupMode(QToolButton.InstantPopup)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.__navigationButton.setMenu(self.__navigationMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.__navigationButton.setEnabled(False)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.__rightCornerWidgetLayout.addWidget(self.__navigationButton)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
104 self.__closedTabsMenu = QMenu(self)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
105 self.__closedTabsMenu.aboutToShow.connect(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
106 self.__aboutToShowClosedTabsMenu)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
107
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
108 self.__closedTabsButton = QToolButton(self)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
109 self.__closedTabsButton.setIcon(UI.PixmapCache.getIcon("trash.png"))
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
110 self.__closedTabsButton.setToolTip(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
111 self.tr("Show a navigation menu for closed tabs"))
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
112 self.__closedTabsButton.setPopupMode(QToolButton.InstantPopup)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
113 self.__closedTabsButton.setMenu(self.__closedTabsMenu)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
114 self.__closedTabsButton.setEnabled(False)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
115 self.__rightCornerWidgetLayout.addWidget(self.__closedTabsButton)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
116
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
117 self.__closeButton = QToolButton(self)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
118 self.__closeButton.setIcon(UI.PixmapCache.getIcon("close.png"))
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
119 self.__closeButton.setToolTip(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
120 self.tr("Close the current help window"))
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
121 self.__closeButton.setEnabled(False)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
122 self.__closeButton.clicked[bool].connect(self.closeBrowser)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
123 self.__rightCornerWidgetLayout.addWidget(self.__closeButton)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if Preferences.getUI("SingleCloseButton") or \
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 not hasattr(self, 'setTabsClosable'):
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
126 self.__closeButton.show()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.setTabsClosable(True)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.tabCloseRequested.connect(self.closeBrowserAt)
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
130 self.__closeButton.hide()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.setCornerWidget(self.__rightCornerWidget, Qt.TopRightCorner)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.__newTabButton = QToolButton(self)
1652
4719bf3fe8d8 Change the icon on the "Add tab" button of the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1651
diff changeset
135 self.__newTabButton.setIcon(UI.PixmapCache.getIcon("plus.png"))
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
136 self.__newTabButton.setToolTip(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
137 self.tr("Open a new help window tab"))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.setCornerWidget(self.__newTabButton, Qt.TopLeftCorner)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.__newTabButton.clicked[bool].connect(self.newBrowser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.__initTabContextMenu()
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
142
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
143 self.__historyCompleter = None
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 def __initTabContextMenu(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
147 Private method to create the tab context menu.
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.__tabContextMenu = QMenu(self)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
150 self.tabContextNewAct = self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
151 UI.PixmapCache.getIcon("tabNew.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
152 self.tr('New Tab'), self.newBrowser)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.__tabContextMenu.addSeparator()
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
154 self.leftMenuAct = self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
155 UI.PixmapCache.getIcon("1leftarrow.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
156 self.tr('Move Left'), self.__tabContextMenuMoveLeft)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
157 self.rightMenuAct = self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
158 UI.PixmapCache.getIcon("1rightarrow.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
159 self.tr('Move Right'), self.__tabContextMenuMoveRight)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__tabContextMenu.addSeparator()
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
161 self.tabContextCloneAct = self.__tabContextMenu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
162 self.tr("Duplicate Page"), self.__tabContextMenuClone)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 self.__tabContextMenu.addSeparator()
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
164 self.tabContextCloseAct = self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
165 UI.PixmapCache.getIcon("tabClose.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
166 self.tr('Close'), self.__tabContextMenuClose)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
167 self.tabContextCloseOthersAct = self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
168 UI.PixmapCache.getIcon("tabCloseOther.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
169 self.tr("Close Others"), self.__tabContextMenuCloseOthers)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
170 self.__tabContextMenu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
171 self.tr('Close All'), self.closeAllBrowsers)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.__tabContextMenu.addSeparator()
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
173 self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
174 UI.PixmapCache.getIcon("printPreview.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
175 self.tr('Print Preview'), self.__tabContextMenuPrintPreview)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
176 self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
177 UI.PixmapCache.getIcon("print.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
178 self.tr('Print'), self.__tabContextMenuPrint)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
179 self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
180 UI.PixmapCache.getIcon("printPdf.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
181 self.tr('Print as PDF'), self.__tabContextMenuPrintPdf)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 self.__tabContextMenu.addSeparator()
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
183 self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
184 UI.PixmapCache.getIcon("reload.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
185 self.tr('Reload All'), self.reloadAllBrowsers)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
186 self.__tabContextMenu.addSeparator()
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
187 self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
188 UI.PixmapCache.getIcon("addBookmark.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
189 self.tr('Bookmark All Tabs'), self.__mainWindow.bookmarkAll)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
190
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
191 self.__tabBackContextMenu = QMenu(self)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
192 self.__tabBackContextMenu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
193 self.tr('Close All'), self.closeAllBrowsers)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
194 self.__tabBackContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
195 UI.PixmapCache.getIcon("reload.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
196 self.tr('Reload All'), self.reloadAllBrowsers)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
197 self.__tabBackContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
198 UI.PixmapCache.getIcon("addBookmark.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
199 self.tr('Bookmark All Tabs'), self.__mainWindow.bookmarkAll)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
200 self.__tabBackContextMenu.addSeparator()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
201 self.__restoreClosedTabAct = self.__tabBackContextMenu.addAction(
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
202 UI.PixmapCache.getIcon("trash.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
203 self.tr('Restore Closed Tab'), self.restoreClosedTab)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
204 self.__restoreClosedTabAct.setEnabled(False)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
205 self.__restoreClosedTabAct.setData(0)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 def __showContextMenu(self, coord, index):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 Private slot to show the tab context menu.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 @param coord the position of the mouse pointer (QPoint)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 @param index index of the tab the menu is requested for (integer)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 coord = self.mapToGlobal(coord)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
215 if index == -1:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
216 self.__tabBackContextMenu.popup(coord)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
217 else:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
218 self.__tabContextMenuIndex = index
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
219 self.leftMenuAct.setEnabled(index > 0)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
220 self.rightMenuAct.setEnabled(index < self.count() - 1)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
221
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
222 self.tabContextCloseOthersAct.setEnabled(self.count() > 1)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
223
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
224 self.__tabContextMenu.popup(coord)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 def __tabContextMenuMoveLeft(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 Private method to move a tab one position to the left.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
230 self.moveTab(self.__tabContextMenuIndex,
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
231 self.__tabContextMenuIndex - 1)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 def __tabContextMenuMoveRight(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 Private method to move a tab one position to the right.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
237 self.moveTab(self.__tabContextMenuIndex,
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
238 self.__tabContextMenuIndex + 1)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 def __tabContextMenuClone(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 Private method to clone the selected tab.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 idx = self.__tabContextMenuIndex
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 if idx < 0:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 idx = self.currentIndex()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 if idx < 0 or idx > self.count():
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1781
diff changeset
250 req = QNetworkRequest(self.widget(idx).url())
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1781
diff changeset
251 req.setRawHeader("X-Eric5-UserLoadAction", b"1")
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1781
diff changeset
252 self.newBrowser(None, (req, QNetworkAccessManager.GetOperation, b""))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 def __tabContextMenuClose(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 Private method to close the selected tab.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 self.closeBrowserAt(self.__tabContextMenuIndex)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 def __tabContextMenuCloseOthers(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 Private slot to close all other tabs.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 index = self.__tabContextMenuIndex
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 for i in list(range(self.count() - 1, index, -1)) + \
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
266 list(range(index - 1, -1, -1)):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 self.closeBrowserAt(i)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 def __tabContextMenuPrint(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 Private method to print the selected tab.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 browser = self.widget(self.__tabContextMenuIndex)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 self.printBrowser(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 def __tabContextMenuPrintPdf(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 Private method to print the selected tab as PDF.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 browser = self.widget(self.__tabContextMenuIndex)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 self.printBrowserPdf(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 def __tabContextMenuPrintPreview(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 Private method to show a print preview of the selected tab.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 browser = self.widget(self.__tabContextMenuIndex)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 self.printPreviewBrowser(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
290 def newBrowser(self, link=None, requestData=None, position=-1):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 Public method to create a new web browser tab.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 @param link link to be shown (string or QUrl)
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 953
diff changeset
295 @param requestData tuple containing the request data (QNetworkRequest,
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 953
diff changeset
296 QNetworkAccessManager.Operation, QByteArray)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
297 @keyparam position position to create the new tab at or -1 to add it
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
298 to the end (integer)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 if link is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 linkName = ""
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 elif isinstance(link, QUrl):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 linkName = link.toString()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 linkName = link
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
307 from .UrlBar.UrlBar import UrlBar
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
308 urlbar = UrlBar(self.__mainWindow, self)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
309 if self.__historyCompleter is None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
310 import Helpviewer.HelpWindow
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
311 from .History.HistoryCompleter import HistoryCompletionModel, \
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
312 HistoryCompleter
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
313 self.__historyCompletionModel = HistoryCompletionModel(self)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
314 self.__historyCompletionModel.setSourceModel(
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
315 Helpviewer.HelpWindow.HelpWindow.historyManager()
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
316 .historyFilterModel())
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
317 self.__historyCompleter = HistoryCompleter(
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
318 self.__historyCompletionModel, self)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
319 self.__historyCompleter.activated[str].connect(self.__pathSelected)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
320 urlbar.setCompleter(self.__historyCompleter)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
321 urlbar.returnPressed.connect(self.__lineEditReturnPressed)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
322 if position == -1:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
323 self.__stackedUrlBar.addWidget(urlbar)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
324 else:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
325 self.__stackedUrlBar.insertWidget(position, urlbar)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
326
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 browser = HelpBrowser(self.__mainWindow, self)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
328 urlbar.setBrowser(browser)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 browser.sourceChanged.connect(self.__sourceChanged)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 browser.titleChanged.connect(self.__titleChanged)
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
332 browser.highlighted.connect(self.showMessage)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
333 browser.backwardAvailable.connect(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
334 self.__mainWindow.setBackwardAvailable)
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
335 browser.forwardAvailable.connect(self.__mainWindow.setForwardAvailable)
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
336 browser.loadStarted.connect(self.__loadStarted)
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
337 browser.loadFinished.connect(self.__loadFinished)
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
338 browser.iconChanged.connect(self.__iconChanged)
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
339 browser.search.connect(self.newBrowser)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
340 browser.page().windowCloseRequested.connect(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
341 self.__windowCloseRequested)
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
342 browser.page().printRequested.connect(self.__printRequested)
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
343 browser.zoomValueChanged.connect(self.browserZoomValueChanged)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
345 if position == -1:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
346 index = self.addTab(browser, self.tr("..."))
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
347 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
348 index = self.insertTab(position, browser, self.tr("..."))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 self.setCurrentIndex(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
351 self.__mainWindow.closeAct.setEnabled(True)
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
352 self.__mainWindow.closeAllAct.setEnabled(True)
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
353 self.__closeButton.setEnabled(True)
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
354 self.__navigationButton.setEnabled(True)
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 638
diff changeset
355
1670
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
356 if not linkName and not requestData:
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
357 if Preferences.getHelp("StartupBehavior") == 0:
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
358 linkName = Preferences.getHelp("HomePage")
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
359 elif Preferences.getHelp("StartupBehavior") == 1:
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
360 linkName = "eric:speeddial"
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 if linkName:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 browser.setSource(QUrl(linkName))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 if not browser.documentTitle():
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 self.setTabText(index, self.__elide(linkName, Qt.ElideMiddle))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 self.setTabToolTip(index, linkName)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 else:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
368 self.setTabText(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
369 index,
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 self.__elide(browser.documentTitle().replace("&", "&&")))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 self.setTabToolTip(index, browser.documentTitle())
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 953
diff changeset
372 elif requestData:
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 953
diff changeset
373 browser.load(*requestData)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
3077
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
375 def newBrowserAfter(self, browser, link=None, requestData=None):
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
376 """
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
377 Public method to create a new web browser tab after a given one.
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
378
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
379 @param browser reference to the browser to add after (HelpBrowser)
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
380 @param link link to be shown (string or QUrl)
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
381 @param requestData tuple containing the request data (QNetworkRequest,
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
382 QNetworkAccessManager.Operation, QByteArray)
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
383 """
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
384 if browser:
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
385 position = self.indexOf(browser) + 1
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
386 else:
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
387 position = -1
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
388 self.newBrowser(link, requestData, position)
8d2e69e02e19 Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3048
diff changeset
389
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 def __showNavigationMenu(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 Private slot to show the navigation button menu.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 self.__navigationMenu.clear()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 for index in range(self.count()):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 act = self.__navigationMenu.addAction(
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 self.tabIcon(index), self.tabText(index))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 act.setData(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 def __navigationMenuTriggered(self, act):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 Private slot called to handle the navigation button menu selection.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 @param act reference to the selected action (QAction)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 index = act.data()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 if index is not None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 self.setCurrentIndex(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 def __windowCloseRequested(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 Private slot to handle the windowCloseRequested signal of a browser.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 page = self.sender()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 if page is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 browser = page.view()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 if browser is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 index = self.indexOf(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 self.closeBrowserAt(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
425 def reloadAllBrowsers(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
426 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
427 Public slot to reload all browsers.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
428 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
429 for index in range(self.count()):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
430 browser = self.widget(index)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
431 browser and browser.reload()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
432
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 def closeBrowser(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 Public slot called to handle the close action.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 self.closeBrowserAt(self.currentIndex())
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 def closeAllBrowsers(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 Public slot called to handle the close all action.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 for index in range(self.count() - 1, -1, -1):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 self.closeBrowserAt(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 def closeBrowserAt(self, index):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 """
2763
e4794166ad70 Fixed a serious typo.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
448 Public slot to close a browser based on its index.
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 @param index index of browser to close (integer)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 """
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
452 urlbar = self.__stackedUrlBar.widget(index)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
453 self.__stackedUrlBar.removeWidget(urlbar)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
454 del urlbar
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
455
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 browser = self.widget(index)
1670
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
457 if browser is None:
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
458 return
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
459
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
460 self.__closedTabsManager.recordBrowser(browser, index)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
461
1651
bc68f24d5658 Added the ClickToFlash plug-in to (temporarily) block Flash and related content.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1645
diff changeset
462 browser.home()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 self.removeTab(index)
1196
77da430b4080 Added an action to preview the file in the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1155
diff changeset
464 self.browserClosed.emit(browser)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 del browser
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
466
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 if self.count() == 0:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 self.newBrowser()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 self.currentChanged[int].emit(self.currentIndex())
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 def currentBrowser(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 Public method to get a reference to the current browser.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 @return reference to the current browser (HelpBrowser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 return self.currentWidget()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480 def browserAt(self, index):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 Public method to get a reference to the browser with the given index.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 @param index index of the browser to get (integer)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 @return reference to the indexed browser (HelpBrowser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487 return self.widget(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 def browsers(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491 Public method to get a list of references to all browsers.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 @return list of references to browsers (list of HelpBrowser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
495 li = []
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496 for index in range(self.count()):
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
497 li.append(self.widget(index))
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
498 return li
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
500 @pyqtSlot()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
501 def printBrowser(self, browser=None):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 Public slot called to print the displayed page.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 @param browser reference to the browser to be printed (HelpBrowser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 if browser is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 browser = self.currentBrowser()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 self.__printRequested(browser.page().mainFrame())
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 def __printRequested(self, frame):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 Private slot to handle a print request.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
516 @param frame reference to the frame to be printed (QWebFrame)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
518 printer = QPrinter(mode=QPrinter.HighResolution)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519 if Preferences.getPrinter("ColorMode"):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 printer.setColorMode(QPrinter.Color)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 printer.setColorMode(QPrinter.GrayScale)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523 if Preferences.getPrinter("FirstPageFirst"):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524 printer.setPageOrder(QPrinter.FirstPageFirst)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
525 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 printer.setPageOrder(QPrinter.LastPageFirst)
1155
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
527 printer.setPageMargins(
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
528 Preferences.getPrinter("LeftMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
529 Preferences.getPrinter("TopMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
530 Preferences.getPrinter("RightMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
531 Preferences.getPrinter("BottomMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
532 QPrinter.Millimeter
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
533 )
3048
83f86da6344e Fixed an issue causing trouble if the printer name is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
534 printerName = Preferences.getPrinter("PrinterName")
83f86da6344e Fixed an issue causing trouble if the printer name is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
535 if printerName:
3158
c91f976a2395 Fixed a severe issue assigning a name to a printer in several dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3077
diff changeset
536 printer.setPrinterName(printerName)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
537
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
538 printDialog = QPrintDialog(printer, self)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 if printDialog.exec_() == QDialog.Accepted:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540 try:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 frame.print_(printer)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542 except AttributeError:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
543 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
544 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
545 self.tr("eric5 Web Browser"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
546 self.tr(
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
547 """<p>Printing is not available due to a bug in"""
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
548 """ PyQt4. Please upgrade.</p>"""))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
551 @pyqtSlot()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
552 def printBrowserPdf(self, browser=None):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 Public slot called to print the displayed page to PDF.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 @param browser reference to the browser to be printed (HelpBrowser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 if browser is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 browser = self.currentBrowser()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
561 self.__printPdfRequested(browser.page().mainFrame())
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 def __printPdfRequested(self, frame):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565 Private slot to handle a print to PDF request.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 @param frame reference to the frame to be printed (QWebFrame)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
569 printer = QPrinter(mode=QPrinter.HighResolution)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
570 if Preferences.getPrinter("ColorMode"):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
571 printer.setColorMode(QPrinter.Color)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
572 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
573 printer.setColorMode(QPrinter.GrayScale)
3048
83f86da6344e Fixed an issue causing trouble if the printer name is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
574 printerName = Preferences.getPrinter("PrinterName")
83f86da6344e Fixed an issue causing trouble if the printer name is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
575 if printerName:
3158
c91f976a2395 Fixed a severe issue assigning a name to a printer in several dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3077
diff changeset
576 printer.setPrinterName(printerName)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
577 printer.setOutputFormat(QPrinter.PdfFormat)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
578 name = frame.url().path().rsplit('/', 1)[-1]
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
579 if name:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
580 name = name.rsplit('.', 1)[0]
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
581 name += '.pdf'
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
582 printer.setOutputFileName(name)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
583
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584 printDialog = QPrintDialog(printer, self)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
585 if printDialog.exec_() == QDialog.Accepted:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
586 try:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587 frame.print_(printer)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588 except AttributeError:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
589 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
590 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
591 self.tr("eric5 Web Browser"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
592 self.tr(
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
593 """<p>Printing is not available due to a bug in"""
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
594 """ PyQt4. Please upgrade.</p>"""))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
595 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
597 @pyqtSlot()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
598 def printPreviewBrowser(self, browser=None):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
599 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 Public slot called to show a print preview of the displayed file.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
601
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
602 @param browser reference to the browser to be printed (HelpBrowserWV)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
603 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
604 from PyQt4.QtGui import QPrintPreviewDialog
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
605
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
606 if browser is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
607 browser = self.currentBrowser()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
608
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
609 printer = QPrinter(mode=QPrinter.HighResolution)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 if Preferences.getPrinter("ColorMode"):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611 printer.setColorMode(QPrinter.Color)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
612 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
613 printer.setColorMode(QPrinter.GrayScale)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 if Preferences.getPrinter("FirstPageFirst"):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
615 printer.setPageOrder(QPrinter.FirstPageFirst)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
616 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
617 printer.setPageOrder(QPrinter.LastPageFirst)
1155
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
618 printer.setPageMargins(
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
619 Preferences.getPrinter("LeftMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
620 Preferences.getPrinter("TopMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
621 Preferences.getPrinter("RightMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
622 Preferences.getPrinter("BottomMargin") * 10,
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
623 QPrinter.Millimeter
4cbef040f07e Fixed issues setting the printer margins correctly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
624 )
3048
83f86da6344e Fixed an issue causing trouble if the printer name is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
625 printerName = Preferences.getPrinter("PrinterName")
83f86da6344e Fixed an issue causing trouble if the printer name is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
626 if printerName:
3158
c91f976a2395 Fixed a severe issue assigning a name to a printer in several dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3077
diff changeset
627 printer.setPrinterName(printerName)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
629 self.__printPreviewBrowser = browser
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630 preview = QPrintPreviewDialog(printer, self)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
631 preview.paintRequested.connect(self.__printPreview)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 preview.exec_()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634 def __printPreview(self, printer):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 Private slot to generate a print preview.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
638 @param printer reference to the printer object (QPrinter)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
639 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 try:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641 self.__printPreviewBrowser.print_(printer)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642 except AttributeError:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
643 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
644 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
645 self.tr("eric5 Web Browser"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
646 self.tr(
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
647 """<p>Printing is not available due to a bug in PyQt4."""
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
648 """Please upgrade.</p>"""))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
649 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
650
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
651 def __sourceChanged(self, url):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
652 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
653 Private slot to handle a change of a browsers source.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
654
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
655 @param url URL of the new site (QUrl)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
656 """
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
657 browser = self.sender()
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
658
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
659 if browser is not None:
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
660 self.sourceChanged.emit(browser, url)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 def __titleChanged(self, title):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
663 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
664 Private slot to handle a change of a browsers title.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
665
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
666 @param title new title (string)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
667 """
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
668 browser = self.sender()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
669
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
670 if browser is not None:
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
671 index = self.indexOf(browser)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
672 if title == "":
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
673 title = browser.url().toString()
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
674
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
675 self.setTabText(index, self.__elide(title.replace("&", "&&")))
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
676 self.setTabToolTip(index, title)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
677
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
678 self.titleChanged.emit(browser, title)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
679
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
680 def __elide(self, txt, mode=Qt.ElideRight, length=40):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
681 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
682 Private method to elide some text.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
683
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684 @param txt text to be elided (string)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
685 @keyparam mode elide mode (Qt.TextElideMode)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686 @keyparam length amount of characters to be used (integer)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
687 @return the elided text (string)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
688 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689 if mode == Qt.ElideNone or len(txt) < length:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 return txt
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
691 elif mode == Qt.ElideLeft:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692 return "...{0}".format(txt[-length:])
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
693 elif mode == Qt.ElideMiddle:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 return "{0}...{1}".format(txt[:length // 2], txt[-(length // 2):])
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
695 elif mode == Qt.ElideRight:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
696 return "{0}...".format(txt[:length])
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
697 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
698 # just in case
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
699 return txt
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
700
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
701 def preferencesChanged(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
702 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
703 Public slot to handle a change of preferences.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
704 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
705 for browser in self.browsers():
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
706 browser.preferencesChanged()
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
707
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
708 for urlbar in self.__stackedUrlBar.urlBars():
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
709 urlbar.preferencesChanged()
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
710
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
711 if Preferences.getUI("SingleCloseButton") or \
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
712 not hasattr(self, 'setTabsClosable'):
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
713 if hasattr(self, 'setTabsClosable'):
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
714 self.setTabsClosable(False)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
715 try:
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
716 self.tabCloseRequested.disconnect(self.closeBrowserAt)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
717 except TypeError:
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
718 pass
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
719 self.__closeButton.show()
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
720 else:
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
721 self.setTabsClosable(True)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
722 self.tabCloseRequested.connect(self.closeBrowserAt)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
723 self.__closeButton.hide()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
724
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
725 def __loadStarted(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
726 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
727 Private method to handle the loadStarted signal.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
728 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
729 browser = self.sender()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
730
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
731 if browser is not None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
732 index = self.indexOf(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
733 anim = self.animationLabel(
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
734 index, os.path.join(getConfig("ericPixDir"), "loading.gif"),
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
735 100)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
736 if not anim:
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
737 loading = QIcon(os.path.join(getConfig("ericPixDir"),
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
738 "loading.gif"))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
739 self.setTabIcon(index, loading)
1539
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
740 else:
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
741 self.setTabIcon(index, QIcon())
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
742 self.setTabText(index, self.tr("Loading..."))
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
743 self.setTabToolTip(index, self.tr("Loading..."))
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
744 self.showMessage.emit(self.tr("Loading..."))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
745
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
746 self.__mainWindow.setLoadingActions(True)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
747
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
748 def __loadFinished(self, ok):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
749 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
750 Private method to handle the loadFinished signal.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
751
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
752 @param ok flag indicating the result (boolean)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
753 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
754 browser = self.sender()
1670
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
755 if not isinstance(browser, HelpBrowser):
6fd889391d2c Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1665
diff changeset
756 return
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
757
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
758 if browser is not None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
759 import Helpviewer.HelpWindow
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
760 index = self.indexOf(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
761 self.resetAnimation(index)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
762 self.setTabIcon(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
763 index, Helpviewer.HelpWindow.HelpWindow.icon(browser.url()))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
764 if ok:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
765 self.showMessage.emit(self.tr("Finished loading"))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
766 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
767 self.showMessage.emit(self.tr("Failed to load"))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
768
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
769 self.__mainWindow.setLoadingActions(False)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
770
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
771 def __iconChanged(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
772 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
773 Private slot to handle the icon change.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
774 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
775 browser = self.sender()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
776
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
777 if browser is not None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
778 import Helpviewer.HelpWindow
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
779 self.setTabIcon(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
780 self.indexOf(browser),
1781
34a44041c4cb Improved the icon handling in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1694
diff changeset
781 Helpviewer.HelpWindow.HelpWindow.icon(browser.url()))
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
782 Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
783 .iconChanged(browser.url())
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
784
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
785 def getSourceFileList(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
786 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
787 Public method to get a list of all opened source files.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
789 @return dictionary with tab id as key and host/namespace as value
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
790 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
791 sourceList = {}
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
792 for i in range(self.count()):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793 browser = self.widget(i)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
794 if browser is not None and \
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
795 browser.source().isValid():
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
796 sourceList[i] = browser.source().host()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
797
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
798 return sourceList
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
799
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
800 def shallShutDown(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
801 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
802 Public method to check, if the application should be shut down.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
803
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804 @return flag indicating a shut down (boolean)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
805 """
1636
6a25bb84e2a3 Added the capability to configure the web browser behavior, when multiple tabs are about to be closed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1539
diff changeset
806 if self.count() > 1 and Preferences.getHelp("WarnOnMultipleClose"):
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
807 mb = E5MessageBox.E5MessageBox(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
808 E5MessageBox.Information,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
809 self.tr("Are you sure you want to close the window?"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
810 self.tr("""Are you sure you want to close the window?\n"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
811 """You have %n tab(s) open.""", "", self.count()),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
812 modal=True,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
813 parent=self)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
814 if self.__mainWindow.fromEric:
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
815 quitButton = mb.addButton(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
816 self.tr("&Close"), E5MessageBox.AcceptRole)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
817 quitButton.setIcon(UI.PixmapCache.getIcon("close.png"))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
818 else:
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
819 quitButton = mb.addButton(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
820 self.tr("&Quit"), E5MessageBox.AcceptRole)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
821 quitButton.setIcon(UI.PixmapCache.getIcon("exit.png"))
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
822 closeTabButton = mb.addButton(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
823 self.tr("C&lose Current Tab"), E5MessageBox.AcceptRole)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
824 closeTabButton.setIcon(UI.PixmapCache.getIcon("tabClose.png"))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
825 mb.addButton(E5MessageBox.Cancel)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
826 mb.exec_()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
827 if mb.clickedButton() == quitButton:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
828 return True
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
829 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
830 if mb.clickedButton() == closeTabButton:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
831 self.closeBrowser()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
832 return False
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
833
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
834 return True
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
835
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
836 def stackedUrlBar(self):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
837 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
838 Public method to get a reference to the stacked url bar.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
839
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
840 @return reference to the stacked url bar (StackedUrlBar)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
841 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
842 return self.__stackedUrlBar
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
843
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
844 def currentUrlBar(self):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
845 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
846 Public method to get a reference to the current url bar.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
847
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
848 @return reference to the current url bar (UrlBar)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
849 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
850 return self.__stackedUrlBar.currentWidget()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
851
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
852 def __lineEditReturnPressed(self):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
853 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
854 Private slot to handle the entering of an URL.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
855 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
856 edit = self.sender()
953
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
857 url = self.__guessUrlFromPath(edit.text())
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1781
diff changeset
858 request = QNetworkRequest(url)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1781
diff changeset
859 request.setRawHeader("X-Eric5-UserLoadAction", b"1")
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
860 if e5App().keyboardModifiers() == Qt.AltModifier:
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
861 self.newBrowser(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
862 None, (request, QNetworkAccessManager.GetOperation, b""))
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
863 else:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
864 self.currentBrowser().setSource(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
865 None, (request, QNetworkAccessManager.GetOperation, b""))
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
866 self.currentBrowser().setFocus()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
867
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
868 def __pathSelected(self, path):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
869 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
870 Private slot called when a URL is selected from the completer.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
871
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
872 @param path path to be shown (string)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
873 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
874 url = self.__guessUrlFromPath(path)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
875 self.currentBrowser().setSource(url)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
876
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
877 def __guessUrlFromPath(self, path):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
878 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
879 Private method to guess an URL given a path string.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
880
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
881 @param path path string to guess an URL for (string)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
882 @return guessed URL (QUrl)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
883 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
884 manager = self.__mainWindow.openSearchManager()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
885 path = Utilities.fromNativeSeparators(path)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
886 url = manager.convertKeywordSearchToUrl(path)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
887 if url.isValid():
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
888 return url
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
889
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
890 try:
953
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
891 url = QUrl.fromUserInput(path)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
892 except AttributeError:
953
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
893 url = QUrl(path)
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
894
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
895 if url.scheme() == "about" and \
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
896 url.path() == "home":
1665
b248526d3a1b Reworked some stuff in the web browser to use Qt resources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1652
diff changeset
897 url = QUrl("eric:home")
953
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
898
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
899 if url.scheme() in ["s", "search"]:
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
900 url = manager.currentEngine().searchUrl(url.path().strip())
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
901
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
902 if url.scheme() != "" and \
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
903 (url.host() != "" or url.path() != ""):
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
904 return url
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
905
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
906 urlString = Preferences.getHelp("DefaultScheme") + path.strip()
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
907 url = QUrl.fromEncoded(urlString.encode(), QUrl.TolerantMode)
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
908
7c42d54ba205 Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
909 return url
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
910
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
911 def __currentChanged(self, index):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
912 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
913 Private slot to handle an index change.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
914
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
915 @param index new index (integer)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
916 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
917 self.__stackedUrlBar.setCurrentIndex(index)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
918
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
919 browser = self.browserAt(index)
717
3ebae1fae98d Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 653
diff changeset
920 if browser is not None:
3ebae1fae98d Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 653
diff changeset
921 if browser.url() == "" and browser.hasFocus():
3ebae1fae98d Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 653
diff changeset
922 self.__stackedUrlBar.currentWidget.setFocus()
3ebae1fae98d Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 653
diff changeset
923 elif browser.url() != "":
3ebae1fae98d Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 653
diff changeset
924 browser.setFocus()
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
925
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
926 def restoreClosedTab(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
927 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
928 Public slot to restore the most recently closed tab.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
929 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
930 if not self.canRestoreClosedTab():
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
931 return
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
932
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
933 act = self.sender()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
934 tab = self.__closedTabsManager.getClosedTabAt(act.data())
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
935
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1953
diff changeset
936 self.newBrowser(tab.url.toString(), position=tab.position)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
937
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
938 def canRestoreClosedTab(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
939 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
940 Public method to check, if closed tabs can be restored.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
941
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
942 @return flag indicating that closed tabs can be restored (boolean)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
943 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
944 return self.__closedTabsManager.isClosedTabAvailable()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
945
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
946 def restoreAllClosedTabs(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
947 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
948 Public slot to restore all closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
949 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
950 if not self.canRestoreClosedTab():
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
951 return
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
952
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
953 for tab in self.__closedTabsManager.allClosedTabs():
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1953
diff changeset
954 self.newBrowser(tab.url.toString(), position=tab.position)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
955 self.__closedTabsManager.clearList()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
956
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
957 def clearClosedTabsList(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
958 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
959 Public slot to clear the list of closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
960 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
961 self.__closedTabsManager.clearList()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
962
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
963 def __aboutToShowClosedTabsMenu(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
964 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
965 Private slot to populate the closed tabs menu.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
966 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
967 fm = self.__closedTabsMenu.fontMetrics()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
968 maxWidth = fm.width('m') * 40
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
969
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
970 self.__closedTabsMenu.clear()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
971 index = 0
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
972 for tab in self.__closedTabsManager.allClosedTabs():
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
973 title = fm.elidedText(tab.title, Qt.ElideRight, maxWidth)
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
974 self.__closedTabsMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
975 self.__mainWindow.icon(tab.url), title,
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
976 self.restoreClosedTab).setData(index)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
977 index += 1
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
978 self.__closedTabsMenu.addSeparator()
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
979 self.__closedTabsMenu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
980 self.tr("Restore All Closed Tabs"), self.restoreAllClosedTabs)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
981 self.__closedTabsMenu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
982 self.tr("Clear List"), self.clearClosedTabsList)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
983
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
984 def closedTabsManager(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
985 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
986 Public slot to get a reference to the closed tabs manager.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
987
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
988 @return reference to the closed tabs manager (ClosedTabsManager)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
989 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
990 return self.__closedTabsManager
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
991
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
992 def __closedTabAvailable(self, avail):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
993 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
994 Private slot to handle changes of the availability of closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
995
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
996 @param avail flag indicating the availability of closed tabs (boolean)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
997 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
998 self.__closedTabsButton.setEnabled(avail)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
999 self.__restoreClosedTabAct.setEnabled(avail)

eric ide

mercurial