Please send questions to st10@humboldt.edu .
"""
Module wxpython_ex5.py
Fifth wxpython example

from: http://wiki.wxpython.org/index.cgi/Getting_20Started,
      wxPython Wiki, Getting Started subsection

slightly adapted by: Sharon M. Tuttle
last modified: 12-7-05
"""

import os

import wx

ID_ABOUT=101
ID_OPEN = 102
ID_EXIT=110

class MainWindow(wx.Frame):
    """customized subclass of Frame for our baby editor"""
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = ( 200,100),
                          style=wx.DEFAULT_FRAME_STYLE|
                          wx.NO_FULL_REPAINT_ON_RESIZE)

        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)

        # A StatusBar in the bottom of the window
        self.CreateStatusBar() 		

        # Setting up the menu.
        filemenu= wx.Menu()
        filemenu.Append(ID_ABOUT, "&About"," Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")

        filemenu.AppendSeparator()
        filemenu.Append(ID_OPEN, "&Open", " Open a file")

        # Creating the menubar.
        menuBar = wx.MenuBar()

        # Adding the "filemenu" to the MenuBar
        menuBar.Append(filemenu,"&File")         

        # Adding the MenuBar to the Frame content.
        self.SetMenuBar(menuBar)                 

        # attach the menu-event ID_ABOUT to the method self.OnAbout
        wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) 

        # attach the menu-event ID_EXIT to the method self.OnExit
        wx.EVT_MENU(self, ID_EXIT, self.OnExit)   
                                                          
        wx.EVT_MENU(self, ID_OPEN, self.OnOpen)
        self.Show(True)

    def OnAbout(self,e):
        """method for the "About" menu item action"""

        # Create a message dialog box
        d= wx.MessageDialog( self, " A sample editor \n"
                            " in wxPython","About Sample Editor", wx.OK)

        # Shows it
        d.ShowModal() 

        # finally destroy it when finished.
        d.Destroy() 

    def OnExit(self,e):
        """method for the "Exit" menu item action"""
        self.Close(True)  # Close the frame.

    def OnOpen(self, e):
        """ Open a file"""
        self.dirname = ''

        dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)

        if dlg.ShowModal() == wx.ID_OK:
            self.filename=dlg.GetFilename()
            self.dirname=dlg.GetDirectory()

            f=open(os.path.join(self.dirname,self.filename),'r')
            self.control.SetValue(f.read())
            f.close()

        dlg.Destroy()

app = wx.PySimpleApp()

frame = MainWindow(None, -1, "Sample editor")

app.MainLoop()