wxPython 2.1b1:

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
This commit is contained in:
Robin Dunn
1999-07-31 07:56:15 +00:00
parent f91cd38969
commit 8bf5d46efb
123 changed files with 12610 additions and 1642 deletions

View File

@@ -3,5 +3,7 @@
The tests in this directory are being depreciated in favor of the demo
program found in ../demo.
They are still used from time to time for my development efforts, but
they should not be included with any distributions.
Robin

View File

@@ -0,0 +1,108 @@
#!/bin/env python
#----------------------------------------------------------------------------
# Name: TstLstIcon.py
# Purpose: Lest Icon List
#
# Author: Lorne White
#
# Version: 0.8
# Licence: wxWindows, wxPython license
#----------------------------------------------------------------------------
import sys, os
from wxPython.wx import *
class AppFrame(wxFrame):
def __init__(self, parent, id=-1, title="New"):
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(420, 320))
if wxPlatform == '__WXMSW__':
self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
self.SetIcon(self.icon)
self.CreateStatusBar()
self.mainmenu = wxMenuBar()
menu = wxMenu()
menu = self.MakeFileMenu()
self.mainmenu.Append(menu, '&File')
self.SetMenuBar(self.mainmenu)
self.il = wxImageList(32, 32)
self.idx1 = idx1 = self.il.Add(wxNoRefBitmap('table.bmp', wxBITMAP_TYPE_BMP))
self.idx2 = idx2 = self.il.Add(wxNoRefBitmap('query.bmp', wxBITMAP_TYPE_BMP))
self.nb = nb = wxNotebook(self, -1)
self.list = wxListCtrl(nb, 1100, wxDefaultPosition, wxDefaultSize)
nb.AddPage(self.list, "Tables")
self.list.SetSingleStyle(wxLC_ICON)
self.list.SetWindowStyleFlag(wxSTATIC_BORDER|wxVSCROLL)
self.list.SetImageList(self.il, wxIMAGE_LIST_NORMAL)
self.qlist = wxListCtrl(nb, 1200, wxDefaultPosition, wxDefaultSize)
nb.AddPage(self.qlist, "Queries")
self.qlist.SetSingleStyle(wxLC_ICON)
self.qlist.SetWindowStyleFlag(wxSTATIC_BORDER|wxVSCROLL)
self.qlist.SetImageList(self.il, wxIMAGE_LIST_NORMAL)
self.UpdateView2()
self.UpdateView1()
self.nb.SetSelection(1)
self.nb.SetSelection(0)
#self.nb.Refresh()
#self.nb.ResizeChildren()
def MakeFileMenu(self):
self.fl_mn = menu = wxMenu()
mID = NewId()
menu.Append(mID, 'E&xit', 'Exit')
EVT_MENU(self, mID, self.OnFileExit)
return menu
def UpdateView1(self):
vset = "ViewA "
for i in range(20):
self.list.InsertImageStringItem(i, vset + str(i), self.idx1)
def UpdateView2(self):
vset = "ViewB "
for i in range(5):
self.qlist.InsertImageStringItem(i, vset + str(i), self.idx2)
def OnFileExit(self, event):
self.Close()
#---------------------------------------------------------------------------
class MyApp(wxApp):
def OnInit(self):
frame = AppFrame(NULL, -1, "Demo")
frame.Show(true)
self.SetTopWindow(frame)
return true
#---------------------------------------------------------------------------
def main():
app = MyApp(0)
app.MainLoop()
def t():
import pdb
pdb.run('main()')
if __name__ == '__main__':
main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

View File

