This commit was manufactured by cvs2svn to create tag 'wxPy_2_3_4_1'.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/wxPy_2_3_4_1@18324 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2002-12-18 06:48:23 +00:00
parent bf4a027ddb
commit ea5a206d1d
1457 changed files with 66856 additions and 42992 deletions

View File

@@ -124,7 +124,8 @@ class DoodleDropTarget(wxPyDropTarget):
self.dv = window
# specify the type of data we will accept
self.data = wxCustomDataObject(wxCustomDataFormat("DoodleLines"))
self.df = wxCustomDataFormat("DoodleLines")
self.data = wxCustomDataObject(self.df)
self.SetDataObject(self.data)
@@ -326,21 +327,20 @@ if __name__ == '__main__':
#----------------------------------------------------------------------
overview = """<html><body>
This demo shows Drag and Drop using a custom data type and a custom
data object. A type called "DoodleLines" is created and a Python
Pickle of a list is actually transfered in the drag and drop
opperation.
A second data object is also created containing a bitmap of the image
and is made available to any drop target that accepts bitmaps, such as
MS Word.
overview = """\
This demo shows Drag and Drop using a custom data type and a custom data object. A type called "DoodleLines" is created and a Python Pickle of a list is actually transfered in the drag and drop opperation.
A second data object is also created containing a bitmap of the image and is made available to any drop target that accepts bitmaps, such as MS Word.
The two data objects are combined in a wxDataObjectComposite and the rest is handled by the framework.
The two data objects are combined in a wxDataObjectComposite and the
rest is handled by the framework.
</body></html>
"""

View File

@@ -0,0 +1,281 @@
#---------------------------------------------------------------------------
# Name: EventManager.py
# Purpose: A module to demonstrate the wxPython.lib.EventManager.
#
# Author: Robb Shecter <robb@acm.org>
#
# Created: 16-December-2002
# Copyright: (c) 2002 by Robb Shecter <robb@acm.org>
# Licence: wxWindows license
#---------------------------------------------------------------------------
from wxPython.wx import *
from wxPython.lib.evtmgr import eventManager
#----------------------------------------------------------------------
class TestPanel(wxPanel):
def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1)
self.log = log
fsize = self.GetFont().GetPointSize()
f1 = wxFont(fsize+0, wxSWISS, wxNORMAL, wxNORMAL)
f2 = wxFont(fsize+2, wxSWISS, wxNORMAL, wxBOLD)
f3 = wxFont(fsize+6, wxSWISS, wxNORMAL, wxBOLD)
title1 = wxStaticText(self, -1, 'EventManager')
title1.SetFont(f3)
txt = """\
This demo shows (1) basic uses and features of the EventManager, as well
as (2) how it helps with a real-world task: creating independent, object-
oriented components."""
message0 = wxStaticText(self, -1, txt)
message0.SetFont(f1)
title2 = wxStaticText(self, -1, 'Event Listeners')
title2.SetFont(f2)
txt = """\
These objects listen to motion events from the target window, using the ability
to register one event with multiple listeners. They also register for mouse events
on themselves to implement toggle-button functionality."""
message1 = wxStaticText(self, -1, txt)
message1.SetFont(f1)
title3 = wxStaticText(self, -1, 'Target Window')
title3.SetFont(f2)
txt = """\
A passive window that's used as an event generator. Move the mouse over it to
send events to the listeners above."""
message2 = wxStaticText(self, -1, txt)
message2.SetFont(f1)
targetPanel = Tile(self, log, bgColor=wxColor(80,10,10), active=0)
buttonPanel = wxPanel(self ,-1)
sizer = wxBoxSizer(wxHORIZONTAL)
target = targetPanel.tile
sizer.Add(0,0,1)
for factor in [0.2, 0.3, 0.35, 0.4, 0.5, 0.6, 0.7]:
sizer.Add(Tile(buttonPanel, log, factor, target), 0, 0)
sizer.Add(0,0,1)
buttonPanel.SetAutoLayout(1)
buttonPanel.SetSizer(sizer)
sizer.Fit(buttonPanel)
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(title1, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 6)
sizer.Add(message0, 0, wxALIGN_CENTER | wxALL, 6)
sizer.Add(title2, 0, wxALIGN_CENTER | wxLEFT | wxTOP | wxRIGHT, 16)
sizer.Add(message1, 0, wxALIGN_CENTER | wxALL, 6)
sizer.Add(buttonPanel, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 16)
sizer.Add(title3, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 16)
sizer.Add(message2, 0, wxALIGN_CENTER | wxALL, 6)
sizer.Add(targetPanel, 2, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 16)
self.SetAutoLayout(1)
self.SetSizer(sizer)
class Tile(wxPanel):
"""
This outer class is responsible for changing
its border color in response to certain mouse
events over its contained 'InnerTile'.
"""
normal = wxColor(150,150,150)
bright = wxColor(230,115,115)
active = wxColor(255,240,240)
def __init__(self, parent, log, factor=1, thingToWatch=None, bgColor=None, active=1):
wxPanel.__init__(self, parent, -1, size=(45,45))
self.tile = InnerTile(self, log, factor, thingToWatch, bgColor)
self.log = log
sizer = wxBoxSizer(wxHORIZONTAL)
sizer.Add(self.tile, 1, wxEXPAND | wxALL, 4)
self.SetAutoLayout(1)
self.SetSizer(sizer)
self.Layout()
self.SetBackgroundColour(Tile.normal)
if active:
# Register myself for mouse events over self.tile in order to
# create typical button/hyperlink visual effects.
eventManager.Register(self.setBright, EVT_ENTER_WINDOW, self.tile)
eventManager.Register(self.setNormal, EVT_LEAVE_WINDOW, self.tile)
eventManager.Register(self.setActive, EVT_LEFT_DOWN, self.tile)
eventManager.Register(self.setBright, EVT_LEFT_UP, self.tile)
def setBright(self, event):
self.SetBackgroundColour(Tile.bright)
self.Refresh()
def setActive(self, event):
self.SetBackgroundColour(Tile.active)
self.Refresh()
def setNormal(self, event):
self.SetBackgroundColour(Tile.normal)
self.Refresh()
class InnerTile(wxPanel):
START_COLOR = wxColor(200, 70, 70)
FINAL_COLOR = wxColor(50, 80, 220)
OFF_COLOR = wxColor(180, 185, 180)
DELTAS = map(lambda a,b: b-a, START_COLOR.Get(), FINAL_COLOR.Get())
"""
This inner panel changes its color in reaction to mouse
events over the 'thingToWatch'.
"""
def __init__(self, parent, log, factor, thingToWatch=None, bgColor=None):
wxPanel.__init__(self, parent, -1)
self.log=log
if bgColor:
self.SetBackgroundColour(bgColor)
if thingToWatch:
self.factor = factor
self.thingToWatch = thingToWatch
self.state = 0
self.toggleOnOff()
# Watch for the mouse click to enable/disable myself, and
# reset my color when the mouse leaves the watched window.
eventManager.Register(self.toggleOnOff, EVT_LEFT_UP, self)
eventManager.Register(self.resetColor, EVT_LEAVE_WINDOW, thingToWatch)
def toggleOnOff(self, event=None):
# Implement being on or off by registering and
# de-registering self.makeColor() from the event manager.
if self.state:
eventManager.DeregisterListener(self.makeColor)
else:
eventManager.Register(self.makeColor, EVT_MOTION, self.thingToWatch)
self.state = 1 - self.state
self.resetColor()
def resetColor(self, event=None):
if self.state:
self.setColor(InnerTile.START_COLOR)
else:
self.setColor(InnerTile.OFF_COLOR)
def setColor(self, color):
self.SetBackgroundColour(color)
self.Refresh()
def makeColor(self, mouseEvent):
z = 250.0
(x, y) = mouseEvent.GetPositionTuple()
a = (x + y) * self.factor
percent = min(a, z) / z
r, g, b = map(lambda start, delta, pct=percent: start+(delta*pct),
InnerTile.START_COLOR.Get(),
InnerTile.DELTAS)
self.setColor(wxColor(r,g,b))
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2>EventManager</h2>
<p> The goal of the EventManager is to make wxWindows events more
'Pythonic' (ie. object-oriented) and easier to work with, without
impacting performance. It offers these features:
<p>
<ul>
<li> Allows any number of listeners to register for a single
event. (In addition to the standard wxPython feature of a single
listener being able to respond to many events.)
<li> Makes it easy to disconnect and reconnect listeners. This
has the effect of reducing the need for case-based branching in
application code.
<li> Has an object-oriented API. Programmers register to get
events directly from the objects that generate them, instead of
using ID numbers.
</ul>
<h3>Usage</h3>
<p>The EventManager class has three public methods. First get a
reference to it:
<PRE>
from wxPython.lib.evtmgr import eventManager
</PRE>
<p>...and then invoke any of the following methods. These methods are
'safe'; duplicate registrations or de-registrations will have no
effect.
<p><b>Registering a listener:</b>
<PRE>
eventManager.Register(listener, event, event-source)
</PRE>
<p><b>De-registering by window:</b>
<PRE>
eventManager.DeregisterWindow(event-source)
</PRE>
<p><b>De-registering by listener:</b>
<PRE>
eventManager.DeregisterListener(listener)
</PRE>
<p><b>Simple Example:</b>
<PRE>
from wxPython.lib.evtmgr import eventManager
aButton = wxButton(somePanel, -1, 'Click me')
eventManager.Register(self.someMethod, EVT_BUTTON, aButton)
</PRE>
<p> See the demo code as well as the documentation in the source of
<tt>wxPython.lib.evtmgr</tt> for more details.
<p>
by Robb Shecter (robb@acm.org)
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -46,6 +46,12 @@ class TestPanel(wxPanel):
EVT_BUTTON(self, b.GetId(), self.OnButton)
sizer.Add(b)
bmp = images.getTest2Bitmap()
b = wxGenBitmapButton(self, -1, bmp)
EVT_BUTTON(self, b.GetId(), self.OnButton)
sizer.Add(b)
b.Enable(FALSE)
b = wxGenBitmapButton(self, -1, None)
EVT_BUTTON(self, b.GetId(), self.OnButton)
bmp = images.getBulb1Bitmap()
@@ -58,7 +64,6 @@ class TestPanel(wxPanel):
b.SetBitmapSelected(bmp)
b.SetBestSize()
sizer.Add(b)
sizer.Add(10,10)
b = wxGenToggleButton(self, -1, "Toggle Button")
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
@@ -128,3 +133,11 @@ def runTest(frame, nb, log):
import wxPython.lib.buttons
overview = wxPython.lib.buttons.__doc__
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -149,6 +149,7 @@ class MyCellEditor(wxPyGridCellEditor):
# For this example, replace the text. Normally we would append it.
#self._tc.AppendText(ch)
self._tc.SetValue(ch)
self._tc.SetInsertionPointEnd()
else:
evt.Skip()

View File

@@ -45,7 +45,10 @@ class CustomDataTable(wxPyGridTableBase):
return len(self.data[0])
def IsEmptyCell(self, row, col):
return not self.data[row][col]
try:
return not self.data[row][col]
except IndexError:
return true
# Get/Set values in the table. The Python version of these
# methods can handle any data-type, (as long as the Editor and
@@ -138,8 +141,22 @@ class CustTableGrid(wxGrid):
class TestFrame(wxFrame):
def __init__(self, parent, log):
wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480))
grid = CustTableGrid(self, log)
p = wxPanel(self, -1, style=0)
grid = CustTableGrid(p, log)
b = wxButton(p, -1, "Another Control...")
b.SetDefault()
EVT_BUTTON(self, b.GetId(), self.OnButton)
EVT_SET_FOCUS(b, self.OnButtonFocus)
bs = wxBoxSizer(wxVERTICAL)
bs.Add(grid, 1, wxGROW|wxALL, 5)
bs.Add(b)
p.SetSizer(bs)
def OnButton(self, evt):
print "button selected"
def OnButtonFocus(self, evt):
print "button focus"
#---------------------------------------------------------------------------

View File

@@ -0,0 +1,193 @@
from wxPython.wx import *
from wxPython.grid import *
from wxPython.lib.gridmovers import wxGridColMover, EVT_GRID_COL_MOVE
from wxPython.lib.gridmovers import wxGridRowMover, EVT_GRID_ROW_MOVE
#---------------------------------------------------------------------------
class CustomDataTable(wxPyGridTableBase):
"""
"""
def __init__(self, log):
wxPyGridTableBase.__init__(self)
self.log = log
self.identifiers = ['id','ds','sv','pr','pl','op','fx','ts']
self.rowLabels = ['Row1','Row2','Row3']
self.colLabels = {'id':'ID','ds':'Description','sv':'Severity',
'pr':'Priority','pl':'Platform','op':'Opened?',
'fx':'Fixed?','ts':'Tested?'}
self.data = [{'id':1010,
'ds':"The foo doesn't bar",
'sv':"major",
'pr':1,
'pl':'MSW',
'op':1,
'fx':1,
'ts':1
},
{'id':1011,
'ds':"I've got a wicket in my wocket",
'sv':"wish list",
'pr':2,
'pl':'other',
'op':0,
'fx':0,
'ts':0
},
{'id':1012,
'ds':"Rectangle() returns a triangle",
'sv':"critical",
'pr':5,
'pl':'all',
'op':0,
'fx':0,
'ts':0
}
]
#--------------------------------------------------
# required methods for the wxPyGridTableBase interface
def GetNumberRows(self):
return len(self.data)
def GetNumberCols(self):
return len(self.identifiers)
def IsEmptyCell(self, row, col):
id = self.identifiers[col]
return not self.data[row][id]
def GetValue(self, row, col):
id = self.identifiers[col]
return self.data[row][id]
def SetValue(self, row, col, value):
id = self.identifiers[col]
self.data[row][id] = value
#--------------------------------------------------
# Some optional methods
# Called when the grid needs to display column labels
def GetColLabelValue(self, col):
id = self.identifiers[col]
return self.colLabels[id]
# Called when the grid needs to display row labels
def GetRowLabelValue(self,row):
return self.rowLabels[row]
#--------------------------------------------------
# Methods added for demo purposes.
# The physical moving of the cols/rows is left to the implementer.
# Because of the dynamic nature of a wxGrid the physical moving of
# columns differs from implementation to implementation
# Move the column
def MoveColumn(self,frm,to):
grid = self.GetView()
if grid:
# Move the identifiers
old = self.identifiers[frm]
del self.identifiers[frm]
if to > frm:
self.identifiers.insert(to-1,old)
else:
self.identifiers.insert(to,old)
# Notify the grid
grid.BeginBatch()
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_COLS_DELETED,
frm,1)
grid.ProcessTableMessage(msg)
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_COLS_INSERTED,
to,1)
grid.ProcessTableMessage(msg)
grid.EndBatch()
# Move the row
def MoveRow(self,frm,to):
grid = self.GetView()
if grid:
# Move the rowLabels and data rows
oldLabel = self.rowLabels[frm]
oldData = self.data[frm]
del self.rowLabels[frm]
del self.data[frm]
if to > frm:
self.rowLabels.insert(to-1,oldLabel)
self.data.insert(to-1,oldData)
else:
self.rowLabels.insert(to,oldLabel)
self.data.insert(to,oldData)
# Notify the grid
grid.BeginBatch()
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_ROWS_DELETED,
frm,1)
grid.ProcessTableMessage(msg)
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
to,1)
grid.ProcessTableMessage(msg)
grid.EndBatch()
#---------------------------------------------------------------------------
class DragableGrid(wxGrid):
def __init__(self, parent, log):
wxGrid.__init__(self, parent, -1)
table = CustomDataTable(log)
# The second parameter means that the grid is to take ownership of the
# table and will destroy it when done. Otherwise you would need to keep
# a reference to it and call it's Destroy method later.
self.SetTable(table, true)
# Enable Column moving
wxGridColMover(self)
EVT_GRID_COL_MOVE(self,self.GetId(),self.OnColMove)
# Enable Row moving
wxGridRowMover(self)
EVT_GRID_ROW_MOVE(self,self.GetId(),self.OnRowMove)
# Event method called when a column move needs to take place
def OnColMove(self,evt):
frm = evt.GetMoveColumn() # Column being moved
to = evt.GetBeforeColumn() # Before which column to insert
self.GetTable().MoveColumn(frm,to)
# Event method called when a row move needs to take place
def OnRowMove(self,evt):
frm = evt.GetMoveRow() # Row being moved
to = evt.GetBeforeRow() # Before which row to insert
self.GetTable().MoveRow(frm,to)
#---------------------------------------------------------------------------
class TestFrame(wxFrame):
def __init__(self, parent, log):
wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480))
grid = DragableGrid(self, log)
#---------------------------------------------------------------------------
if __name__ == '__main__':
import sys
app = wxPySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(true)
app.MainLoop()
#---------------------------------------------------------------------------

View File

@@ -28,7 +28,7 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin):
self.SetCellBackgroundColour(2, 2, wxCYAN)
self.SetReadOnly(3, 3, true)
self.SetCellEditor(5, 0, wxGridCellNumberEditor())
self.SetCellEditor(5, 0, wxGridCellNumberEditor(1,1000))
self.SetCellValue(5, 0, "123")
self.SetCellEditor(6, 0, wxGridCellFloatEditor())
self.SetCellValue(6, 0, "123.34")
@@ -53,6 +53,14 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin):
self.SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_BOTTOM)
# overflow cells
self.SetCellValue( 9, 1, "This default cell will overflow into neighboring cells, but not if you turn overflow off.");
self.SetCellSize(11, 1, 3, 3);
self.SetCellAlignment(11, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
self.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns");
# test all the events
EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellLeftClick)
EVT_GRID_CELL_RIGHT_CLICK(self, self.OnCellRightClick)

View File

@@ -25,18 +25,11 @@ import images
_treeList = [
# new stuff
('New since last release', [
'RowColSizer',
'Unicode',
'wxFileHistory',
'wxGenericDirCtrl',
'wxImageFromStream',
'wxArtProvider',
'ScrolledPanel',
'wxMenu',
'wxIEHtmlWin',
'wxKeyEvents',
'wxWizard',
'wxXmlResourceHandler',
'wxRadioButton',
'Throbber',
'wxPopupControl',
'wxMultiSash',
'EventManager',
]),
# managed windows == things with a caption you can close
@@ -88,14 +81,15 @@ _treeList = [
'wxNotebook',
'wxPopupWindow',
'wxRadioBox',
'wxRadioButton',
'wxSashWindow',
'wxSlider',
'wxScrolledWindow',
'wxSplitterWindow',
'wxSlider',
'wxSpinButton',
'wxSpinCtrl',
'wxStaticText',
'wxSplitterWindow',
'wxStaticBitmap',
'wxStaticText',
'wxStatusBar',
'wxTextCtrl',
'wxToggleButton',
@@ -106,6 +100,8 @@ _treeList = [
# controls coming from other librairies
('More Windows/Controls', [
#'wxFloatBar', deprecated
#'wxMVCTree', deprecated
'ColourSelect',
'ContextHelp',
'FancyText',
@@ -115,20 +111,22 @@ _treeList = [
'PyCrustWithFilling',
'SplitTree',
'TablePrint',
'Throbber',
'wxCalendar',
'wxCalendarCtrl',
'wxDynamicSashWindow',
'wxEditableListBox',
'wxEditor',
#'wxFloatBar', deprecated
'wxHtmlWindow',
'wxIEHtmlWin',
'wxLEDNumberCtrl',
'wxMimeTypesManager',
#'wxMVCTree', deprecated
'wxMultiSash',
'wxPopupControl',
'wxRightTextCtrl',
'wxStyledTextCtrl_1',
'wxStyledTextCtrl_2',
'wxTimeCtrl',
]),
# How to lay out the controls in a frame/dialog
@@ -145,6 +143,7 @@ _treeList = [
# ditto
('Process and Events', [
'EventManager',
'infoframe',
'OOR',
'PythonEvents',
@@ -163,6 +162,7 @@ _treeList = [
# Images
('Images', [
'Throbber',
'wxDragImage',
'wxImage',
'wxImageFromStream',
@@ -177,6 +177,7 @@ _treeList = [
'DrawXXXList',
'FontEnumerator',
'PrintFramework',
'Throbber',
'Unicode',
'wxFileHistory',
'wxJoystick',
@@ -212,7 +213,8 @@ class MyLog(wxPyLog):
if self.logTime:
message = time.strftime("%X", time.localtime(timeStamp)) + \
": " + message
self.tc.AppendText(message + '\n')
if self.tc:
self.tc.AppendText(message + '\n')
class MyTP(wxPyTipProvider):
@@ -250,9 +252,9 @@ class wxPythonDemo(wxFrame):
EVT_MENU(self.tbicon, self.TBMENU_RESTORE, self.OnTaskBarActivate)
EVT_MENU(self.tbicon, self.TBMENU_CLOSE, self.OnTaskBarClose)
wxCallAfter(self.ShowTip)
self.otherWin = None
self.showTip = true
EVT_IDLE(self, self.OnIdle)
EVT_CLOSE(self, self.OnCloseWindow)
EVT_ICONIZE(self, self.OnIconfiy)
@@ -358,7 +360,7 @@ class wxPythonDemo(wxFrame):
# Set up a TextCtrl on the Demo Code Notebook page
self.txt = wxTextCtrl(self.nb, -1,
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL|wxTE_RICH2)
self.nb.AddPage(self.txt, "Demo Code")
@@ -453,6 +455,7 @@ class wxPythonDemo(wxFrame):
if self.nb.GetPageCount() == 3:
if self.nb.GetSelection() == 2:
self.nb.SetSelection(0)
wxSafeYield() # in case the page has pending events
self.nb.DeletePage(2)
if itemText == self.overviewText:
@@ -541,10 +544,6 @@ class wxPythonDemo(wxFrame):
self.window = self.otherWin
self.otherWin = None
if self.showTip:
self.ShowTip()
self.showTip = false
#---------------------------------------------
def ShowTip(self):

View File

@@ -76,8 +76,7 @@ class TestPanel(wxPanel):
wxNO_BORDER )
valueWindow = TestValueWindow(splitter, -1, style=wxNO_BORDER)
splitter.SplitVertically(tree, valueWindow)
splitter.SetSashPosition(150)
splitter.SplitVertically(tree, valueWindow, 150)
scroller.SetTargetWindow(tree)
scroller.EnableScrolling(FALSE, FALSE)
@@ -93,6 +92,10 @@ class TestPanel(wxPanel):
#----------------------------------------------------------------------
def runTest(frame, nb, log):
if wxPlatform == "__WXMAC__":
wxMessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
return
win = TestPanel(nb, log)
return win

175
wxPython/demo/Throbber.py Normal file
View File

@@ -0,0 +1,175 @@
#
# Throbber.py - Cliff Wells <clifford.wells@attbi.com>
#
from wxPython.wx import *
from wxPython.lib.rcsizer import RowColSizer
from wxPython.lib.throbber import Throbber, __doc__ as docString
import throbImages # this was created using a modified version of img2py
#----------------------------------------------------------------------
class TestPanel(wxPanel):
def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1)
self.log = log
# create the throbbers
self.throbbers = {
'plain': { 'throbber': None,
'text': "Plain throbber." },
'reverse': { 'throbber': None,
'text': "This throbber runs in reverse and faster." },
'autoreverse': { 'throbber': None,
'text': "This throbber switches direction." },
'label': { 'throbber': None,
'text': "With a label." },
'overlay': { 'throbber': None,
'text': "With an overlayed image." },
'overlay+text': { 'throbber': None,
'text': "With a label and an overlayed image." },
}
images = [throbImages.catalog[i].getBitmap()
for i in throbImages.index
if i not in ['eclouds', 'logo']]
self.throbbers['plain']['throbber'] = Throbber(self, -1,
images, size=(36, 36),
frameDelay = 0.1)
self.throbbers['reverse']['throbber'] = Throbber(self, -1, images, #size=(36, 36),
frameDelay = 0.07)
self.throbbers['reverse']['throbber'].Reverse()
self.throbbers['autoreverse']['throbber'] = Throbber(self, -1,
images, #size=(36, 36),
frameDelay = 0.1,
reverse = true)
self.throbbers['autoreverse']['throbber'].sequence.append(0)
self.throbbers['label']['throbber'] = Throbber(self, -1,
images, #size=(36, 36),
frameDelay = 0.1,
label = 'Label')
self.throbbers['label']['throbber'].SetFont(wxFont(pointSize = 10,
family = wxDEFAULT,
style = wxNORMAL,
weight = wxBOLD))
self.throbbers['overlay']['throbber'] = Throbber(self, -1,
images, #size=(36, 36),
frameDelay = 0.1,
overlay = throbImages.catalog['logo'].getBitmap())
self.throbbers['overlay+text']['throbber'] = Throbber(self, -1,
images, #size=(36, 36),
frameDelay = 0.1,
overlay = throbImages.catalog['logo'].getBitmap(),
label = "Python!")
self.throbbers['overlay+text']['throbber'].SetFont(wxFont(pointSize = 8,
family = wxDEFAULT,
style = wxNORMAL,
weight = wxBOLD))
# this throbber is created using a single, composite image
self.otherThrobber = Throbber(self, -1,
throbImages.catalog['eclouds'].getBitmap(), #size=(48, 48),
frameDelay = 0.15,
frames = 12,
frameWidth = 48,
label = "Stop")
EVT_LEFT_DOWN(self.otherThrobber, self.OnClickThrobber)
box = wxBoxSizer(wxVERTICAL)
sizer = RowColSizer()
box.Add(sizer, 1, wxEXPAND|wxALL, 5)
sizer.AddGrowableCol(1)
sizer.Add(self.otherThrobber, row = 0, col = 2, rowspan = 4, flag = wxALIGN_CENTER_VERTICAL)
row = 2
# use a list so we can keep our order
for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
sizer.Add(self.throbbers[t]['throbber'], row = row, col = 0, flag = wxALIGN_CENTER|wxALL, border=2)
sizer.Add(wxStaticText(self, -1, self.throbbers[t]['text']), row = row, col = 1,
flag = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT)
row += 1
# start and stop buttons
startButton = wxButton(self, -1, "Start")
EVT_BUTTON(self, startButton.GetId(), self.OnStartAnimation)
stopButton = wxButton(self, -1, "Stop")
EVT_BUTTON(self, stopButton.GetId(), self.OnStopAnimation)
buttonBox = wxBoxSizer(wxHORIZONTAL)
buttonBox.AddMany([
(startButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
(stopButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
])
sizer.Add(buttonBox,
row = len(self.throbbers) + 3,
col = 0,
colspan = 3,
flag = wxALIGN_CENTER)
self.SetSizer(box)
self.SetAutoLayout(true)
self.Layout()
sizer.SetSizeHints(self)
sizer.Fit(self)
for t in self.throbbers.keys():
self.throbbers[t]['throbber'].Start()
self.otherThrobber.Start()
self.otherThrobber.Reverse()
EVT_WINDOW_DESTROY(self, self.OnDestroy)
def OnDestroy(self, event):
self.log.write("got it")
event.Skip()
def OnStartAnimation(self, event):
for t in self.throbbers.keys():
self.throbbers[t]['throbber'].Start()
def OnStopAnimation(self, event):
for t in self.throbbers.keys():
self.throbbers[t]['throbber'].Rest()
def OnClickThrobber(self, event):
if self.otherThrobber.Running():
self.otherThrobber.Rest()
self.otherThrobber.SetLabel("Start")
else:
self.otherThrobber.Start()
self.otherThrobber.SetLabel("Stop")
#----------------------------------------------------------------------
def runTest(frame, nb, log):
if wxPlatform == "__WXMAC__":
wxMessageBox("This demo currently fails on the Mac, I think because of the lack of EVT_WINDOW_DESTROY...",
"Sorry")
return
else:
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h4><center>Throbber</center></h4>
<p>%s</p>
</body></html>
""" % docString
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -4,24 +4,30 @@
</head>
<body bgcolor="#00CCFF">
<h2>Mixing wxPython and wxHTML</h2>
The widgets on this page were created dynamically on the fly by a custom
wxTagHandler found in wxPython.lib.wxpTag. You can look at the sources
and doc-string <a href="../../lib/wxpTag.py">here</a>.
The widgets on this page were created dynamically on the fly by a
custom wxTagHandler found in wxPython.lib.wxpTag. You can look at the
sources and doc-string <a href="../../lib/wxpTag.py">here</a>.
<p>
The button below is added to the page like this:
<pre>
&lt;center>&lt;wxp class="wxButton" width="50%">
&lt;param name="label" value="It works!">
&lt;param name="id" value="wxID_OK">
&lt;/wxp>&lt;/center>
</pre>
<hr>
<center>
<wxp class="wxButton" width="50%">
<param name="label" value="It works!">
<param name="id" value="wxID_OK">
</wxp>
</center>
<p>
Notice that the <b>button click</b> event is actually caught by the panel
that contains this window, which then logs it in the window below.

