File: test_grid.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 (385 lines) | stat: -rw-r--r-- 11,090 bytes parent folder | download | duplicates (2)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import unittest
from unittests import wtc
import wx
import wx.grid


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



class grid_Tests(wtc.WidgetTestCase):

    # NOTE: Most of these tests simply check that the class exists and can be
    # instantiated. It would be nice to add more here, but in the meantime it
    # will probably be easier to test features and interoperability between
    # the classes in a non-unitest situation. See Phoenix/samples/grid

    def test_grid00(self):
        wx.grid.GRID_AUTOSIZE
        wx.grid.GRID_DRAW_ROWS_HEADER
        wx.grid.GRID_DRAW_COLS_HEADER
        wx.grid.GRID_DRAW_CELL_LINES
        wx.grid.GRID_DRAW_BOX_RECT
        wx.grid.GRID_DRAW_SELECTION
        wx.grid.GRID_DRAW_DEFAULT


    def test_grid01(self):
        c1 = wx.grid.GridCellCoords()
        c2 = wx.grid.GridCellCoords(5,10)


    def test_grid02(self):
        r = wx.grid.GridCellAutoWrapStringRenderer()

    def test_grid03(self):
        r = wx.grid.GridCellBoolRenderer()

    def test_grid04(self):
        r = wx.grid.GridCellDateTimeRenderer()

    def test_grid05(self):
        r = wx.grid.GridCellEnumRenderer()

    def test_grid06(self):
        r = wx.grid.GridCellFloatRenderer()

    def test_grid07(self):
        r = wx.grid.GridCellNumberRenderer()

    def test_grid08(self):
        r = wx.grid.GridCellStringRenderer()

    def test_grid09(self):
        class MyRenderer(wx.grid.GridCellRenderer):
            def Clone(self):
                return MyRenderer()

            def Draw(self, grid, attr, dc, rect, row, col, isSelected):
                pass

            def GetBestSize(self, grid, attr, dc, row, col):
                return (80,20)

        r = MyRenderer()



    def test_grid10(self):
        e = wx.grid.GridCellAutoWrapStringEditor()

    def test_grid11(self):
        e = wx.grid.GridCellBoolEditor()

    def test_grid12(self):
        e = wx.grid.GridCellChoiceEditor('one two three'.split())

    def test_grid13(self):
        e = wx.grid.GridCellEnumEditor()

    def test_grid14(self):
        e = wx.grid.GridCellTextEditor()

    def test_grid15(self):
        e = wx.grid.GridCellFloatEditor()

    def test_grid16(self):
        e = wx.grid.GridCellNumberEditor()

    def test_grid17(self):
        class MyEditor(wx.grid.GridCellEditor):
            def Clone(self): return MyEditor()
            def BeginEdit(self, row, col, grid): pass
            def Create(self, parent, id, evtHandler): pass
            def EndEdit(self, row, col, grid, oldval): return None
            def ApplyEdit(self, row, col, grid): pass
            def Reset(self): pass
            def GetValue(self): return ""

        e = MyEditor()
        return e

    def test_grid17a(self):
        e = self.test_grid17()
        e.GetControl
        e.SetControl


    def test_grid18(self):
        a = wx.grid.GridCellAttr()
        a.DecRef()

    def test_grid18a(self):
        # test that some GCA methods which were missing are now present
        a = wx.grid.GridCellAttr()
        b = wx.grid.GridCellAttr()
        a.MergeWith(b)

        a.SetFont(wx.NORMAL_FONT)
        a.SetOverflow(True)
        a.SetSize(3,4)
        a.SetKind(wx.grid.GridCellAttr.Cell)

        a.HasReadWriteMode()
        a.HasOverflowMode()
        a.HasSize()

        a.GetSize()
        a.GetOverflow()
        a.GetKind()

        a.DecRef()


    def test_grid19(self):
        wx.grid.GridCellAttr.Any
        wx.grid.GridCellAttr.Cell
        wx.grid.GridCellAttr.Row
        wx.grid.GridCellAttr.Col
        wx.grid.GridCellAttr.Default
        wx.grid.GridCellAttr.Merged


    def test_grid20(self):
        class MyRenderer(wx.grid.GridCornerHeaderRenderer):
            def DrawBorder(self, grid, dc, rect):
                pass
        r = MyRenderer()

    def test_grid21(self):
        class MyRenderer(wx.grid.GridHeaderLabelsRenderer):
            def DrawBorder(self, grid, dc, rect):
                pass
            def DrawLabel(self, grid, dc, value, rect, horizAlign, vertAlign, textOrientation):
                pass
        r = MyRenderer()

    def test_grid22(self):
        class MyRenderer(wx.grid.GridRowHeaderRenderer):
            def DrawBorder(self, grid, dc, rect):
                pass
            def DrawLabel(self, grid, dc, value, rect, horizAlign, vertAlign, textOrientation):
                pass
        r = MyRenderer()

    def test_grid23(self):
        class MyRenderer(wx.grid.GridColumnHeaderRenderer):
            def DrawBorder(self, grid, dc, rect):
                pass
            def DrawLabel(self, grid, dc, value, rect, horizAlign, vertAlign, textOrientation):
                pass
        r = MyRenderer()

    def test_grid24(self):
        r = wx.grid.GridRowHeaderRendererDefault()

    def test_grid25(self):
        r = wx.grid.GridColumnHeaderRendererDefault()

    def test_grid26(self):
        r = wx.grid.GridCornerHeaderRendererDefault()



    def test_grid27(self):
        p = wx.grid.GridCellAttrProvider()

    def test_grid28(self):
        class MyTable(wx.grid.GridTableBase):
            def GetNumberRows(self): return 1
            def GetNumberCols(self): return 1
            def GetValue(self, row, col): return ""
            def SetValue(self, row, col, value): pass
        t = MyTable()


    def test_grid29(self):
        t = wx.grid.GridStringTable()

    def test_grid30(self):
        m = wx.grid.GridTableMessage()

    def test_grid31(self):
        m = wx.grid.GridSizesInfo()



    def test_grid32(self):
        g = wx.grid.Grid(self.frame)
        g.CreateGrid(10,5)



    def test_grid33(self):
        g = wx.grid.Grid(self.frame)
        g.CreateGrid(10,5)
        ul = wx.grid.GridUpdateLocker(g)
        g.SetCellValue(1,2, 'hello')
        g.SetCellValue((2,2), 'world')
        del ul

    def test_grid34(self):
        g = wx.grid.Grid(self.frame)
        g.CreateGrid(10,5)
        with wx.grid.GridUpdateLocker(g):
            g.SetCellValue(1,2, 'hello')
            g.SetCellValue((2,2), 'world')


    def test_grid35(self):
        e = wx.grid.GridEvent()

    def test_grid36(self):
        e = wx.grid.GridSizeEvent()

    def test_grid37(self):
        e = wx.grid.GridRangeSelectEvent()

    def test_grid38(self):
        e = wx.grid.GridEditorCreatedEvent()

    def test_grid39(self):
        wx.grid.wxEVT_GRID_CELL_LEFT_CLICK
        wx.grid.wxEVT_GRID_CELL_RIGHT_CLICK
        wx.grid.wxEVT_GRID_CELL_LEFT_DCLICK
        wx.grid.wxEVT_GRID_CELL_RIGHT_DCLICK
        wx.grid.wxEVT_GRID_LABEL_LEFT_CLICK
        wx.grid.wxEVT_GRID_LABEL_RIGHT_CLICK
        wx.grid.wxEVT_GRID_LABEL_LEFT_DCLICK
        wx.grid.wxEVT_GRID_LABEL_RIGHT_DCLICK
        wx.grid.wxEVT_GRID_ROW_SIZE
        wx.grid.wxEVT_GRID_COL_SIZE
        wx.grid.wxEVT_GRID_COL_AUTO_SIZE
        wx.grid.wxEVT_GRID_RANGE_SELECT
        wx.grid.wxEVT_GRID_RANGE_SELECTING
        wx.grid.wxEVT_GRID_RANGE_SELECTED
        wx.grid.wxEVT_GRID_CELL_CHANGING
        wx.grid.wxEVT_GRID_CELL_CHANGED
        wx.grid.wxEVT_GRID_SELECT_CELL
        wx.grid.wxEVT_GRID_EDITOR_SHOWN
        wx.grid.wxEVT_GRID_EDITOR_HIDDEN
        wx.grid.wxEVT_GRID_EDITOR_CREATED
        wx.grid.wxEVT_GRID_CELL_BEGIN_DRAG
        wx.grid.wxEVT_GRID_ROW_MOVE
        wx.grid.wxEVT_GRID_COL_MOVE
        wx.grid.wxEVT_GRID_COL_SORT
        wx.grid.wxEVT_GRID_TABBING

    def test_grid40(self):
        wx.grid.EVT_GRID_CELL_LEFT_CLICK
        wx.grid.EVT_GRID_CELL_RIGHT_CLICK
        wx.grid.EVT_GRID_CELL_LEFT_DCLICK
        wx.grid.EVT_GRID_CELL_RIGHT_DCLICK
        wx.grid.EVT_GRID_LABEL_LEFT_CLICK
        wx.grid.EVT_GRID_LABEL_RIGHT_CLICK
        wx.grid.EVT_GRID_LABEL_LEFT_DCLICK
        wx.grid.EVT_GRID_LABEL_RIGHT_DCLICK
        wx.grid.EVT_GRID_ROW_SIZE
        wx.grid.EVT_GRID_COL_SIZE
        wx.grid.EVT_GRID_COL_AUTO_SIZE
        wx.grid.EVT_GRID_RANGE_SELECT
        wx.grid.EVT_GRID_RANGE_SELECTING
        wx.grid.EVT_GRID_RANGE_SELECTED
        wx.grid.EVT_GRID_CELL_CHANGING
        wx.grid.EVT_GRID_CELL_CHANGED
        wx.grid.EVT_GRID_SELECT_CELL
        wx.grid.EVT_GRID_EDITOR_SHOWN
        wx.grid.EVT_GRID_EDITOR_HIDDEN
        wx.grid.EVT_GRID_EDITOR_CREATED
        wx.grid.EVT_GRID_CELL_BEGIN_DRAG
        wx.grid.EVT_GRID_ROW_MOVE
        wx.grid.EVT_GRID_COL_MOVE
        wx.grid.EVT_GRID_COL_SORT
        wx.grid.EVT_GRID_TABBING

        wx.grid.EVT_GRID_CMD_CELL_LEFT_CLICK
        wx.grid.EVT_GRID_CMD_CELL_RIGHT_CLICK
        wx.grid.EVT_GRID_CMD_CELL_LEFT_DCLICK
        wx.grid.EVT_GRID_CMD_CELL_RIGHT_DCLICK
        wx.grid.EVT_GRID_CMD_LABEL_LEFT_CLICK
        wx.grid.EVT_GRID_CMD_LABEL_RIGHT_CLICK
        wx.grid.EVT_GRID_CMD_LABEL_LEFT_DCLICK
        wx.grid.EVT_GRID_CMD_LABEL_RIGHT_DCLICK
        wx.grid.EVT_GRID_CMD_ROW_SIZE
        wx.grid.EVT_GRID_CMD_COL_SIZE
        wx.grid.EVT_GRID_CMD_RANGE_SELECT
        wx.grid.EVT_GRID_CMD_CELL_CHANGING
        wx.grid.EVT_GRID_CMD_CELL_CHANGED
        wx.grid.EVT_GRID_CMD_SELECT_CELL
        wx.grid.EVT_GRID_CMD_EDITOR_SHOWN
        wx.grid.EVT_GRID_CMD_EDITOR_HIDDEN
        wx.grid.EVT_GRID_CMD_EDITOR_CREATED
        wx.grid.EVT_GRID_CMD_CELL_BEGIN_DRAG
        wx.grid.EVT_GRID_CMD_COL_MOVE
        wx.grid.EVT_GRID_CMD_COL_SORT
        wx.grid.EVT_GRID_CMD_TABBING


    def test_grid41(self):
        wx.grid.Grid.SetCellHighlightPenWidth  # Does it exist


    def test_grid43(self):
        # new names
        wx.grid.Grid.SelectCells
        wx.grid.Grid.SelectRows
        wx.grid.Grid.SelectColumns
        wx.grid.Grid.SelectRowsOrColumns


    def test_GetIM(self):
        # Test the immutable version returned by GetIM
        obj = wx.grid.GridCellCoords(1,2)
        im = obj.GetIM()
        assert isinstance(im, tuple)
        assert im.Row == obj.Row
        assert im.Col == obj.Col
        obj2 = wx.grid.GridCellCoords(im)
        assert obj == obj2


    def test_grid44(self):
        g = wx.grid.Grid(self.frame)
        g.CreateGrid(10,10)
        g.SelectBlock((1,1), (5,5))

        tl = g.GetSelectionBlockTopLeft()
        br = g.GetSelectionBlockBottomRight()

        assert tl[0].Get() == (1,1)
        assert br[0].Get() == (5,5)


    def test_grid45(self):
        # See issue #297
        g = wx.grid.Grid(self.frame)
        g.CreateGrid(10,10)
        g.SelectBlock((1,1), (5,5))

        tl = g.GetSelectionBlockTopLeft()[0]
        br = g.GetSelectionBlockBottomRight()[0]

        assert tl.Get() == (1,1)
        assert br.Get() == (5,5)

    def test_grid46(self):
        g = wx.grid.Grid(self.frame)
        g.CreateGrid(10,10)
        g.SelectBlock((1,1), (5,5))
        g.SelectBlock((6,5), (7,9), addToSelected=True)

        blocks = g.GetSelectedBlocks()
        assert isinstance(blocks, wx.grid.GridBlocks)

        count = 0
        for block in blocks:
            count += 1
            assert isinstance(block, wx.grid.GridBlockCoords)

        assert count == 2

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

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