@@ -0,0 +1,48 @@
from wxPython.wx import *
class MyDlg(wxDialog):
def __init__(self, parent):
wxDialog.__init__(self, parent, -1, "This is a test",
wxDefaultPosition, wxSize(150, 150))
self.text1 = wxTextCtrl(self, -1, "", wxPoint(10, 10), wxSize(120, -1))
self.text2 = wxTextCtrl(self, -1, "", wxPoint(10, 40), wxSize(120, -1))
wxButton(self, wxID_OK, "Okay", wxPoint(10,70)).SetDefault()
wxButton(self, wxID_CANCEL, "Cancel", wxPoint(60, 70))
def GetValues(self):
val1 = self.text1.GetValue()
val2 = self.text2.GetValue()
return (val1, val2)
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "")
wxButton(frame, 101, "test it", wxDefaultPosition, wxSize(50, 25))
EVT_BUTTON(frame, 101, self.OnClick)
frame.Fit()
frame.Show(true)
self.SetTopWindow(frame)
return true
def OnClick(self, event):
dlg = MyDlg(NULL)
if dlg.ShowModal() == wxID_OK:
values = dlg.GetValues()
print "Your values are: %s" % str(values)
else:
print "You canceled!"
dlg.Destroy()
app = MyApp(0)
app.MainLoop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

View File

@@ -0,0 +1,157 @@
from wxPython.wx import *
#-------------------------------------------------------------------
# class MyWindow(wxScrolledWindow):
#----------------------------------
# Copes with the drawing of the main scrolled window.
#
# Data members:
# num - <int> number of list entries
# ostart - <int> line number of the top line of the previous redraw
# vw - <int> width of the viewing window
# vh - <int> height of the viewing window
# smalltext - <int> 0 = size 12pt, 1 = size 9pt text
#
# Method members:
# OnPaint(evt) - basic draw handler
# OnDraw(dc) - called by OnPaint, redraws the screen if required
# update(updatelist) - called every 3 seconds if updates are needed.
class MyWindow(wxScrolledWindow):
def __init__(self,num,parent,id,pos,size,style):
wxScrolledWindow.__init__(self,parent,id,pos,size,style)
self.SetBackgroundColour(wxWHITE)
self.num=num
self.ostart=0
self.smalltext = 0
self.vw,self.vh=self.GetClientSizeTuple()
# calculate font pt size needed: a bit of a kludge to get round
# font compatibility problems of X and Windows.
dc=wxClientDC(self)
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
if dc.GetTextExtent("XXXXXXXXXX")[0] > 100:
self.smalltext = 1
def OnPaint(self,evt):
""" overriding OnPaint to give handler. """
dc = wxPaintDC(self)
self.PrepareDC(dc)
self.OnDraw(dc)
def update(self,updlist):
""" handles line by line updating of list entries. """
dc = wxClientDC(self)
self.PrepareDC(dc)
dc.SetBrush(wxWHITE_BRUSH)
dc.SetPen(wxWHITE_PEN)
if self.smalltext == 1:
dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
else:
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
dc.BeginDrawing()
for i in updlist:
if i >= self.ostart and i < self.ostart+self.vh/17+1:
dc.DrawRectangle(0,i*17,self.vw,17)
dc.DrawText("This is a simple test.Line "+str(i)+".",
10,i*17+2)
dc.EndDrawing()
def OnDraw(self,dc):
""" Main redraw function. """
if self.smalltext == 1:
dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
else:
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
vx,vstart=self.ViewStart()
self.vw,self.vh=self.GetClientSizeTuple()
vend=vstart+(self.vh/17) + 1
if vend > self.num: vend = self.num
dc.BeginDrawing()
if vstart > self.ostart: # if moving downwards...
for i in range(vend-(vstart-self.ostart+1),vend):
dc.DrawText("This is a simple test. Line "+str(i)+".",
10,i*17+2)
elif vstart < self.ostart: # if moving upwards...
for i in range(vstart,self.ostart):
dc.DrawText("This is a simple test. Line "+str(i)+".",
10,i*17+2)
elif vstart == self.ostart: # if not moving (redraw)...
#dc.Clear()
for i in range(vstart,vend):
dc.DrawText("This is a simple test. Line "+str(i)+".",
10,i*17+2)
dc.EndDrawing()
self.ostart=vstart
#--------------------------------------------------------------------
class MyTimer(wxTimer):
def __init__(self,frame):
wxTimer.__init__(self)
self.frame_ = frame
def Notify(self):
self.frame_.idle()
class MyFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title,
wxPoint(100, 100), wxSize(500, 300))
# number of entries
self.num = 30
# set up the scrolling window...
self.sw = MyWindow(self.num,self, -1,
wxDefaultPosition, wxDefaultSize,
wxVSCROLL|wxSUNKEN_BORDER)
self.sw.SetScrollbars(1,17,0,self.num+1)
lc = wxLayoutConstraints()
lc.top.SameAs(self, wxTop, 5)
lc.left.SameAs(self, wxLeft, 5)
lc.bottom.SameAs(self, wxBottom, 5)
lc.right.SameAs(self, wxRight,5)
self.sw.SetConstraints(lc)
self.timer=MyTimer(self)
# stupidly short interval time to accelerate memory leak problem:
self.timer.Start(80)
def idle(self):
#usually just update one or two lines; to accelerate problem,
#every line is updated here.
self.sw.update(range(self.num))
######################################################################
# Main procedure....
if __name__ == "__main__":
class MyApp(wxApp):
def OnInit(self):
self.frame = MyFrame(NULL, -1, "Memory Leak Tester")
self.frame.Show(true)
self.exiting = FALSE;
return true
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events

