]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/tests/memleak.py
Updated testconf,
[wxWidgets.git] / utils / wxPython / tests / memleak.py
1
2 from wxPython.wx import *
3
4 #-------------------------------------------------------------------
5 # class MyWindow(wxScrolledWindow):
6 #----------------------------------
7 # Copes with the drawing of the main scrolled window.
8 #
9 # Data members:
10 # num - <int> number of list entries
11 # ostart - <int> line number of the top line of the previous redraw
12 # vw - <int> width of the viewing window
13 # vh - <int> height of the viewing window
14 # smalltext - <int> 0 = size 12pt, 1 = size 9pt text
15 #
16 # Method members:
17 # OnPaint(evt) - basic draw handler
18 # OnDraw(dc) - called by OnPaint, redraws the screen if required
19 # update(updatelist) - called every 3 seconds if updates are needed.
20
21 class MyWindow(wxScrolledWindow):
22 def __init__(self,num,parent,id,pos,size,style):
23 wxScrolledWindow.__init__(self,parent,id,pos,size,style)
24 self.SetBackgroundColour(wxWHITE)
25
26 self.num=num
27 self.ostart=0
28 self.smalltext = 0
29 self.vw,self.vh=self.GetClientSizeTuple()
30
31 # calculate font pt size needed: a bit of a kludge to get round
32 # font compatibility problems of X and Windows.
33 dc=wxClientDC(self)
34
35 dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
36 if dc.GetTextExtent("XXXXXXXXXX")[0] > 100:
37 self.smalltext = 1
38
39 def OnPaint(self,evt):
40 """ overriding OnPaint to give handler. """
41 dc = wxPaintDC(self)
42 self.PrepareDC(dc)
43 self.OnDraw(dc)
44
45 def update(self,updlist):
46 """ handles line by line updating of list entries. """
47 dc = wxClientDC(self)
48 self.PrepareDC(dc)
49 dc.SetBrush(wxWHITE_BRUSH)
50 dc.SetPen(wxWHITE_PEN)
51
52 if self.smalltext == 1:
53 dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
54 else:
55 dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
56
57 dc.BeginDrawing()
58
59 for i in updlist:
60 if i >= self.ostart and i < self.ostart+self.vh/17+1:
61 dc.DrawRectangle(0,i*17,self.vw,17)
62 dc.DrawText("This is a simple test.Line "+str(i)+".",
63 10,i*17+2)
64 dc.EndDrawing()
65
66 def OnDraw(self,dc):
67 """ Main redraw function. """
68
69 if self.smalltext == 1:
70 dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
71 else:
72 dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
73
74 vx,vstart=self.ViewStart()
75 self.vw,self.vh=self.GetClientSizeTuple()
76 vend=vstart+(self.vh/17) + 1
77 if vend > self.num: vend = self.num
78
79 dc.BeginDrawing()
80 if vstart > self.ostart: # if moving downwards...
81 for i in range(vend-(vstart-self.ostart+1),vend):
82 dc.DrawText("This is a simple test. Line "+str(i)+".",
83 10,i*17+2)
84
85 elif vstart < self.ostart: # if moving upwards...
86 for i in range(vstart,self.ostart):
87 dc.DrawText("This is a simple test. Line "+str(i)+".",
88 10,i*17+2)
89
90 elif vstart == self.ostart: # if not moving (redraw)...
91 #dc.Clear()
92 for i in range(vstart,vend):
93 dc.DrawText("This is a simple test. Line "+str(i)+".",
94 10,i*17+2)
95
96 dc.EndDrawing()
97 self.ostart=vstart
98
99 #--------------------------------------------------------------------
100
101 class MyTimer(wxTimer):
102 def __init__(self,frame):
103 wxTimer.__init__(self)
104 self.frame_ = frame
105
106 def Notify(self):
107 self.frame_.idle()
108
109
110 class MyFrame(wxFrame):
111 def __init__(self, parent, id, title):
112 wxFrame.__init__(self, parent, id, title,
113 wxPoint(100, 100), wxSize(500, 300))
114
115 # number of entries
116 self.num = 30
117
118 # set up the scrolling window...
119 self.sw = MyWindow(self.num,self, -1,
120 wxDefaultPosition, wxDefaultSize,
121 wxVSCROLL|wxSUNKEN_BORDER)
122
123 self.sw.SetScrollbars(1,17,0,self.num+1)
124
125 lc = wxLayoutConstraints()
126 lc.top.SameAs(self, wxTop, 5)
127 lc.left.SameAs(self, wxLeft, 5)
128 lc.bottom.SameAs(self, wxBottom, 5)
129 lc.right.SameAs(self, wxRight,5)
130 self.sw.SetConstraints(lc)
131
132 self.timer=MyTimer(self)
133 # stupidly short interval time to accelerate memory leak problem:
134 self.timer.Start(80)
135
136 def idle(self):
137 #usually just update one or two lines; to accelerate problem,
138 #every line is updated here.
139 self.sw.update(range(self.num))
140
141
142 ######################################################################
143 # Main procedure....
144
145 if __name__ == "__main__":
146 class MyApp(wxApp):
147 def OnInit(self):
148
149 self.frame = MyFrame(NULL, -1, "Memory Leak Tester")
150 self.frame.Show(true)
151
152 self.exiting = FALSE;
153 return true
154
155 app = MyApp(0) # Create an instance of the application class
156 app.MainLoop() # Tell it to start processing events
157