Helpviewer/History/HistoryMenu.py

Mon, 25 Mar 2013 03:11:06 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Mon, 25 Mar 2013 03:11:06 +0100
branch
Py2 comp.
changeset 2525
8b507a9a2d40
parent 2403
e3d7a861547c
child 3057
10516539f238
permissions
-rw-r--r--

Script changes: Future import added, super calls modified and unicode behavior for str.

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
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1965
diff changeset
3 # Copyright (c) 2009 - 2013 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 history 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
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
10 from __future__ import unicode_literals # __IGNORE_WARNING__
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
11
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import sys
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
14 from PyQt4.QtCore import pyqtSignal, Qt, QMimeData, QUrl, QModelIndex
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
15 from PyQt4.QtGui import QAbstractProxyModel, QSortFilterProxyModel, QMenu
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
17 from E5Gui.E5ModelMenu import E5ModelMenu
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
18 from E5Gui import E5MessageBox
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
20 from .HistoryModel import HistoryModel
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 import UI.PixmapCache
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
24
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 class HistoryMenuModel(QAbstractProxyModel):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class implementing a model for the history menu.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 It maps the first bunch of items of the source model to the root.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 MOVEDROWS = 15
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
33 def __init__(self, sourceModel, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 Constructor
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 @param sourceModel reference to the source model (QAbstractItemModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param parent reference to the parent object (QObject)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
40 super(HistoryMenuModel, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.__treeModel = sourceModel
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.setSourceModel(sourceModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def bumpedRows(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Public method to determine the number of rows moved to the root.
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 @return number of rows moved to the root (integer)
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 first = self.__treeModel.index(0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 if not first.isValid():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 return 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 return min(self.__treeModel.rowCount(first), self.MOVEDROWS)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
57 def columnCount(self, parent=QModelIndex()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 Public method to get the number of columns.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 @param parent index of parent (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 @return number of columns (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 return self.__treeModel.columnCount(self.mapToSource(parent))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
66 def rowCount(self, parent=QModelIndex()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 Public method to determine the number of rows.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @param parent index of parent (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @return number of rows (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 if parent.column() > 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 return 0
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 if not parent.isValid():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 folders = self.sourceModel().rowCount()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 bumpedItems = self.bumpedRows()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 if bumpedItems <= self.MOVEDROWS and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 bumpedItems == self.sourceModel().rowCount(self.sourceModel().index(0, 0)):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 folders -= 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 return bumpedItems + folders
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
84 if parent.internalId() == sys.maxsize:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if parent.row() < self.bumpedRows():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 return 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 idx = self.mapToSource(parent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 defaultCount = self.sourceModel().rowCount(idx)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 if idx == self.sourceModel().index(0, 0):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 return defaultCount - self.bumpedRows()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 return defaultCount
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 def mapFromSource(self, sourceIndex):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 Public method to map an index to the proxy model index.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 @param sourceIndex reference to a source model index (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 @return proxy model index (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 sourceRow = self.__treeModel.mapToSource(sourceIndex).row()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 return self.createIndex(sourceIndex.row(), sourceIndex.column(), sourceRow)
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 def mapToSource(self, proxyIndex):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 Public method to map an index to the source model index.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 @param proxyIndex reference to a proxy model index (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 @return source model index (QModelIndex)
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 proxyIndex.isValid():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 return QModelIndex()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
115 if proxyIndex.internalId() == sys.maxsize:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 bumpedItems = self.bumpedRows()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if proxyIndex.row() < bumpedItems:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
118 return self.__treeModel.index(proxyIndex.row(), proxyIndex.column(),
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__treeModel.index(0, 0))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 if bumpedItems <= self.MOVEDROWS and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 bumpedItems == self.sourceModel().rowCount(self.__treeModel.index(0, 0)):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 bumpedItems -= 1
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
123 return self.__treeModel.index(proxyIndex.row() - bumpedItems,
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 proxyIndex.column())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 historyIndex = self.__treeModel.sourceModel()\
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 .index(proxyIndex.internalId(), proxyIndex.column())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 treeIndex = self.__treeModel.mapFromSource(historyIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 return treeIndex
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
131 def index(self, row, column, parent=QModelIndex()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 Public method to create an index.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @param row row number for the index (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @param column column number for the index (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @param parent index of the parent item (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 @return requested index (QModelIndex)
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 row < 0 or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 column < 0 or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 column >= self.columnCount(parent) or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 parent.column() > 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 return QModelIndex()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 if not parent.isValid():
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
147 return self.createIndex(row, column, sys.maxsize)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 treeIndexParent = self.mapToSource(parent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 bumpedItems = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if treeIndexParent == self.sourceModel().index(0, 0):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 bumpedItems = self.bumpedRows()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 treeIndex = self.__treeModel.index(row + bumpedItems, column, treeIndexParent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 historyIndex = self.__treeModel.mapToSource(treeIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 historyRow = historyIndex.row()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 if historyRow == -1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 historyRow = treeIndex.row()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 return self.createIndex(row, column, historyRow)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 def parent(self, index):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 Public method to get the parent index.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @param index index of item to get parent (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @return index of parent (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 offset = index.internalId()
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
169 if offset == sys.maxsize or not index.isValid():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 return QModelIndex()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 historyIndex = self.__treeModel.sourceModel().index(index.internalId(), 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 treeIndex = self.__treeModel.mapFromSource(historyIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 treeIndexParent = treeIndex.parent()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
535
4b00d7336e19 Streamlined the use of QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
176 sourceRow = self.sourceModel().mapToSource(treeIndexParent).row()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 bumpedItems = self.bumpedRows()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 if bumpedItems <= self.MOVEDROWS and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 bumpedItems == self.sourceModel().rowCount(self.sourceModel().index(0, 0)):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 bumpedItems -= 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
182 return self.createIndex(bumpedItems + treeIndexParent.row(),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
183 treeIndexParent.column(),
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 sourceRow)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 def mimeData(self, indexes):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 Public method to return the mime data.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 @param indexes list of indexes (QModelIndexList)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 @return mime data (QMimeData)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 urls = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 for index in indexes:
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
195 url = index.data(HistoryModel.UrlRole)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 urls.append(url)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 mdata = QMimeData()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 mdata.setUrls(urls)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 return mdata
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
202
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
203 class HistoryMostVisitedMenuModel(QSortFilterProxyModel):
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
204 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
205 Class implementing a model to show the most visited history entries.
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
206 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
207 def __init__(self, sourceModel, parent=None):
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
208 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
209 Constructor
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
210
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
211 @param sourceModel reference to the source model (QAbstractItemModel)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
212 @param parent reference to the parent object (QObject)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
213 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
214 super(HistoryMostVisitedMenuModel, self).__init__(parent)
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
215
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
216 self.setDynamicSortFilter(True)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
217 self.setSourceModel(sourceModel)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
218
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
219 def lessThan(self, left, right):
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
220 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
221 Protected method used to sort the displayed items.
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
222
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
223 @param left index of left item (QModelIndex)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
224 @param right index of right item (QModelIndex)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
225 @return true, if left is less than right (boolean)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
226 """
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
227 from .HistoryFilterModel import HistoryFilterModel
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
228 frequency_L = \
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
229 self.sourceModel().data(left, HistoryFilterModel.FrequencyRole)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
230 dateTime_L = \
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
231 self.sourceModel().data(left, HistoryModel.DateTimeRole)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
232 frequency_R = \
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
233 self.sourceModel().data(right, HistoryFilterModel.FrequencyRole)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
234 dateTime_R = \
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
235 self.sourceModel().data(right, HistoryModel.DateTimeRole)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
236
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
237 # Sort results in descending frequency-derived score. If frequencies are equal,
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
238 # sort on most recently viewed
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
239 if frequency_R == frequency_L:
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
240 return dateTime_R < dateTime_L
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
241
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
242 return frequency_R < frequency_L
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
243
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
244
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
245 class HistoryMenu(E5ModelMenu):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 Class implementing the history menu.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 488
diff changeset
249 @signal openUrl(QUrl, str) emitted to open a URL in the current tab
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 488
diff changeset
250 @signal newUrl(QUrl, str) emitted to open a URL in a new tab
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 """
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
252 openUrl = pyqtSignal(QUrl, str)
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
253 newUrl = pyqtSignal(QUrl, str)
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
254
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
255 def __init__(self, parent=None, tabWidget=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 Constructor
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 @param parent reference to the parent widget (QWidget)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
260 @param tabWidget reference to the tab widget managing the browser
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
261 tabs (HelpTabWidget
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 """
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
263 E5ModelMenu.__init__(self, parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
265 self.__tabWidget = tabWidget
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
266
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 self.__historyManager = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 self.__historyMenuModel = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 self.__initialActions = []
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
270 self.__mostVisitedMenu = None
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
272 self.__closedTabsMenu = QMenu(self.trUtf8("Closed Tabs"))
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
273 self.__closedTabsMenu.aboutToShow.connect(self.__aboutToShowClosedTabsMenu)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
274 self.__tabWidget.closedTabsManager().closedTabAvailable.connect(
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
275 self.__closedTabAvailable)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
276
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 self.setMaxRows(7)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
279 self.activated.connect(self.__activated)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 self.setStatusBarTextRole(HistoryModel.UrlStringRole)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 def __activated(self, idx):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 Private slot handling the activated signal.
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 @param idx index of the activated item (QModelIndex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 if self._keyboardModifiers & Qt.ControlModifier:
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
289 self.newUrl.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
290 idx.data(HistoryModel.UrlRole),
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
291 idx.data(HistoryModel.TitleRole))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 else:
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
293 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
294 idx.data(HistoryModel.UrlRole),
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
295 idx.data(HistoryModel.TitleRole))
0
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 def prePopulated(self):
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 Public method to add any actions before the tree.
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 @return flag indicating if any actions were added (boolean)
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 if self.__historyManager is None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
304 import Helpviewer.HelpWindow
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 self.__historyManager = Helpviewer.HelpWindow.HelpWindow.historyManager()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 self.__historyMenuModel = \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 HistoryMenuModel(self.__historyManager.historyTreeModel(), self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 self.setModel(self.__historyMenuModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 # initial actions
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 for act in self.__initialActions:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 self.addAction(act)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 if len(self.__initialActions) != 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 self.addSeparator()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 self.setFirstSeparator(self.__historyMenuModel.bumpedRows())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 return False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 def postPopulated(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 Public method to add any actions after the tree.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 if len(self.__historyManager.history()) > 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 self.addSeparator()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
326 if self.__mostVisitedMenu is None:
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
327 self.__mostVisitedMenu = HistoryMostVisitedMenu(10, self)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
328 self.__mostVisitedMenu.setTitle(self.trUtf8("Most Visited"))
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
329 self.__mostVisitedMenu.openUrl.connect(self.openUrl)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
330 self.__mostVisitedMenu.newUrl.connect(self.newUrl)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
331 self.addMenu(self.__mostVisitedMenu)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
332 act = self.addMenu(self.__closedTabsMenu)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
333 act.setIcon(UI.PixmapCache.getIcon("trash.png"))
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
334 act.setEnabled(self.__tabWidget.canRestoreClosedTab())
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
335 self.addSeparator()
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
336
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
337 act = self.addAction(UI.PixmapCache.getIcon("history.png"),
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 self.trUtf8("Show All History..."))
454
d28d558f7484 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 453
diff changeset
339 act.triggered[()].connect(self.__showHistoryDialog)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
340 act = self.addAction(UI.PixmapCache.getIcon("historyClear.png"),
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 self.trUtf8("Clear History..."))
454
d28d558f7484 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 453
diff changeset
342 act.triggered[()].connect(self.__clearHistoryDialog)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 def setInitialActions(self, actions):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 Public method to set the list of actions that should appear first in the menu.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 @param actions list of initial actions (list of QAction)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 self.__initialActions = actions[:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 for act in self.__initialActions:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 self.addAction(act)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 def __showHistoryDialog(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 Private slot to show the history dialog.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 """
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
358 from .HistoryDialog import HistoryDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 dlg = HistoryDialog(self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 dlg.setAttribute(Qt.WA_DeleteOnClose)
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
361 dlg.newUrl.connect(self.newUrl)
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
362 dlg.openUrl.connect(self.openUrl)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 dlg.show()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 def __clearHistoryDialog(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 Private slot to clear the history.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 if self.__historyManager is not None and \
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 538
diff changeset
370 E5MessageBox.yesNo(self,
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 self.trUtf8("Clear History"),
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 538
diff changeset
372 self.trUtf8("""Do you want to clear the history?""")):
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 538
diff changeset
373 self.__historyManager.clear()
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
374
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
375 def __aboutToShowClosedTabsMenu(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
376 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
377 Private slot to populate the closed tabs menu.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
378 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
379 fm = self.__closedTabsMenu.fontMetrics()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
380 maxWidth = fm.width('m') * 40
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
381
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
382 import Helpviewer.HelpWindow
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
383 self.__closedTabsMenu.clear()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
384 index = 0
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
385 for tab in self.__tabWidget.closedTabsManager().allClosedTabs():
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
386 title = fm.elidedText(tab.title, Qt.ElideRight, maxWidth)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
387 self.__closedTabsMenu.addAction(
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1694
diff changeset
388 Helpviewer.HelpWindow.HelpWindow.icon(tab.url), title,
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
389 self.__tabWidget.restoreClosedTab).setData(index)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
390 index += 1
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
391 self.__closedTabsMenu.addSeparator()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
392 self.__closedTabsMenu.addAction(self.trUtf8("Restore All Closed Tabs"),
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
393 self.__tabWidget.restoreAllClosedTabs)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
394 self.__closedTabsMenu.addAction(self.trUtf8("Clear List"),
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
395 self.__tabWidget.clearClosedTabsList)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
396
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
397 def __closedTabAvailable(self, avail):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
398 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
399 Private slot to handle changes of the availability of closed tabs.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
400
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
401 @param avail flag indicating the availability of closed tabs (boolean)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
402 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
403 self.__closedTabsMenu.setEnabled(avail)
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
404
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
405
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
406 class HistoryMostVisitedMenu(E5ModelMenu):
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
407 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
408 Class implementing the most visited history menu.
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
409
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
410 @signal openUrl(QUrl, str) emitted to open a URL in the current tab
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
411 @signal newUrl(QUrl, str) emitted to open a URL in a new tab
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
412 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
413 openUrl = pyqtSignal(QUrl, str)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
414 newUrl = pyqtSignal(QUrl, str)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
415
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
416 def __init__(self, count, parent=None):
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
417 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
418 Constructor
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
419
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
420 @param count maximum number of entries to be shown (integer)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
421 @param parent reference to the parent widget (QWidget)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
422 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
423 E5ModelMenu.__init__(self, parent)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
424
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
425 self.__historyMenuModel = None
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
426
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
427 self.setMaxRows(count + 1)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
428
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
429 self.activated.connect(self.__activated)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
430 self.setStatusBarTextRole(HistoryModel.UrlStringRole)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
431
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
432 def __activated(self, idx):
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
433 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
434 Private slot handling the activated signal.
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
435
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
436 @param idx index of the activated item (QModelIndex)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
437 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
438 if self._keyboardModifiers & Qt.ControlModifier:
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
439 self.newUrl.emit(
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
440 idx.data(HistoryModel.UrlRole),
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
441 idx.data(HistoryModel.TitleRole))
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
442 else:
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
443 self.openUrl.emit(
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
444 idx.data(HistoryModel.UrlRole),
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
445 idx.data(HistoryModel.TitleRole))
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
446
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
447 def prePopulated(self):
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
448 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
449 Public method to add any actions before the tree.
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
450
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
451 @return flag indicating if any actions were added (boolean)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
452 """
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
453 if self.__historyMenuModel is None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
454 import Helpviewer.HelpWindow
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
455 historyManager = Helpviewer.HelpWindow.HelpWindow.historyManager()
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
456 self.__historyMenuModel = \
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
457 HistoryMostVisitedMenuModel(historyManager.historyFilterModel(), self)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
458 self.setModel(self.__historyMenuModel)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
459 self.__historyMenuModel.sort(0)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
460
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
461 return False

eric ide

mercurial