View File

@@ -60,6 +60,42 @@ command_lines = [
"-a -u -n WizTest1 bmp_source/wiztest1.bmp images.py",
"-a -u -n WizTest2 bmp_source/wiztest2.bmp images.py",
" -u -c bmp_source/001.png throbImages.py",
"-a -u -c bmp_source/002.png throbImages.py",
"-a -u -c bmp_source/003.png throbImages.py",
"-a -u -c bmp_source/004.png throbImages.py",
"-a -u -c bmp_source/005.png throbImages.py",
"-a -u -c bmp_source/006.png throbImages.py",
"-a -u -c bmp_source/007.png throbImages.py",
"-a -u -c bmp_source/008.png throbImages.py",
"-a -u -c bmp_source/009.png throbImages.py",
"-a -u -c bmp_source/010.png throbImages.py",
"-a -u -c bmp_source/011.png throbImages.py",
"-a -u -c bmp_source/012.png throbImages.py",
"-a -u -c bmp_source/013.png throbImages.py",
"-a -u -c bmp_source/014.png throbImages.py",
"-a -u -c bmp_source/015.png throbImages.py",
"-a -u -c bmp_source/016.png throbImages.py",
"-a -u -c bmp_source/017.png throbImages.py",
"-a -u -c bmp_source/018.png throbImages.py",
"-a -u -c bmp_source/019.png throbImages.py",
"-a -u -c bmp_source/020.png throbImages.py",
"-a -u -c bmp_source/021.png throbImages.py",
"-a -u -c bmp_source/022.png throbImages.py",
"-a -u -c bmp_source/023.png throbImages.py",
"-a -u -c bmp_source/024.png throbImages.py",
"-a -u -c bmp_source/025.png throbImages.py",
"-a -u -c bmp_source/026.png throbImages.py",
"-a -u -c bmp_source/027.png throbImages.py",
"-a -u -c bmp_source/028.png throbImages.py",
"-a -u -c bmp_source/029.png throbImages.py",
"-a -u -c bmp_source/030.png throbImages.py",
"-a -u -c bmp_source/eclouds.png throbImages.py",
"-a -u -c bmp_source/logo.png throbImages.py",
"-a -u -c bmp_source/rest.png throbImages.py",
]

