File: test_stc.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 (263 lines) | stat: -rw-r--r-- 8,213 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
import unittest
from unittests import wtc
import wx
import wx.stc as stc

text = """\
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.
""" * 2

if wx.Platform == '__WXMSW__':
    face1 = 'Arial'
    face2 = 'Times New Roman'
    face3 = 'Courier New'
    pb = 10
else:
    face1 = 'Helvetica'
    face2 = 'Times'
    face3 = 'Courier'
    pb = 12

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

class stc_Tests(wtc.WidgetTestCase):

    def test_stcCtor(self):
        ed = stc.StyledTextCtrl(self.frame)

    def test_stcDefaultCtor(self):
        ed = stc.StyledTextCtrl()
        ed.Create(self.frame)

    def test_stcStyleTextCtrl1(self):
        ed = stc.StyledTextCtrl(self.frame)
        ed.SetText(text)
        ed.EmptyUndoBuffer()
        ed.GotoPos(0)

        ed.SetMarginType(1, stc.STC_MARGIN_SYMBOL)
        ed.MarkerDefine(0, stc.STC_MARK_ROUNDRECT, "#CCFF00", "RED")
        ed.MarkerDefine(1, stc.STC_MARK_CIRCLE, "FOREST GREEN", "SIENNA")
        ed.MarkerDefine(2, stc.STC_MARK_SHORTARROW, "blue", "blue")
        ed.MarkerDefine(3, stc.STC_MARK_ARROW, "#00FF00", "#00FF00")
        ed.MarkerAdd(1, 0)
        ed.MarkerAdd(2, 1)
        ed.MarkerAdd(3, 2)
        ed.MarkerAdd(4, 3)
        ed.MarkerAdd(5, 0)


    def test_stcStyleTextCtrl2(self):
        ed = stc.StyledTextCtrl(self.frame)
        ed.SetText(text)
        ed.EmptyUndoBuffer()
        ed.GotoPos(0)

        ed.INDICSTYLE00 = 0
        ed.INDICSTYLE01 = 1
        ed.INDICSTYLE02 = 2

        ed.IndicatorSetStyle(ed.INDICSTYLE00, stc.STC_INDIC_SQUIGGLE)
        ed.IndicatorSetForeground(ed.INDICSTYLE00, wx.RED)
        ed.IndicatorSetStyle(ed.INDICSTYLE01, stc.STC_INDIC_DIAGONAL)
        ed.IndicatorSetForeground(ed.INDICSTYLE01, wx.BLUE)
        ed.IndicatorSetStyle(ed.INDICSTYLE02, stc.STC_INDIC_STRIKE)
        ed.IndicatorSetForeground(ed.INDICSTYLE02, wx.RED)

        ed.StartStyling(100)

        ed.SetIndicatorCurrent(ed.INDICSTYLE00)
        ed.IndicatorFillRange(836, 10)
        ed.SetIndicatorCurrent(ed.INDICSTYLE01)
        ed.IndicatorFillRange(846, 8)
        ed.SetIndicatorCurrent(ed.INDICSTYLE02)
        ed.IndicatorFillRange(854, 10)


    def test_stcStyleTextCtrl3(self):
        ed = stc.StyledTextCtrl(self.frame)
        ed.SetText(text)
        ed.EmptyUndoBuffer()
        ed.GotoPos(0)

        ed.StyleSetSpec(stc.STC_STYLE_DEFAULT, "size:%d,face:%s" % (pb, face3))
        ed.StyleClearAll()
        ed.StyleSetSpec(1, "size:%d,bold,face:%s,fore:#0000FF" % (pb, face1))
        ed.StyleSetSpec(2, "face:%s,italic,fore:#FF0000,size:%d" % (face2, pb))
        ed.StyleSetSpec(3, "face:%s,bold,size:%d" % (face2, pb))
        ed.StyleSetSpec(4, "face:%s,size:%d" % (face1, pb-1))
        ed.StyleSetSpec(5, "back:#FFF0F0")

        ed.StartStyling(80)
        ed.SetStyling(6, 1)
        ed.StartStyling(100)
        ed.SetStyling(20, 2)
        ed.StartStyling(180)
        ed.SetStyling(4, 3)
        ed.SetStyling(2, 0)
        ed.SetStyling(10, 4)


    def test_stcStyleTextCtrl5(self):
        ed = stc.StyledTextCtrl(self.frame)
        ed.SetText(text)
        ed.EmptyUndoBuffer()
        ed.GotoPos(0)

        ed.SetMarginType(0, stc.STC_MARGIN_NUMBER)
        ed.SetMarginWidth(0, 22)
        ed.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "size:%d,face:%s" % (pb-2, face1))


    def test_stcStyleTextCtrl6(self):
        ed = stc.StyledTextCtrl(self.frame)
        ed.SetText(text)
        ed.EmptyUndoBuffer()
        ed.GotoPos(10)

        textbytes = ed.GetStyledText(100,150)
        self.assertTrue(isinstance(textbytes, memoryview))

        pointer = ed.GetCharacterPointer()
        self.assertTrue(isinstance(pointer, memoryview))

        line, pos = ed.GetCurLine()
        self.assertTrue(len(line) != 0)
        self.assertTrue(isinstance(pos, int))


    def test_stcStyleTextCtrl8(self):
        ed = stc.StyledTextCtrl(self.frame)
        ed.SetText(text)
        ed.EmptyUndoBuffer()
        ed.GotoPos(10)

        raw = ed.GetLineRaw(5)
        self.assertTrue(isinstance(raw, bytes))

        ed.AddTextRaw(b"some new text")



    def test_stcStyleTextCtrlConstantsExist(self):
        # This is not even close to the full set of constants in the module,
        # but just a represenative few to help ensure that the code
        # generation is continuing to do what it is supposed to be doing.
        stc.STC_P_DEFAULT
        stc.STC_P_DECORATOR
        stc.STC_KEY_DOWN
        stc.STC_MARK_CIRCLE
        stc.STC_MARGIN_NUMBER
        stc.STC_STYLE_BRACELIGHT
        stc.STC_CHARSET_MAC
        stc.STC_INDIC_DIAGONAL
        stc.STC_LEX_PYTHON
        stc.STC_CMD_REDO
        stc.STC_CMD_LINEENDEXTEND
        stc.STC_CMD_PARADOWN


    def test_stcEvent(self):
        evt = stc.StyledTextEvent(stc.wxEVT_STC_CHANGE)

    def test_stcEventConstantsExist(self):
        stc.wxEVT_STC_CHANGE
        stc.wxEVT_STC_STYLENEEDED
        stc.wxEVT_STC_CHARADDED
        stc.wxEVT_STC_SAVEPOINTREACHED
        stc.wxEVT_STC_SAVEPOINTLEFT
        stc.wxEVT_STC_ROMODIFYATTEMPT
        stc.wxEVT_STC_KEY
        stc.wxEVT_STC_DOUBLECLICK
        stc.wxEVT_STC_UPDATEUI
        stc.wxEVT_STC_MODIFIED
        stc.wxEVT_STC_MACRORECORD
        stc.wxEVT_STC_MARGINCLICK
        stc.wxEVT_STC_NEEDSHOWN
        stc.wxEVT_STC_PAINTED
        stc.wxEVT_STC_USERLISTSELECTION
        stc.wxEVT_STC_URIDROPPED
        stc.wxEVT_STC_DWELLSTART
        stc.wxEVT_STC_DWELLEND
        stc.wxEVT_STC_START_DRAG
        stc.wxEVT_STC_DRAG_OVER
        stc.wxEVT_STC_DO_DROP
        stc.wxEVT_STC_ZOOM
        stc.wxEVT_STC_HOTSPOT_CLICK
        stc.wxEVT_STC_HOTSPOT_DCLICK
        stc.wxEVT_STC_HOTSPOT_RELEASE_CLICK
        stc.wxEVT_STC_CALLTIP_CLICK
        stc.wxEVT_STC_AUTOCOMP_SELECTION
        stc.wxEVT_STC_INDICATOR_CLICK
        stc.wxEVT_STC_INDICATOR_RELEASE
        stc.wxEVT_STC_AUTOCOMP_CANCELLED
        stc.wxEVT_STC_AUTOCOMP_CHAR_DELETED
        stc.wxEVT_STC_HOTSPOT_RELEASE_CLICK

    def test_stcEventBinderssExist(self):
        stc.EVT_STC_CHANGE
        stc.EVT_STC_STYLENEEDED
        stc.EVT_STC_CHARADDED
        stc.EVT_STC_SAVEPOINTREACHED
        stc.EVT_STC_SAVEPOINTLEFT
        stc.EVT_STC_ROMODIFYATTEMPT
        stc.EVT_STC_KEY
        stc.EVT_STC_DOUBLECLICK
        stc.EVT_STC_UPDATEUI
        stc.EVT_STC_MODIFIED
        stc.EVT_STC_MACRORECORD
        stc.EVT_STC_MARGINCLICK
        stc.EVT_STC_NEEDSHOWN
        stc.EVT_STC_PAINTED
        stc.EVT_STC_USERLISTSELECTION
        stc.EVT_STC_URIDROPPED
        stc.EVT_STC_DWELLSTART
        stc.EVT_STC_DWELLEND
        stc.EVT_STC_START_DRAG
        stc.EVT_STC_DRAG_OVER
        stc.EVT_STC_DO_DROP
        stc.EVT_STC_ZOOM
        stc.EVT_STC_HOTSPOT_CLICK
        stc.EVT_STC_HOTSPOT_DCLICK
        stc.EVT_STC_HOTSPOT_RELEASE_CLICK
        stc.EVT_STC_CALLTIP_CLICK
        stc.EVT_STC_AUTOCOMP_SELECTION
        stc.EVT_STC_INDICATOR_CLICK
        stc.EVT_STC_INDICATOR_RELEASE
        stc.EVT_STC_AUTOCOMP_CANCELLED
        stc.EVT_STC_AUTOCOMP_CHAR_DELETED


    def test_stcHasTextCtrlMethods(self):
        # Just ensure that the common TextCtrl methods are present. This is
        # done because the C++ class either derives from wxTextEntryBase
        # or from wxTextCtrlIface, but these classes are not part of the API
        # (and thus are not wrapped), so we have to kludge things.
        # See etg/_stc.py for details.

        t = stc.StyledTextCtrl(self.frame)
        t.Cut
        t.CanCut
        t.DiscardEdits
        t.GetDefaultStyle
        t.GetNumberOfLines
        t.GetStyle
        t.IsModified
        t.HitTest
        t.AppendText
        t.WriteText
        t.ChangeValue



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


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