How to close wxGrid located inside wxFrame
Pekka Niiranen
krissepu at vip.fi
Mon Apr 1 12:51:12 EST 2002
Hi,
how should I define the OnExit -method in MainFrame -class below
so that wxWindows would not leak memory, when "Exit" is selected
from the menu. I should somehow close the grid before the frame, but
how ?
------------------xxxx-------------------
from wxPython.wx import *
from wxPython.grid import *
from wxPython.lib.mixins.grid import wxGridAutoEditMixin
import sys, pprint
ID_EXIT = 102
class PnGrid(wxGrid):
def __init__(self, parent):
wxGrid.__init__(self, parent, -1)
self.moveTo = None
EVT_IDLE(self, self.OnIdle)
self.CreateGrid(25, 25)
.... lots of code...copied from wxWindows demofile
SimpleGrid.py...
class MainFrame(wxFrame):
""" Creates and initializes the main window"""
def __init__(self, parent, id, title, style):
# First, call the base class' __init__ method to create the
frame
wxFrame.__init__(self, parent, id, title, wxPoint(100, 100),
wxSize(640, 480), style)
self.CreateStatusBar()
self.SetStatusText("This is the statusbar")
# Make menu with separate MakeMenus -method
menu = self.MakeMenus()
self.SetMenuBar(menu)
# Associate some events with methods of this class
EVT_MENU(self, ID_EXIT, self.OnExit)
# Create grid
pn_grid = PnGrid(self)
def MakeMenus(self):
"""Creates the menus of the main window"""
# Filemenu contents
filemenu = wxMenu()
filemenu.Append(ID_EXIT, "Exit", "Terminate the program")
# Collect all menus
main = wxMenuBar()
main.Append(filemenu, "File")
return main
def OnExit(self, event):
# Close program
self.Close(true)
class MainApp(wxApp):
# wxWindows calls this method to initialize the application
def OnInit(self):
# Create an instance of our customized Frame class
frame = MainFrame(NULL, -1, " PnGrid", wxSTAY_ON_TOP |
wxCAPTION)
frame.Show(true)
# Tell wxWindows that this is our main window
self.SetTopWindow(frame)
return true
if __name__ == "__main__":
app = MainApp(0)
app.MainLoop()
---------------------------xxxx----------------
-pekka-
More information about the Python-list
mailing list