View File

@@ -1,5 +1,5 @@
#----------------------------------------------------------------------
# This file was generated by C:\projects\wx\wxPython\demo\encode_bitmaps.py
# This file was generated by encode_bitmaps.py
#
from wxPython.wx import wxImageFromStream, wxBitmapFromImage
from wxPython.wx import wxEmptyIcon

View File

@@ -25,7 +25,9 @@ from wxPython.wx import *
class Log:
def WriteText(self, text):
sys.stdout.write(text)
if text[-1:] == '\n':
text = text[:-1]
wxLogMessage(text)
write = WriteText
@@ -38,6 +40,8 @@ class RunDemoApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
wxLog_SetActiveTarget(wxLogStderr())
frame = wxFrame(None, -1, "RunDemo: " + self.name, size=(0,0),
style=wxNO_FULL_REPAINT_ON_RESIZE|wxDEFAULT_FRAME_STYLE)
frame.CreateStatusBar()

1
wxPython/demo/setup.sh Executable file
View File

@@ -0,0 +1 @@
export PYTHONPATH=/projects/wx/wxPython

4362
wxPython/demo/throbImages.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -19,19 +19,33 @@ class TestPanel(wxPanel):
b = wxButton(self, 20, "HELLO AGAIN!", wxPoint(20, 60), wxSize(120, 45))
EVT_BUTTON(self, 20, self.OnClick)
b.SetToolTipString("This is a Hello button...")
bmp = images.getTest2Bitmap()
mask = wxMaskColour(bmp, wxBLUE)
bmp.SetMask(mask)
if 0: # a test case for catching wxPyAssertionError
#wxGetApp().SetAssertMode(wxPYAPP_ASSERT_SUPPRESS)
#wxGetApp().SetAssertMode(wxPYAPP_ASSERT_EXCEPTION)
#wxGetApp().SetAssertMode(wxPYAPP_ASSERT_DIALOG)
#wxGetApp().SetAssertMode(wxPYAPP_ASSERT_EXCEPTION | wxPYAPP_ASSERT_DIALOG)
try:
bmp = wxBitmap("nosuchfile.bmp", wxBITMAP_TYPE_BMP)
mask = wxMaskColour(bmp, wxBLUE)
except wxPyAssertionError:
self.log.write("Caught wxPyAssertionError! I will fix the problem.\n")
bmp = images.getTest2Bitmap()
mask = wxMaskColour(bmp, wxBLUE)
else:
bmp = images.getTest2Bitmap()
mask = wxMaskColour(bmp, wxBLUE)
bmp.SetMask(mask)
wxBitmapButton(self, 30, bmp, wxPoint(160, 20),
wxSize(bmp.GetWidth()+10, bmp.GetHeight()+10))
EVT_BUTTON(self, 30, self.OnClick)
def OnClick(self, event):
self.log.WriteText("Click! (%d)\n" % event.GetId())
self.log.write("Click! (%d)\n" % event.GetId())
#----------------------------------------------------------------------
@@ -43,15 +57,19 @@ def runTest(frame, nb, log):
#----------------------------------------------------------------------
overview = """<html><body>
<h2>wxButton</h2>
A button is a control that contains a text string or a bitmap and cab be
placed on nearly any kind of window.
overview = """\
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -19,6 +19,11 @@ class TestPanel(wxPanel):
EVT_BUTTON(self, b.GetId(), self.OnButton)
self.cal = cal
# Set up control to display a set of holidays:
EVT_CALENDAR_MONTH(self, cal.GetId(), self.OnChangeMonth)
self.holidays = [(1,1), (10,31), (12,25) ] # (these don't move around)
self.OnChangeMonth()
def OnButton(self, evt):
self.cal.Destroy()
self.cal = None
@@ -26,6 +31,11 @@ class TestPanel(wxPanel):
def OnCalSelected(self, evt):
self.log.write('OnCalSelected: %s\n' % evt.GetDate())
def OnChangeMonth(self, evt=None):
cur_month = self.cal.GetDate().GetMonth() + 1 # convert wxDateTime 0-11 => 1-12
for month, day in self.holidays:
if month == cur_month:
self.cal.SetHoliday(day)
#----------------------------------------------------------------------

