Skip to content

Commit 396d1ad

Browse files
added all the demos (hopefully all!)
1 parent 94ef9e1 commit 396d1ad

File tree

124 files changed

+17122
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+17122
-0
lines changed

AboutDialog.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Simple about Dialog class -- I like it better than the one that wxPython comes with
5+
6+
-Chris Barker
7+
8+
9+
10+
"""
11+
12+
import wx
13+
from wx.lib.hyperlink import HyperLinkCtrl
14+
15+
class AboutDialog(wx.Dialog):
16+
"""
17+
18+
"""
19+
def __init__(self, parent, icon1=None,
20+
icon2=None,
21+
short_name=None,
22+
long_name=None,
23+
version=None,
24+
description=None,
25+
urls=None,
26+
licence=None,
27+
developers = []):
28+
wx.Dialog.__init__(self, parent)
29+
30+
self.icon1 = icon1
31+
self.icon2 = icon2
32+
self.short_name = short_name
33+
self.long_name = long_name
34+
self.version = version
35+
self.version = version
36+
self.description = description
37+
self.urls = urls
38+
self.licence = licence
39+
self.developers = developers
40+
41+
self.Build()
42+
43+
def Build(self):
44+
45+
# Build the header
46+
Header = wx.BoxSizer(wx.HORIZONTAL)
47+
if self.icon1:
48+
Header.Add(wx.StaticBitmap(self, bitmap=self.icon1), 0)
49+
else:
50+
Header.Add((64,64))
51+
Header.Add((20,1),1)
52+
if self.short_name:
53+
Label = wx.StaticText(self, label=self.short_name)
54+
of = Label.GetFont()
55+
Font = wx.Font(int(of.GetPointSize() * 2), of.GetFamily(), wx.NORMAL, wx.FONTWEIGHT_BOLD)
56+
Label.SetFont(Font)
57+
Header.Add(Label, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
58+
else:
59+
Header.Add((1,1), 1)
60+
Header.Add((20,1),1)
61+
if self.icon2:
62+
Header.Add(wx.StaticBitmap(self, bitmap=self.icon2), 0)
63+
else:
64+
Header.Add((64,64))
65+
width = Header.MinSize[0]
66+
67+
# Now the rest;
68+
MainSizer = wx.BoxSizer(wx.VERTICAL)
69+
70+
MainSizer.Add(Header, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 5)
71+
72+
if self.long_name:
73+
Label = wx.StaticText(self, label=self.long_name)
74+
of = Label.GetFont()
75+
Font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL)
76+
Label.SetFont(Font)
77+
MainSizer.Add(Label, 0, wx.TOP|wx.RIGHT|wx.LEFT|wx.ALIGN_CENTER, 5)
78+
width = max(width, Label.Size[0])
79+
80+
if self.version:
81+
Label = wx.StaticText(self, label="version: "+self.version)
82+
#of = Label.GetFont()
83+
#Font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL)
84+
#Label.SetFont(Font)
85+
MainSizer.Add(Label, 0, wx.BOTTOM|wx.ALIGN_CENTER, 5)
86+
87+
if self.description:
88+
Label = wx.StaticText(self, label=self.description)
89+
#of = Label.GetFont()
90+
#Font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL)
91+
#Label.SetFont(Font)
92+
93+
Label.Wrap(max(250, 0.9*width))
94+
MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_CENTER, 5)
95+
96+
97+
if self.licence:
98+
Label = wx.StaticText(self, label="License:")
99+
of = Label.GetFont()
100+
Font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD)
101+
Label.SetFont(Font)
102+
MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 5)
103+
Label = wx.StaticText(self, label=self.licence)
104+
Label.Wrap(max(250, 0.9*width))
105+
MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_CENTER, 2)
106+
107+
if self.developers:
108+
Label = wx.StaticText(self, label="Developed by:")
109+
of = Label.GetFont()
110+
Font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD)
111+
Label.SetFont(Font)
112+
MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 5)
113+
114+
for developer in self.developers:
115+
Label = wx.StaticText(self, label=" "+developer)
116+
MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 0)
117+
118+
if self.urls:
119+
Label = wx.StaticText(self, label="For more information:")
120+
of = Label.GetFont()
121+
Font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD)
122+
Label.SetFont(Font)
123+
MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 5)
124+
for url in self.urls:
125+
Link = HyperLinkCtrl(self,
126+
label=url,
127+
URL=url)
128+
MainSizer.Add(Link, 0, wx.ALL|wx.ALIGN_CENTER, 2)
129+
130+
MainSizer.Add((1,5),1)
131+
MainSizer.Add(wx.Button(self, id=wx.ID_OK, label="Dismiss"), 0, wx.ALL|wx.ALIGN_RIGHT,5)
132+
SpaceSizer = wx.BoxSizer(wx.VERTICAL)
133+
SpaceSizer.Add(MainSizer, 0, wx.ALL, 10)
134+
self.SetSizerAndFit(SpaceSizer)
135+
136+
if __name__ == "__main__":
137+
138+
a = wx.App(False)
139+
d = AboutDialog(None,
140+
icon1=wx.Bitmap("Images/GNOME64.png"),
141+
icon2=wx.Bitmap("Images/NOAA.png"),
142+
short_name='Acronym',
143+
long_name='A Longer Name for the Program',
144+
version = "1.2.3",
145+
description="A description of the program. This could be a pretty long bit of text. How shall I know how long to make it? How will it fit in?",
146+
urls = ["http://www.some.website.org",
147+
"mailto:[email protected]"],
148+
licence="This is a short description of the license used for the program.",
149+
developers = ["A Developer", "Another Developer"])
150+
151+
d.ShowModal()

Append_test.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python
2+
3+
import wx
4+
5+
BUFFERED = 1
6+
7+
#----------------------------------------------------------------------
8+
9+
class MyFrame(wx.Frame):
10+
def __init__(self):
11+
wx.Frame.__init__(self, None, -1, "Append_Test",
12+
wx.DefaultPosition,
13+
size=(800,600),
14+
style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
15+
16+
self.objects = []
17+
self.dragImage = None
18+
self.DragPaper = None
19+
self.hiliteObjects = None
20+
self.lines = []
21+
self.maxWidth = 1000
22+
self.maxHeight = 1000
23+
self.x = self.y = 0
24+
self.curLine = []
25+
self.drawing = False
26+
27+
self.Paper = wx.Bitmap("Paper.BMP", wx.BITMAP_TYPE_BMP)
28+
if self.Paper.Ok():
29+
print "bitmap loaded OK"
30+
else:
31+
raise Exception("bitmap DID NOT load OK")
32+
33+
self.DrawTextOnPaper()
34+
35+
#--------------------------------------------------------------------------
36+
if BUFFERED:
37+
self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight)
38+
dc = wx.BufferedDC(None, self.buffer)
39+
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
40+
dc.Clear()
41+
self.DoDrawing(dc)
42+
43+
self.Bind(wx.EVT_PAINT, self.OnPaint)
44+
45+
def OnPaint(self, event):
46+
if BUFFERED:
47+
dc = wx.BufferedPaintDC(self, self.buffer)
48+
else:
49+
dc = wx.PaintDC(self)
50+
self.PrepareDC(dc)
51+
self.DoDrawing(dc)
52+
53+
def DrawTextOnPaper(self):
54+
55+
l1 = ['a','b','c','d']
56+
text = " "+"".join(l1)
57+
58+
dc = wx.MemoryDC()
59+
dc.SelectObject(self.Paper)
60+
dc.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, "Arial"))
61+
dc.SetTextForeground(wx.BLACK)
62+
dc.DrawText(text, 155, 25)
63+
64+
def DoDrawing(self, dc, printing=False):
65+
dc.BeginDrawing()
66+
67+
## l1 = ['a','b','c','d']
68+
## text = " "+"".join(l1)
69+
## bg_colour = wx.Colour(57, 115, 57) # matches the bg image
70+
## dc.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, "Arial"))
71+
## dc.SetTextForeground(wx.BLACK)
72+
## te = dc.GetTextExtent(text)
73+
74+
75+
dc.DrawBitmap(self.Paper, 200, 20, True)
76+
77+
78+
#dc = wx.MemoryDC()
79+
#dc.SelectObject(self.manuscript)
80+
#self.DoDrawing(dc)
81+
82+
## dc.DrawText(text, 225, 25)
83+
84+
dc.EndDrawing()
85+
#--------------------------------------------------------------------------
86+
class MyApp(wx.App):
87+
def OnInit(self):
88+
#wx.InitAllImageHandlers
89+
frame = MyFrame()
90+
self.SetTopWindow(frame)
91+
frame.Show(True)
92+
93+
return True
94+
95+
if __name__ == "__main__":
96+
app = MyApp(0)
97+
app.MainLoop()
98+

BitmapFromBufferTest.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
A test of wx.BitmapFromBuffer
5+
"""
6+
7+
import numpy as np
8+
import numpy.random as random
9+
import wx
10+
11+
12+
class BitmapWindow(wx.Window):
13+
def __init__(self, parent, bytearray, *args, **kwargs):
14+
wx.Window.__init__(self, parent, *args, **kwargs)
15+
16+
self.bytearray = bytearray
17+
self.Bind(wx.EVT_PAINT, self.OnPaint)
18+
19+
def OnPaint(self, evt):
20+
dc = wx.PaintDC(self)
21+
bmp = wx.BitmapFromBufferRGBA(200,200, self.bytearray)
22+
dc.DrawBitmap(bmp, 50, 0 )
23+
24+
class DemoFrame(wx.Frame):
25+
""" This window displays a button """
26+
def __init__(self, title = "Bitmap Demo"):
27+
wx.Frame.__init__(self, None , -1, title)#, size = (800,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
28+
29+
# create the array and bitmap:
30+
self.bytearray = np.zeros((200,200,4), dtype=np.uint8)
31+
self.bytearray[:,:,3] = 255
32+
33+
#bmp = wx.BitmapFromBufferRGBA(200,200, self.bytearray)
34+
#bmp = wx.Bitmap("Images/smalltest.jpg")
35+
36+
self.BitmapWindow = BitmapWindow(self, self.bytearray)
37+
38+
sizer = wx.BoxSizer(wx.VERTICAL)
39+
sizer.Add(self.BitmapWindow, 1, wx.GROW)
40+
# set up the buttons
41+
ButtonSizer = self.SetUpTheButtons()
42+
sizer.Add(ButtonSizer, 0, wx.GROW)
43+
self.SetSizer(sizer)
44+
45+
# now set up the timer:
46+
self.Timer = wx.Timer(self)
47+
self.Bind(wx.EVT_TIMER, self.OnTimer)
48+
49+
self.Counter = 0
50+
51+
def SetUpTheButtons(self):
52+
StartButton = wx.Button(self, wx.NewId(), "Start")
53+
StartButton.Bind(wx.EVT_BUTTON, self.OnStart)
54+
55+
StopButton = wx.Button(self, wx.NewId(), "Stop")
56+
StopButton.Bind(wx.EVT_BUTTON, self.OnStop)
57+
58+
QuitButton = wx.Button(self, wx.NewId(), "Quit")
59+
QuitButton.Bind(wx.EVT_BUTTON, self.OnQuit)
60+
61+
self.Bind(wx.EVT_CLOSE, self.OnQuit)
62+
63+
sizer = wx.BoxSizer(wx.HORIZONTAL)
64+
sizer.Add((1,1), 1)
65+
sizer.Add(StartButton, 0, wx.ALIGN_CENTER | wx.ALL, 4 )
66+
sizer.Add((1,1), 1)
67+
sizer.Add(StopButton, 0, wx.ALIGN_CENTER | wx.ALL, 4 )
68+
sizer.Add((1,1), 1)
69+
sizer.Add(QuitButton, 0, wx.ALIGN_CENTER | wx.ALL, 4 )
70+
sizer.Add((1,1), 1)
71+
return sizer
72+
73+
def OnTimer(self,Event):
74+
print "The timer fired"
75+
r, g, b, a = random.randint(255, size = (4,))
76+
self.bytearray[:,:,0] = r
77+
self.bytearray[:,:,1] = g
78+
self.bytearray[:,:,2] = b
79+
self.Refresh()
80+
self.Update()
81+
82+
def OnStart(self,Event):
83+
self.Timer.Start(500) # time between events (in milliseconds)
84+
85+
def OnStop(self, Event=None):
86+
self.Timer.Stop()
87+
88+
def OnQuit(self,Event):
89+
self.Destroy()
90+
91+
app = wx.PySimpleApp(0)
92+
frame = DemoFrame()
93+
frame.Show()
94+
app.MainLoop()

BitmapFromPILTest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
A test of making wx.Bitmap from a PIL image
5+
"""
6+
7+
import wx
8+
import PIL.Image
9+
10+
class DemoFrame(wx.Frame):
11+
""" This window displays a button """
12+
def __init__(self, title = "Bitmap Demo"):
13+
wx.Frame.__init__(self, None , -1, title)#, size = (800,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
14+
15+
# load the PIL image:
16+
17+
image = PIL.Image.open('splash.png')
18+
image = image.convert('RGB')
19+
image = image.resize((100,100), PIL.Image.ANTIALIAS)
20+
w, h = image.size
21+
self.bitmap = wx.BitmapFromBuffer(w, h, image.tostring() )
22+
23+
self.Bind(wx.EVT_PAINT, self.OnPaint)
24+
25+
def OnPaint(self, evt):
26+
dc = wx.PaintDC(self)
27+
dc.DrawBitmap(self.bitmap, 10, 10 )
28+
29+
def OnQuit(self,Event):
30+
self.Destroy()
31+
32+
app = wx.App(False)
33+
frame = DemoFrame()
34+
frame.Show()
35+
app.MainLoop()

0 commit comments

Comments
 (0)