eric6/E5Gui/E5TreeWidget.py

Wed, 30 Dec 2020 11:00:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:05 +0100
changeset 7923
91e843545d9a
parent 7780
41420f82c0ac
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing specialized tree views.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5522b3266c8b Added an extended tree widget.
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
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 class E5TreeWidget(QTreeWidget):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 Class implementing an extended tree widget.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 @signal itemControlClicked(QTreeWidgetItem) emitted after a Ctrl-Click
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 on an item
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 @signal itemMiddleButtonClicked(QTreeWidgetItem) emitted after a click
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 of the middle button on an item
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 ItemsCollapsed = 0
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 ItemsExpanded = 1
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 itemControlClicked = pyqtSignal(QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 itemMiddleButtonClicked = pyqtSignal(QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def __init__(self, parent=None):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param parent reference to the parent widget (QWidget)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
35 super(E5TreeWidget, self).__init__(parent)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__refreshAllItemsNeeded = True
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__allTreeItems = []
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.__showMode = E5TreeWidget.ItemsCollapsed
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.itemChanged.connect(self.__scheduleRefresh)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def setDefaultItemShowMode(self, mode):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Public method to set the default item show mode.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param mode default mode (ItemsCollapsed, ItemsExpanded)
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
50 @exception ValueError raised to indicate a bad parameter value
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
52 if mode not in [E5TreeWidget.ItemsCollapsed,
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
53 E5TreeWidget.ItemsExpanded]:
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
54 raise ValueError("Bad value for 'mode' parameter.")
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__showMode = mode
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 def allItems(self):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Public method to get a list of all items.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 @return list of all items (list of QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 if self.__refreshAllItemsNeeded:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.__allTreeItems = []
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.__iterateAllItems(None)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__refreshAllItemsNeeded = False
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 return self.__allTreeItems
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 def appendToParentItem(self, parent, item):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 Public method to append an item to a parent item.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
2016
2bbc81fcce4a Fixed a few PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1969
diff changeset
75 @param parent text of the parent item (string) or
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 the parent item (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @param item item to be appended (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @return flag indicating success (boolean)
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
79 @exception RuntimeError raised to indicate an illegal type for
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
80 the parent
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if isinstance(parent, QTreeWidgetItem):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 if parent is None or parent.treeWidget() != self:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 return False
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 parentItem = parent
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 elif isinstance(parent, str):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 lst = self.findItems(parent, Qt.MatchExactly)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 if not lst:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 return False
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 parentItem = lst[0]
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 if parentItem is None:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 return False
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 else:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 raise RuntimeError("illegal type for parent")
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.__allTreeItems.append(item)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 parentItem.addChild(item)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 return True
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def prependToParentItem(self, parent, item):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Public method to prepend an item to a parent item.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
2016
2bbc81fcce4a Fixed a few PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1969
diff changeset
104 @param parent text of the parent item (string) or
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 the parent item (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @param item item to be prepended (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @return flag indicating success (boolean)
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
108 @exception RuntimeError raised to indicate an illegal type for
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
109 the parent
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 if isinstance(parent, QTreeWidgetItem):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 if parent is None or parent.treeWidget() != self:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 return False
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 parentItem = parent
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 elif isinstance(parent, str):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 lst = self.findItems(parent, Qt.MatchExactly)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if not lst:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 return False
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 parentItem = lst[0]
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 if parentItem is None:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 return False
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 else:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 raise RuntimeError("illegal type for parent")
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.__allTreeItems.append(item)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 parentItem.insertChild(0, item)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 return True
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 def addTopLevelItem(self, item):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 Public method to add a top level item.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @param item item to be added as a top level item (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 self.__allTreeItems.append(item)
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
136 super(E5TreeWidget, self).addTopLevelItem(item)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 def addTopLevelItems(self, items):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 Public method to add a list of top level items.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
142 @param items items to be added as top level items
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
143 (list of QTreeWidgetItem)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 self.__allTreeItems.extend(items)
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
146 super(E5TreeWidget, self).addTopLevelItems(items)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 def insertTopLevelItem(self, index, item):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 Public method to insert a top level item.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 @param index index for the insertion (integer)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 @param item item to be inserted as a top level item (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.__allTreeItems.append(item)
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
156 super(E5TreeWidget, self).insertTopLevelItem(index, item)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 def insertTopLevelItems(self, index, items):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 Public method to insert a list of top level items.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @param index index for the insertion (integer)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
163 @param items items to be inserted as top level items
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
164 (list of QTreeWidgetItem)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__allTreeItems.extend(items)
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
167 super(E5TreeWidget, self).insertTopLevelItems(index, items)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 def deleteItem(self, item):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 Public method to delete an item.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 @param item item to be deleted (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 if item in self.__allTreeItems:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 self.__allTreeItems.remove(item)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 self.__refreshAllItemsNeeded = True
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 del item
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 def deleteItems(self, items):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 Public method to delete a list of items.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @param items items to be deleted (list of QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 for item in items:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.deleteItem(item)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
191 def filterString(self, filterStr):
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 Public slot to set a new filter.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
195 @param filterStr filter to be set (string)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.expandAll()
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 allItems = self.allItems()
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
200 if filterStr:
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
201 lFilter = filterStr.lower()
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 for itm in allItems:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 itm.setHidden(lFilter not in itm.text(0).lower())
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 itm.setExpanded(True)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 for index in range(self.topLevelItemCount()):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self.topLevelItem(index).setHidden(False)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 firstItm = self.topLevelItem(0)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 belowItm = self.itemBelow(firstItm)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 topLvlIndex = 0
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 while firstItm:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 if lFilter in firstItm.text(0).lower():
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 firstItm.setHidden(False)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 elif not firstItm.parent() and not belowItm:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 firstItm.setHidden(True)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 elif not belowItm:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 break
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 elif not firstItm.parent() and not belowItm.parent():
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 firstItm.setHidden(True)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 topLvlIndex += 1
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 firstItm = self.topLevelItem(topLvlIndex)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 belowItm = self.itemBelow(firstItm)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 else:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 for itm in allItems:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 itm.setHidden(False)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 for index in range(self.topLevelItemCount()):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 self.topLevelItem(index).setHidden(False)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 if self.__showMode == E5TreeWidget.ItemsCollapsed:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 self.collapseAll()
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 def clear(self):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 Public slot to clear the tree.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.__allTreeItems = []
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
237 super(E5TreeWidget, self).clear()
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 def __scheduleRefresh(self):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 Private slot to schedule a refresh of the tree.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 self.__refreshAllItemsNeeded = True
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 def mousePressEvent(self, evt):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 Protected method handling mouse press events.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 @param evt mouse press event (QMouseEvent)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 """
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
251 if (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
252 evt.modifiers() == Qt.ControlModifier and
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
253 evt.buttons() == Qt.LeftButton
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
254 ):
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 self.itemControlClicked.emit(self.itemAt(evt.pos()))
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 return
3375
03f1833b601e Replaced Qt.MiddleButton by Qt.MidButton due to old Qt versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
257 elif evt.buttons() == Qt.MidButton:
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 self.itemMiddleButtonClicked.emit(self.itemAt(evt.pos()))
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 return
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 else:
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
261 super(E5TreeWidget, self).mousePressEvent(evt)
1969
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 def __iterateAllItems(self, parent):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 Private method to iterate over the child items of the parent.
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 @param parent parent item to iterate (QTreeWidgetItem)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 """
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 if parent:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 count = parent.childCount()
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 else:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 count = self.topLevelItemCount()
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 for index in range(count):
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 if parent:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 itm = parent.child(index)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 else:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 itm = self.topLevelItem(index)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 if itm.childCount() == 0:
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 self.__allTreeItems.append(itm)
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
5522b3266c8b Added an extended tree widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 self.__iterateAllItems(itm)

eric ide

mercurial