1
1
#!/usr/bin/env python
2
2
3
3
"""
4
- Example of the very basic, minimal farmework for a wxPython application
4
+ Example of the very basic, minimal framework for a wxPython application
5
5
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
7
7
"""
8
8
9
9
import wx
10
- import os
11
10
12
11
#---------------------------------------------------------------------------
13
12
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.
16
15
wildcard = "Python source (*.py)|*.py|" \
17
16
"Compiled Python (*.pyc)|*.pyc|" \
18
17
"SPAM files (*.spam)|*.spam|" \
21
20
22
21
#---------------------------------------------------------------------------
23
22
24
-
25
23
class AppLogic (object ):
26
24
"""
27
25
A class to hold the application Application Logic.
@@ -46,12 +44,27 @@ class ButtonPanel(wx.Panel):
46
44
def __init__ (self , * args , ** kwargs ):
47
45
wx .Panel .__init__ (self , * args , ** kwargs )
48
46
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
+
53
65
def onButton (self , evt = None ):
54
- print "You pushed the button!"
66
+ print "You pushed one of the buttons!"
67
+
55
68
56
69
class TestFrame (wx .Frame ):
57
70
def __init__ (self , app_logic , * args , ** kwargs ):
@@ -83,13 +96,12 @@ def __init__(self, app_logic, *args, **kwargs):
83
96
84
97
self .SetMenuBar (menuBar )
85
98
86
-
87
99
def onOpen (self , evt = None ):
88
100
"""This method opens an existing file"""
89
101
print "Open a file: "
90
102
# 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
93
105
# file selections as well.
94
106
#
95
107
# Finally, if the directory is changed in the process of getting files, this
@@ -111,16 +123,11 @@ def onOpen(self, evt=None):
111
123
self .app_logic .file_open ( path )
112
124
else :
113
125
print "The file dialog was canceled before anything was selected"
114
-
115
-
116
-
117
126
118
127
# Destroy the dialog. Don't do this until you are done with it!
119
128
# BAD things can happen otherwise!
120
129
dlg .Destroy ()
121
130
122
-
123
-
124
131
def onClose (self , evt = None ):
125
132
print "close menu selected"
126
133
self .app_logic .file_close ()
0 commit comments