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:
21
wxPython/samples/wxPIA_book/Chapter-08/frame_subclass.py
Normal file
21
wxPython/samples/wxPIA_book/Chapter-08/frame_subclass.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import wx
|
||||
|
||||
class SubclassFrame(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, -1, 'Frame Subclass',
|
||||
size=(300, 100))
|
||||
panel = wx.Panel(self, -1)
|
||||
button = wx.Button(panel, -1, "Close Me", pos=(15, 15))
|
||||
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
def OnCloseMe(self, event):
|
||||
self.Close(True)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
SubclassFrame().Show()
|
||||
app.MainLoop()
|
16
wxPython/samples/wxPIA_book/Chapter-08/help_context.py
Normal file
16
wxPython/samples/wxPIA_book/Chapter-08/help_context.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import wx
|
||||
|
||||
class HelpFrame(wx.Frame):
|
||||
|
||||
def __init__(self):
|
||||
pre = wx.PreFrame()
|
||||
pre.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP)
|
||||
pre.Create(None, -1, "Help Context", size=(300, 100),
|
||||
style=wx.DEFAULT_FRAME_STYLE ^
|
||||
(wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX))
|
||||
self.PostCreate(pre)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
HelpFrame().Show()
|
||||
app.MainLoop()
|
1424
wxPython/samples/wxPIA_book/Chapter-08/images.py
Normal file
1424
wxPython/samples/wxPIA_book/Chapter-08/images.py
Normal file
File diff suppressed because it is too large
Load Diff
29
wxPython/samples/wxPIA_book/Chapter-08/mdi.py
Normal file
29
wxPython/samples/wxPIA_book/Chapter-08/mdi.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
|
||||
class MDIFrame(wx.MDIParentFrame):
|
||||
def __init__(self):
|
||||
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent",
|
||||
size=(600,400))
|
||||
menu = wx.Menu()
|
||||
menu.Append(5000, "&New Window")
|
||||
menu.Append(5001, "E&xit")
|
||||
menubar = wx.MenuBar()
|
||||
menubar.Append(menu, "&File")
|
||||
self.SetMenuBar(menubar)
|
||||
self.Bind(wx.EVT_MENU, self.OnNewWindow, id=5000)
|
||||
self.Bind(wx.EVT_MENU, self.OnExit, id=5001)
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close(True)
|
||||
|
||||
def OnNewWindow(self, evt):
|
||||
win = wx.MDIChildFrame(self, -1, "Child Window")
|
||||
win.Show(True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
frame = MDIFrame()
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
21
wxPython/samples/wxPIA_book/Chapter-08/miniframe.py
Normal file
21
wxPython/samples/wxPIA_book/Chapter-08/miniframe.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import wx
|
||||
|
||||
class MiniFrame(wx.MiniFrame):
|
||||
def __init__(self):
|
||||
wx.MiniFrame.__init__(self, None, -1, 'Mini Frame',
|
||||
size=(300, 100))
|
||||
panel = wx.Panel(self, -1, size=(300, 100))
|
||||
button = wx.Button(panel, -1, "Close Me", pos=(15, 15))
|
||||
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
def OnCloseMe(self, event):
|
||||
self.Close(True)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
MiniFrame().Show()
|
||||
app.MainLoop()
|
26
wxPython/samples/wxPIA_book/Chapter-08/scroll_window.py
Normal file
26
wxPython/samples/wxPIA_book/Chapter-08/scroll_window.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import wx
|
||||
|
||||
class ScrollbarFrame(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, -1, 'Scrollbar Example',
|
||||
size=(300, 200))
|
||||
self.scroll = wx.ScrolledWindow(self, -1)
|
||||
self.scroll.SetScrollbars(1, 1, 600, 400)
|
||||
self.button = wx.Button(self.scroll, -1, "Scroll Me", pos=(50, 20))
|
||||
self.Bind(wx.EVT_BUTTON, self.OnClickTop, self.button)
|
||||
self.button2 = wx.Button(self.scroll, -1, "Scroll Back", pos=(500, 350))
|
||||
self.Bind(wx.EVT_BUTTON, self.OnClickBottom, self.button2)
|
||||
|
||||
def OnClickTop(self, event):
|
||||
self.scroll.Scroll(600, 400)
|
||||
|
||||
def OnClickBottom(self, event):
|
||||
self.scroll.Scroll(1, 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
frame = ScrollbarFrame()
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
43
wxPython/samples/wxPIA_book/Chapter-08/shaped_frame.py
Normal file
43
wxPython/samples/wxPIA_book/Chapter-08/shaped_frame.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import wx
|
||||
import images
|
||||
|
||||
class ShapedFrame(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, -1, "Shaped Window",
|
||||
style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER |
|
||||
wx.FRAME_NO_TASKBAR)
|
||||
self.hasShape = False
|
||||
self.bmp = images.getVippiBitmap()
|
||||
self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
|
||||
dc = wx.ClientDC(self)
|
||||
dc.DrawBitmap(self.bmp, 0,0, True)
|
||||
self.SetWindowShape()
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
|
||||
self.Bind(wx.EVT_RIGHT_UP, self.OnExit)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
|
||||
|
||||
def SetWindowShape(self, evt=None):
|
||||
r = wx.RegionFromBitmap(self.bmp)
|
||||
self.hasShape = self.SetShape(r)
|
||||
|
||||
def OnDoubleClick(self, evt):
|
||||
if self.hasShape:
|
||||
self.SetShape(wx.Region())
|
||||
self.hasShape = False
|
||||
else:
|
||||
self.SetWindowShape()
|
||||
|
||||
def OnPaint(self, evt):
|
||||
dc = wx.PaintDC(self)
|
||||
dc.DrawBitmap(self.bmp, 0,0, True)
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
ShapedFrame().Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
@@ -0,0 +1,64 @@
|
||||
import wx
|
||||
import images
|
||||
|
||||
class ShapedFrame(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, -1, "Shaped Window",
|
||||
style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER )
|
||||
self.hasShape = False
|
||||
self.delta = wx.Point(0,0)
|
||||
self.bmp = images.getVippiBitmap()
|
||||
self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
|
||||
dc = wx.ClientDC(self)
|
||||
dc.DrawBitmap(self.bmp, 0,0, True)
|
||||
self.SetWindowShape()
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
|
||||
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
|
||||
self.Bind(wx.EVT_RIGHT_UP, self.OnExit)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
|
||||
|
||||
def SetWindowShape(self, evt=None):
|
||||
r = wx.RegionFromBitmap(self.bmp)
|
||||
self.hasShape = self.SetShape(r)
|
||||
|
||||
def OnDoubleClick(self, evt):
|
||||
if self.hasShape:
|
||||
self.SetShape(wx.Region())
|
||||
self.hasShape = False
|
||||
else:
|
||||
self.SetWindowShape()
|
||||
|
||||
def OnPaint(self, evt):
|
||||
dc = wx.PaintDC(self)
|
||||
dc.DrawBitmap(self.bmp, 0,0, True)
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close()
|
||||
|
||||
def OnLeftDown(self, evt):
|
||||
self.CaptureMouse()
|
||||
pos = self.ClientToScreen(evt.GetPosition())
|
||||
origin = self.GetPosition()
|
||||
self.delta = wx.Point(pos.x - origin.x, pos.y - origin.y)
|
||||
|
||||
def OnMouseMove(self, evt):
|
||||
if evt.Dragging() and evt.LeftIsDown():
|
||||
pos = self.ClientToScreen(evt.GetPosition())
|
||||
newPos = (pos.x - self.delta.x, pos.y - self.delta.y)
|
||||
self.Move(newPos)
|
||||
|
||||
def OnLeftUp(self, evt):
|
||||
if self.HasCapture():
|
||||
self.ReleaseMouse()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
ShapedFrame().Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
8
wxPython/samples/wxPIA_book/Chapter-08/simple_frame.py
Normal file
8
wxPython/samples/wxPIA_book/Chapter-08/simple_frame.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import wx
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
frame = wx.Frame(None, -1, "A Frame", style=wx.DEFAULT_FRAME_STYLE,
|
||||
size=(200, 100))
|
||||
frame.Show()
|
||||
app.MainLoop()
|
101
wxPython/samples/wxPIA_book/Chapter-08/splitter.py
Normal file
101
wxPython/samples/wxPIA_book/Chapter-08/splitter.py
Normal file
@@ -0,0 +1,101 @@
|
||||
import wx
|
||||
|
||||
class SplitterExampleFrame(wx.Frame):
|
||||
def __init__(self, parent, title):
|
||||
wx.Frame.__init__(self, parent, title=title)
|
||||
self.MakeMenuBar()
|
||||
self.minpane = 0
|
||||
self.initpos = 0
|
||||
self.sp = wx.SplitterWindow(self)
|
||||
self.p1 = wx.Panel(self.sp, style=wx.SUNKEN_BORDER)
|
||||
self.p2 = wx.Panel(self.sp, style=wx.SUNKEN_BORDER)
|
||||
self.p1.SetBackgroundColour("pink")
|
||||
self.p2.SetBackgroundColour("sky blue")
|
||||
self.p1.Hide()
|
||||
self.p2.Hide()
|
||||
|
||||
self.sp.Initialize(self.p1)
|
||||
|
||||
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING,
|
||||
self.OnSashChanging, self.sp)
|
||||
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,
|
||||
self.OnSashChanged, self.sp)
|
||||
|
||||
|
||||
def MakeMenuBar(self):
|
||||
menu = wx.Menu()
|
||||
item = menu.Append(-1, "Split horizontally")
|
||||
self.Bind(wx.EVT_MENU, self.OnSplitH, item)
|
||||
self.Bind(wx.EVT_UPDATE_UI, self.OnCheckCanSplit, item)
|
||||
item = menu.Append(-1, "Split vertically")
|
||||
self.Bind(wx.EVT_MENU, self.OnSplitV, item)
|
||||
self.Bind(wx.EVT_UPDATE_UI, self.OnCheckCanSplit, item)
|
||||
item = menu.Append(-1, "Unsplit")
|
||||
self.Bind(wx.EVT_MENU, self.OnUnsplit, item)
|
||||
self.Bind(wx.EVT_UPDATE_UI, self.OnCheckCanUnsplit, item)
|
||||
|
||||
menu.AppendSeparator()
|
||||
item = menu.Append(-1, "Set initial sash position")
|
||||
self.Bind(wx.EVT_MENU, self.OnSetPos, item)
|
||||
item = menu.Append(-1, "Set minimum pane size")
|
||||
self.Bind(wx.EVT_MENU, self.OnSetMin, item)
|
||||
|
||||
menu.AppendSeparator()
|
||||
item = menu.Append(wx.ID_EXIT, "E&xit")
|
||||
self.Bind(wx.EVT_MENU, self.OnExit, item)
|
||||
|
||||
mbar = wx.MenuBar()
|
||||
mbar.Append(menu, "Splitter")
|
||||
self.SetMenuBar(mbar)
|
||||
|
||||
|
||||
def OnSashChanging(self, evt):
|
||||
print "OnSashChanging:", evt.GetSashPosition()
|
||||
|
||||
def OnSashChanged(self, evt):
|
||||
print "OnSashChanged:", evt.GetSashPosition()
|
||||
|
||||
|
||||
def OnSplitH(self, evt):
|
||||
self.sp.SplitHorizontally(self.p1, self.p2, self.initpos)
|
||||
|
||||
def OnSplitV(self, evt):
|
||||
self.sp.SplitVertically(self.p1, self.p2, self.initpos)
|
||||
|
||||
def OnCheckCanSplit(self, evt):
|
||||
evt.Enable(not self.sp.IsSplit())
|
||||
|
||||
def OnCheckCanUnsplit(self, evt):
|
||||
evt.Enable(self.sp.IsSplit())
|
||||
|
||||
def OnUnsplit(self, evt):
|
||||
self.sp.Unsplit()
|
||||
|
||||
def OnSetMin(self, evt):
|
||||
minpane = wx.GetNumberFromUser(
|
||||
"Enter the minimum pane size",
|
||||
"", "Minimum Pane Size", self.minpane,
|
||||
0, 1000, self)
|
||||
if minpane != -1:
|
||||
self.minpane = minpane
|
||||
self.sp.SetMinimumPaneSize(self.minpane)
|
||||
|
||||
def OnSetPos(self, evt):
|
||||
initpos = wx.GetNumberFromUser(
|
||||
"Enter the initial sash position (to be used in the Split call)",
|
||||
"", "Initial Sash Position", self.initpos,
|
||||
-1000, 1000, self)
|
||||
if initpos != -1:
|
||||
self.initpos = initpos
|
||||
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close()
|
||||
|
||||
|
||||
app = wx.PySimpleApp(redirect=True)
|
||||
frm = SplitterExampleFrame(None, "Splitter Example")
|
||||
frm.SetSize((600,500))
|
||||
frm.Show()
|
||||
app.SetTopWindow(frm)
|
||||
app.MainLoop()
|
Reference in New Issue
Block a user