Added the sample code from wxPython In Action to the samples dir

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42925 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2006-11-01 22:36:23 +00:00
parent bb2775b9e8
commit be05b43451
184 changed files with 9122 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -0,0 +1,25 @@
import wx
class BitmapButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Bitmap Button Example',
size=(200, 150))
panel = wx.Panel(self, -1)
bmp = wx.Image("bitmap.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
self.button = wx.BitmapButton(panel, -1, bmp, pos=(10, 20))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
self.button.SetDefault()
self.button2 = wx.BitmapButton(panel, -1, bmp, pos=(100, 20),
style=0)
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button2)
def OnClick(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = BitmapButtonFrame()
frame.Show()
app.MainLoop()

View File

@@ -0,0 +1,21 @@
import wx
class ButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Button Example',
size=(300, 100))
panel = wx.Panel(self, -1)
self.button = wx.Button(panel, -1, "Hello", pos=(50, 20))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
self.button.SetDefault()
def OnClick(self, event):
self.button.SetLabel("Clicked")
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ButtonFrame()
frame.Show()
app.MainLoop()

View File

@@ -0,0 +1,16 @@
import wx
class CheckBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Checkbox Example',
size=(150, 200))
panel = wx.Panel(self, -1)
wx.CheckBox(panel, -1, "Alpha", (35, 40), (150, 20))
wx.CheckBox(panel, -1, "Beta", (35, 60), (150, 20))
wx.CheckBox(panel, -1, "Gamma", (35, 80), (150, 20))
if __name__ == '__main__':
app = wx.PySimpleApp()
CheckBoxFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,16 @@
import wx
class ChoiceFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Choice Example',
size=(250, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
wx.StaticText(panel, -1, "Select one:", (15, 20))
wx.Choice(panel, -1, (85, 18), choices=sampleList)
if __name__ == '__main__':
app = wx.PySimpleApp()
ChoiceFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,19 @@
import wx
class ComboBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Combo Box Example',
size=(350, 300))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
wx.StaticText(panel, -1, "Select one:", (15, 15))
wx.ComboBox(panel, -1, "default value", (15, 30), wx.DefaultSize,
sampleList, wx.CB_DROPDOWN)
wx.ComboBox(panel, -1, "default value", (150, 30), wx.DefaultSize,
sampleList, wx.CB_SIMPLE)
if __name__ == '__main__':
app = wx.PySimpleApp()
ComboBoxFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,23 @@
import wx
class GaugeFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Gauge Example',
size=(350, 150))
panel = wx.Panel(self, -1)
self.count = 0
self.gauge = wx.Gauge(panel, -1, 50, (20, 50), (250, 25))
self.gauge.SetBezelFace(3)
self.gauge.SetShadowWidth(3)
self.Bind(wx.EVT_IDLE, self.OnIdle)
def OnIdle(self, event):
self.count = self.count + 1
if self.count >= 50:
self.count = 0
self.gauge.SetValue(self.count)
if __name__ == '__main__':
app = wx.PySimpleApp()
GaugeFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,56 @@
import wx
import wx.lib.buttons as buttons
class GenericButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Generic Button Example',
size=(500, 350))
panel = wx.Panel(self, -1)
sizer = wx.FlexGridSizer(1, 3, 20, 20)
b = wx.Button(panel, -1, "A wx.Button")
b.SetDefault()
sizer.Add(b)
b = wx.Button(panel, -1, "non-default wx.Button")
sizer.Add(b)
sizer.Add((10,10))
b = buttons.GenButton(panel, -1, 'Generic Button')
sizer.Add(b)
b = buttons.GenButton(panel, -1, 'disabled Generic')
b.Enable(False)
sizer.Add(b)
b = buttons.GenButton(panel, -1, 'bigger')
b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
b.SetBezelWidth(5)
b.SetBackgroundColour("Navy")
b.SetForegroundColour("white")
b.SetToolTipString("This is a BIG button...")
sizer.Add(b)
bmp = wx.Image("bitmap.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
b = buttons.GenBitmapButton(panel, -1, bmp)
sizer.Add(b)
b = buttons.GenBitmapToggleButton(panel, -1, bmp)
sizer.Add(b)
b = buttons.GenBitmapTextButton(panel, -1, bmp, "Bitmapped Text",
size=(175, 75))
b.SetUseFocusIndicator(False)
sizer.Add(b)
b = buttons.GenToggleButton(panel, -1, "Toggle Button")
sizer.Add(b)
panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = GenericButtonFrame()
frame.Show()
app.MainLoop()

View File

@@ -0,0 +1,21 @@
import wx
class ListBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'List Box Example',
size=(250, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']
listBox = wx.ListBox(panel, -1, (20, 20), (80, 120), sampleList,
wx.LB_SINGLE)
listBox.SetSelection(3)
if __name__ == '__main__':
app = wx.PySimpleApp()
ListBoxFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,32 @@
import wx
class RadioButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Radio Example',
size=(200, 200))
panel = wx.Panel(self, -1)
radio1 = wx.RadioButton(panel, -1, "Elmo", pos=(20, 50), style=wx.RB_GROUP)
radio2 = wx.RadioButton(panel, -1, "Ernie", pos=(20, 80))
radio3 = wx.RadioButton(panel, -1, "Bert", pos=(20, 110))
text1 = wx.TextCtrl(panel, -1, "", pos=(80, 50))
text2 = wx.TextCtrl(panel, -1, "", pos=(80, 80))
text3 = wx.TextCtrl(panel, -1, "", pos=(80, 110))
self.texts = {"Elmo": text1, "Ernie": text2, "Bert": text3}
for eachText in [text2, text3]:
eachText.Enable(False)
for eachRadio in [radio1, radio2, radio3]:
self.Bind(wx.EVT_RADIOBUTTON, self.OnRadio, eachRadio)
self.selectedText = text1
def OnRadio(self, event):
if self.selectedText:
self.selectedText.Enable(False)
radioSelected = event.GetEventObject()
text = self.texts[radioSelected.GetLabel()]
text.Enable(True)
self.selectedText = text
if __name__ == '__main__':
app = wx.PySimpleApp()
RadioButtonFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,19 @@
import wx
class RadioBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Radio Box Example',
size=(350, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
wx.RadioBox(panel, -1, "A Radio Box", (10, 10), wx.DefaultSize,
sampleList, 2, wx.RA_SPECIFY_COLS)
wx.RadioBox(panel, -1, "", (150, 10), wx.DefaultSize,
sampleList, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
if __name__ == '__main__':
app = wx.PySimpleApp()
RadioBoxFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,22 @@
import wx
class SliderFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Slider Example',
size=(300, 350))
panel = wx.Panel(self, -1)
self.count = 0
slider = wx.Slider(panel, 100, 25, 1, 100, pos=(10, 10),
size=(250, -1),
style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
slider.SetTickFreq(5, 1)
slider = wx.Slider(panel, 100, 25, 1, 100, pos=(125, 70),
size=(-1, 250),
style=wx.SL_VERTICAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
slider.SetTickFreq(20, 1)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SliderFrame()
frame.Show()
app.MainLoop()

View File

@@ -0,0 +1,15 @@
import wx
class SpinnerFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Spinner Example',
size=(100, 100))
panel = wx.Panel(self, -1)
sc = wx.SpinCtrl(panel, -1, "", (30, 20), (80, -1))
sc.SetRange(1,100)
sc.SetValue(5)
if __name__ == '__main__':
app = wx.PySimpleApp()
SpinnerFrame().Show()
app.MainLoop()

View File

@@ -0,0 +1,38 @@
import wx
class StaticTextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Static Text Example',
size=(400, 300))
panel = wx.Panel(self, -1)
wx.StaticText(panel, -1, "This is an example of static text",
(100, 10))
rev = wx.StaticText(panel, -1, "Static Text With Reversed Colors",
(100, 30))
rev.SetForegroundColour('white')
rev.SetBackgroundColour('black')
center = wx.StaticText(panel, -1, "align center", (100, 50),
(160, -1), wx.ALIGN_CENTER)
center.SetForegroundColour('white')
center.SetBackgroundColour('black')
right = wx.StaticText(panel, -1, "align right", (100, 70),
(160, -1), wx.ALIGN_RIGHT)
right.SetForegroundColour('white')
right.SetBackgroundColour('black')
str = "You can also change the font."
text = wx.StaticText(panel, -1, str, (20, 100))
font = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)
text.SetFont(font)
wx.StaticText(panel, -1, "Your text\ncan be split\n"
"over multiple lines\n\neven blank ones", (20,150))
wx.StaticText(panel, -1, "Multi-line text\ncan also\n"
"be right aligned\n\neven with a blank", (220,150),
style=wx.ALIGN_RIGHT)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = StaticTextFrame()
frame.Show()
app.MainLoop()

View File

@@ -0,0 +1,25 @@
import wx
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Text Entry Example',
size=(300, 100))
panel = wx.Panel(self, -1)
basicLabel = wx.StaticText(panel, -1, "Basic Control:")
basicText = wx.TextCtrl(panel, -1, "I've entered some text!",
size=(175, -1))
basicText.SetInsertionPoint(0)
pwdLabel = wx.StaticText(panel, -1, "Password:")
pwdText = wx.TextCtrl(panel, -1, "password", size=(175, -1),
style=wx.TE_PASSWORD)
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([basicLabel, basicText, pwdLabel, pwdText])
panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TextFrame()
frame.Show()
app.MainLoop()

View File

@@ -0,0 +1,33 @@
import wx
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Text Entry Example',
size=(300, 250))
panel = wx.Panel(self, -1)
multiLabel = wx.StaticText(panel, -1, "Multi-line")
multiText = wx.TextCtrl(panel, -1,
"Here is a looooooooooooooong line of text set in the control.\n\n"
"See that it wrapped, and that this line is after a blank",
size=(200, 100), style=wx.TE_MULTILINE)
multiText.SetInsertionPoint(0)
richLabel = wx.StaticText(panel, -1, "Rich Text")
richText = wx.TextCtrl(panel, -1,
"If supported by the native control, this is reversed, and this is a different font.",
size=(200, 100), style=wx.TE_MULTILINE|wx.TE_RICH2)
richText.SetInsertionPoint(0)
richText.SetStyle(44, 52, wx.TextAttr("white", "black"))
points = richText.GetFont().GetPointSize()
f = wx.Font(points + 3, wx.ROMAN, wx.ITALIC, wx.BOLD, True)
richText.SetStyle(68, 82, wx.TextAttr("blue", wx.NullColour, f))
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([multiLabel, multiText, richLabel, richText])
panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TextFrame()
frame.Show()
app.MainLoop()