View File

@@ -0,0 +1,28 @@
from wxPython.wx import *
class MyFrame(wxFrame):
def __init__(self, parent, id, title='A pxFrame!'):
wxFrame.__init__(self, parent, id, title,
wxPyDefaultPosition, wxSize(50, 50))
def get_filename(self):
dlg = wxFileDialog(self, "Choose a file", ".", "", "*.*", wxOPEN)
dlg.ShowModal()
self.file = dlg.GetPath()
dlg.Destroy()
self.Iconize(true)
return self.file
class FilePicker(wxApp):
def OnInit(self):
return true
def get_filename(self):
dlg = wxFileDialog(NULL, "Choose a file", ".", "", "*.*", wxOPEN)
dlg.ShowModal()
self.file = dlg.GetPath()
dlg.Destroy()
return self.file

Binary file not shown.

View File

@@ -0,0 +1,123 @@
# popup.py:
# Illustrates how to create a wxListCtrl with an associated pop-up menu, which is
# activated when the right mouse button is clicked.
from wxPython.wx import *
class cPopupHandler(wxEvtHandler):
def __init__(self, this):
wxEvtHandler.__init__(self, this)
def ProcessEvent(self, event):
print "G"
#wxEvtHandler.ProcessEvent(self, event)
if event.GetEventClass() != wxTYPE_MOUSE_EVENT:
return
if not event.ButtonUp(3):
return
if event.ButtonDown(1):
print "left down"
elif event.ButtonUp(1):
print "left up"
elif event.ButtonDown(3):
print "right down"
elif event.ButtonUp(3):
print "right up"
def xProcessEvent(self, event):
# I tried to pass this one in as the Connect() handler,
# but all I got from that was that the icons disappeared
# from the wxListCtrl.
print "H"
pass
class cMyFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, -1, title, wxDefaultPosition, wxSize(800, 600))
self.Centre(wxBOTH)
# create a dummy icon; can't seem to get the wxListCtrl to work without an icon
#self.imagelist = wxImageList(16, 16)
#self.image = self.imagelist.Add(wxNoRefBitmap('smile.bmp', wxBITMAP_TYPE_BMP))
# create a ListCtrl
id = NewId()
self.listctrl = wxListCtrl(self, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT)
#self.listctrl.SetImageList(self.imagelist, wxIMAGE_LIST_SMALL)
if 1:
# install a handler for mouse right button up events
#EVT_RIGHT_DOWN(self.listctrl, self.OnListMouseEvent)
#EVT_RIGHT_UP(self.listctrl, self.OnListMouseEvent)
#EVT_RIGHT_DOWN(self.listctrl, self.OnSaveMousePos)
EVT_LIST_ITEM_SELECTED(self, id, self.OnSaveSelection)
EVT_COMMAND_RIGHT_CLICK(self, id, self.OnListRightClick)
else:
# create an wxEvtHandler and connect it to the wxListCtrl
print "A"
self.listctrl.handler = cPopupHandler(self.listctrl)
print "B"
id = NewId()
self.listctrl.Connect(id, id, wxEVT_RIGHT_DOWN, self.OnListMouseEvent)
print "C"
# define the ListCtrl column
self.listctrl.InsertColumn(0, "Name")
# create a set of dummy ListCtrl entries
for Index in range(20):
self.listctrl.InsertStringItem(Index, "Item number %d" % Index)
# re-adjust the width of the column
self.listctrl.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
def OnSaveSelection(self, event):
self.lastSelection = event.m_itemIndex
print self.lastSelection
def OnListRightClick(self, event):
menu = wxPyMenu()
menu.Append(0, "One")
menu.Append(1, "Two")
menu.Append(2, "Three")
pos = self.listctrl.GetItemPosition(self.lastSelection)
self.listctrl.PopupMenu(menu, pos.x, pos.y)
class cMyApp(wxApp):
def OnInit(self):
frame = cMyFrame(NULL, -1, "Popup Sample")
frame.Show(true)
self.SetTopWindow(frame)
return true
def main():
App = cMyApp(0)
App.MainLoop()
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,203 @@
"""
Hello, and welcome to this test of the wxTreeItemData class.
The wxTreeItemData class can be used to associate a python object with
a wxTreeCtrl item. In this sample, its use is demonstrated via a tree
control that shows the contents of a python namespace according to the
standard dir() command. Every item in the tree has its label taken
from the dir() output, and 'behind it' a reference to the python
object is stored in a wxTreeItemData object.
As you may have guessed by now, this sample automatically displays
'__doc__' strings if the selected python object happens to have
one. Please expand the pyTree object to learn more about the
implementation.
Version 1.0, April 4 1999.
Harm van der Heijden (H.v.d.Heijden@phys.tue.nl)
P.S. Check out the string module. It's imported in this sample not
because it's used, but because it's so beautifully documented...
"""
from wxPython import wx
import string # Don't use it, but it's fun expanding :-)
#----------------------------------------------------------------------
def _getindent(line):
"""Returns the indentation level of the given line."""
indent = 0
for c in line:
if c == ' ': indent = indent + 1
elif c == '\t': indent = indent + 8
else: break
return indent
def _sourcefinder(func):
"""Given a func_code object, this function tries to find and return
the python source code of the function."""
try:
f = open(func.co_filename,"r")
except:
return "(could not open file %s)" % (func.co_filename,)
for i in range(func.co_firstlineno):
line = f.readline()
ind = _getindent(line)
msg = ""
while line:
msg = msg + line
line = f.readline()
# the following should be <= ind, but then we get
# confused by multiline docstrings. Using == works most of
# the time... but not always!
if _getindent(line) == ind: break
return msg
#----------------------------------------------------------------------
class pyTree(wx.wxTreeCtrl):
"""
This wxTreeCtrl derivative displays a tree view of a Python namespace.
Anything from which the dir() command returns a non-empty list is a branch
in this tree.
"""
def __init__(self, parent, id, root):
"""
Initialize function; because we insert branches into the tree
as needed, we use the ITEM_EXPANDING event handler. The
ITEM_COLLAPSED handler removes the stuff afterwards. The
SEL_CHANGED handler attempts to display interesting
information about the selected object.
"""
wx.wxTreeCtrl.__init__(self, parent, id)
self.root = self.AddRoot(str(root), -1, -1, wx.wxTreeItemData(root))
if dir(root):
self.SetItemHasChildren(self.root, wx.TRUE)
wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
self.output = None
def SetOutput(self, output):
"""
Set output function (accepts single string). Used to display string
representation of the selected object by OnSelChanged.
"""
self.output = output
def OnItemExpanding(self,event):
"""
The real workhorse of this class. First we retrieve the object
(parent) belonging to the branch that is to be expanded. This
is done by calling GetPyData(parent), which is a short-cut for
GetPyItemData(parent).Get().
Then we get the dir() list of that object. For each item in
this list, a tree item is created with associated
wxTreeItemData referencing the child object. We get this
object using child = getattr(parent, item).
Finally, we check wether the child returns a non-empty dir()
list. If so, it is labeled as 'having children', so that it
may be expanded. When it actually is expanded, this function
will again figure out what the offspring is.
"""
item = event.GetItem()
obj = self.GetPyData( item )
lst = dir(obj)
for key in lst:
new_obj = getattr(obj,key)
new_item = self.AppendItem( item, key, -1, -1,
wx.wxTreeItemData(new_obj) )
if dir(new_obj):
self.SetItemHasChildren(new_item, wx.TRUE)
def OnItemCollapsed(self, event):
"""
We need to remove all children here, otherwise we'll see all
that old rubbish again after the next expansion.
"""
item = event.GetItem()
self.DeleteChildren(item)
def OnSelChanged(self, event):
"""
If an output function is defined, we try to print some
informative, interesting and thought-provoking stuff to it.
If it has a __doc__ string, we print it. If it's a function or
unbound class method, we attempt to find the python source.
"""
if not self.output:
return
obj = self.GetPyData( event.GetItem() )
msg = str(obj)
if hasattr(obj, '__doc__'):
msg = msg+"\n\nDocumentation string:\n\n%s" % ( getattr(obj, '__doc__'),)
# Is it a function?
func = None
if hasattr(obj, "func_code"): # normal function
func = getattr(obj, "func_code")
elif hasattr(obj, "im_func"): # unbound class method
func = getattr(getattr(obj, "im_func"), "func_code")
if func: # if we found one, let's try to print the source
msg = msg+"\n\nFunction source:\n\n" + _sourcefinder(func)
apply(self.output, (msg,))
#----------------------------------------------------------------------
overview = __doc__
def runTest(frame, nb, log):
split = wx.wxSplitterWindow(nb, -1)
tree = pyTree(split, -1, __main__)
text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
wx.wxDefaultSize, wx.wxTE_MULTILINE)
split.SplitVertically(tree, text, 200)
tree.SetOutput(text.SetValue)
tree.SelectItem(tree.root)
text.SetBackgroundColour(wxNamedColour("LIGHT BLUE"))
tree.SetBackgroundColour(wxNamedColour("LIGHT BLUE"))
return split
#----------------------------------------------------------------------
if __name__ == '__main__':
class MyFrame(wx.wxFrame):
"""Very standard Frame class. Nothing special here!"""
def __init__(self):
"""Make a splitter window; left a tree, right a textctrl. Wow."""
import __main__
wx.wxFrame.__init__(self, wx.NULL, -1, "PyTreeItemData Test",
wx.wxDefaultPosition, wx.wxSize(800,500))
split = wx.wxSplitterWindow(self, -1)
tree = pyTree(split, -1, __main__)
text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
wx.wxDefaultSize, wx.wxTE_MULTILINE)
split.SplitVertically(tree, text, 200)
tree.SetOutput(text.SetValue)
tree.SelectItem(tree.root)
class MyApp(wx.wxApp):
"""This class is even less interesting than MyFrame."""
def OnInit(self):
"""OnInit. Boring, boring, boring!"""
frame = MyFrame()
frame.Show(wx.TRUE)
self.SetTopWindow(frame)
return wx.TRUE
app = MyApp(0)
app.MainLoop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

