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:
48
wxPython/samples/wxPIA_book/Chapter-04/PyWrap.py
Normal file
48
wxPython/samples/wxPIA_book/Chapter-04/PyWrap.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""PyWrap is a command line utility that runs a wxPython program with
|
||||
additional runtime-tools, such as PyCrust."""
|
||||
|
||||
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
||||
__cvsid__ = "$Id$"
|
||||
__revision__ = "$Revision$"[11:-2]
|
||||
|
||||
import wx
|
||||
from wx import py
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def wrap(app):
|
||||
wx.InitAllImageHandlers()
|
||||
frame = py.crust.CrustFrame()
|
||||
frame.SetSize((750, 525))
|
||||
frame.Show(True)
|
||||
frame.shell.interp.locals['app'] = app
|
||||
app.MainLoop()
|
||||
|
||||
def main(modulename=None):
|
||||
sys.path.insert(0, os.curdir)
|
||||
if not modulename:
|
||||
if len(sys.argv) < 2:
|
||||
print "Please specify a module name."
|
||||
raise SystemExit
|
||||
modulename = sys.argv[1]
|
||||
if modulename.endswith('.py'):
|
||||
modulename = modulename[:-3]
|
||||
module = __import__(modulename)
|
||||
# Find the App class.
|
||||
App = None
|
||||
d = module.__dict__
|
||||
for item in d.keys():
|
||||
try:
|
||||
if issubclass(d[item], wx.App):
|
||||
App = d[item]
|
||||
except (NameError, TypeError):
|
||||
pass
|
||||
if App is None:
|
||||
print "No App class was found."
|
||||
raise SystemExit
|
||||
app = App()
|
||||
wrap(app)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
24
wxPython/samples/wxPIA_book/Chapter-04/images.py
Normal file
24
wxPython/samples/wxPIA_book/Chapter-04/images.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#----------------------------------------------------------------------
|
||||
# This file was generated by encode_bitmaps.py
|
||||
#
|
||||
from wx import ImageFromStream, BitmapFromImage
|
||||
from wx import EmptyIcon
|
||||
import cStringIO
|
||||
|
||||
def getNewData():
|
||||
return \
|
||||
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x0f\x08\x06\
|
||||
\x00\x00\x00\xedsO/\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\
|
||||
\x00YIDATx\x9c\xed\xd31\n@!\x0c\x03\xd0\xa4\xfe\xfb\xdfX\xe3\xf0\x97R\xa5(.\
|
||||
\x0ef\x13\xe45\xa2\x92Vp\x92\xcf/\xd4\xaa\xb2\xcd\xb4\xc2\x14\x00\x00in\x90\
|
||||
\x84ZUDl\xa9\xa7\xc3c\xcb-\x80\xfc\x87{d8B6=B\xdb\rfy\xc0\r\xc0\xf0\x0e\xfc\
|
||||
\x1d\xaf\x84\xa7\xbf\xb1\x03\xe1,\x19&\x93\x9a\xd2\x97\x00\x00\x00\x00IEND\
|
||||
\xaeB`\x82'
|
||||
|
||||
def getNewBitmap():
|
||||
return BitmapFromImage(getNewImage())
|
||||
|
||||
def getNewImage():
|
||||
stream = cStringIO.StringIO(getNewData())
|
||||
return ImageFromStream(stream)
|
||||
|
60
wxPython/samples/wxPIA_book/Chapter-04/pycrust-foundation.py
Normal file
60
wxPython/samples/wxPIA_book/Chapter-04/pycrust-foundation.py
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import wx
|
||||
from wx.py.shell import ShellFrame
|
||||
from wx.py.filling import FillingFrame
|
||||
import images
|
||||
|
||||
class ToolbarFrame(wx.Frame):
|
||||
|
||||
def __init__(self, parent, id):
|
||||
wx.Frame.__init__(self, parent, id, 'Toolbars',
|
||||
size=(300, 200))
|
||||
panel = wx.Panel(self, -1)
|
||||
panel.SetBackgroundColour('White')
|
||||
statusBar = self.CreateStatusBar()
|
||||
toolbar = self.CreateToolBar()
|
||||
toolbar.AddSimpleTool(wx.NewId(), images.getNewBitmap(),
|
||||
"New", "Long help for 'New'")
|
||||
toolbar.Realize()
|
||||
menuBar = wx.MenuBar()
|
||||
menu1 = wx.Menu()
|
||||
menuBar.Append(menu1, "&File")
|
||||
menu2 = wx.Menu()
|
||||
menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
|
||||
menu2.Append(wx.NewId(), "C&ut", "")
|
||||
menu2.Append(wx.NewId(), "Paste", "")
|
||||
menu2.AppendSeparator()
|
||||
menu2.Append(wx.NewId(), "&Options...", "Display Options")
|
||||
menuBar.Append(menu2, "&Edit")
|
||||
|
||||
menu3 = wx.Menu()
|
||||
shell = menu3.Append(-1, "&Python shell",
|
||||
"Open Python shell frame")
|
||||
filling = menu3.Append(-1, "&Namespace viewer",
|
||||
"Open namespace viewer frame")
|
||||
menuBar.Append(menu3, "&Debug")
|
||||
self.Bind(wx.EVT_MENU, self.OnShell, shell)
|
||||
self.Bind(wx.EVT_MENU, self.OnFilling, filling)
|
||||
|
||||
self.SetMenuBar(menuBar)
|
||||
|
||||
def OnCloseMe(self, event):
|
||||
self.Close(True)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
def OnShell(self, event):
|
||||
frame = ShellFrame(parent=self)
|
||||
frame.Show()
|
||||
|
||||
def OnFilling(self, event):
|
||||
frame = FillingFrame(parent=self)
|
||||
frame.Show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
app.frame = ToolbarFrame(parent=None, id=-1)
|
||||
app.frame.Show()
|
||||
app.MainLoop()
|
4
wxPython/samples/wxPIA_book/Chapter-04/pywrap
Normal file
4
wxPython/samples/wxPIA_book/Chapter-04/pywrap
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from wx.py.PyWrap import main
|
||||
main()
|
20
wxPython/samples/wxPIA_book/Chapter-04/spare.py
Normal file
20
wxPython/samples/wxPIA_book/Chapter-04/spare.py
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Spare.py is a starting point for simple wxPython programs."""
|
||||
|
||||
import wx
|
||||
|
||||
class Frame(wx.Frame):
|
||||
pass
|
||||
|
||||
class App(wx.App):
|
||||
|
||||
def OnInit(self):
|
||||
self.frame = Frame(parent=None, id=-1, title='Spare')
|
||||
self.frame.Show()
|
||||
self.SetTopWindow(self.frame)
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = App()
|
||||
app.MainLoop()
|
Reference in New Issue
Block a user