]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Dialog.py
Another package name fix
[wxWidgets.git] / wxPython / demo / Dialog.py
CommitLineData
cf694132 1
8fa876ca 2import wx
cf694132
RD
3
4#---------------------------------------------------------------------------
1e4a197e
RD
5# Create and set a help provider. Normally you would do this in
6# the app's OnInit as it must be done before any SetHelpText calls.
8fa876ca 7provider = wx.SimpleHelpProvider()
ce1522a1 8wx.HelpProvider.Set(provider)
031787de 9
1e4a197e
RD
10#---------------------------------------------------------------------------
11
8fa876ca
RD
12class TestDialog(wx.Dialog):
13 def __init__(
14 self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition,
f70ec5b8
RD
15 style=wx.DEFAULT_DIALOG_STYLE,
16 useMetal=False,
8fa876ca 17 ):
1e4a197e 18
95bfd958 19 # Instead of calling wx.Dialog.__init__ we precreate the dialog
8fa876ca 20 # so we can set an extra style that must be set before
f70ec5b8 21 # creation, and then we create the GUI object using the Create
1e4a197e 22 # method.
8fa876ca
RD
23 pre = wx.PreDialog()
24 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1e4a197e
RD
25 pre.Create(parent, ID, title, pos, size, style)
26
27 # This next step is the most important, it turns this Python
28 # object into the real wrapper of the dialog (instead of pre)
29 # as far as the wxPython extension is concerned.
56b98bac 30 self.PostCreate(pre)
1e4a197e 31
f70ec5b8
RD
32 # This extra style can be set after the UI object has been created.
33 if 'wxMac' in wx.PlatformInfo and useMetal:
34 self.SetExtraStyle(wx.DIALOG_EX_METAL)
35
36
1e4a197e
RD
37 # Now continue with the normal construction of the dialog
38 # contents
8fa876ca 39 sizer = wx.BoxSizer(wx.VERTICAL)
1e4a197e 40
95bfd958 41 label = wx.StaticText(self, -1, "This is a wx.Dialog")
1e4a197e 42 label.SetHelpText("This is the help text for the label")
8fa876ca 43 sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
1e4a197e 44
8fa876ca 45 box = wx.BoxSizer(wx.HORIZONTAL)
1e4a197e 46
8fa876ca 47 label = wx.StaticText(self, -1, "Field #1:")
1e4a197e 48 label.SetHelpText("This is the help text for the label")
8fa876ca 49 box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 50
8fa876ca 51 text = wx.TextCtrl(self, -1, "", size=(80,-1))
1e4a197e 52 text.SetHelpText("Here's some help text for field #1")
8fa876ca 53 box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 54
ab5b7b61 55 sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
031787de 56
8fa876ca 57 box = wx.BoxSizer(wx.HORIZONTAL)
031787de 58
8fa876ca 59 label = wx.StaticText(self, -1, "Field #2:")
1e4a197e 60 label.SetHelpText("This is the help text for the label")
8fa876ca 61 box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 62
8fa876ca 63 text = wx.TextCtrl(self, -1, "", size=(80,-1))
1e4a197e 64 text.SetHelpText("Here's some help text for field #2")
8fa876ca 65 box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 66
ab5b7b61 67 sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
031787de 68
8fa876ca
RD
69 line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
70 sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
031787de 71
0f9da074
RD
72 btnsizer = wx.StdDialogButtonSizer()
73
8fa876ca
RD
74 if wx.Platform != "__WXMSW__":
75 btn = wx.ContextHelpButton(self)
0f9da074
RD
76 btnsizer.AddButton(btn)
77
78 btn = wx.Button(self, wx.ID_OK)
1e4a197e 79 btn.SetHelpText("The OK button completes the dialog")
b3b61cda 80 btn.SetDefault()
0f9da074 81 btnsizer.AddButton(btn)
031787de 82
0f9da074 83 btn = wx.Button(self, wx.ID_CANCEL)
8fa876ca 84 btn.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)")
0f9da074 85 btnsizer.AddButton(btn)
b3b61cda 86 btnsizer.Realize()
031787de 87
0f9da074 88 sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
031787de 89
1e4a197e 90 self.SetSizer(sizer)
1e4a197e 91 sizer.Fit(self)
031787de 92
1e4a197e
RD
93#---------------------------------------------------------------------------
94
34a544a6
RD
95class TestPanel(wx.Panel):
96 def __init__(self, parent, log):
97 self.log = log
98 wx.Panel.__init__(self, parent, -1)
99
100 b = wx.Button(self, -1, "Create and Show a custom Dialog", (50,50))
101 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
102
f70ec5b8
RD
103 if 'wxMac' in wx.PlatformInfo:
104 self.cb = wx.CheckBox(self, -1, "Set Metal appearance", (50,90))
105
34a544a6
RD
106
107 def OnButton(self, evt):
f70ec5b8
RD
108 useMetal = False
109 if 'wxMac' in wx.PlatformInfo:
110 useMetal = self.cb.IsChecked()
111
112 dlg = TestDialog(self, -1, "Sample Dialog", size=(350, 200),
113 #style=wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME,
114 style=wx.DEFAULT_DIALOG_STYLE,
115 useMetal=useMetal,
34a544a6
RD
116 )
117 dlg.CenterOnScreen()
118
119 # this does not return until the dialog is closed.
120 val = dlg.ShowModal()
8fa876ca 121
34a544a6
RD
122 if val == wx.ID_OK:
123 self.log.WriteText("You pressed OK\n")
124 else:
125 self.log.WriteText("You pressed Cancel\n")
8fa876ca 126
34a544a6
RD
127 dlg.Destroy()
128
cf694132 129
34a544a6
RD
130#---------------------------------------------------------------------------
131
132
133def runTest(frame, nb, log):
134 win = TestPanel(nb, log)
135 return win
cf694132 136
cf694132 137
8fa876ca 138#---------------------------------------------------------------------------
cf694132
RD
139
140
8fa876ca
RD
141overview = """\
142wxPython offers quite a few general purpose dialogs for useful data input from
143the user; they are all based on the wx.Dialog class, which you can also subclass
144to create custom dialogs to suit your needs.
cf694132 145
8fa876ca
RD
146The Dialog class, in addition to dialog-like behaviors, also supports the full
147wxWindows layout featureset, which means that you can incorporate sizers or
148layout constraints as needed to achieve the look and feel desired. It even supports
149context-sensitive help, which is illustrated in this example.
cf694132 150
8fa876ca
RD
151The example is very simple; in real world situations, a dialog that had input
152fields such as this would no doubt be required to deliver those values back to
153the calling function. The Dialog class supports data retrieval in this manner.
154<b>However, the data must be retrieved prior to the dialog being destroyed.</b>
155The example shown here is <i>modal</i>; non-modal dialogs are possible as well.
cf694132 156
8fa876ca 157See the documentation for the <code>Dialog</code> class for more details.
cf694132 158
8fa876ca 159"""
cf694132 160
1e4a197e
RD
161if __name__ == '__main__':
162 import sys,os
163 import run
8eca4fef 164 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
cf694132 165