View File

@@ -22,7 +22,8 @@ class TestPanel(wxPanel):
lb.SetSelection(0)
self.lb = lb
btn = wxButton(self, -1, "Test SetString", (180, 50))
pos = lb.GetPosition().x + lb.GetSize().width + 25
btn = wxButton(self, -1, "Test SetString", (pos, 50))
EVT_BUTTON(self, btn.GetId(), self.OnTestButton)
EVT_RIGHT_UP(self, self.OnDoPopup)

View File

@@ -4,7 +4,10 @@ from wxPython.wx import *
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = wxDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200), style=wxCAPTION)
win = wxDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200),
style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
#style = wxDEFAULT_DIALOG_STYLE
)
sizer = wxBoxSizer(wxVERTICAL)
@@ -63,10 +66,13 @@ def runTest(frame, nb, log):
overview = """\
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -89,6 +89,10 @@ class SimpleView(wxPanel):
#----------------------------------------------------------------------
def runTest(frame, nb, log):
if wxPlatform == "__WXMAC__":
wxMessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
return
if 1:
win = wxDynamicSashWindow(nb, -1, style = 0
| wxCLIP_CHILDREN
@@ -149,3 +153,10 @@ You will need to set the scrollbars' event handler at three times:
</ul>
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -4,12 +4,13 @@ from wxPython.wx import *
#---------------------------------------------------------------------------
buttonDefs = {
814 : ('GridSimple', 'Simple wxGrid, catching all events'),
815 : ('GridStdEdRend', 'wxGrid showing Editors and Renderers'),
818 : ('GridHugeTable', 'A wxGrid with a HUGE table (100 MILLION cells!)'),
817 : ('GridCustTable', 'wxGrid using a custom Table, with non-string data'),
819 : ('GridEnterHandler','Remapping keys to behave differently'),
820 : ('GridCustEditor', 'Shows how to create a custom Cell Editor'),
814 : ('GridSimple', ' Simple wxGrid, catching all events '),
815 : ('GridStdEdRend', ' wxGrid showing Editors and Renderers '),
818 : ('GridHugeTable', ' A wxGrid with a HUGE table (100 MILLION cells!) '),
817 : ('GridCustTable', ' wxGrid using a custom Table, with non-string data '),
819 : ('GridEnterHandler',' Remapping keys to behave differently '),
820 : ('GridCustEditor', ' Shows how to create a custom Cell Editor '),
821 : ('GridDragable', ' A wxGrid with dragable rows and columns '),
}

View File

@@ -43,6 +43,23 @@ class MyHtmlWindow(wxHtmlWindow):
self.base_OnCellClicked(cell, x, y, evt)
# This filter doesn't really do anything but show how to use filters
class MyHtmlFilter(wxHtmlFilter):
def __init__(self, log):
wxHtmlFilter.__init__(self)
self.log = log
# This method decides if this filter is able to read the file
def CanRead(self, fsfile):
self.log.write("CanRead: %s\n" % fsfile.GetMimeType())
return FALSE
# If CanRead returns true then this method is called to actually
# read the file and return the contents.
def ReadFile(self, fsfile):
return ""
class TestHtmlPanel(wxPanel):
def __init__(self, parent, frame, log):
wxPanel.__init__(self, parent, -1, style=wxNO_FULL_REPAINT_ON_RESIZE)
@@ -52,6 +69,8 @@ class TestHtmlPanel(wxPanel):
if not self.cwd:
self.cwd = os.getcwd()
wxHtmlWindow_AddFilter(MyHtmlFilter(log))
self.html = MyHtmlWindow(self, -1, log)
self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
self.html.SetRelatedStatusBar(0)
@@ -168,15 +187,27 @@ def runTest(frame, nb, log):
overview = """\
wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
overview = """<html><body>
<h2>wxHtmlWindow</h2>
It is not intended to be a high-end HTML browser. If you're looking for something like that try http://www.mozilla.org - there's a chance you'll be able to make their widget wxWindows-compatible. I'm sure everyone will enjoy your work in that case...
<p>wxHtmlWindow is capable of parsing and rendering most
simple HTML tags.
<p>It is not intended to be a high-end HTML browser. If you're
looking for something like that try http://www.mozilla.org - there's a
chance you'll be able to make their widget wxWindows-compatible. I'm
sure everyone will enjoy your work in that case...
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -9,7 +9,7 @@ if wxPlatform == '__WXMSW__':
class TestPanel(wxWindow):
def __init__(self, parent, log, frame=None):
wxWindow.__init__(self, parent, -1,
style=wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
style=wxTAB_TRAVERSAL|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
self.log = log
self.current = "http://wxWindows.org/"
self.frame = frame

View File

@@ -10,7 +10,7 @@ class TestPanel(wxPanel):
def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1)
data = open(opj('bitmaps/image.gif'), "rb").read()
data = open(opj('bitmaps/image.png'), "rb").read()
stream = StringIO(data)
bmp = wxBitmapFromImage( wxImageFromStream( stream ))
@@ -18,8 +18,7 @@ class TestPanel(wxPanel):
wxStaticText(self, -1,
"This image was loaded from a Python file-like object:",
(15, 15))
wxStaticBitmap(self, -1, bmp, (15, 45))
wxStaticBitmap(self, -1, bmp, (15, 45))#, (bmp.GetWidth(), bmp.GetHeight()))

View File

@@ -10,10 +10,12 @@ class wxFindPrefixListBox(wxListBox):
choices=[], style=0, validator=wxDefaultValidator):
wxListBox.__init__(self, parent, id, pos, size, choices, style, validator)
self.typedText = ''
EVT_KEY_UP(self, self.OnKey)
self.log = parent.log
EVT_KEY_DOWN(self, self.OnKey)
def FindPrefix(self, prefix):
self.log.WriteText('Looking for prefix: %s\n' % prefix)
if prefix:
prefix = string.lower(prefix)
length = len(prefix)
@@ -21,7 +23,9 @@ class wxFindPrefixListBox(wxListBox):
text = self.GetString(x)
text = string.lower(text)
if text[:length] == prefix:
self.log.WriteText('Prefix %s is found.\n' % prefix)
return x
self.log.WriteText('Prefix %s is not found.\n' % prefix)
return -1
@@ -43,8 +47,12 @@ class wxFindPrefixListBox(wxListBox):
self.SetSelection(item)
else:
self.typedText = ''
evt.Skip()
def OnKeyDown(self, evt):
pass
#---------------------------------------------------------------------------
@@ -90,7 +98,9 @@ class TestListBox(wxPanel):
def EvtListBox(self, event):
self.log.WriteText('EvtListBox: %s\n' % event.GetString())
self.log.WriteText('EvtListBox: %s, %s, %s\n' %
(event.GetString(), event.IsSelection(), event.GetSelection()))
lb = event.GetEventObject()
data = lb.GetClientData(lb.GetSelection())
if data is not None:
@@ -127,14 +137,19 @@ def runTest(frame, nb, log):
overview = """\
A listbox is used to select one or more of a list of strings. The strings are displayed in a scrolling box, with the selected string(s) marked in reverse video. A listbox can be single selection (if an item is selected, the previous selection is removed) or multiple selection (clicking an item toggles the item on or off independently of other selections).
overview = """<html><body>
A listbox is used to select one or more of a list of
strings. The strings are displayed in a scrolling box, with the
selected string(s) marked in reverse video. A listbox can be single
selection (if an item is selected, the previous selection is removed)
or multiple selection (clicking an item toggles the item on or off
independently of other selections).
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -191,7 +191,9 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin):
self.x = event.GetX()
self.y = event.GetY()
self.log.WriteText("x, y = %s\n" % str((self.x, self.y)))
print event.GetEventObject()
item, flags = self.list.HitTest((self.x, self.y))
if flags & wxLIST_HITTEST_ONITEM:
self.list.Select(item)
event.Skip()
@@ -213,17 +215,19 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin):
# this does
self.list.SetItemState(10, 0, wxLIST_STATE_SELECTED)
# Show how to reselect something we don't want deselected
def OnItemDeselected(self, evt):
item = evt.GetItem()
print evt.m_itemIndex
self.log.WriteText("OnItemDeselected: %d" % evt.m_itemIndex)
# Show how to reselect something we don't want deselected
if evt.m_itemIndex == 11:
wxCallAfter(self.list.SetItemState, 11, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
def OnItemActivated(self, event):
self.currentItem = event.m_itemIndex
self.log.WriteText("OnItemActivated: %s\n" % self.list.GetItemText(self.currentItem))
self.log.WriteText("OnItemActivated: %s\nTopItem: %s" %
(self.list.GetItemText(self.currentItem), self.list.GetTopItem()))
def OnItemDelete(self, event):
self.log.WriteText("OnItemDelete\n")

View File

@@ -45,7 +45,8 @@ class TestVirtualList(wxListCtrl):
def OnItemActivated(self, event):
self.currentItem = event.m_itemIndex
self.log.WriteText("OnItemActivated: %s\n" % self.GetItemText(self.currentItem))
self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
(self.GetItemText(self.currentItem), self.GetTopItem()))
def getColumnText(self, index, col):
item = self.GetItem(index, col)

View File

@@ -17,6 +17,7 @@ class MyMiniFrame(wxMiniFrame):
self.Close(true)
def OnCloseWindow(self, event):
print "OnCloseWindow"
self.Destroy()
#---------------------------------------------------------------------------

View File

@@ -0,0 +1,90 @@
from wxPython.wx import *
from wxPython.lib.multisash import wxMultiSash
from wxPython.stc import *
#---------------------------------------------------------------------------
sampleText="""\
You can drag the little tab on the vertical sash left to create another view,
or you can drag the tab on the horizontal sash to the top to create another
horizontal view.
The red blocks on the sashes will destroy the view (bottom,left) this block
belongs to.
A yellow rectangle also highlights the current selected view.
By calling GetSaveData on the multiSash control the control will return its
contents and the positions of each sash as a dictionary.
Calling SetSaveData with such a dictionary will restore the control to the
state it was in when it was saved.
If the class, that is used as a view, has GetSaveData/SetSaveData implemented,
these will also be called to save/restore their state. Any object can be
returned by GetSaveData, as it is just another object in the dictionary.
"""
#---------------------------------------------------------------------------
class TestWindow(wxStyledTextCtrl):
def __init__(self, parent):
wxStyledTextCtrl.__init__(self, parent, -1, style=wxNO_BORDER)
self.SetMarginWidth(1,0)
if wxPlatform == '__WXMSW__':
fSize = 10
else:
fSize = 12
self.StyleSetFont(wxSTC_STYLE_DEFAULT,
wxFont(fSize, wxMODERN, wxNORMAL, wxNORMAL))
self.SetText(sampleText)
class TestFrame(wxFrame):
def __init__(self, parent, log):
wxFrame.__init__(self, parent, -1, "Multi Sash Demo",
size=(640,480))
self.multi = wxMultiSash(self,-1,pos = wxPoint(0,0),
size = (640,480))
# Use this method to set the default class that will be created when
# a new sash is created. The class's constructor needs 1 parameter
# which is the parent of the window
self.multi.SetDefaultChildClass(TestWindow)
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
multi = wxMultiSash(nb, -1, pos = (0,0), size = (640,480))
# Use this method to set the default class that will be created when
# a new sash is created. The class's constructor needs 1 parameter
# which is the parent of the window
multi.SetDefaultChildClass(TestWindow)
return multi
# win = TestPanel(nb, log)
# return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2><center>wxMultiSash</center></h2>
wxMultiSash allows the user to split a window any number of times
either horizontally or vertically, and to close the split off windows
when desired.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -0,0 +1,94 @@
from wxPython.wx import *
from wxPython.lib.popupctl import wxPopupControl
from wxPython.calendar import *
class TestDateControl(wxPopupControl):
def __init__(self,*_args,**_kwargs):
apply(wxPopupControl.__init__,(self,) + _args,_kwargs)
self.win = wxWindow(self,-1,pos = (0,0),style = 0)
self.cal = wxCalendarCtrl(self.win,-1,pos = (0,0))
bz = self.cal.GetBestSize()
self.win.SetSize(bz)
# This method is needed to set the contents that will be displayed
# in the popup
self.SetPopupContent(self.win)
# Event registration for date selection
EVT_CALENDAR_DAY(self.cal,self.cal.GetId(),self.OnCalSelected)
# Method called when a day is selected in the calendar
def OnCalSelected(self,evt):
self.PopDown()
date = self.cal.GetDate()
# Format the date that was selected for the text part of the control
self.SetValue('%02d/%02d/%04d' % (date.GetDay(),
date.GetMonth()+1,
date.GetYear()))
evt.Skip()
# Method overridden from wxPopupControl
# This method is called just before the popup is displayed
# Use this method to format any controls in the popup
def FormatContent(self):
# I parse the value in the text part to resemble the correct date in
# the calendar control
txtValue = self.GetValue()
dmy = txtValue.split('/')
didSet = false
if len(dmy) == 3:
date = self.cal.GetDate()
d = int(dmy[0])
m = int(dmy[1]) - 1
y = int(dmy[2])
if d > 0 and d < 31:
if m >= 0 and m < 12:
if y > 1000:
self.cal.SetDate(wxDateTimeFromDMY(d,m,y))
didSet = true
if not didSet:
self.cal.SetDate(wxDateTime_Today())
#---------------------------------------------------------------------------
class TestPanel(wxPanel):
def __init__(self, parent, log):
self.log = log
wxPanel.__init__(self, parent, -1)
date = TestDateControl(self, -1, pos = (30,30), size = (100,22))
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2><center>wxPopupControl</center></h2>
wxPopupControl is a class that can display a value and has a button
that will popup another window similar to how a wxComboBox works. The
popup window can contain whatever is needed to edit the value. This
example uses a wxCalendarCtrl.
<p>Currently a wxDialog is used for the popup. Eventually a
wxPopupWindow should be used...
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -70,7 +70,7 @@ class TestPanel(wxPanel):
self.process = wxProcess(self)
self.process.Redirect();
pid = wxExecute(cmd, false, self.process)
pid = wxExecute(cmd, wxEXEC_ASYNC, self.process)
self.log.write('OnExecuteBtn: "%s" pid: %s\n' % (cmd, pid))
self.inp.Enable(true)
@@ -99,11 +99,7 @@ class TestPanel(wxPanel):
if self.process is not None:
stream = self.process.GetInputStream()
# Yes, this is weird. For this particular stream, EOF
# simply means that there is no data available to be read,
# not truly the end of file. Also, read() just reads all
# the currently available data, not until the real EOF...
if not stream.eof():
if stream.CanRead():
text = stream.read()
self.out.AppendText(text)
@@ -113,7 +109,7 @@ class TestPanel(wxPanel):
(evt.GetPid(), evt.GetExitCode()))
stream = self.process.GetInputStream()
if not stream.eof():
if stream.CanRead():
text = stream.read()
self.out.AppendText(text)

View File

@@ -3,10 +3,13 @@ from wxPython.wx import *
#---------------------------------------------------------------------------
RBOX1 = wxNewId()
RBOX2 = wxNewId()
RBUT1 = wxNewId()
RBUT2 = wxNewId()
RBUT3 = wxNewId()
RBUT4 = wxNewId()
RBOX1 = wxNewId()
RBOX2 = wxNewId()
class TestRadioButtons(wxPanel):
def __init__(self, parent, log):
@@ -33,15 +36,6 @@ class TestRadioButtons(wxPanel):
rb.SetToolTip(wxToolTip("This box has no label"))
sizer.Add(rb, 0, wxLEFT|wxRIGHT|wxBOTTOM, 20)
sizer.Add(wxStaticText(self, -1, "These are plain wxRadioButtons"),
0, wxLEFT|wxRIGHT, 20)
sizer.Add(wxRadioButton(self, RBUT1, "wxRadioButton 1"),
0, wxLEFT|wxRIGHT, 20)
sizer.Add(wxRadioButton(self, RBUT2, "wxRadioButton 2"),
0, wxLEFT|wxRIGHT, 20)
EVT_RADIOBUTTON(self, RBUT1, self.EvtRadioButton)
EVT_RADIOBUTTON(self, RBUT2, self.EvtRadioButton)
self.SetSizer(sizer)
@@ -49,7 +43,7 @@ class TestRadioButtons(wxPanel):
self.log.WriteText('EvtRadioBox: %d\n' % event.GetInt())
def EvtRadioButton(self, event):
self.log.write('EvtRadioButton:%d\n' % event.GetInt())
self.log.write('EvtRadioButton:%d\n' % event.GetId())
#---------------------------------------------------------------------------
@@ -57,21 +51,19 @@ def runTest(frame, nb, log):
win = TestRadioButtons(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
A radio box item is used to select one of number of mutually exclusive choices. It is displayed as a vertical column or horizontal row of labelled buttons.
A radio box item is used to select one of number of mutually exclusive
choices. It is displayed as a vertical column or horizontal row of
labelled buttons.
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -0,0 +1,119 @@
from wxPython.wx import *
#----------------------------------------------------------------------
class TestPanel( wxPanel ):
def __init__( self, parent, log ):
wxPanel.__init__( self, parent, -1 )
self.log = log
panel = wxPanel( self, -1 )
# 1st group of controls:
self.group1_ctrls = []
radio1 = wxRadioButton( panel, -1, "Radio1", style = wxRB_GROUP )
text1 = wxTextCtrl( panel, -1, "" )
radio2 = wxRadioButton( panel, -1, "Radio2" )
text2 = wxTextCtrl( panel, -1, "" )
radio3 = wxRadioButton( panel, -1, "Radio3" )
text3 = wxTextCtrl( panel, -1, "" )
self.group1_ctrls.append((radio1, text1))
self.group1_ctrls.append((radio2, text2))
self.group1_ctrls.append((radio3, text3))
# 2nd group of controls:
self.group2_ctrls = []
radio4 = wxRadioButton( panel, -1, "Radio1", style = wxRB_GROUP )
text4 = wxTextCtrl( panel, -1, "" )
radio5 = wxRadioButton( panel, -1, "Radio2" )
text5 = wxTextCtrl( panel, -1, "" )
radio6 = wxRadioButton( panel, -1, "Radio3" )
text6 = wxTextCtrl( panel, -1, "" )
self.group2_ctrls.append((radio4, text4))
self.group2_ctrls.append((radio5, text5))
self.group2_ctrls.append((radio6, text6))
# Layout controls on panel:
vs = wxBoxSizer( wxVERTICAL )
box1_title = wxStaticBox( panel, -1, "Group 1" )
box1 = wxStaticBoxSizer( box1_title, wxVERTICAL )
grid1 = wxFlexGridSizer( 0, 2, 0, 0 )
for radio, text in self.group1_ctrls:
grid1.AddWindow( radio, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
grid1.AddWindow( text, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
box1.AddSizer( grid1, 0, wxALIGN_CENTRE|wxALL, 5 )
vs.AddSizer( box1, 0, wxALIGN_CENTRE|wxALL, 5 )
box2_title = wxStaticBox( panel, -1, "Group 2" )
box2 = wxStaticBoxSizer( box2_title, wxVERTICAL )
grid2 = wxFlexGridSizer( 0, 2, 0, 0 )
for radio, text in self.group2_ctrls:
grid2.AddWindow( radio, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
grid2.AddWindow( text, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
box2.AddSizer( grid2, 0, wxALIGN_CENTRE|wxALL, 5 )
vs.AddSizer( box2, 0, wxALIGN_CENTRE|wxALL, 5 )
panel.SetSizer( vs )
vs.Fit( panel )
panel.Move( (50,50) )
self.panel = panel
# Setup event handling and initial state for controls:
for radio, text in self.group1_ctrls:
EVT_RADIOBUTTON( self, radio.GetId(), self.OnGroup1Select )
for radio, text in self.group2_ctrls:
EVT_RADIOBUTTON( self, radio.GetId(), self.OnGroup2Select )
for radio, text in self.group1_ctrls + self.group2_ctrls:
radio.SetValue(0)
text.Enable(FALSE)
def OnGroup1Select( self, event ):
radio_selected = event.GetEventObject()
self.log.write('Group1 %s selected\n' % radio_selected.GetLabel() )
for radio, text in self.group1_ctrls:
if radio is radio_selected:
text.Enable(TRUE)
else:
text.Enable(FALSE)
def OnGroup2Select( self, event ):
radio_selected = event.GetEventObject()
self.log.write('Group2 %s selected\n' % radio_selected.GetLabel() )
for radio, text in self.group2_ctrls:
if radio is radio_selected:
text.Enable(TRUE)
else:
text.Enable(FALSE)
#----------------------------------------------------------------------
def runTest( frame, nb, log ):
win = TestPanel( nb, log )
return win
#----------------------------------------------------------------------
overview = """
<html><body>
<P>
This demo shows how individual radio buttons can be used to build
more complicated selection mechanisms...
<P>
It uses 2 groups of wxRadioButtons, where the groups are defined by
instantiation. When a wxRadioButton is created with the <I>wxRB_GROUP</I>
style, all subsequent wxRadioButtons created without it are implicitly
added to that group by the framework.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -149,6 +149,7 @@ class MyCanvas(wxScrolledWindow):
def OnLeftButtonEvent(self, event):
if event.LeftDown():
self.SetFocus()
self.SetXY(event)
self.curLine = []
self.CaptureMouse()

