#! /usr/bin/python
from wxPython.wx import *
from wxPython.grid import *

class MyFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, id, title,
                         wxPoint(100, 100), wxSize(360, 240))
        TriPanel(self)

#----------------------------------------------------------------------

class TriPanel(wxPanel):
    def __init__(self,window):
        wxPanel.__init__(self,window,-1)
        splitter = wxSplitterWindow(self,-1)
        textpanel = TextPanel(self)
        gridpanel = GridPanel(splitter)
        treepanel = TreePanel(splitter)

        splitter.SetMinimumPaneSize(20)
        splitter.SplitVertically(treepanel, gridpanel, 120)

        sizer = wxBoxSizer(wxVERTICAL)
        sizer.Add(textpanel,1,wxEXPAND|wxLEFT|wxRIGHT,2)
        sizer.Add(splitter,6,wxEXPAND|wxLEFT|wxRIGHT,2)

        self.SetSizer(sizer)
        self.Layout()

#----------------------------------------------------------------------

class TextPanel(wxStaticBox):
    def __init__(self,panel):
        wxStaticBox.__init__(self,panel,-1,'')
        wxStaticText(panel,-1,'Documentation for tree and grid',(10,8))

#----------------------------------------------------------------------

class GridPanel(wxPanel):
    def __init__(self,splitter):
        wxPanel.__init__(self,splitter,-1)
        grid = wxGrid(self,-1)
        grid.CreateGrid(5,2)
        grid.SetRowLabelSize(0)
        grid.SetColLabelSize(20)
        help = wxStaticText(self,-1,'This is a help message')

        sizer = wxBoxSizer(wxVERTICAL)
        sizer.Add(grid,1,wxEXPAND)
        sizer.Add(help,0,wxLEFT|wxBOTTOM,5)
        self.SetSizer(sizer)
        self.Layout()

#----------------------------------------------------------------------

class TreePanel(wxPanel):
    def __init__(self,splitter):
        wxPanel.__init__(self,splitter,-1)
        tb = wxToolBar(self,-1,style=wxTB_NODIVIDER|wxNO_BORDER|wxTB_FLAT)
        tree = wxTreeCtrl(self,-1,style=wxTR_HAS_BUTTONS|wxTR_EDIT_LABELS)
        root = tree.AddRoot('Root')
        for i in range(1,5):
            node = tree.AppendItem(root,'%s' % i)
            for j in range(1,5):
                leaf = tree.AppendItem(node,'%s.%s' % (i,j))
        tree.Expand(root)
        tree.SetFocus()

        sizer = wxBoxSizer(wxVERTICAL)
        sizer.Add(tb,0,wxEXPAND|wxALIGN_CENTRE_HORIZONTAL|wxALL,2)
        sizer.Add(tree,1,wxEXPAND)
        self.SetSizer(sizer)
        self.Layout()

        EVT_TREE_BEGIN_LABEL_EDIT(self,tree.GetId(),self.OnBeginLabelEdit)
        EVT_TREE_END_LABEL_EDIT(self,tree.GetId(),self.OnEndLabelEdit)

    def OnBeginLabelEdit(self,evt):
        print 'begin edit'

    def OnEndLabelEdit(self,evt):
        print 'end edit'

#----------------------------------------------------------------------

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(NULL, -1, "Test splitter window")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

def run():
    app = MyApp(0)     # Create an instance of the application class
    app.MainLoop()     # Tell it to start processing events

if __name__ == '__main__':
    run()