View File

@@ -0,0 +1,38 @@
from wxPython.wx import *
class MyWindow(wxScrolledWindow):
def __init__(self,parent,id,pos,size,style):
wxScrolledWindow.__init__(self,parent,id,pos,size,style)
self.SetBackgroundColour(wxWHITE)
def OnPaint(self,evt):
dc = wxPaintDC(self)
# normally call a redraw/draw function here.
# this time, print 'redraw!'
print "redraw!"
class MyFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title,
wxPoint(100, 100), wxSize(500, 300))
self.sw = MyWindow(self, -1,
wxDefaultPosition, wxDefaultSize,
wxVSCROLL|wxSUNKEN_BORDER)
self.sw.SetScrollbars(1,20,0,30)
if __name__ == "__main__":
class MyApp(wxApp):
def OnInit(self):
self.frame = MyFrame(NULL, -1, "Scrolling Test App")
self.frame.Show(true)
self.exiting = FALSE;
return true
app = MyApp(0) # Create an instance of the app class
app.MainLoop() # Tell it to start processing events

View File

@@ -0,0 +1,136 @@
## import all of the wxPython GUI package
from wxPython.wx import *
"""
I am trying to write a routine which will produce an entryform which I can
later use to write GUI entryforms for databasis work. When you run this
program and chose option 150 (Invoer) under "L=EAers" the following error
appears (repeated 6 times):
Gtk-CRITICAL **: file gtkwidget.c: line 1592 (gtk_widget_map): assertion
`GTK_WIDGET_VISIBLE (widget) == TRUE' failed.=20
"""
class ToetsInvoer(wxPanel):
def __init__(self, parent):
wxPanel.__init__(self, parent, -1)
wxStaticText(self, -1, "wxTextCtrl", wxPoint(5, 25), wxSize(75, 20))
wxTextCtrl(self, 10, "", wxPoint(80, 25), wxSize(150, 20))
EVT_TEXT(self, 10, self.EvtText)
wxStaticText(self, -1, "Passsword", wxPoint(5, 50), wxSize(75, 20))
wxTextCtrl(self, 20, "", wxPoint(80, 50), wxSize(150, 20), wxTE_PASSWORD)
EVT_TEXT(self, 20, self.EvtText)
wxStaticText(self, -1, "Multi-line", wxPoint(5, 75), wxSize(75, 20))
wxTextCtrl(self, 30, "", wxPoint(80, 75), wxSize(200, 150), wxTE_MULTILINE)
EVT_TEXT(self, 30, self.EvtText)
self.Show(true)
def EvtText(self, event):
self.log.WriteText('EvtText: %s\n' % event.GetString())
#---------------------------------------------------------------------------
## Create a new frame class, derived from the wxPython Frame.
class HoofRaam(wxFrame):
def __init__(self, pa, id, titel):
# First, call the base class' __init__ method to create the frame
wxFrame.__init__(self, pa, id, titel,wxPyDefaultPosition,
wxSize(420, 200))
self.CreateStatusBar(2)
mainmenu = wxMenuBar()
menu = wxMenu()
menu.Append(100, '&Kopieer', 'Maak rugsteun')
menu.Append(101, '&Nuwe stel', 'Begin nuwe databasis')
menu.Append(150, '&Invoer', 'Toets invoervorm')
menu.AppendSeparator()
menu.Append(200, 'Kl&aar', 'Gaan uit die program uit!')
mainmenu.Append(menu, "&L=EAers")
self.SetMenuBar(mainmenu)
# if wxPlatform == '__WXMSW__':
# print menu.GetHelpString(100)
# print mainmenu.GetHelpString(101)
# print mainmenu.GetHelpString(200)
# self.DragAcceptFiles(true)
# Associate some events with methods of this class
self.Connect(-1, -1, wxEVT_SIZE, self.OnSize)
self.Connect(-1, -1, wxEVT_MOVE, self.OnMove)
self.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED, self.OnMenuCommand)
self.Connect(-1, -1, wxEVT_DROP_FILES, self.OnDropFiles)
self.child = None
#self.child = ToetsInvoer(self)
# This method is called automatically when the CLOSE event is
# sent to this window
def OnCloseWindow(self, event):
# tell the window to kill itself
self.Destroy()
# This method is called by the System when the window is resized,
# because of the association above.
def OnSize(self, event):
size = event.GetSize()
print "grootte:", size.width, size.height
event.Skip()
# This method is called by the System when the window is moved,
# because of the association above.
def OnMove(self, event):
pos = event.GetPosition()
print "pos:", pos.x, pos.y
def OnMenuCommand(self, event):
# why isn't this a wxMenuEvent???
print event, event.GetInt()
if event.GetInt() == 200:
self.Close()
if event.GetInt() == 150:
x = ToetsInvoer(self)
if event.GetInt() == 101:
print "Nommer 101 is gekies"
def OnDropFiles(self, event): #werk net in windows
fileList = event.GetFiles()
for file in fileList:
print file
def OnCloseWindow(self, event):
print 'Klaar'
self.Destroy()
#---------------------------------------------------------------------------
# Every wxWindows application must have a class derived from wxApp
class MyProg(wxApp):
# wxWindows calls this method to initialize the application
def OnInit(self):
# Create an instance of our customized Frame class
raam = HoofRaam(NULL, -1, "Taalunie")
raam.Show(true)
# Tell wxWindows that this is our main window
self.SetTopWindow(raam)
# Return a success flag
return true
#---------------------------------------------------------------------------
app = MyProg(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events

View File

@@ -0,0 +1,69 @@
from wxPython.wx import *
#---------------------------------------------------------------------------
class TestComboBox(wxDialog):
def __init__(self, parent):
wxDialog.__init__(self, parent, -1, "This is a test",
wxDefaultPosition, wxSize(550, 250))
self.s = ['aaaaaaaaaaaaaa',
'bbbbbbb',
'cccccccccccccccccccccccccccccccccccc',
'ddddddddddd',
'eeeeeeeeeee',
'ffffffff',
'gggggggggggggggggggggggg',
'hhhhhhhhhhhhhhhhhh',
'iiiiiiiiii']
wxStaticText(self, -1, "This example uses the wxListBox control.",
wxPoint(45, 10))
xwaarde = 35*12
wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(65, -1))
dv = self.s[4]
self.lb= wxComboBox(self, 50, dv, wxPoint(80, 50), wxSize(xwaarde, -1),
self.s, wxCB_DROPDOWN)
wxButton(self, wxID_OK, "Okay", wxPoint(10,90)).SetDefault()
wxButton(self, wxID_CANCEL, "Cancel", wxPoint(60, 90))
def GetSelection(self,leer):
val1 = self.lb.GetStringSelection()
#leer.commit()
return val1
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "")
wxButton(frame, 101, "test it", wxDefaultPosition, wxSize(50, 25))
EVT_BUTTON(frame, 101, self.OnClick)
frame.Fit()
frame.Show(true)
self.SetTopWindow(frame)
return true
def OnClick(self, event):
dlg = TestComboBox(NULL)
if dlg.ShowModal() == wxID_OK:
values = dlg.GetSelection(NULL)
print "Your values are: %s" % str(values)
else:
print "You canceled!"
dlg.Destroy()
app = MyApp(0)
app.MainLoop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

