2 from wxPython
.wx 
import * 
   4 #------------------------------------------------------------------- 
   5 # class MyWindow(wxScrolledWindow): 
   6 #---------------------------------- 
   7 # Copes with the drawing of the main scrolled window. 
  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 
  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. 
  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
) 
  29     self
.vw
,self
.vh
=self
.GetClientSizeTuple() 
  31     # calculate font pt size needed: a bit of a kludge to get round 
  32     # font compatibility problems of X and Windows. 
  35     dc
.SetFont(wxFont(12,wxDEFAULT
,wxNORMAL
,wxNORMAL
,FALSE
)) 
  36     if dc
.GetTextExtent("XXXXXXXXXX")[0] > 100: 
  39   def OnPaint(self
,evt
): 
  40     """ overriding OnPaint to give handler. """ 
  45   def update(self
,updlist
): 
  46     """ handles line by line updating of list entries. """ 
  49     dc
.SetBrush(wxWHITE_BRUSH
) 
  50     dc
.SetPen(wxWHITE_PEN
) 
  52     if self
.smalltext 
== 1: 
  53       dc
.SetFont(wxFont(9,wxDEFAULT
,wxNORMAL
,wxNORMAL
,FALSE
)) 
  55       dc
.SetFont(wxFont(12,wxDEFAULT
,wxNORMAL
,wxNORMAL
,FALSE
)) 
  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
)+".", 
  67     """ Main redraw function. """ 
  69     if self
.smalltext 
== 1: 
  70       dc
.SetFont(wxFont(9,wxDEFAULT
,wxNORMAL
,wxNORMAL
,FALSE
)) 
  72       dc
.SetFont(wxFont(12,wxDEFAULT
,wxNORMAL
,wxNORMAL
,FALSE
)) 
  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
 
  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
)+".", 
  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
)+".", 
  90     elif vstart 
== self
.ostart
: # if not moving (redraw)... 
  92       for i 
in range(vstart
,vend
): 
  93         dc
.DrawText("This is a simple test. Line "+str(i
)+".", 
  99 #-------------------------------------------------------------------- 
 101 class MyTimer(wxTimer
): 
 102   def __init__(self
,frame
): 
 103     wxTimer
.__init
__(self
) 
 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)) 
 118     # set up the scrolling window... 
 119     self
.sw 
= MyWindow(self
.num
,self
, -1, 
 120                        wxDefaultPosition
, wxDefaultSize
, 
 121                        wxVSCROLL|wxSUNKEN_BORDER
) 
 123     self
.sw
.SetScrollbars(1,17,0,self
.num
+1) 
 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
) 
 132     self
.timer
=MyTimer(self
) 
 133     # stupidly short interval time to accelerate memory leak problem: 
 137     #usually just update one or two lines; to accelerate problem, 
 138     #every line is updated here. 
 139     self
.sw
.update(range(self
.num
)) 
 142 ###################################################################### 
 145 if __name__ 
== "__main__": 
 149       self
.frame 
= MyFrame(NULL
, -1, "Memory Leak Tester") 
 150       self
.frame
.Show(true
) 
 152       self
.exiting 
= FALSE
; 
 155   app 
= MyApp(0)     # Create an instance of the application class 
 156   app
.MainLoop()     # Tell it to start processing events