View File

@@ -35,8 +35,12 @@ def runTest(frame, nb, log):
wxStaticText(p2, -1, "Panel Two", wxPoint(5,5)).SetBackgroundColour(wxBLUE)
splitter.SetMinimumPaneSize(20)
splitter.SplitVertically(p1, p2)
splitter.SetSashPosition(100)
splitter.SplitVertically(p1, p2, 100)
## splitter.SetSize((300,300))
## print splitter.GetSashPosition()
## splitter.SetSashPosition(100)
## print splitter.GetSashPosition()
return splitter

View File

@@ -20,50 +20,64 @@ class TestPanel(wxPanel):
self.log = log
l1 = wxStaticText(self, -1, "wxTextCtrl")
t1 = wxTextCtrl(self, 10, "Test it out and see", size=(125, -1))
t1 = wxTextCtrl(self, -1, "Test it out and see", size=(125, -1))
t1.SetInsertionPoint(0)
EVT_TEXT(self, 10, self.EvtText)
self.tc1 = t1
EVT_TEXT(self, t1.GetId(), self.EvtText)
EVT_CHAR(t1, self.EvtChar)
EVT_SET_FOCUS(t1, self.OnSetFocus)
EVT_KILL_FOCUS(t1, self.OnKillFocus)
EVT_WINDOW_DESTROY(t1, self.OnWindowDestroy)
l2 = wxStaticText(self, -1, "Passsword")
t2 = wxTextCtrl(self, 20, "", size=(125, -1), style=wxTE_PASSWORD)
EVT_TEXT(self, 20, self.EvtText)
t2 = wxTextCtrl(self, -1, "", size=(125, -1), style=wxTE_PASSWORD)
EVT_TEXT(self, t2.GetId(), self.EvtText)
l3 = wxStaticText(self, -1, "Multi-line")
t3 = wxTextCtrl(self, 30,
t3 = wxTextCtrl(self, -1,
"Here is a looooooooooooooong line of text set in the control.\n\n"
"The quick brown fox jumped over the lazy dog...",
size=(200, 100), style=wxTE_MULTILINE)
t3.SetInsertionPoint(0)
EVT_TEXT(self, 30, self.EvtText)
EVT_TEXT(self, t3.GetId(), self.EvtText)
b = wxButton(self, -1, "Test Replace")
EVT_BUTTON(self, b.GetId(), self.OnTestReplace)
b2 = wxButton(self, -1, "Test GetSelection")
EVT_BUTTON(self, b2.GetId(), self.OnTestGetSelection)
b3 = wxButton(self, -1, "Test WriteText")
EVT_BUTTON(self, b3.GetId(), self.OnTestWriteText)
self.tc = t3
l4 = wxStaticText(self, -1, "Rich Text")
t4 = wxTextCtrl(self, 40, "If supported by the native control, this is red, and this is a different font.",
t4 = wxTextCtrl(self, -1, "If supported by the native control, this is red, and this is a different font.",
size=(200, 100), style=wxTE_MULTILINE|wxTE_RICH2)
t4.SetInsertionPoint(0)
t4.SetStyle(44, 47, wxTextAttr("RED", "YELLOW"))
points = t4.GetFont().GetPointSize() # get the current size
f = wxFont(points+3, wxROMAN, wxITALIC, wxBOLD, true)
t4.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour, f))
l5 = wxStaticText(self, -1, "Test Positions")
t5 = wxTextCtrl(self, -1, "0123456789\n" * 5, size=(200, 100),
style = wxTE_MULTILINE
#| wxTE_RICH
| wxTE_RICH2
)
EVT_LEFT_DOWN(t5, self.OnT5LeftDown)
self.t5 = t5
bsizer = wxBoxSizer(wxVERTICAL)
bsizer.Add(b, 0, wxGROW)
bsizer.Add(b2, 0, wxGROW)
bsizer.Add(b, 0, wxGROW|wxALL, 4)
bsizer.Add(b2, 0, wxGROW|wxALL, 4)
bsizer.Add(b3, 0, wxGROW|wxALL, 4)
sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6)
sizer.AddMany([ l1, t1, (0,0),
l2, t2, (0,0),
l3, t3, bsizer,
l4, t4, (0,0),
l5, t5, (0,0),
])
border = wxBoxSizer(wxVERTICAL)
border.Add(sizer, 0, wxALL, 25)
@@ -84,6 +98,9 @@ class TestPanel(wxPanel):
self.tc.Replace(5, 9, "IS A")
#self.tc.Remove(5, 9)
def OnTestWriteText(self, evt):
self.tc.WriteText("TEXT")
def OnTestGetSelection(self, evt):
start, end = self.tc.GetSelection()
text = self.tc.GetValue()
@@ -96,6 +113,22 @@ class TestPanel(wxPanel):
self.tc.GetStringSelection(),
repr(text[start:end])))
def OnT5LeftDown(self, evt):
evt.Skip()
wxCallAfter(self.LogT5Position, evt)
def LogT5Position(self, evt):
text = self.t5.GetValue()
ip = self.t5.GetInsertionPoint()
lp = self.t5.GetLastPosition()
self.log.write("LogT5Position:\n"
"\tGetInsertionPoint:\t%d\n"
"\ttext[insertionpoint]:\t%s\n"
"\tGetLastPosition:\t%d\n"
"\tlen(text):\t\t%d\n"
% (ip, text[ip], lp, len(text)))
#---------------------------------------------------------------------------