View File

@@ -0,0 +1,38 @@
from wxPython.wx import *
import string, sys
class Test:
def __init__(self):
self.panel = wxPanel(frame, -1)
self.box = wxListBox(self.panel, 100, wxPoint(10,10),
wxSize(300,100), [], wxLB_SINGLE|wxLB_SORT)
self.text = wxTextCtrl(self.panel, 110,'', wxPoint(310,10),
wxSize(300,100),wxTE_MULTILINE|wxTE_READONLY)
self.FillList()
def FillList(self):
line = 'This is a test'
self.box.Append(line)
self.text.AppendText(line)
def OnCloseWindow(self, event):
self.panel.Close(true)
class MyApp(wxApp):
def OnInit(self):
global frame
frame = wxFrame(NULL,-1,'Main',wxDefaultPosition,wxSize(630,150))
test = Test()
frame.Show(true)
self.SetTopWindow(frame)
return true
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = MyApp(0)
app.MainLoop()

View File

@@ -12,16 +12,7 @@
#----------------------------------------------------------------------------
<<<<<<< test1.py
<<<<<<< test1.py
#from wxPython import *
from wxpc import *
=======
=======
## import all of the wxPython GUI package
>>>>>>> 1.4
from wxPython.wx import *
>>>>>>> 1.3
#---------------------------------------------------------------------------
@@ -62,10 +53,7 @@ class MyFrame(wxFrame):
#---------------------------------------------------------------------------
<<<<<<< test1.py
=======
# Every wxWindows application must have a class derived from wxApp
>>>>>>> 1.4
class MyApp(wxApp):
# wxWindows calls this method to initialize the application
@@ -83,67 +71,13 @@ class MyApp(wxApp):
#---------------------------------------------------------------------------
<<<<<<< test1.py
def main():
app = MyApp(0)
app.MainLoop()
def t():
import pdb
pdb.run('main()')
=======
>>>>>>> 1.4
<<<<<<< test1.py
if __name__ == '__main__':
main()
=======
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events
>>>>>>> 1.4
print 'done!'
#----------------------------------------------------------------------------
#
# $Log$
# Revision 1.6 1999/06/28 21:39:48 VZ
# 1. wxStaticLine implemented (generic (ugly) and MSW versions)
# 2. wxTextDialog looks fine under MSW again
# 3. startup tips added: code, sample, docs
# 4. read-only text controls don't participate in TAB traversal
#
# Revision 1.3 1998/12/15 20:44:34 RD
# Changed the import semantics from "from wxPython import *" to "from
# wxPython.wx import *" This is for people who are worried about
# namespace pollution, they can use "from wxPython import wx" and then
# prefix all the wxPython identifiers with "wx."
#
# Added wxTaskbarIcon for wxMSW.
#
# Made the events work for wxGrid.
#
# Added wxConfig.
#
# Added wxMiniFrame for wxGTK, (untested.)
#
# Changed many of the args and return values that were pointers to gdi
# objects to references to reflect changes in the wxWindows API.
#
<<<<<<< test1.py
# Other assorted fixes and additions.
#
# Revision 1.2 1998/10/02 06:42:27 RD
#
# Version 0.4 of wxPython for MSW.
#
# Revision 1.1 1998/08/09 08:28:05 RD
# Initial version
#
#
=======
>>>>>>> 1.4

