[Tutor] WxPython, Grid, MDI, and Toolbars

Brett Magill bmagill@earthlink.net
Thu Apr 17 00:01:02 2003


Hello,

I am new to programming, learning through python, and starting to be 
productive.  But I want to develop graphical application so I am trying to 
learn wxPython, which I find much more difficult, and with little 
documentation, especially since I don't know C++ and can't translate the 
extensive WxWindows docs to python.

In any case.  My specific problem...  See the code below.  Creates an MDI 
with a parent and a child.  The parent holds a filemenu, and statusbar, and 
a toolbar.  Unfortunately, the child window doesn't play nicely with the 
toolbar.  What am I doing wrong?  Help is appreciated!


__________________________________________________________

from wxPython.wx import *
from   wxPython.grid import *
from   wxPython.lib.mixins.grid import wxGridAutoEditMixin
import sys, os

ID_ABOUT  = 102
ID_HELP   = 103
ID_EXIT   = 104
ID_VIEW   = 105
ID_OPEND  = 107
ID_OPENS  = 101
ID_SETUP  = 108
ID_OUTPUT = 106
ID_TEST_BUTTON = 109

class DataGrid(wxGrid):
	def __init__(self, parent):
		wxGrid.__init__(self, parent, -1)
		self.wxPostion=(50,50)
		self.moveTo = None

		self.CreateGrid(25, 25)
		self.SetCellValue(6, 0, "123.34")

		attr = wxGridCellAttr()
		attr.SetTextColour(wxBLACK)
		attr.SetBackgroundColour(wxRED)
		attr.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD))

		self.SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_BOTTOM)

class MyParentFrame(wxMDIParentFrame):
     def __init__(self):
         wxMDIParentFrame.__init__(self, None, -1, "My App")

         self.CreateStatusBar()
         self.SetStatusText("This is the statusbar")

         tb = wxToolBar(self,-1)
         tb.AddControl(wxButton(tb, ID_TEST_BUTTON, 
"Button",wxDefaultPosition, wxDefaultSize))
         tb.Realize()

         FileMenu = wxMenu()
         FileMenu.Append(ID_OPENS, "Open S&etup File", "Open a setup file 
for use in this session")
         FileMenu.Append(ID_OPEND, "Open D&ata File", "Open a data file fo 
ruse in this session")
         FileMenu.Append(ID_EXIT, "E&xit", "Terminate the program")

         ViewMenu = wxMenu()
         ViewMenu.Append(ID_SETUP, "S&etup", "View the current setup file")
         ViewMenu.Append(ID_OUTPUT, "O&utput", "View the current output file")

         HelpMenu = wxMenu()
         HelpMenu.Append(ID_HELP, "H&elp", "More information about this 
program")
         HelpMenu.Append(ID_ABOUT, "A&bout", "More information about this 
program")

         menuBar = wxMenuBar()
         menuBar.Append(FileMenu, "&File")
         menuBar.Append(ViewMenu, "&View")
         menuBar.Append(HelpMenu, "&Help")

         self.SetMenuBar(menuBar)

         EVT_MENU(self, ID_ABOUT, self.OnAbout)
         EVT_MENU(self, ID_EXIT,  self.TimeToQuit)
         EVT_MENU(self, ID_OPEND, self.OpenDataFile)

         DataChildFrame=wxMDIChildFrame(self, -1, "Data View")
         DataChildFrame.Show(true)

         dg = DataGrid(DataChildFrame)

     def OnAbout(self, event):
         dlg = wxMessageDialog(self, "This sample program shows off\n"
                               "frames, menus, statusbars, and this\n"
                              "message dialog.",
                               "About Me", wxOK | wxICON_INFORMATION)
         dlg.ShowModal()
         dlg.Destroy()

     def test():
         pass

     def TimeToQuit(self, event):
         self.Close(true)

     def OpenDataFile(self, event):
         pass

class MyApp(wxApp):
     def OnInit(self):
         frame = MyParentFrame()
         frame.Show(true)
         self.SetTopWindow(frame)
         return true

app = MyApp(0)
app.MainLoop()