8bf5d46efb
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
88 lines
2.4 KiB
Python
88 lines
2.4 KiB
Python
"""
|
|
Build a GUI Tree (wxWindows) from an XML file
|
|
using pyExpat
|
|
"""
|
|
|
|
import sys,string
|
|
from xml.parsers import pyexpat
|
|
|
|
from wxPython.wx import *
|
|
|
|
class MyFrame(wxFrame):
|
|
def __init__(self, parent, id, title):
|
|
wxFrame.__init__(self, parent, id, title, wxPoint(100, 100), wxSize(160,100))
|
|
menu = wxMenu()
|
|
menu.Append (1001,"Open")
|
|
menu.Append (1002,"Close")
|
|
menu.Append (1003,"Exit")
|
|
menubar = wxMenuBar()
|
|
menubar.Append (menu,"File")
|
|
self.SetMenuBar(menubar)
|
|
|
|
class MyApp(wxApp):
|
|
def OnInit(self):
|
|
self.frame = MyFrame(NULL, -1, "Tree View of XML")
|
|
self.tree = wx.wxTreeCtrl(self.frame, -1)
|
|
EVT_MENU(self, 1001, self.OnOpen)
|
|
EVT_MENU(self, 1002, self.OnClose)
|
|
EVT_MENU(self, 1003, self.OnExit)
|
|
self.frame.Show(true)
|
|
self.SetTopWindow(self.frame)
|
|
return true
|
|
|
|
def OnOpen(self,event):
|
|
f = wxFileDialog(self.frame,"Select a file",".","","*.xml",wxOPEN)
|
|
if f.ShowModal() == wxID_OK:
|
|
LoadTree(f.GetPath())
|
|
|
|
def OnClose(self,event):
|
|
self.tree = wx.wxTreeCtrl(self.frame, -1)
|
|
pass
|
|
|
|
def OnExit(self,event):
|
|
self.OnCloseWindow(event)
|
|
|
|
def OnCloseWindow(self, event):
|
|
self.frame.Destroy()
|
|
|
|
|
|
NodeStack = []
|
|
|
|
# Define a handler for start element events
|
|
def StartElement( name, attrs ):
|
|
global NodeStack
|
|
NodeStack.append(app.tree.AppendItem(NodeStack[-1],name))
|
|
|
|
def EndElement( name ):
|
|
global NodeStack
|
|
NodeStack = NodeStack[:-1]
|
|
|
|
def CharacterData ( data ):
|
|
global NodeStack
|
|
if string.strip(data):
|
|
app.tree.AppendItem(NodeStack[-1],data)
|
|
|
|
|
|
def LoadTree (f):
|
|
print f
|
|
# Create a parser
|
|
Parser = pyexpat.ParserCreate()
|
|
|
|
# Tell the parser what the start element handler is
|
|
Parser.StartElementHandler = StartElement
|
|
Parser.EndElementHandler = EndElement
|
|
Parser.CharacterDataHandler = CharacterData
|
|
|
|
# Parse the XML File
|
|
ParserStatus = Parser.Parse(open(f,'r').read(), 1)
|
|
if ParserStatus == 0:
|
|
print "oops!"
|
|
raise SystemExit
|
|
|
|
app = MyApp(0)
|
|
NodeStack = [app.tree.AddRoot("Root")]
|
|
|
|
|
|
app.MainLoop()
|
|
raise SystemExit
|