View File

@@ -0,0 +1,29 @@
from wxPython.wx import *
class someData:
def __init__(self, data="spam"):
self.data = data
class errApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "Close to get an error", wxDefaultPosition,
wxSize(200,200))
tree = wxTreeCtrl(frame, -1, wxDefaultPosition, wxDefaultSize)
root = tree.AddRoot("Spam")
tree.SetPyData(root, someData())
#tree.SetPyData(root, "A string")
#tree.SetPyData(root, ["a list", "A string"])
frame.Show(true)
self.SetTopWindow(frame)
self.frame = frame
return true
app = errApp(0)
app.MainLoop()
print "got to the end"

View File

@@ -0,0 +1,87 @@
"""
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

View File

@@ -0,0 +1,75 @@
#!/bin/env python
#----------------------------------------------------------------------------
## import all of the wxPython GUI package
from wxPython.wx import *
#---------------------------------------------------------------------------
class GeneralTab(wxWindow):
def __init__(self,parent,id):
wxWindow.__init__(self,parent,id,wxPoint(5,25))
self.Opts = {}
hdr = wxStaticText(self,-1,"This space left intentionally blank.",wxPoint(5,10))
def GetOpts(self):
return self.Opts
class ServersTab(wxWindow):
def __init__(self,parent,id):
wxWindow.__init__(self,parent,id,wxPoint(5,25))
hdr = wxStaticText(self,-1,"This is also blank on purpose.",wxPoint(5,10))
self.Opts = {}
def GetOpts(self):
return self.Opts
class OptionsTab(wxWindow):
def __init__(self,parent,id):
wxWindow.__init__(self,parent,id,wxPoint(5,25))
hdr = wxStaticText(self,-1,"Quit bugging me!.",wxPoint(5,10))
self.Opts = {}
def GetOpts(self):
return self.Opts
class SettingsWindow(wxFrame):
NOTEBOOK = 3201
GENERAL_TAB = 3210
OPTIONS_TAB = 3211
SERVERS_TAB = 3212
def __init__(self,parent,id):
self.id = id
self.parent = parent
wxFrame.__init__(self,parent,id,'Pyces Settings',
wxPoint(50,50), wxSize(350,475),
wxDIALOG_MODAL|wxSTATIC_BORDER|wxCAPTION|wxSYSTEM_MENU)
nb = wxNotebook(self, self.NOTEBOOK)
self.GeneralTab = GeneralTab(self,-1)
self.OptionsTab = OptionsTab(self,-1)
self.ServersTab = ServersTab(self,-1)
nb.AddPage(self.GeneralTab,'General')
nb.AddPage(self.OptionsTab,'Options')
nb.AddPage(self.ServersTab,'Servers')
nb.SetSelection(0)
nb.SetSize(wxSize(350,420))
#---------------------------------------------------------------------------
class MyApp(wxApp):
def OnInit(self):
frame = SettingsWindow(NULL, -1)
#frame.ShowModal()
#return false
frame.Show(true)
self.SetTopWindow(frame)
return true
#---------------------------------------------------------------------------
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events
#----------------------------------------------------------------------------
#