eric6/E5Gui/E5TreeWidget.py

Wed, 01 Jan 2020 11:57:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2020 11:57:23 +0100
changeset 7360
9190402e4505
parent 7252
c5e3705073eb
child 7628
f904d0eef264
permissions
-rw-r--r--

Updated copyright for 2020.

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

eric ide

mercurial