]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxDialog.py
backport wxRegConfig enumeration fix
[wxWidgets.git] / wxPython / demo / wxDialog.py
1
2 from wxPython.wx import *
3 from wxPython.help import *
4
5 #---------------------------------------------------------------------------
6 # Create and set a help provider. Normally you would do this in
7 # the app's OnInit as it must be done before any SetHelpText calls.
8 provider = wxSimpleHelpProvider()
9 wxHelpProvider_Set(provider)
10
11
12
13 #---------------------------------------------------------------------------
14
15 class TestDialog(wxDialog):
16 def __init__(self, parent, ID, title,
17 pos=wxDefaultPosition, size=wxDefaultSize,
18 style=wxDEFAULT_DIALOG_STYLE):
19
20 # Instead of calling wxDialog.__init__ we precreate the dialog
21 # object so we can set an extra style that must be set before
22 # creation, and then we create the GUI dialog using the Create
23 # method.
24 pre = wxPreDialog()
25 pre.SetExtraStyle(wxDIALOG_EX_CONTEXTHELP)
26 pre.Create(parent, ID, title, pos, size, style)
27
28 # This next step is the most important, it turns this Python
29 # object into the real wrapper of the dialog (instead of pre)
30 # as far as the wxPython extension is concerned.
31 self.this = pre.this
32 self.thisown = pre.thisown
33 pre.thisown = 0
34
35
36 # Now continue with the normal construction of the dialog
37 # contents
38 sizer = wxBoxSizer(wxVERTICAL)
39
40 label = wxStaticText(self, -1, "This is a wxDialog")
41 label.SetHelpText("This is the help text for the label")
42 sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
43
44 box = wxBoxSizer(wxHORIZONTAL)
45
46 label = wxStaticText(self, -1, "Field #1:")
47 label.SetHelpText("This is the help text for the label")
48 box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
49
50 text = wxTextCtrl(self, -1, "", size=(80,-1))
51 text.SetHelpText("Here's some help text for field #1")
52 box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5)
53
54 sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
55
56 box = wxBoxSizer(wxHORIZONTAL)
57
58 label = wxStaticText(self, -1, "Field #2:")
59 label.SetHelpText("This is the help text for the label")
60 box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
61
62 text = wxTextCtrl(self, -1, "", size=(80,-1))
63 text.SetHelpText("Here's some help text for field #2")
64 box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5)
65
66 sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
67
68 line = wxStaticLine(self, -1, size=(20,-1), style=wxLI_HORIZONTAL)
69 sizer.Add(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5)
70
71 box = wxBoxSizer(wxHORIZONTAL)
72
73 if wxPlatform != "__WXMSW__":
74 btn = wxContextHelpButton(self)
75 box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
76
77 btn = wxButton(self, wxID_OK, " OK ")
78 btn.SetDefault()
79 btn.SetHelpText("The OK button completes the dialog")
80 box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
81
82 btn = wxButton(self, wxID_CANCEL, " Cancel ")
83 btn.SetHelpText("The Cancel button cnacels the dialog. (Duh!)")
84 box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
85
86 sizer.AddSizer(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5)
87
88 self.SetSizer(sizer)
89 self.SetAutoLayout(True)
90 sizer.Fit(self)
91
92
93
94 #---------------------------------------------------------------------------
95
96 def runTest(frame, nb, log):
97 win = TestDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200),
98 #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
99 style = wxDEFAULT_DIALOG_STYLE
100 )
101 win.CenterOnScreen()
102 val = win.ShowModal()
103 if val == wxID_OK:
104 log.WriteText("You pressed OK\n")
105 else:
106 log.WriteText("You pressed Cancel\n")
107 win.Destroy()
108
109
110 #---------------------------------------------------------------------------
111
112
113
114
115
116 overview = """\
117 """
118
119
120
121 if __name__ == '__main__':
122 import sys,os
123 import run
124 run.main(['', os.path.basename(sys.argv[0])])
125