wxWidgets/utils/wxPython/tests/memleak.py

158 lines
4.5 KiB
Python
Raw Normal View History

wxPython 2.1b1: Added the missing wxWindow.GetUpdateRegion() method. Made a new change in SWIG (update your patches everybody) that provides a fix for global shadow objects that get an exception in their __del__ when their extension module has already been deleted. It was only a 1 line change in .../SWIG/Modules/pycpp.cxx at about line 496 if you want to do it by hand. It is now possible to run through MainLoop more than once in any one process. The cleanup that used to happen as MainLoop completed (and prevented it from running again) has been delayed until the wxc module is being unloaded by Python. wxWindow.PopupMenu() now takes a wxPoint instead of x,y. Added wxWindow.PopupMenuXY to be consistent with some other methods. Added wxGrid.SetEditInPlace and wxGrid.GetEditInPlace. You can now provide your own app.MainLoop method. See wxPython/demo/demoMainLoop.py for an example and some explaination. Got the in-place-edit for the wxTreeCtrl fixed and added some demo code to show how to use it. Put the wxIcon constructor back in for GTK as it now has one that matches MSW's. Added wxGrid.GetCells Added wxSystemSettings static methods as functions with names like wxSystemSettings_GetSystemColour. Removed wxPyMenu since using menu callbacks have been depreciated in wxWindows. Use wxMenu and events instead. Added alternate wxBitmap constructor (for MSW only) as wxBitmapFromData(data, type, width, height, depth = 1) Added a helper function named wxPyTypeCast that can convert shadow objects of one type into shadow objects of another type. (Like doing a down-cast.) See the implementation in wx.py for some docs. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3223 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
1999-07-31 03:56:15 -04:00
from wxPython.wx import *
#-------------------------------------------------------------------
# class MyWindow(wxScrolledWindow):
#----------------------------------
# Copes with the drawing of the main scrolled window.
#
# Data members:
# num - <int> number of list entries
# ostart - <int> line number of the top line of the previous redraw
# vw - <int> width of the viewing window
# vh - <int> height of the viewing window
# smalltext - <int> 0 = size 12pt, 1 = size 9pt text
#
# Method members:
# OnPaint(evt) - basic draw handler
# OnDraw(dc) - called by OnPaint, redraws the screen if required
# update(updatelist) - called every 3 seconds if updates are needed.
class MyWindow(wxScrolledWindow):
def __init__(self,num,parent,id,pos,size,style):
wxScrolledWindow.__init__(self,parent,id,pos,size,style)
self.SetBackgroundColour(wxWHITE)
self.num=num
self.ostart=0
self.smalltext = 0
self.vw,self.vh=self.GetClientSizeTuple()
# calculate font pt size needed: a bit of a kludge to get round
# font compatibility problems of X and Windows.
dc=wxClientDC(self)
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
if dc.GetTextExtent("XXXXXXXXXX")[0] > 100:
self.smalltext = 1
def OnPaint(self,evt):
""" overriding OnPaint to give handler. """
dc = wxPaintDC(self)
self.PrepareDC(dc)
self.OnDraw(dc)
def update(self,updlist):
""" handles line by line updating of list entries. """
dc = wxClientDC(self)
self.PrepareDC(dc)
dc.SetBrush(wxWHITE_BRUSH)
dc.SetPen(wxWHITE_PEN)
if self.smalltext == 1:
dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
else:
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
dc.BeginDrawing()
for i in updlist:
if i >= self.ostart and i < self.ostart+self.vh/17+1:
dc.DrawRectangle(0,i*17,self.vw,17)
dc.DrawText("This is a simple test.Line "+str(i)+".",
10,i*17+2)
dc.EndDrawing()
def OnDraw(self,dc):
""" Main redraw function. """
if self.smalltext == 1:
dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
else:
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
vx,vstart=self.ViewStart()
self.vw,self.vh=self.GetClientSizeTuple()
vend=vstart+(self.vh/17) + 1
if vend > self.num: vend = self.num
dc.BeginDrawing()
if vstart > self.ostart: # if moving downwards...
for i in range(vend-(vstart-self.ostart+1),vend):
dc.DrawText("This is a simple test. Line "+str(i)+".",
10,i*17+2)
elif vstart < self.ostart: # if moving upwards...
for i in range(vstart,self.ostart):
dc.DrawText("This is a simple test. Line "+str(i)+".",
10,i*17+2)
elif vstart == self.ostart: # if not moving (redraw)...
#dc.Clear()
for i in range(vstart,vend):
dc.DrawText("This is a simple test. Line "+str(i)+".",
10,i*17+2)
dc.EndDrawing()
self.ostart=vstart
#--------------------------------------------------------------------
class MyTimer(wxTimer):
def __init__(self,frame):
wxTimer.__init__(self)
self.frame_ = frame
def Notify(self):
self.frame_.idle()
class MyFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title,
wxPoint(100, 100), wxSize(500, 300))
# number of entries
self.num = 30
# set up the scrolling window...
self.sw = MyWindow(self.num,self, -1,
wxDefaultPosition, wxDefaultSize,
wxVSCROLL|wxSUNKEN_BORDER)
self.sw.SetScrollbars(1,17,0,self.num+1)
lc = wxLayoutConstraints()
lc.top.SameAs(self, wxTop, 5)
lc.left.SameAs(self, wxLeft, 5)
lc.bottom.SameAs(self, wxBottom, 5)
lc.right.SameAs(self, wxRight,5)
self.sw.SetConstraints(lc)
self.timer=MyTimer(self)
# stupidly short interval time to accelerate memory leak problem:
self.timer.Start(80)
def idle(self):
#usually just update one or two lines; to accelerate problem,
#every line is updated here.
self.sw.update(range(self.num))
######################################################################
# Main procedure....
if __name__ == "__main__":
class MyApp(wxApp):
def OnInit(self):
self.frame = MyFrame(NULL, -1, "Memory Leak Tester")
self.frame.Show(true)
self.exiting = FALSE;
return true
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events