File: test_lib_agw_customtreectrl.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (219 lines) | stat: -rw-r--r-- 7,373 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import unittest
import sys
from unittests import wtc
import wx

import wx.lib.agw.customtreectrl as CT

#---------------------------------------------------------------------------

class lib_agw_customtreectrl_Tests(wtc.WidgetTestCase):

    def test_lib_agw_customtreectrlCtor(self):
        tree = CT.CustomTreeCtrl(self.frame)
        self.assertEqual(tree.GetAGWWindowStyleFlag(), CT.TR_DEFAULT_STYLE)
        self.assertEqual(tree.GetCount(), 0)
        self.assertEqual(tree.GetRootItem(), None)

    def test_lib_agw_customtreectrlTreeItem(self):
        tree = CT.CustomTreeCtrl(self.frame)
        root = tree.AddRoot('root item')
        self.assertTrue(isinstance(root, CT.GenericTreeItem))
        self.assertTrue(root.IsOk())

        r = tree.GetRootItem()
        self.assertTrue(r is root)
        self.assertTrue(r == root)

        child = tree.AppendItem(root, 'child item')
        self.assertTrue(child is not root)
        self.assertTrue(child != root)

    def test_lib_agw_customtreectrlTreeItemData(self):
        value = 'Some Python Object'
        tree = CT.CustomTreeCtrl(self.frame)
        root = tree.AddRoot('root item', data=value)
        v = tree.GetItemData(root)
        self.assertTrue(v == value)
        tree.SetItemData(root, None)
        self.assertTrue(tree.GetItemData(root) is None)

    def test_lib_agw_customtreectrlTreeItemPyData(self):
        # ensure that the "Py" versions works as the normal one
        value = 'Some Python Object'
        tree = CT.CustomTreeCtrl(self.frame)
        root = tree.AddRoot('root item')
        tree.SetItemPyData(root, value)

        v = tree.GetItemPyData(root)
        self.assertTrue(v == value)
        tree.SetItemPyData(root, None)
        self.assertTrue(tree.GetItemPyData(root) is None)

    def test_lib_agw_customtreectrlGetSelections(self):
        tree = CT.CustomTreeCtrl(self.frame, agwStyle=CT.TR_MULTIPLE)
        root = tree.AddRoot('root item')
        c1 = tree.AppendItem(root, 'c1')
        c2 = tree.AppendItem(root, 'c2')
        tree.SelectItem(c1)
        tree.SelectItem(c2)
        self.assertTrue(tree.IsSelected(c1))
        self.assertTrue(tree.IsSelected(c2))

        sel = tree.GetSelections()
        self.assertTrue(isinstance(sel, list))
        self.assertTrue(len(sel) == 2)
        self.assertTrue(isinstance(sel[0], CT.GenericTreeItem))

    def test_lib_agw_customtreectrlItemCheck(self):

        tree = CT.CustomTreeCtrl(self.frame)
        root = tree.AddRoot('root item')

        # Checkboxes, there can be more than one checked at the same level
        c1 = tree.AppendItem(root, 'c1', ct_type=1)
        c2 = tree.AppendItem(root, 'c2', ct_type=1)

        tree.CheckItem(c1)
        tree.CheckItem(c2)

        self.assertTrue(tree.IsItemChecked(c1))
        self.assertTrue(tree.IsItemChecked(c2))

        # RadioButtons, there can NOT be more than one checked at the same level
        c1 = tree.AppendItem(root, 'c1', ct_type=2)
        c2 = tree.AppendItem(root, 'c2', ct_type=2)

        tree.CheckItem(c1)
        tree.CheckItem(c2)

        self.assertTrue(not tree.IsItemChecked(c1))
        self.assertTrue(tree.IsItemChecked(c2))

    def test_lib_agw_customtreectrlSetWindow(self):
        tree = CT.CustomTreeCtrl(self.frame, agwStyle=CT.TR_DEFAULT_STYLE|CT.TR_HAS_VARIABLE_ROW_HEIGHT)
        root = tree.AddRoot('root item')
        c1 = tree.AppendItem(root, 'c1')
        c2 = tree.AppendItem(root, 'c2')

        window = wx.TextCtrl(tree, -1, 'Hello World')
        tree.SetItemWindow(c2, window)

        other = tree.GetItemWindow(c2)
        self.assertTrue(window == other)

        tree.DeleteAllItems()
        self.assertTrue(tree.GetCount() == 0)
        if sys.platform == 'darwin':
            # On Mac the scrollbars and the gripper between them on
            # ScrolledWindows are also wx widgets, so they are in the
            # children list.
            self.assertEqual(len(tree.GetChildren()), 3)
        else:
            self.assertEqual(len(tree.GetChildren()), 0)

    def test_lib_agw_customtreectrlConstantsExist(self):
        CT.TR_NO_BUTTONS
        CT.TR_SINGLE
        CT.TR_HAS_BUTTONS
        CT.TR_NO_LINES
        CT.TR_LINES_AT_ROOT
        CT.TR_DEFAULT_STYLE
        CT.TR_TWIST_BUTTONS
        CT.TR_MULTIPLE
        CT.TR_EXTENDED
        CT.TR_HAS_VARIABLE_ROW_HEIGHT
        CT.TR_EDIT_LABELS
        CT.TR_ROW_LINES
        CT.TR_HIDE_ROOT
        CT.TR_FULL_ROW_HIGHLIGHT
        CT.TR_AUTO_CHECK_CHILD
        CT.TR_AUTO_TOGGLE_CHILD
        CT.TR_AUTO_CHECK_PARENT
        CT.TR_ALIGN_WINDOWS
        CT.TR_ALIGN_WINDOWS_RIGHT
        CT.TR_ELLIPSIZE_LONG_ITEMS
        CT.TR_TOOLTIP_ON_LONG_ITEMS

        CT.TreeItemIcon_Normal
        CT.TreeItemIcon_Selected
        CT.TreeItemIcon_Expanded
        CT.TreeItemIcon_SelectedExpanded

        CT.TreeItemIcon_Checked
        CT.TreeItemIcon_NotChecked
        CT.TreeItemIcon_Undetermined
        CT.TreeItemIcon_Flagged
        CT.TreeItemIcon_NotFlagged

        CT.TREE_HITTEST_ABOVE
        CT.TREE_HITTEST_BELOW
        CT.TREE_HITTEST_NOWHERE
        CT.TREE_HITTEST_ONITEMBUTTON
        CT.TREE_HITTEST_ONITEMICON
        CT.TREE_HITTEST_ONITEMINDENT
        CT.TREE_HITTEST_ONITEMLABEL
        CT.TREE_HITTEST_ONITEM
        CT.TREE_HITTEST_ONITEMRIGHT
        CT.TREE_HITTEST_TOLEFT
        CT.TREE_HITTEST_TORIGHT
        CT.TREE_HITTEST_ONITEMUPPERPART
        CT.TREE_HITTEST_ONITEMLOWERPART
        CT.TREE_HITTEST_ONITEMCHECKICON
        CT.TREE_HITTEST_ONITEM

    def test_lib_agw_customtreectrlEventsExist(self):
        CT.wxEVT_TREE_BEGIN_DRAG
        CT.wxEVT_TREE_BEGIN_RDRAG
        CT.wxEVT_TREE_BEGIN_LABEL_EDIT
        CT.wxEVT_TREE_END_LABEL_EDIT
        CT.wxEVT_TREE_DELETE_ITEM
        CT.wxEVT_TREE_GET_INFO
        CT.wxEVT_TREE_SET_INFO
        CT.wxEVT_TREE_ITEM_EXPANDED
        CT.wxEVT_TREE_ITEM_EXPANDING
        CT.wxEVT_TREE_ITEM_COLLAPSED
        CT.wxEVT_TREE_ITEM_COLLAPSING
        CT.wxEVT_TREE_SEL_CHANGED
        CT.wxEVT_TREE_SEL_CHANGING
        CT.wxEVT_TREE_KEY_DOWN
        CT.wxEVT_TREE_ITEM_ACTIVATED
        CT.wxEVT_TREE_ITEM_RIGHT_CLICK
        CT.wxEVT_TREE_ITEM_MIDDLE_CLICK
        CT.wxEVT_TREE_END_DRAG
        CT.wxEVT_TREE_STATE_IMAGE_CLICK
        CT.wxEVT_TREE_ITEM_GETTOOLTIP
        CT.wxEVT_TREE_ITEM_MENU
        CT.wxEVT_TREE_ITEM_CHECKING
        CT.wxEVT_TREE_ITEM_CHECKED
        CT.wxEVT_TREE_ITEM_HYPERLINK

        CT.EVT_TREE_BEGIN_DRAG
        CT.EVT_TREE_BEGIN_LABEL_EDIT
        CT.EVT_TREE_BEGIN_RDRAG
        CT.EVT_TREE_DELETE_ITEM
        CT.EVT_TREE_END_DRAG
        CT.EVT_TREE_END_LABEL_EDIT
        CT.EVT_TREE_GET_INFO
        CT.EVT_TREE_ITEM_ACTIVATED
        CT.EVT_TREE_ITEM_CHECKED
        CT.EVT_TREE_ITEM_CHECKING
        CT.EVT_TREE_ITEM_COLLAPSED
        CT.EVT_TREE_ITEM_COLLAPSING
        CT.EVT_TREE_ITEM_EXPANDED
        CT.EVT_TREE_ITEM_EXPANDING
        CT.EVT_TREE_ITEM_GETTOOLTIP
        CT.EVT_TREE_ITEM_HYPERLINK
        CT.EVT_TREE_ITEM_MENU
        CT.EVT_TREE_ITEM_MIDDLE_CLICK
        CT.EVT_TREE_ITEM_RIGHT_CLICK
        CT.EVT_TREE_KEY_DOWN
        CT.EVT_TREE_SEL_CHANGED
        CT.EVT_TREE_SEL_CHANGING
        CT.EVT_TREE_SET_INFO
        CT.EVT_TREE_STATE_IMAGE_CLICK

#---------------------------------------------------------------------------

if __name__ == '__main__':
    unittest.main()