Tue, 18 Oct 2022 16:06:21 +0200
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
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 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
3 | # Copyright (c) 2012 - 2022 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 | |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
10 | from PyQt6.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 | |
8207
d359172d11be
Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
13 | class ClosedTab: |
1694
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 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
17 | |
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
|
18 | 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
|
19 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
21 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | @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
|
23 | @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
|
24 | @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
|
25 | """ |
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
|
26 | 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
|
27 | self.title = title |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | self.position = position |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
29 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | def __eq__(self, other): |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | Special method implementing the equality operator. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
33 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | @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
|
35 | @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
|
36 | """ |
7271
2cac5b7abcce
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
37 | return ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
38 | self.url == other.url |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
39 | and self.title == other.title |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
40 | and self.position == other.position |
7271
2cac5b7abcce
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
41 | ) |
1694
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 | |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | class ClosedTabsManager(QObject): |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | Class implementing a manager for closed tabs. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2954
diff
changeset
|
48 | @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
|
49 | availability of closed tabs |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
51 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | closedTabAvailable = pyqtSignal(bool) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
53 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | def __init__(self, parent=None): |
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 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
57 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | @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
|
59 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8207
diff
changeset
|
60 | super().__init__() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
61 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | self.__closedTabs = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
63 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | def recordBrowser(self, browser, position): |
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 | Public method to record the data of a browser about to be closed. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | @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
|
69 | @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
|
70 | """ |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
71 | from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
72 | |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
73 | if WebBrowserWindow.isPrivate(): |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
75 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | if browser.url().isEmpty(): |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
78 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | tab = ClosedTab(browser.url(), browser.title(), position) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | self.__closedTabs.insert(0, tab) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | self.closedTabAvailable.emit(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | def getClosedTabAt(self, index): |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | Public method to get the indexed closed tab. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
86 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | @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
|
88 | @return requested tab (ClosedTab) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | """ |
8260
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
90 | tab = ( |
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
91 | self.__closedTabs.pop(index) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | if (len(self.__closedTabs) > 0 and len(self.__closedTabs) > index) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | else ClosedTab() |
8260
2161475d9639
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
94 | ) |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | self.closedTabAvailable.emit(len(self.__closedTabs) > 0) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | return tab |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
97 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | def isClosedTabAvailable(self): |
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 | Public method to check for closed tabs. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
101 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | @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
|
103 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | return len(self.__closedTabs) > 0 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
105 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | def clearList(self): |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | 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
|
109 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | self.__closedTabs = [] |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | self.closedTabAvailable.emit(False) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
112 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | def allClosedTabs(self): |
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 | Public method to get a list of all closed tabs. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
116 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | @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
|
118 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | return self.__closedTabs |