11#!/usr/bin/env python
22
33"""
4- Example of the very basic, minimal farmework for a wxPython application
4+ Example of the very basic, minimal framework for a wxPython application
55
6- This shows how to do a text box and a dialog box
6+ This version adds a BoxSizer for laying out buttons on the panel
77"""
88
99import wx
10- import os
1110
1211#---------------------------------------------------------------------------
1312
14- # This is how you pre-establish a file filter so that the dialog
15- # only shows the extension(s) you want it to.
13+ # This is how you pre-establish a file filter so that file dialogs
14+ # only show the extension(s) you want it to.
1615wildcard = "Python source (*.py)|*.py|" \
1716 "Compiled Python (*.pyc)|*.pyc|" \
1817 "SPAM files (*.spam)|*.spam|" \
2120
2221#---------------------------------------------------------------------------
2322
24-
2523class AppLogic (object ):
2624 """
2725 A class to hold the application Application Logic.
@@ -46,12 +44,27 @@ class ButtonPanel(wx.Panel):
4644 def __init__ (self , * args , ** kwargs ):
4745 wx .Panel .__init__ (self , * args , ** kwargs )
4846
49- ## add just a single button:
50- self .theButton = wx .Button (self , label = "Push Me" )
51- self .theButton .Bind (wx .EVT_BUTTON , self .onButton )
52-
47+ ## add two buttons:
48+ theButton1 = wx .Button (self , label = "Push Me" )
49+ theButton1 .Bind (wx .EVT_BUTTON , self .onButton )
50+
51+ ## add two buttons:
52+ theButton2 = wx .Button (self , label = "Push Me Also" )
53+ theButton2 .Bind (wx .EVT_BUTTON , self .onButton )
54+
55+ ## do the layout
56+ ## (try uncommenting the other, and see what happens...)
57+ S = wx .BoxSizer (wx .VERTICAL )
58+ #S = wx.BoxSizer(wx.HORIZONTAL)
59+
60+ S .Add (theButton1 , 0 , wx .GROW | wx .ALL , 4 )
61+ S .Add (theButton2 , 0 , wx .GROW | wx .ALL , 4 )
62+
63+ self .SetSizerAndFit (S )
64+
5365 def onButton (self , evt = None ):
54- print "You pushed the button!"
66+ print "You pushed one of the buttons!"
67+
5568
5669class TestFrame (wx .Frame ):
5770 def __init__ (self , app_logic , * args , ** kwargs ):
@@ -83,13 +96,12 @@ def __init__(self, app_logic, *args, **kwargs):
8396
8497 self .SetMenuBar (menuBar )
8598
86-
8799 def onOpen (self , evt = None ):
88100 """This method opens an existing file"""
89101 print "Open a file: "
90102 # Create the dialog. In this case the current directory is forced as the starting
91- # directory for the dialog, and no default file name is forced. This can easilly
92- # be changed in your program. This is an 'open' dialog, and allows multitple
103+ # directory for the dialog, and no default file name is forced. This can easily
104+ # be changed in your program. This is an 'open' dialog, and allows multiple
93105 # file selections as well.
94106 #
95107 # Finally, if the directory is changed in the process of getting files, this
@@ -111,16 +123,11 @@ def onOpen(self, evt=None):
111123 self .app_logic .file_open ( path )
112124 else :
113125 print "The file dialog was canceled before anything was selected"
114-
115-
116-
117126
118127 # Destroy the dialog. Don't do this until you are done with it!
119128 # BAD things can happen otherwise!
120129 dlg .Destroy ()
121130
122-
123-
124131 def onClose (self , evt = None ):
125132 print "close menu selected"
126133 self .app_logic .file_close ()
0 commit comments