eric6/WebBrowser/ClosedTabsManager.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8207
d359172d11be
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class to manage closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
10 from PyQt5.QtCore import pyqtSignal, QUrl, QObject
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 class ClosedTab(object):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 Class implementing a structure to store data about a closed tab.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
5653
c023821bb25f Fixed a few code style issues related to the usage of class instances for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
17 def __init__(self, url=None, title="", position=-1):
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Constructor
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @param url URL of the closed tab (QUrl)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 @param title title of the closed tab (string)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 @param position index of the closed tab (integer)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
5653
c023821bb25f Fixed a few code style issues related to the usage of class instances for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
25 self.url = QUrl() if url is None else QUrl(url)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 self.title = title
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 self.position = position
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def __eq__(self, other):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Special method implementing the equality operator.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param other reference to the object to compare against (ClosedTab)
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
34 @return flag indicating equality of the tabs (boolean)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
36 return (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
37 self.url == other.url and
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
38 self.title == other.title and
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
39 self.position == other.position
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
40 )
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 class ClosedTabsManager(QObject):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 Class implementing a manager for closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
47 @signal closedTabAvailable(boolean) emitted to signal a change of
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
48 availability of closed tabs
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 closedTabAvailable = pyqtSignal(bool)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 def __init__(self, parent=None):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Constructor
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @param parent reference to the parent object (QObject)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
58 super(ClosedTabsManager, self).__init__()
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__closedTabs = []
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 def recordBrowser(self, browser, position):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 Public method to record the data of a browser about to be closed.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @param browser reference to the browser to be closed (HelpBrowser)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 @param position index of the tab to be closed (integer)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
4735
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
69 import WebBrowser.WebBrowserWindow
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
70 if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate():
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 return
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 if browser.url().isEmpty():
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 return
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 tab = ClosedTab(browser.url(), browser.title(), position)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.__closedTabs.insert(0, tab)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.closedTabAvailable.emit(True)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 def getClosedTabAt(self, index):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 Public method to get the indexed closed tab.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @param index index of the tab to return (integer)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @return requested tab (ClosedTab)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if len(self.__closedTabs) > 0 and len(self.__closedTabs) > index:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 tab = self.__closedTabs.pop(index)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 else:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 tab = ClosedTab()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.closedTabAvailable.emit(len(self.__closedTabs) > 0)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 return tab
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 def isClosedTabAvailable(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 Public method to check for closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @return flag indicating the availability of closed tab data (boolean)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 return len(self.__closedTabs) > 0
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 def clearList(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 Public method to clear the list of closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self.__closedTabs = []
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.closedTabAvailable.emit(False)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def allClosedTabs(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 Public method to get a list of all closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @return list of closed tabs (list of ClosedTab)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 return self.__closedTabs

eric ide

mercurial