1+ #!/usr/bin/env python
2+
3+ """
4+ The basic from for the address book
5+
6+ This gets a Panel to itself
7+ """
8+
9+ import wx
10+
11+ class A_Book_Form (wx .Panel ):
12+ def __init__ (self , a_entry , * args , ** kwargs ):
13+ wx .Panel .__init__ (self , * args , ** kwargs )
14+
15+ self .a_entry = a_entry
16+
17+ ## create text boxes to edit: first name, last name, phone, email.
18+ self .fname_text = wx .TextCtrl (self )
19+ self .lname_text = wx .TextCtrl (self )
20+ self .phone_text = wx .TextCtrl (self )
21+ self .email_text = wx .TextCtrl (self )
22+
23+ ## use a FlexGridSizer:
24+ S = wx .FlexGridSizer (rows = 0 , cols = 2 , vgap = 8 , hgap = 8 )
25+ S .AddGrowableCol (idx = 1 , proportion = 1 )
26+
27+ S .Add (wx .StaticText (self , label = "First Name:" ), 0 ,
28+ wx .ALIGN_RIGHT | wx .ALIGN_CENTER_VERTICAL )
29+ S .Add (self .fname_text , flag = wx .EXPAND )
30+
31+ S .Add (wx .StaticText (self , label = "Last Name:" ), 0 ,
32+ wx .ALIGN_RIGHT | wx .ALIGN_CENTER_VERTICAL )
33+ S .Add (self .lname_text , flag = wx .EXPAND )
34+
35+ S .Add (wx .StaticText (self , label = "Phone Number:" ), 0 ,
36+ wx .ALIGN_RIGHT | wx .ALIGN_CENTER_VERTICAL )
37+ S .Add (self .phone_text , flag = wx .EXPAND )
38+
39+ S .Add (wx .StaticText (self , label = "Email Address:" ), 0 ,
40+ wx .ALIGN_RIGHT | wx .ALIGN_CENTER_VERTICAL )
41+ S .Add (self .email_text , flag = wx .EXPAND )
42+
43+ #Put the whole thing in another sizer to give it some space
44+ Outer_Sizer = wx .BoxSizer (wx .VERTICAL )
45+ Outer_Sizer .Add (S , 0 , wx .ALL | wx .EXPAND , 10 )
46+ self .SetSizerAndFit (Outer_Sizer )
47+
48+ self .load_data ()
49+
50+ def load_data (self ):
51+ """
52+ load the data into the form from the data dict
53+ """
54+ data = self .a_entry
55+ self .fname_text .Value = data [u'first_name' ]
56+ self .lname_text .Value = data [u'last_name' ]
57+ self .phone_text .Value = data [u'phone' ]
58+ self .email_text .Value = data [u'email' ]
59+
60+ def save_data (self ):
61+ """
62+ save the data from the form from the data dict
63+ """
64+ data = self .a_entry
65+ data [u'first_name' ] = self .fname_text .Value
66+ data [u'last_name' ] = self .lname_text .Value
67+ data [u'phone' ] = self .phone_text .Value
68+ data [u'email' ] = self .email_text .Value
69+
70+
71+ # I like to have a little test app so it can be done on its own
72+ if __name__ == "__main__" :
73+
74+ # a sample entry:
75+ entry = {
u'email' :
u'[email protected] ' ,
76+ u'first_name' : u'Chris' ,
77+ u'last_name' : u'Barker' ,
78+ u'phone' : u'123-456-7890' }
79+
80+ app = wx .App (False )
81+ f = wx .Frame (None )
82+ p = A_Book_Form (entry , f )
83+ f .Show ()
84+ app .MainLoop ()
0 commit comments