eric6/WebBrowser/Bookmarks/BookmarksMenu.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 8143
2c730d5fd177
permissions
-rw-r--r--

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

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
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) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the bookmarks menu.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
10 from PyQt5.QtCore import pyqtSignal, Qt, QUrl
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtGui import QCursor
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtWidgets import QMenu
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
14 from E5Gui.E5ModelMenu import E5ModelMenu
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
16 from .BookmarksModel import BookmarksModel
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
17 from .BookmarkNode import BookmarkNode
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
20 class BookmarksMenu(E5ModelMenu):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing the bookmarks menu base class.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
24 @signal openUrl(QUrl, str) emitted to open a URL with the given title in
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
25 the current tab
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
26 @signal newTab(QUrl, str) emitted to open a URL with the given title in a
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
27 new tab
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
28 @signal newWindow(QUrl, str) emitted to open a URL with the given title in
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
29 a new window
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
31 openUrl = pyqtSignal(QUrl, str)
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
32 newTab = pyqtSignal(QUrl, str)
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
33 newWindow = pyqtSignal(QUrl, str)
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
34
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
35 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @param parent reference to the parent widget (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
41 E5ModelMenu.__init__(self, parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
43 self.activated.connect(self.__activated)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.setStatusBarTextRole(BookmarksModel.UrlStringRole)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.setSeparatorRole(BookmarksModel.SeparatorRole)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.setContextMenuPolicy(Qt.CustomContextMenu)
458
1695e7a2db54 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
48 self.customContextMenuRequested.connect(self.__contextMenuRequested)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 def createBaseMenu(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 Public method to get the menu that is used to populate sub menu's.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @return reference to the menu (BookmarksMenu)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 menu = BookmarksMenu(self)
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
57 menu.openUrl.connect(self.openUrl)
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
58 menu.newTab.connect(self.newTab)
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
59 menu.newWindow.connect(self.newWindow)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 return menu
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
62 def __updateVisitCount(self, idx):
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
63 """
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
64 Private method to update the visit count of a bookmark.
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
65
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
66 @param idx index of the bookmark item (QModelIndex)
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
67 """
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
68 from WebBrowser.WebBrowserWindow import WebBrowserWindow
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
69
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
70 bookmarkNode = self.model().node(idx)
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
71 manager = WebBrowserWindow.bookmarksManager()
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
72 manager.incVisitCount(bookmarkNode)
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
73
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 def __activated(self, idx):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 Private slot handling the activated signal.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @param idx index of the activated item (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 if self._keyboardModifiers & Qt.ControlModifier:
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
81 self.newTab.emit(
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
82 idx.data(BookmarksModel.UrlRole),
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
83 idx.data(Qt.DisplayRole))
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
84 elif self._keyboardModifiers & Qt.ShiftModifier:
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
85 self.newWindow.emit(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
86 idx.data(BookmarksModel.UrlRole),
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
87 idx.data(Qt.DisplayRole))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 else:
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
89 self.openUrl.emit(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
90 idx.data(BookmarksModel.UrlRole),
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
91 idx.data(Qt.DisplayRole))
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
92 self.__updateVisitCount(idx)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 def postPopulated(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 Public method to add any actions after the tree.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if self.isEmpty():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 parent = self.rootIndex()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 hasBookmarks = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 for i in range(parent.model().rowCount(parent)):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 child = parent.model().index(i, 0, parent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
108 if child.data(BookmarksModel.TypeRole) == BookmarkNode.Bookmark:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 hasBookmarks = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 if not hasBookmarks:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 self.addSeparator()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
116 act = self.addAction(self.tr("Open all in Tabs"))
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
117 act.triggered.connect(lambda: self.openAll(act))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
119 def openAll(self, act):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
121 Public slot to open all the menu's items.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
122
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
123 @param act reference to the action object
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
124 @type QAction
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
126 menu = act.parent()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 if menu is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 parent = menu.rootIndex()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 if not parent.isValid():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 for i in range(parent.model().rowCount(parent)):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 child = parent.model().index(i, 0, parent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
137 if child.data(BookmarksModel.TypeRole) != BookmarkNode.Bookmark:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 if i == 0:
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
141 self.openUrl.emit(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
142 child.data(BookmarksModel.UrlRole),
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
143 child.data(Qt.DisplayRole))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 else:
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
145 self.newTab.emit(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
146 child.data(BookmarksModel.UrlRole),
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
147 child.data(Qt.DisplayRole))
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
148 self.__updateVisitCount(child)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 def __contextMenuRequested(self, pos):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 Private slot to handle the context menu request.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 @param pos position the context menu shall be shown (QPoint)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 act = self.actionAt(pos)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
158 if (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
159 act is not None and
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
160 act.menu() is None and
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
161 self.index(act).isValid()
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
162 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 menu = QMenu()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 v = act.data()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
166 act2 = menu.addAction(self.tr("Open"))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
167 act2.setData(v)
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
168 act2.triggered.connect(
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
169 lambda: self.__openBookmark(act2))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
170 act2 = menu.addAction(self.tr("Open in New Tab\tCtrl+LMB"))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
171 act2.setData(v)
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
172 act2.triggered.connect(
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
173 lambda: self.__openBookmarkInNewTab(act2))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
174 act2 = menu.addAction(self.tr("Open in New Window"))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
175 act2.setData(v)
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
176 act2.triggered.connect(
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
177 lambda: self.__openBookmarkInNewWindow(act2))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178 act2 = menu.addAction(self.tr("Open in New Private Window"))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 act2.setData(v)
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
180 act2.triggered.connect(
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
181 lambda: self.__openBookmarkInPrivateWindow(act2))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 menu.addSeparator()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
184 act2 = menu.addAction(self.tr("Remove"))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
185 act2.setData(v)
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
186 act2.triggered.connect(lambda: self.__removeBookmark(act2))
1733
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
187 menu.addSeparator()
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
188
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
189 act2 = menu.addAction(self.tr("Properties..."))
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
190 act2.setData(v)
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
191 act2.triggered.connect(lambda: self.__edit(act2))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7583
diff changeset
193 execAct = menu.exec(QCursor.pos())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 if execAct is not None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.close()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 parent = self.parent()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 while parent is not None and isinstance(parent, QMenu):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 parent.close()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 parent = parent.parent()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
201 def __openBookmark(self, act):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 Private slot to open a bookmark in the current browser tab.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
204
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
205 @param act reference to the triggering action
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
206 @type QAction
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
208 idx = self.index(act)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
210 self.openUrl.emit(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
211 idx.data(BookmarksModel.UrlRole),
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
212 idx.data(Qt.DisplayRole))
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
213 self.__updateVisitCount(idx)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
215 def __openBookmarkInNewTab(self, act):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 Private slot to open a bookmark in a new browser tab.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
218
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
219 @param act reference to the triggering action
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
220 @type QAction
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
222 idx = self.index(act)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5015
diff changeset
224 self.newTab.emit(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
225 idx.data(BookmarksModel.UrlRole),
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
226 idx.data(Qt.DisplayRole))
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
227 self.__updateVisitCount(idx)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
229 def __openBookmarkInNewWindow(self, act):
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
230 """
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
231 Private slot to open a bookmark in a new window.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
232
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
233 @param act reference to the triggering action
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
234 @type QAction
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
235 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
236 idx = self.index(act)
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
237 url = idx.data(BookmarksModel.UrlRole)
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
238
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
239 from WebBrowser.WebBrowserWindow import WebBrowserWindow
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
240 WebBrowserWindow.mainWindow().newWindow(url)
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
241 self.__updateVisitCount(idx)
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
242
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
243 def __openBookmarkInPrivateWindow(self, act):
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
244 """
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
245 Private slot to open a bookmark in a new private window.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
246
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
247 @param act reference to the triggering action
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
248 @type QAction
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
249 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
250 idx = self.index(act)
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
251 url = idx.data(BookmarksModel.UrlRole)
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
252
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
253 from WebBrowser.WebBrowserWindow import WebBrowserWindow
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
254 WebBrowserWindow.mainWindow().newPrivateWindow(url)
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
255 self.__updateVisitCount(idx)
4808
328e613165fe Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
256
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
257 def __removeBookmark(self, act):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 Private slot to remove a bookmark.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
260
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
261 @param act reference to the triggering action
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
262 @type QAction
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
264 idx = self.index(act)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 self.removeEntry(idx)
1733
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
266
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
267 def __edit(self, act):
1733
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
268 """
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
269 Private slot to edit a bookmarks properties.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
270
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
271 @param act reference to the triggering action
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
272 @type QAction
1733
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
273 """
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
274 from .BookmarkPropertiesDialog import BookmarkPropertiesDialog
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
275
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
276 idx = self.index(act)
1733
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
277 node = self.model().node(idx)
231e6f05d274 Added a dialog to edit bookmark properties and the description to the add bookmark dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
278 dlg = BookmarkPropertiesDialog(node)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7583
diff changeset
279 dlg.exec()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
281 ##############################################################################
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
283
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 class BookmarksMenuBarMenu(BookmarksMenu):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 Class implementing a dynamically populated menu for bookmarks.
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
287
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
288 @signal openUrl(QUrl, str) emitted to open a URL with the given title in
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
289 the current tab
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 """
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
291 openUrl = pyqtSignal(QUrl, str)
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
292
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
293 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 @param parent reference to the parent widget (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 BookmarksMenu.__init__(self, parent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 self.__initialActions = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 def prePopulated(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 Public method to add any actions before the tree.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 @return flag indicating if any actions were added (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 """
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
309 from WebBrowser.WebBrowserWindow import WebBrowserWindow
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
310
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
311 manager = WebBrowserWindow.bookmarksManager()
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
312 self.setModel(manager.bookmarksModel())
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
313 self.setRootIndex(manager.bookmarksModel().nodeIndex(manager.menu()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 # initial actions
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 for act in self.__initialActions:
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1671
diff changeset
317 if act == "--SEPARATOR--":
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1671
diff changeset
318 self.addSeparator()
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1671
diff changeset
319 else:
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1671
diff changeset
320 self.addAction(act)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 if len(self.__initialActions) != 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 self.addSeparator()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 self.createMenu(
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4808
diff changeset
325 manager.bookmarksModel().nodeIndex(manager.toolbar()),
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 1, self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 return True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
329 def postPopulated(self):
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
330 """
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
331 Public method to add any actions after the tree.
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
332 """
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
333 if self.isEmpty():
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
334 return
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
335
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
336 parent = self.rootIndex()
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
337
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
338 hasBookmarks = False
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
339
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
340 for i in range(parent.model().rowCount(parent)):
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
341 child = parent.model().index(i, 0, parent)
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
342
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
343 if child.data(BookmarksModel.TypeRole) == BookmarkNode.Bookmark:
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
344 hasBookmarks = True
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
345 break
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
346
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
347 if not hasBookmarks:
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
348 return
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
349
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
350 self.addSeparator()
7583
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
351 act_1 = self.addAction(self.tr("Default Home Page"))
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
352 act_1.setData("eric:home")
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
353 act_1.triggered.connect(
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
354 lambda: self.__defaultBookmarkTriggered(act_1))
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
355 act_2 = self.addAction(self.tr("Speed Dial"))
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
356 act_2.setData("eric:speeddial")
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
357 act_2.triggered.connect(
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
358 lambda: self.__defaultBookmarkTriggered(act_2))
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
359 self.addSeparator()
7583
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
360 act_3 = self.addAction(self.tr("Open all in Tabs"))
323e47d167e0 Web Browser: added code to ask for the title of a new bookmark folder.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
361 act_3.triggered.connect(lambda: self.openAll(act_3))
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
362
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 def setInitialActions(self, actions):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
365 Public method to set the list of actions that should appear first in
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
366 the menu.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 @param actions list of initial actions (list of QAction)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 self.__initialActions = actions[:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 for act in self.__initialActions:
458
1695e7a2db54 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
372 self.addAction(act)
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
373
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
374 def __defaultBookmarkTriggered(self, act):
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
375 """
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
376 Private slot handling the default bookmark menu entries.
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
377
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
378 @param act reference to the action object
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
379 @type QAction
1671
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
380 """
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
381 urlStr = act.data()
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
382 if urlStr.startswith("eric:"):
1443546b92ad Added default entries to the bookmark menu for the default home page and the speed dial page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
383 self.openUrl.emit(QUrl(urlStr), "")

eric ide

mercurial