213
wxPython/demo/wxTimeCtrl.py Normal file
View File

@@ -0,0 +1,213 @@
from wxPython.wx import *
from wxPython.lib.timectrl import *
#----------------------------------------------------------------------
class TestPanel( wxPanel ):
def __init__( self, parent, log ):
wxPanel.__init__( self, parent, -1 )
self.log = log
panel = wxPanel( self, -1 )
grid = wxFlexGridSizer( 0, 2, 20, 0 )
text1 = wxStaticText( panel, 10, "A 12-hour format wxTimeCtrl:")
self.time12 = wxTimeCtrl( panel, 20, name="12 hour control" )
spin1 = wxSpinButton( panel, 30, wxDefaultPosition, wxSize(-1,20), 0 )
self.time12.BindSpinButton( spin1 )
grid.AddWindow( text1, 0, wxALIGN_RIGHT, 5 )
hbox1 = wxBoxSizer( wxHORIZONTAL )
hbox1.AddWindow( self.time12, 0, wxALIGN_CENTRE, 5 )
hbox1.AddWindow( spin1, 0, wxALIGN_CENTRE, 5 )
grid.AddSizer( hbox1, 0, wxLEFT, 5 )
text2 = wxStaticText( panel, 40, "A 24-hour format wxTimeCtrl:")
self.time24 = wxTimeCtrl( panel, 50, fmt24hr=true, name="24 hour control" )
spin2 = wxSpinButton( panel, 60, wxDefaultPosition, wxSize(-1,20), 0 )
self.time24.BindSpinButton( spin2 )
grid.AddWindow( text2, 0, wxALIGN_RIGHT|wxTOP|wxBOTTOM, 5 )
hbox2 = wxBoxSizer( wxHORIZONTAL )
hbox2.AddWindow( self.time24, 0, wxALIGN_CENTRE, 5 )
hbox2.AddWindow( spin2, 0, wxALIGN_CENTRE, 5 )
grid.AddSizer( hbox2, 0, wxLEFT, 5 )
text3 = wxStaticText( panel, 70, "A wxTimeCtrl without a spin button:")
self.spinless_ctrl = wxTimeCtrl( panel, 80, name="spinless control" )
grid.AddWindow( text3, 0, wxALIGN_RIGHT|wxTOP|wxBOTTOM, 5 )
grid.AddWindow( self.spinless_ctrl, 0, wxLEFT, 5 )
buttonChange = wxButton( panel, 100, "Change Controls")
self.radio12to24 = wxRadioButton( panel, 110, "Copy 12-hour time to 24-hour control", wxDefaultPosition, wxDefaultSize, wxRB_GROUP )
self.radio24to12 = wxRadioButton( panel, 120, "Copy 24-hour time to 12-hour control")
self.radioWx = wxRadioButton( panel, 130, "Set controls to 'now' using wxDateTime")
self.radioMx = wxRadioButton( panel, 140, "Set controls to 'now' using mxDateTime")
radio_vbox = wxBoxSizer( wxVERTICAL )
radio_vbox.AddWindow( self.radio12to24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
radio_vbox.AddWindow( self.radio24to12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
radio_vbox.AddWindow( self.radioWx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
radio_vbox.AddWindow( self.radioMx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
box_label = wxStaticBox( panel, 90, "Change Controls through API" )
buttonbox = wxStaticBoxSizer( box_label, wxHORIZONTAL )
buttonbox.AddWindow( buttonChange, 0, wxALIGN_CENTRE|wxALL, 5 )
buttonbox.AddSizer( radio_vbox, 0, wxALIGN_CENTRE|wxALL, 5 )
outer_box = wxBoxSizer( wxVERTICAL )
outer_box.AddSizer( grid, 0, wxALIGN_CENTRE|wxBOTTOM, 20 )
outer_box.AddSizer( buttonbox, 0, wxALIGN_CENTRE|wxALL, 5 )
# Turn on mxDateTime option only if we can import the module:
try:
from mx import DateTime
except ImportError:
self.radioMx.Enable( false )
panel.SetAutoLayout( true )
panel.SetSizer( outer_box )
outer_box.Fit( panel )
panel.Move( (50,50) )
self.panel = panel
EVT_TIMEUPDATE( self, self.time12.GetId(), self.OnTimeChange )
EVT_TIMEUPDATE( self, self.time24.GetId(), self.OnTimeChange )
EVT_TIMEUPDATE( self, self.spinless_ctrl.GetId(), self.OnTimeChange )
EVT_BUTTON( self, buttonChange.GetId(), self.OnButtonClick )
def OnTimeChange( self, event ):
timectrl = self.panel.FindWindowById( event.GetId() )
self.log.write('%s time = %s\n' % ( timectrl.GetName(), timectrl.GetValue() ) )
def OnButtonClick( self, event ):
if self.radio12to24.GetValue():
self.time24.SetValue( self.time12.GetValue() )
elif self.radio24to12.GetValue():
self.time12.SetValue( self.time24.GetValue() )
elif self.radioWx.GetValue():
now = wxDateTime_Now()
self.time12.SetWxDateTime( now )
self.time24.SetWxDateTime( now )
self.spinless_ctrl.SetWxDateTime( now )
elif self.radioMx.GetValue():
from mx import DateTime
now = DateTime.now()
self.time12.SetMxDateTime( now )
self.time24.SetMxDateTime( now )
self.spinless_ctrl.SetMxDateTime( now )
#----------------------------------------------------------------------
def runTest( frame, nb, log ):
win = TestPanel( nb, log )
return win
#----------------------------------------------------------------------
overview = """<html><body>
<P>
<B>wxTimeCtrl</B> provides a multi-cell control that allows manipulation of a time
value. It supports 12 or 24 hour format, and you can use wxDateTime or mxDateTime
to get/set values from the control.
<P>
Left/right/tab keys to switch cells within a wxTimeCtrl, and the up/down arrows act
like a spin control. wxTimeCtrl also allows for an actual spin button to be attached
to the control, so that it acts like the up/down arrow keys.
<P>
The <B>!</B> or <B>c</B> key sets the value of the control to <B><I>now.</I></B>
<P>
Here's the API for wxTimeCtrl:
<DL><PRE>
<B>wxTimeCtrl</B>(
parent, id = -1,
<B>value</B> = '12:00:00 AM',
pos = wxDefaultPosition,
size = wxDefaultSize,
<B>fmt24hr</B> = false,
<B>spinButton</B> = None,
<B>style</B> = wxTE_PROCESS_TAB,
name = "time")
</PRE>
<UL>
<DT><B>value</B>
<DD>If no initial value is set, the default will be midnight; if an illegal string
is specified, a ValueError will result. (You can always later set the initial time
with SetValue() after instantiation of the control.)
<DL><B>size</B>
<DD>The size of the control will be automatically adjusted for 12/24 hour format
if wxDefaultSize is specified.
<BR>
<DT><B>fmt24hr</B>
<DD>If true, control will display time in 24 hour time format; if false, it will
use 12 hour AM/PM format. SetValue() will adjust values accordingly for the
control, based on the format specified.
<BR>
<DT><B>spinButton</B>
<DD>If specified, this button's events will be bound to the behavior of the
wxTimeCtrl, working like up/down cursor key events. (See BindSpinButton.)
<BR>
<DT><B>style</B>
<DD>By default, wxTimeCtrl will process TAB events, by allowing tab to the
different cells within the control.
</DL>
</UL>
<BR>
<BR>
<DT><B>SetValue(time_string)</B>
<DD>Sets the value of the control to a particular time, given a valid time string;
raises ValueError on invalid value
<BR>
<DT><B>GetValue()</B>
<DD>Retrieves the string value of the time from the control
<BR>
<DT><B>SetWxDateTime(wxDateTime)</B>
<DD>Uses the time portion of a wxDateTime to construct a value for the control.
<BR>
<DT><B>GetWxDateTime()</B>
<DD>Retrieves the value of the control, and applies it to the wxDateTimeFromHMS()
constructor, and returns the resulting value. (This returns the date portion as
"today".)
<BR>
<DT><B>SetMxDateTime(mxDateTime)</B>
<DD>Uses the time portion of an mxDateTime to construct a value for the control.
<EM>NOTE:</EM> This imports mx.DateTime at runtime only if this or the Get function
is called.
<BR>
<DT><B>GetMxDateTime()</B>
<DD>Retrieves the value of the control and applies it to the DateTime.Time()
constructor, and returns the resulting value. (mxDateTime is smart enough to
know this is just a time value.)
<BR>
<DT><B>BindSpinButton(wxSpinBtton)</B>
<DD>Binds an externally created spin button to the control, so that up/down spin
events change the active cell or selection in the control (in addition to the
up/down cursor keys.) (This is primarily to allow you to create a "standard"
interface to time controls, as seen in Windows.)
<BR>
<DT><B>EVT_TIMEUPDATE(win, id, func)</B>
<DD>func is fired whenever the value of the control changes.
</DL>
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -15,7 +15,7 @@ class TestToolBar(wxFrame):
wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER|wxTB_FLAT)
tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER|wxTB_FLAT|wxTB_TEXT)
# wxTB_VERTICAL
#tb = wxToolBarSimple(self, -1, wxDefaultPosition, wxDefaultSize,
# wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
@@ -23,7 +23,8 @@ class TestToolBar(wxFrame):
self.CreateStatusBar()
tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'")
#tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'")
tb.AddLabelTool(10, "New", images.getNewBitmap(), shortHelp="New", longHelp="Long help for 'New'")
EVT_TOOL(self, 10, self.OnToolClick)
EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)

View File

@@ -30,7 +30,9 @@ class TestTreeCtrlPanel(wxPanel):
tID = NewId()
self.tree = MyTreeCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS# | wxTR_MULTIPLE
wxTR_HAS_BUTTONS
| wxTR_EDIT_LABELS
#| wxTR_MULTIPLE
#| wxTR_HIDE_ROOT
, self.log)
@@ -105,8 +107,20 @@ class TestTreeCtrlPanel(wxPanel):
if self.tree.GetItemText(event.GetItem()) == "The Root Item":
wxBell()
self.log.WriteText("You can't edit this one...\n")
# Lets just see what's visible of its children
cookie = 0
root = event.GetItem()
(child, cookie) = self.tree.GetFirstChild(root, cookie)
while child.IsOk():
self.log.WriteText("Child [%s] visible = %d" %
(self.tree.GetItemText(child),
self.tree.IsVisible(child)))
(child, cookie) = self.tree.GetNextChild(root, cookie)
event.Veto()
def OnEndEdit(self, event):
self.log.WriteText("OnEndEdit\n")
# show how to reject edit, we'll not allow any digits

View File

@@ -203,6 +203,10 @@ class TestValidateDialog(wxDialog):
#----------------------------------------------------------------------
def runTest(frame, nb, log):
if wxPlatform == "__WXMAC__":
wxMessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
return
win = TestValidatorPanel(nb)
return win
@@ -210,12 +214,6 @@ def runTest(frame, nb, log):
overview = """\
wxValidator is the base class for a family of validator classes that mediate between a class of control, and application data.
@@ -230,3 +228,11 @@ A validator has three major roles:
Validators can be plugged into controls dynamically.
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -11,7 +11,7 @@ resourceText = r'''<?xml version="1.0"?>
<object class="MyBluePanel" name="MyPanel">
<size>200,100</size>
<object class="wxStaticText" name="lable1">
<object class="wxStaticText" name="lable1" subclass="wxPython.wx.wxPreStaticText">
<label>This blue panel is a class derived from wxPanel,\nand is loaded by a custom wxXmlResourceHandler.</label>
<pos>10,10</pos>
</object>