1. wxHtmlHelpController and related classes
2. the C++ versions of wxSizer and firends, Python versions are 'depreciated' 3. wxPyEvent and wxPyCommandEvent, event classes that can carry some python objects through the event system and safely come back out again. 4. wxGridSizer and wxFlexGridSizer 5. wxValidator 6. wxPyOnDemandOutputWindow 7. several tweaks, fixes and additions of missing methods, etc. 8. and probably several other things I am forgetting since CVS was down so long... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3758 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -9,7 +9,8 @@ class MyAboutBox(wxDialog):
|
||||
text = '''
|
||||
<html>
|
||||
<body bgcolor="#AC76DE">
|
||||
<center><table bgcolor="#458154" width="100%%" cellspacing="0" cellpadding="0" border="1">
|
||||
<center><table bgcolor="#458154" width="100%%" cellspacing="0"
|
||||
cellpadding="0" border="1">
|
||||
<tr>
|
||||
<td align="center"><h1>wxPython %s</h1></td>
|
||||
</tr>
|
||||
@@ -24,9 +25,11 @@ sit back and enjoy. Be sure to take a peek at the source code for each
|
||||
demo item so you can learn how to use the classes yourself.</p>
|
||||
|
||||
<p><b>wxPython</b> is brought to you by <b>Robin Dunn</b> and<br>
|
||||
<b>Total Control Software</b>, Copyright (c) 1998-1999.</p>
|
||||
<b>Total Control Software</b>, Copyright (c) 1997-1999.</p>
|
||||
|
||||
<p><font size="-1">Please see <i>license.txt</i> for licensing information.</font></p>
|
||||
<p>
|
||||
<font size="-1">Please see <i>license.txt</i> for licensing information.</font>
|
||||
</p>
|
||||
|
||||
<p><wxp class="wxButton">
|
||||
<param name="label" value="Okay">
|
||||
@@ -37,10 +40,25 @@ demo item so you can learn how to use the classes yourself.</p>
|
||||
</html>
|
||||
'''
|
||||
def __init__(self, parent):
|
||||
wxDialog.__init__(self, parent, -1, 'About wxPython')
|
||||
self.html = wxHtmlWindow(self, -1, wxPoint(5,5), wxSize(400, 350))
|
||||
wxDialog.__init__(self, parent, -1, 'About the wxPython demo',
|
||||
size=wxSize(420, 380))
|
||||
self.html = wxHtmlWindow(self, -1)
|
||||
self.html.SetPage(self.text % wx.__version__)
|
||||
self.Fit()
|
||||
self.SetAutoLayout(true)
|
||||
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.html.SetConstraints(lc)
|
||||
self.Layout()
|
||||
|
||||
self.CentreOnParent(wxBOTH)
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -36,12 +36,12 @@ _treeList = [
|
||||
'wxTreeCtrl', 'wxSpinButton', 'wxStaticText', 'wxStaticBitmap',
|
||||
'wxRadioBox', 'wxSlider']),
|
||||
|
||||
('Window Layout', ['wxLayoutConstraints', 'Sizers']),
|
||||
('Window Layout', ['wxLayoutConstraints', 'Sizers', 'OldSizers']),
|
||||
|
||||
('Miscellaneous', ['wxTimer', 'wxGLCanvas', 'DialogUnits', 'wxImage',
|
||||
'PrintFramework', 'wxOGL']),
|
||||
('Miscellaneous', ['wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits',
|
||||
'wxImage', 'PrintFramework', 'wxOGL']),
|
||||
|
||||
('wxPython Library', ['Sizers', 'Layoutf', 'wxScrolledMessageDialog',
|
||||
('wxPython Library', ['OldSizers', 'Layoutf', 'wxScrolledMessageDialog',
|
||||
'wxMultipleChoiceDialog', 'wxPlotCanvas']),
|
||||
|
||||
('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']),
|
||||
@@ -52,8 +52,8 @@ _treeList = [
|
||||
|
||||
class wxPythonDemo(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, -1, title,
|
||||
wxDefaultPosition, wxSize(700, 550))
|
||||
wxFrame.__init__(self, parent, -1, title, size = (725, 550))
|
||||
|
||||
if wxPlatform == '__WXMSW__':
|
||||
self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
|
||||
self.SetIcon(self.icon)
|
||||
@@ -72,9 +72,9 @@ class wxPythonDemo(wxFrame):
|
||||
# Make a File menu
|
||||
self.mainmenu = wxMenuBar()
|
||||
menu = wxMenu()
|
||||
mID = wxNewId()
|
||||
menu.Append(mID, 'E&xit', 'Get the heck outta here!')
|
||||
EVT_MENU(self, mID, self.OnFileExit)
|
||||
exitID = wxNewId()
|
||||
menu.Append(exitID, 'E&xit\tCtrl-X', 'Get the heck outta here!')
|
||||
EVT_MENU(self, exitID, self.OnFileExit)
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
|
||||
# Make a Demo menu
|
||||
@@ -90,13 +90,18 @@ class wxPythonDemo(wxFrame):
|
||||
|
||||
|
||||
# Make a Help menu
|
||||
mID = wxNewId()
|
||||
helpID = wxNewId()
|
||||
menu = wxMenu()
|
||||
menu.Append(mID, '&About', 'wxPython RULES!!!')
|
||||
EVT_MENU(self, mID, self.OnHelpAbout)
|
||||
menu.Append(helpID, '&About\tCtrl-H', 'wxPython RULES!!!')
|
||||
EVT_MENU(self, helpID, self.OnHelpAbout)
|
||||
self.mainmenu.Append(menu, '&Help')
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
|
||||
# set the menu accellerator table...
|
||||
aTable = wxAcceleratorTable([(wxACCEL_CTRL, ord('X'), exitID),
|
||||
(wxACCEL_CTRL, ord('H'), helpID)])
|
||||
self.SetAcceleratorTable(aTable)
|
||||
|
||||
|
||||
# Create a TreeCtrl
|
||||
tID = wxNewId()
|
||||
@@ -113,6 +118,7 @@ class wxPythonDemo(wxFrame):
|
||||
EVT_TREE_ITEM_EXPANDED (self.tree, tID, self.OnItemExpanded)
|
||||
EVT_TREE_ITEM_COLLAPSED (self.tree, tID, self.OnItemCollapsed)
|
||||
EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged)
|
||||
###EVT_TREE_SEL_CHANGING (self.tree, tID, self.OnSelChanging)
|
||||
|
||||
# Create a Notebook
|
||||
self.nb = wxNotebook(splitter2, -1)
|
||||
@@ -190,6 +196,7 @@ class wxPythonDemo(wxFrame):
|
||||
def OnSelChanged(self, event):
|
||||
if self.dying:
|
||||
return
|
||||
###print 'OnSelChanged entry'
|
||||
|
||||
if self.nb.GetPageCount() == 3:
|
||||
if self.nb.GetSelection() == 2:
|
||||
@@ -228,6 +235,11 @@ class wxPythonDemo(wxFrame):
|
||||
self.txt.Clear()
|
||||
self.window = None
|
||||
|
||||
###print 'OnSelChanged exit: ', itemText
|
||||
|
||||
###def OnSelChanging(self, event):
|
||||
### print 'OnSelChanging'
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
# Get the Demo files
|
||||
@@ -288,15 +300,15 @@ class wxPythonDemo(wxFrame):
|
||||
|
||||
#---------------------------------------------
|
||||
def OnDemoMenu(self, event):
|
||||
print event.GetId(), self.mainmenu.GetLabel(event.GetId())
|
||||
try:
|
||||
selectedDemo = self.treeMap[self.mainmenu.GetLabel(event.GetId())]
|
||||
except:
|
||||
selectedDemo = None
|
||||
if selectedDemo:
|
||||
###print "---- start ----"
|
||||
self.tree.SelectItem(selectedDemo)
|
||||
self.tree.EnsureVisible(selectedDemo)
|
||||
|
||||
###print "---- end ----"
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
365
utils/wxPython/demo/OldSizers.py
Normal file
365
utils/wxPython/demo/OldSizers.py
Normal file
@@ -0,0 +1,365 @@
|
||||
#----------------------------------------------------------------------
|
||||
# sizer test code
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.sizers import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox1(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 0)
|
||||
box.Add(wxButton(win, 1010, "four"), 0)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox2(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 0)
|
||||
box.Add(wxButton(win, 1010, "four"), 0)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox3(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 0)
|
||||
box.Add(wxButton(win, 1010, "four"), 0)
|
||||
box.Add(wxButton(win, 1010, "five"), 1)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox4(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 1)
|
||||
box.Add(wxButton(win, 1010, "four"), 1)
|
||||
box.Add(wxButton(win, 1010, "five"), 1)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox5(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 3)
|
||||
box.Add(wxButton(win, 1010, "four"), 1)
|
||||
box.Add(wxButton(win, 1010, "five"), 1)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox6(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL, wxSize(250, 50))
|
||||
box.Add(wxButton(win, 1010, "10"), 10)
|
||||
box.Add(wxButton(win, 1010, "20"), 20)
|
||||
box.Add(wxButton(win, 1010, "30"), 30)
|
||||
box.Add(wxButton(win, 1010, "15"), 15)
|
||||
box.Add(wxButton(win, 1010, "5"), 5)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder1(win):
|
||||
bdr = wxBorderSizer(wxALL)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder2(win):
|
||||
bdr = wxBorderSizer(wxEAST | wxWEST)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder3(win):
|
||||
bdr = wxBorderSizer(wxNORTH | wxWEST)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeBoxInBox(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
box.Add(wxButton(win, 1010, "one"))
|
||||
|
||||
box2 = wxBoxSizer(wxHORIZONTAL)
|
||||
box2.AddMany([ wxButton(win, 1010, "two"),
|
||||
wxButton(win, 1010, "three"),
|
||||
wxButton(win, 1010, "four"),
|
||||
wxButton(win, 1010, "five"),
|
||||
])
|
||||
|
||||
box3 = wxBoxSizer(wxVERTICAL)
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0),
|
||||
(wxButton(win, 1010, "seven"), 2),
|
||||
(wxButton(win, 1010, "eight"), 1),
|
||||
(wxButton(win, 1010, "nine"), 1),
|
||||
])
|
||||
|
||||
box2.Add(box3, 1)
|
||||
box.Add(box2, 1)
|
||||
|
||||
box.Add(wxButton(win, 1010, "ten"))
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeBoxInBorder(win):
|
||||
bdr = wxBorderSizer(wxALL)
|
||||
box = makeSimpleBox3(win)
|
||||
bdr.Add(box, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeBorderInBox(win):
|
||||
insideBox = wxBoxSizer(wxHORIZONTAL)
|
||||
|
||||
box2 = wxBoxSizer(wxHORIZONTAL)
|
||||
box2.AddMany([ wxButton(win, 1010, "one"),
|
||||
wxButton(win, 1010, "two"),
|
||||
wxButton(win, 1010, "three"),
|
||||
wxButton(win, 1010, "four"),
|
||||
wxButton(win, 1010, "five"),
|
||||
])
|
||||
|
||||
insideBox.Add(box2, 0)
|
||||
|
||||
bdr = wxBorderSizer(wxALL)
|
||||
bdr.Add(wxButton(win, 1010, "border"), 20)
|
||||
insideBox.Add(bdr, 1)
|
||||
|
||||
box3 = wxBoxSizer(wxVERTICAL)
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0),
|
||||
(wxButton(win, 1010, "seven"), 2),
|
||||
(wxButton(win, 1010, "eight"), 1),
|
||||
(wxButton(win, 1010, "nine"), 1),
|
||||
])
|
||||
insideBox.Add(box3, 1)
|
||||
|
||||
outsideBox = wxBoxSizer(wxVERTICAL)
|
||||
outsideBox.Add(wxButton(win, 1010, "top"))
|
||||
outsideBox.Add(insideBox, 1)
|
||||
outsideBox.Add(wxButton(win, 1010, "bottom"))
|
||||
|
||||
return outsideBox
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
theTests = [
|
||||
("Simple horizontal boxes", makeSimpleBox1,
|
||||
"This is a HORIZONTAL box sizer with four non-stretchable buttons held "
|
||||
"within it. Notice that the buttons are added and aligned in the horizontal "
|
||||
"dimension. Also notice that they are fixed size in the horizontal dimension, "
|
||||
"but will stretch vertically."
|
||||
),
|
||||
|
||||
("Simple vertical boxes", makeSimpleBox2,
|
||||
"Exactly the same as the previous sample but using a VERTICAL box sizer "
|
||||
"instead of a HORIZONTAL one."
|
||||
),
|
||||
|
||||
("Add a stretchable", makeSimpleBox3,
|
||||
"We've added one more button with the strechable flag turned on. Notice "
|
||||
"how it grows to fill the extra space in the otherwise fixed dimension."
|
||||
),
|
||||
|
||||
("More than one stretchable", makeSimpleBox4,
|
||||
"Here there are several items that are stretchable, they all divide up the "
|
||||
"extra space evenly."
|
||||
),
|
||||
|
||||
("Weighting factor", makeSimpleBox5,
|
||||
"This one shows more than one strechable, but one of them has a weighting "
|
||||
"factor so it gets more of the free space."
|
||||
),
|
||||
|
||||
# ("Percent Sizer", makeSimpleBox6,
|
||||
# "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
|
||||
# "the weighting factors add up to 100!"
|
||||
# ),
|
||||
|
||||
("", None, ""),
|
||||
|
||||
("Simple border sizer", makeSimpleBorder1,
|
||||
"The wxBorderSizer leaves empty space around its contents. This one "
|
||||
"gives a border all the way around."
|
||||
),
|
||||
|
||||
("East and West border", makeSimpleBorder2,
|
||||
"You can pick and choose which sides have borders."
|
||||
),
|
||||
|
||||
("North and West border", makeSimpleBorder3,
|
||||
"You can pick and choose which sides have borders."
|
||||
),
|
||||
|
||||
("", None, ""),
|
||||
|
||||
("Boxes inside of boxes", makeBoxInBox,
|
||||
"This one shows nesting of boxes within boxes within boxes, using both "
|
||||
"orientations. Notice also that button seven has a greater weighting "
|
||||
"factor than its siblings."
|
||||
),
|
||||
|
||||
("Boxes inside a Border", makeBoxInBorder,
|
||||
"Sizers of different types can be nested withing each other as well. "
|
||||
"Here is a box sizer with several buttons embedded within a border sizer."
|
||||
),
|
||||
|
||||
("Border in a Box", makeBorderInBox,
|
||||
"Another nesting example. This one has Boxes and a Border inside another Box."
|
||||
),
|
||||
|
||||
]
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, title, sizerFunc):
|
||||
wxFrame.__init__(self, parent, -1, title)
|
||||
EVT_BUTTON(self, 1010, self.OnButton)
|
||||
|
||||
self.sizer = sizerFunc(self)
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("Resize this frame to see how the sizers respond...")
|
||||
self.sizer.FitWindow(self)
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
self.sizer.Layout(size)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.MakeModal(false)
|
||||
self.Destroy()
|
||||
|
||||
def OnButton(self, event):
|
||||
self.Close(true)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
class TestSelectionPanel(wxPanel):
|
||||
def __init__(self, parent, frame):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.frame = frame
|
||||
|
||||
self.list = wxListBox(self, 401,
|
||||
wxDLG_PNT(self, 10, 10), wxDLG_SZE(self, 100, 60),
|
||||
[])
|
||||
EVT_LISTBOX(self, 401, self.OnSelect)
|
||||
EVT_LISTBOX_DCLICK(self, 401, self.OnDClick)
|
||||
|
||||
wxButton(self, 402, "Try it!", wxDLG_PNT(self, 120, 10)).SetDefault()
|
||||
EVT_BUTTON(self, 402, self.OnDClick)
|
||||
|
||||
self.text = wxTextCtrl(self, -1, "",
|
||||
wxDLG_PNT(self, 10, 80),
|
||||
wxDLG_SZE(self, 200, 60),
|
||||
wxTE_MULTILINE | wxTE_READONLY)
|
||||
|
||||
for item in theTests:
|
||||
self.list.Append(item[0])
|
||||
|
||||
|
||||
|
||||
def OnSelect(self, event):
|
||||
pos = self.list.GetSelection()
|
||||
self.text.SetValue(theTests[pos][2])
|
||||
|
||||
|
||||
def OnDClick(self, event):
|
||||
pos = self.list.GetSelection()
|
||||
title = theTests[pos][0]
|
||||
func = theTests[pos][1]
|
||||
|
||||
if func:
|
||||
win = TestFrame(self, title, func)
|
||||
win.CentreOnParent(wxBOTH)
|
||||
win.Show(true)
|
||||
win.MakeModal(true)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestSelectionPanel(nb, frame)
|
||||
return win
|
||||
|
||||
overview = wxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
|
||||
wxBoxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
|
||||
wxBorderSizer.__doc__
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
class MainFrame(wxFrame):
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self, NULL, -1, "Testing...")
|
||||
|
||||
self.CreateStatusBar()
|
||||
mainmenu = wxMenuBar()
|
||||
menu = wxMenu()
|
||||
menu.Append(200, 'E&xit', 'Get the heck outta here!')
|
||||
mainmenu.Append(menu, "&File")
|
||||
self.SetMenuBar(mainmenu)
|
||||
EVT_MENU(self, 200, self.OnExit)
|
||||
self.panel = TestSelectionPanel(self, self)
|
||||
self.SetSize(wxSize(400, 380))
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
def OnExit(self, event):
|
||||
self.Close(true)
|
||||
|
||||
|
||||
class TestApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MainFrame()
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
app = TestApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
@@ -1,6 +1,5 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.sizers import *
|
||||
from wxScrolledWindow import MyCanvas
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@@ -97,31 +96,29 @@ class TestPrintPanel(wxPanel):
|
||||
self.printData = wxPrintData()
|
||||
self.printData.SetPaperId(wxPAPER_LETTER)
|
||||
|
||||
self.box = box.wxBoxSizer(wxVERTICAL)
|
||||
self.box = wxBoxSizer(wxVERTICAL)
|
||||
self.canvas = MyCanvas(self)
|
||||
self.box.Add(self.canvas, 1)
|
||||
self.box.Add(self.canvas, 1, wxGROW)
|
||||
|
||||
subbox = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(self, 1201, "Print Setup")
|
||||
EVT_BUTTON(self, 1201, self.OnPrintSetup)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1202, "Print Preview")
|
||||
EVT_BUTTON(self, 1202, self.OnPrintPreview)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1203, "Print")
|
||||
EVT_BUTTON(self, 1203, self.OnDoPrint)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
self.box.Add(subbox)
|
||||
self.box.Add(subbox, 0, wxGROW)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(self.box)
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
self.box.Layout(size)
|
||||
|
||||
def OnPrintSetup(self, event):
|
||||
printerDialog = wxPrintDialog(self)
|
||||
printerDialog.GetPrintDialogData().SetPrintData(self.printData)
|
||||
|
@@ -2,17 +2,17 @@
|
||||
# sizer test code
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.sizers import *
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.grids import wxGridSizer, wxFlexGridSizer
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox1(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 0)
|
||||
box.Add(wxButton(win, 1010, "four"), 0)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxGROW)
|
||||
|
||||
return box
|
||||
|
||||
@@ -20,10 +20,10 @@ def makeSimpleBox1(win):
|
||||
|
||||
def makeSimpleBox2(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 0)
|
||||
box.Add(wxButton(win, 1010, "four"), 0)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxGROW)
|
||||
|
||||
return box
|
||||
|
||||
@@ -31,11 +31,11 @@ def makeSimpleBox2(win):
|
||||
|
||||
def makeSimpleBox3(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 0)
|
||||
box.Add(wxButton(win, 1010, "four"), 0)
|
||||
box.Add(wxButton(win, 1010, "five"), 1)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxGROW)
|
||||
|
||||
return box
|
||||
|
||||
@@ -43,11 +43,11 @@ def makeSimpleBox3(win):
|
||||
|
||||
def makeSimpleBox4(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 1)
|
||||
box.Add(wxButton(win, 1010, "four"), 1)
|
||||
box.Add(wxButton(win, 1010, "five"), 1)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "three"), 1, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "four"), 1, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxGROW)
|
||||
|
||||
return box
|
||||
|
||||
@@ -55,53 +55,66 @@ def makeSimpleBox4(win):
|
||||
|
||||
def makeSimpleBox5(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0)
|
||||
box.Add(wxButton(win, 1010, "two"), 0)
|
||||
box.Add(wxButton(win, 1010, "three"), 3)
|
||||
box.Add(wxButton(win, 1010, "four"), 1)
|
||||
box.Add(wxButton(win, 1010, "five"), 1)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "three"), 3, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "four"), 1, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxGROW)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox6(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL, wxSize(250, 50))
|
||||
box.Add(wxButton(win, 1010, "10"), 10)
|
||||
box.Add(wxButton(win, 1010, "20"), 20)
|
||||
box.Add(wxButton(win, 1010, "30"), 30)
|
||||
box.Add(wxButton(win, 1010, "15"), 15)
|
||||
box.Add(wxButton(win, 1010, "5"), 5)
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 1, wxALIGN_TOP)
|
||||
box.Add(wxButton(win, 1010, "two"), 1, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "three"), 1, wxCENTER)
|
||||
box.Add(wxButton(win, 1010, "four"), 1, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxALIGN_BOTTOM)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox7(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxGROW)
|
||||
box.Add(60, 20, 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxGROW)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder1(win):
|
||||
bdr = wxBorderSizer(wxALL)
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 15)
|
||||
bdr.Add(btn, 1, wxGROW|wxALL, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder2(win):
|
||||
bdr = wxBorderSizer(wxEAST | wxWEST)
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 15)
|
||||
bdr.Add(btn, 1, wxGROW | wxEAST | wxWEST, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder3(win):
|
||||
bdr = wxBorderSizer(wxNORTH | wxWEST)
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 15)
|
||||
bdr.Add(btn, 1, wxGROW | wxNORTH | wxWEST, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
@@ -111,35 +124,35 @@ def makeSimpleBorder3(win):
|
||||
def makeBoxInBox(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
box.Add(wxButton(win, 1010, "one"))
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxGROW)
|
||||
|
||||
box2 = wxBoxSizer(wxHORIZONTAL)
|
||||
box2.AddMany([ wxButton(win, 1010, "two"),
|
||||
wxButton(win, 1010, "three"),
|
||||
wxButton(win, 1010, "four"),
|
||||
wxButton(win, 1010, "five"),
|
||||
box2.AddMany([ (wxButton(win, 1010, "two"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "three"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "four"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "five"), 0, wxGROW),
|
||||
])
|
||||
|
||||
box3 = wxBoxSizer(wxVERTICAL)
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0),
|
||||
(wxButton(win, 1010, "seven"), 2),
|
||||
(wxButton(win, 1010, "eight"), 1),
|
||||
(wxButton(win, 1010, "nine"), 1),
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "seven"), 2, wxGROW),
|
||||
(wxButton(win, 1010, "eight"), 1, wxGROW),
|
||||
(wxButton(win, 1010, "nine"), 1, wxGROW),
|
||||
])
|
||||
|
||||
box2.Add(box3, 1)
|
||||
box.Add(box2, 1)
|
||||
box2.Add(box3, 1, wxGROW)
|
||||
box.Add(box2, 1, wxGROW)
|
||||
|
||||
box.Add(wxButton(win, 1010, "ten"))
|
||||
box.Add(wxButton(win, 1010, "ten"), 0, wxGROW)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeBoxInBorder(win):
|
||||
bdr = wxBorderSizer(wxALL)
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
box = makeSimpleBox3(win)
|
||||
bdr.Add(box, 15)
|
||||
bdr.Add(box, 1, wxGROW | wxALL, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
@@ -149,37 +162,106 @@ def makeBorderInBox(win):
|
||||
insideBox = wxBoxSizer(wxHORIZONTAL)
|
||||
|
||||
box2 = wxBoxSizer(wxHORIZONTAL)
|
||||
box2.AddMany([ wxButton(win, 1010, "one"),
|
||||
wxButton(win, 1010, "two"),
|
||||
wxButton(win, 1010, "three"),
|
||||
wxButton(win, 1010, "four"),
|
||||
wxButton(win, 1010, "five"),
|
||||
box2.AddMany([ (wxButton(win, 1010, "one"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "two"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "three"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "four"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "five"), 0, wxGROW),
|
||||
])
|
||||
|
||||
insideBox.Add(box2, 0)
|
||||
insideBox.Add(box2, 0, wxGROW)
|
||||
|
||||
bdr = wxBorderSizer(wxALL)
|
||||
bdr.Add(wxButton(win, 1010, "border"), 20)
|
||||
insideBox.Add(bdr, 1)
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
bdr.Add(wxButton(win, 1010, "border"), 1, wxGROW | wxALL)
|
||||
insideBox.Add(bdr, 1, wxGROW | wxALL, 20)
|
||||
|
||||
box3 = wxBoxSizer(wxVERTICAL)
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0),
|
||||
(wxButton(win, 1010, "seven"), 2),
|
||||
(wxButton(win, 1010, "eight"), 1),
|
||||
(wxButton(win, 1010, "nine"), 1),
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0, wxGROW),
|
||||
(wxButton(win, 1010, "seven"), 2, wxGROW),
|
||||
(wxButton(win, 1010, "eight"), 1, wxGROW),
|
||||
(wxButton(win, 1010, "nine"), 1, wxGROW),
|
||||
])
|
||||
insideBox.Add(box3, 1)
|
||||
insideBox.Add(box3, 1, wxGROW)
|
||||
|
||||
outsideBox = wxBoxSizer(wxVERTICAL)
|
||||
outsideBox.Add(wxButton(win, 1010, "top"))
|
||||
outsideBox.Add(insideBox, 1)
|
||||
outsideBox.Add(wxButton(win, 1010, "bottom"))
|
||||
outsideBox.Add(wxButton(win, 1010, "top"), 0, wxGROW)
|
||||
outsideBox.Add(insideBox, 1, wxGROW)
|
||||
outsideBox.Add(wxButton(win, 1010, "bottom"), 0, wxGROW)
|
||||
|
||||
return outsideBox
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid1(win):
|
||||
gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'two'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'three'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'four'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'five'), 0, wxGROW),
|
||||
#(75, 50),
|
||||
(wxButton(win, 1010, 'six'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'seven'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'eight'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'nine'), 0, wxGROW),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid2(win):
|
||||
gs = wxGridSizer(3, 3) # rows, cols, hgap, vgap
|
||||
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(win, 1010, 'A'), 0, wxGROW)
|
||||
box.Add(wxButton(win, 1010, 'B'), 1, wxGROW)
|
||||
|
||||
gs2 = wxGridSizer(2,2, 4, 4)
|
||||
gs2.AddMany([ (wxButton(win, 1010, 'C'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'E'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'F'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'G'), 0, wxGROW)])
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxALIGN_RIGHT | wxALIGN_BOTTOM),
|
||||
(wxButton(win, 1010, 'two'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'three'), 0, wxALIGN_LEFT | wxALIGN_BOTTOM),
|
||||
(wxButton(win, 1010, 'four'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'five'), 0, wxCENTER),
|
||||
(wxButton(win, 1010, 'six'), 0, wxGROW),
|
||||
(box, 0, wxGROW | wxALL, 10),
|
||||
(wxButton(win, 1010, 'eight'), 0, wxGROW),
|
||||
(gs2, 0, wxGROW | wxALL, 4),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid3(win):
|
||||
gs = wxFlexGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'two'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'three'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'four'), 0, wxGROW),
|
||||
#(wxButton(win, 1010, 'five'), 0, wxGROW),
|
||||
(175, 50),
|
||||
(wxButton(win, 1010, 'six'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'seven'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'eight'), 0, wxGROW),
|
||||
(wxButton(win, 1010, 'nine'), 0, wxGROW),
|
||||
])
|
||||
|
||||
gs.AddGrowableRow(0)
|
||||
gs.AddGrowableRow(2)
|
||||
gs.AddGrowableCol(1)
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
theTests = [
|
||||
("Simple horizontal boxes", makeSimpleBox1,
|
||||
"This is a HORIZONTAL box sizer with four non-stretchable buttons held "
|
||||
@@ -208,6 +290,17 @@ theTests = [
|
||||
"factor so it gets more of the free space."
|
||||
),
|
||||
|
||||
("Edge Affinity", makeSimpleBox6,
|
||||
"For items that don't completly fill their allotted space, and don't "
|
||||
"stretch, you can specify which side (or the center) they should stay "
|
||||
"attached to."
|
||||
),
|
||||
|
||||
("Spacer", makeSimpleBox7,
|
||||
"You can add empty space to be managed by a Sizer just as if it were a "
|
||||
"window or another Sizer."
|
||||
),
|
||||
|
||||
# ("Percent Sizer", makeSimpleBox6,
|
||||
# "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
|
||||
# "the weighting factors add up to 100!"
|
||||
@@ -245,6 +338,29 @@ theTests = [
|
||||
"Another nesting example. This one has Boxes and a Border inside another Box."
|
||||
),
|
||||
|
||||
("", None, ""),
|
||||
|
||||
("Simple Grid", makeGrid1,
|
||||
"This is an example of the wxGridSizer. In this case all row heights "
|
||||
"and column widths are kept the same as all the others and all items "
|
||||
"fill their available space. The horzontal and vertical gaps are set to "
|
||||
"2 pixels each."
|
||||
),
|
||||
|
||||
("More Grid Features", makeGrid2,
|
||||
"This is another example of the wxGridSizer. This one has no gaps in the grid, "
|
||||
"but various cells are given different alignment options and some of them "
|
||||
"hold nested sizers."
|
||||
),
|
||||
|
||||
("Flexible Grid", makeGrid3,
|
||||
"This grid allows the rows to have different heights and the columns to have "
|
||||
"different widths. You can also specify rows and columns that are growable, "
|
||||
"which we have done for the first and last row and the middle column for "
|
||||
"this example.\n"
|
||||
"\nThere is also a spacer in the middle cell instead of an actual window."
|
||||
),
|
||||
|
||||
]
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
@@ -256,12 +372,10 @@ class TestFrame(wxFrame):
|
||||
self.sizer = sizerFunc(self)
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("Resize this frame to see how the sizers respond...")
|
||||
self.sizer.FitWindow(self)
|
||||
self.sizer.Fit(self)
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
self.sizer.Layout(size)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.MakeModal(false)
|
||||
@@ -280,17 +394,17 @@ class TestSelectionPanel(wxPanel):
|
||||
self.frame = frame
|
||||
|
||||
self.list = wxListBox(self, 401,
|
||||
wxDLG_PNT(self, 10, 10), wxDLG_SZE(self, 100, 60),
|
||||
wxDLG_PNT(self, 10, 10), wxDLG_SZE(self, 100, 100),
|
||||
[])
|
||||
EVT_LISTBOX(self, 401, self.OnSelect)
|
||||
EVT_LISTBOX_DCLICK(self, 401, self.OnDClick)
|
||||
|
||||
wxButton(self, 402, "Try it!", wxDLG_PNT(self, 120, 10)).SetDefault()
|
||||
self.btn = wxButton(self, 402, "Try it!", wxDLG_PNT(self, 120, 10)).SetDefault()
|
||||
EVT_BUTTON(self, 402, self.OnDClick)
|
||||
|
||||
self.text = wxTextCtrl(self, -1, "",
|
||||
wxDLG_PNT(self, 10, 80),
|
||||
wxDLG_SZE(self, 200, 60),
|
||||
wxDLG_PNT(self, 10, 115),
|
||||
wxDLG_SZE(self, 200, 50),
|
||||
wxTE_MULTILINE | wxTE_READONLY)
|
||||
|
||||
for item in theTests:
|
||||
@@ -320,9 +434,10 @@ def runTest(frame, nb, log):
|
||||
win = TestSelectionPanel(nb, frame)
|
||||
return win
|
||||
|
||||
overview = wxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
|
||||
wxBoxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
|
||||
wxBorderSizer.__doc__
|
||||
overview = ""
|
||||
#wxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
|
||||
#wxBoxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
|
||||
#wxBorderSizer.__doc__
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
@@ -341,7 +456,7 @@ if __name__ == '__main__':
|
||||
mainmenu.Append(menu, "&File")
|
||||
self.SetMenuBar(mainmenu)
|
||||
EVT_MENU(self, 200, self.OnExit)
|
||||
self.panel = TestSelectionPanel(self)
|
||||
self.panel = TestSelectionPanel(self, self)
|
||||
self.SetSize(wxSize(400, 380))
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
|
@@ -3,7 +3,6 @@ import sys, os
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.html import *
|
||||
from wxPython.lib.sizers import *
|
||||
import wxPython.lib.wxpTag
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@@ -34,35 +33,37 @@ class TestHtmlPanel(wxPanel):
|
||||
self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
|
||||
self.html.SetRelatedStatusBar(0)
|
||||
|
||||
self.box = box.wxBoxSizer(wxVERTICAL)
|
||||
self.box.Add(self.html, 1)
|
||||
self.box = wxBoxSizer(wxVERTICAL)
|
||||
self.box.Add(self.html, 1, wxGROW)
|
||||
|
||||
subbox = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(self, 1201, "Show Default")
|
||||
EVT_BUTTON(self, 1201, self.OnShowDefault)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1202, "Load File")
|
||||
EVT_BUTTON(self, 1202, self.OnLoadFile)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1203, "With Widgets")
|
||||
EVT_BUTTON(self, 1203, self.OnWithWidgets)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1204, "Back")
|
||||
EVT_BUTTON(self, 1204, self.OnBack)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1205, "Forward")
|
||||
EVT_BUTTON(self, 1205, self.OnForward)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1206, "View Source")
|
||||
EVT_BUTTON(self, 1206, self.OnViewSource)
|
||||
subbox.Add(btn, 1)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
self.box.Add(subbox)
|
||||
self.box.Add(subbox, 0, wxGROW)
|
||||
self.SetSizer(self.box)
|
||||
self.SetAutoLayout(true)
|
||||
|
||||
# A button with this ID is created on the widget test page.
|
||||
EVT_BUTTON(self, wxID_OK, self.OnOk)
|
||||
@@ -71,10 +72,6 @@ class TestHtmlPanel(wxPanel):
|
||||
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
self.box.Layout(size)
|
||||
|
||||
|
||||
def OnShowDefault(self, event):
|
||||
name = os.path.join(os.path.split(sys.argv[0])[0], 'data/test.htm')
|
||||
|
@@ -123,10 +123,12 @@ class TestWindow(wxShapeCanvas):
|
||||
self.diagram.SetCanvas(self)
|
||||
self.shapes = []
|
||||
|
||||
self.MyAddShape(wxCircleShape(80), 100, 100, wxPen(wxBLUE, 3), wxGREEN_BRUSH)
|
||||
self.MyAddShape(wxRectangleShape(85, 50), 305, 60, wxBLACK_PEN, wxLIGHT_GREY_BRUSH)
|
||||
self.MyAddShape(DiamondShape(90, 90), 345, 235, wxPen(wxBLUE, 3, wxDOT), wxRED_BRUSH)
|
||||
self.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED, 1), wxBLUE_BRUSH)
|
||||
rRectBrush = wxBrush(wxNamedColour("MEDIUM TURQUOISE"), wxSOLID)
|
||||
|
||||
self.MyAddShape(wxCircleShape(80), 100, 100, wxPen(wxBLUE, 3), wxGREEN_BRUSH, "Circle")
|
||||
self.MyAddShape(wxRectangleShape(85, 50), 305, 60, wxBLACK_PEN, wxLIGHT_GREY_BRUSH, "Rectangle")
|
||||
self.MyAddShape(DiamondShape(90, 90), 345, 235, wxPen(wxBLUE, 3, wxDOT), wxRED_BRUSH, "Polygon")
|
||||
self.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED, 1), rRectBrush, "Rounded Rect")
|
||||
|
||||
dc = wxClientDC(self)
|
||||
self.PrepareDC(dc)
|
||||
@@ -151,13 +153,14 @@ class TestWindow(wxShapeCanvas):
|
||||
|
||||
|
||||
|
||||
def MyAddShape(self, shape, x, y, pen, brush):
|
||||
def MyAddShape(self, shape, x, y, pen, brush, text):
|
||||
shape.SetDraggable(true)
|
||||
shape.SetCanvas(self)
|
||||
shape.SetX(x)
|
||||
shape.SetY(y)
|
||||
shape.SetPen(pen)
|
||||
shape.SetBrush(brush)
|
||||
shape.AddText(text)
|
||||
#shape.SetShadowMode(SHADOW_RIGHT)
|
||||
self.diagram.AddShape(shape)
|
||||
shape.Show(true)
|
||||
|
@@ -15,9 +15,9 @@ def runTest(frame, nb, log):
|
||||
p2.SetBackgroundColour(wxBLUE)
|
||||
wxStaticText(p2, -1, "Panel Two", wxPoint(5,5)).SetBackgroundColour(wxBLUE)
|
||||
|
||||
splitter.SetMinimumPaneSize(20)
|
||||
splitter.SplitVertically(p1, p2)
|
||||
splitter.SetSashPosition(100)
|
||||
splitter.SetMinimumPaneSize(20)
|
||||
|
||||
return splitter
|
||||
|
||||
|
@@ -18,37 +18,37 @@ class TestToolBar(wxFrame):
|
||||
|
||||
self.CreateStatusBar()
|
||||
|
||||
tb.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "New", "Long help for 'New'")
|
||||
tb.AddTool(10, wxBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "New", "Long help for 'New'")
|
||||
EVT_TOOL(self, 10, self.OnToolClick)
|
||||
EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
|
||||
|
||||
tb.AddTool(20, wxNoRefBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "Open")
|
||||
tb.AddTool(20, wxBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "Open")
|
||||
EVT_TOOL(self, 20, self.OnToolClick)
|
||||
EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
|
||||
|
||||
tb.AddSeparator()
|
||||
tb.AddTool(30, wxNoRefBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "Copy")
|
||||
tb.AddTool(30, wxBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "Copy")
|
||||
EVT_TOOL(self, 30, self.OnToolClick)
|
||||
EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
|
||||
|
||||
tb.AddTool(40, wxNoRefBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "Paste")
|
||||
tb.AddTool(40, wxBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, false, -1, -1, "Paste")
|
||||
EVT_TOOL(self, 40, self.OnToolClick)
|
||||
EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
|
||||
|
||||
tb.AddSeparator()
|
||||
|
||||
tb.AddTool(50, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, true, -1, -1, "Toggle this")
|
||||
tb.AddTool(50, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNullBitmap, true, -1, -1, "Toggle this")
|
||||
EVT_TOOL(self, 50, self.OnToolClick)
|
||||
EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
|
||||
|
||||
tb.AddTool(60, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxNoRefBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
|
||||
true, -1, -1, "Toggle with 2 bitmaps")
|
||||
tb.AddTool(60, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
|
||||
wxBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
|
||||
true, -1, -1, "Toggle with 2 bitmaps")
|
||||
EVT_TOOL(self, 60, self.OnToolClick)
|
||||
EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
|
||||
|
||||
|
@@ -13,7 +13,7 @@ class TestTreeCtrlPanel(wxPanel):
|
||||
tID = NewId()
|
||||
|
||||
self.tree = wxTreeCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
|
||||
wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS)
|
||||
wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS) #| wxTR_MULTIPLE)
|
||||
|
||||
self.root = self.tree.AddRoot("The Root Item")
|
||||
for x in range(15):
|
||||
|
119
utils/wxPython/demo/wxValidator.py
Normal file
119
utils/wxPython/demo/wxValidator.py
Normal file
@@ -0,0 +1,119 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.grids import wxFlexGridSizer
|
||||
|
||||
import string
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
ALPHA_ONLY = 1
|
||||
DIGIT_ONLY = 2
|
||||
|
||||
class MyValidator(wxPyValidator):
|
||||
def __init__(self, flag=None, pyVar=None):
|
||||
wxPyValidator.__init__(self)
|
||||
self.flag = flag
|
||||
EVT_CHAR(self, self.OnChar)
|
||||
|
||||
def Clone(self):
|
||||
return MyValidator(self.flag)
|
||||
|
||||
def Validate(self, win):
|
||||
print 'validate'
|
||||
tc = wxPyTypeCast(win, "wxTextCtrl")
|
||||
val = tc.GetValue()
|
||||
if self.flag == ALPHA_ONLY:
|
||||
for x in val:
|
||||
if x not in string.letters:
|
||||
return false
|
||||
|
||||
elif self.flag == DIGIT_ONLY:
|
||||
for x in val:
|
||||
if x not in string.digits:
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
|
||||
def OnChar(self, event):
|
||||
key = event.KeyCode()
|
||||
if key < WXK_SPACE or key == WXK_DELETE or key > 255:
|
||||
event.Skip()
|
||||
return
|
||||
if self.flag == ALPHA_ONLY and chr(key) in string.letters:
|
||||
event.Skip()
|
||||
return
|
||||
if self.flag == DIGIT_ONLY and chr(key) in string.digits:
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
if not wxValidator_IsSilent():
|
||||
wxBell()
|
||||
|
||||
# Returning without calling even.Skip eats the event before it
|
||||
# gets to the text control
|
||||
return
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestValidatorPanel(wxPanel):
|
||||
def __init__(self, parent):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.SetAutoLayout(true)
|
||||
VSPACE = 10
|
||||
|
||||
fgs = wxFlexGridSizer(0, 2)
|
||||
|
||||
fgs.Add(1,1);
|
||||
fgs.Add(wxStaticText(self, -1, "These controls have validators that limit\n"
|
||||
"the type of characters that can be entered."))
|
||||
|
||||
fgs.Add(1,VSPACE); fgs.Add(1,VSPACE)
|
||||
|
||||
label = wxStaticText(self, -1, "Alpha Only: ")
|
||||
fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER)
|
||||
|
||||
fgs.Add(wxTextCtrl(self, -1, "", validator = MyValidator(ALPHA_ONLY))
|
||||
|
||||
fgs.Add(1,VSPACE); fgs.Add(1,VSPACE)
|
||||
|
||||
label = wxStaticText(self, -1, "Digits Only: ")
|
||||
fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER)
|
||||
fgs.Add(wxTextCtrl(self, -1, "", validator = MyValidator(DIGITS_ONLY)))
|
||||
|
||||
border = wxBoxSizer()
|
||||
border.Add(fgs, 1, wxGROW|wxALL, 25)
|
||||
self.SetSizer(border)
|
||||
self.Layout()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestValidatorPanel(nb)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
wxValidator is the base class for a family of validator classes that mediate between a class of control, and application data.
|
||||
|
||||
A validator has three major roles:
|
||||
|
||||
1. to transfer data from a C++ variable or own storage to and from a control;
|
||||
|
||||
2. to validate data in a control, and show an appropriate error message;
|
||||
|
||||
3. to filter events (such as keystrokes), thereby changing the behaviour of the associated control.
|
||||
|
||||
Validators can be plugged into controls dynamically.
|
||||
|
||||
"""
|
Reference in New Issue
Block a user