1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
2003-03-25 01:35:27 -05:00
|
|
|
# Create and set a help provider. Normally you would do this in
|
|
|
|
# the app's OnInit as it must be done before any SetHelpText calls.
|
2003-12-08 20:23:28 -05:00
|
|
|
provider = wx.SimpleHelpProvider()
|
2006-03-20 12:56:42 -05:00
|
|
|
wx.HelpProvider.Set(provider)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestDialog(wx.Dialog):
|
|
|
|
def __init__(
|
|
|
|
self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition,
|
2006-03-18 17:17:39 -05:00
|
|
|
style=wx.DEFAULT_DIALOG_STYLE,
|
|
|
|
useMetal=False,
|
2003-12-08 20:23:28 -05:00
|
|
|
):
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
# Instead of calling wx.Dialog.__init__ we precreate the dialog
|
2003-12-08 20:23:28 -05:00
|
|
|
# so we can set an extra style that must be set before
|
2006-03-18 17:17:39 -05:00
|
|
|
# creation, and then we create the GUI object using the Create
|
2003-03-25 01:35:27 -05:00
|
|
|
# method.
|
2003-12-08 20:23:28 -05:00
|
|
|
pre = wx.PreDialog()
|
|
|
|
pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
|
2003-03-25 01:35:27 -05:00
|
|
|
pre.Create(parent, ID, title, pos, size, style)
|
|
|
|
|
|
|
|
# This next step is the most important, it turns this Python
|
|
|
|
# object into the real wrapper of the dialog (instead of pre)
|
|
|
|
# as far as the wxPython extension is concerned.
|
2004-04-22 18:57:50 -04:00
|
|
|
self.PostCreate(pre)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2006-03-18 17:17:39 -05:00
|
|
|
# This extra style can be set after the UI object has been created.
|
|
|
|
if 'wxMac' in wx.PlatformInfo and useMetal:
|
|
|
|
self.SetExtraStyle(wx.DIALOG_EX_METAL)
|
|
|
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
# Now continue with the normal construction of the dialog
|
|
|
|
# contents
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
label = wx.StaticText(self, -1, "This is a wx.Dialog")
|
2003-03-25 01:35:27 -05:00
|
|
|
label.SetHelpText("This is the help text for the label")
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
box = wx.BoxSizer(wx.HORIZONTAL)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
label = wx.StaticText(self, -1, "Field #1:")
|
2003-03-25 01:35:27 -05:00
|
|
|
label.SetHelpText("This is the help text for the label")
|
2003-12-08 20:23:28 -05:00
|
|
|
box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
text = wx.TextCtrl(self, -1, "", size=(80,-1))
|
2003-03-25 01:35:27 -05:00
|
|
|
text.SetHelpText("Here's some help text for field #1")
|
2003-12-08 20:23:28 -05:00
|
|
|
box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2004-05-06 21:51:14 -04:00
|
|
|
sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
box = wx.BoxSizer(wx.HORIZONTAL)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
label = wx.StaticText(self, -1, "Field #2:")
|
2003-03-25 01:35:27 -05:00
|
|
|
label.SetHelpText("This is the help text for the label")
|
2003-12-08 20:23:28 -05:00
|
|
|
box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
text = wx.TextCtrl(self, -1, "", size=(80,-1))
|
2003-03-25 01:35:27 -05:00
|
|
|
text.SetHelpText("Here's some help text for field #2")
|
2003-12-08 20:23:28 -05:00
|
|
|
box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2004-05-06 21:51:14 -04:00
|
|
|
sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
|
|
|
|
sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2005-02-07 14:27:56 -05:00
|
|
|
btnsizer = wx.StdDialogButtonSizer()
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
if wx.Platform != "__WXMSW__":
|
|
|
|
btn = wx.ContextHelpButton(self)
|
2005-02-07 14:27:56 -05:00
|
|
|
btnsizer.AddButton(btn)
|
|
|
|
|
|
|
|
btn = wx.Button(self, wx.ID_OK)
|
2003-03-25 01:35:27 -05:00
|
|
|
btn.SetHelpText("The OK button completes the dialog")
|
2005-02-17 23:38:30 -05:00
|
|
|
btn.SetDefault()
|
2005-02-07 14:27:56 -05:00
|
|
|
btnsizer.AddButton(btn)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2005-02-07 14:27:56 -05:00
|
|
|
btn = wx.Button(self, wx.ID_CANCEL)
|
2003-12-08 20:23:28 -05:00
|
|
|
btn.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)")
|
2005-02-07 14:27:56 -05:00
|
|
|
btnsizer.AddButton(btn)
|
2005-02-17 23:38:30 -05:00
|
|
|
btnsizer.Realize()
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2005-02-07 14:27:56 -05:00
|
|
|
sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
self.SetSizer(sizer)
|
|
|
|
sizer.Fit(self)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2004-08-09 21:21:16 -04:00
|
|
|
class TestPanel(wx.Panel):
|
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
|
|
|
wx.Panel.__init__(self, parent, -1)
|
|
|
|
|
|
|
|
b = wx.Button(self, -1, "Create and Show a custom Dialog", (50,50))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
|
|
|
|
2006-03-18 17:17:39 -05:00
|
|
|
if 'wxMac' in wx.PlatformInfo:
|
|
|
|
self.cb = wx.CheckBox(self, -1, "Set Metal appearance", (50,90))
|
|
|
|
|
2004-08-09 21:21:16 -04:00
|
|
|
|
|
|
|
def OnButton(self, evt):
|
2006-03-18 17:17:39 -05:00
|
|
|
useMetal = False
|
|
|
|
if 'wxMac' in wx.PlatformInfo:
|
|
|
|
useMetal = self.cb.IsChecked()
|
|
|
|
|
|
|
|
dlg = TestDialog(self, -1, "Sample Dialog", size=(350, 200),
|
|
|
|
#style=wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME,
|
|
|
|
style=wx.DEFAULT_DIALOG_STYLE,
|
|
|
|
useMetal=useMetal,
|
2004-08-09 21:21:16 -04:00
|
|
|
)
|
|
|
|
dlg.CenterOnScreen()
|
|
|
|
|
|
|
|
# this does not return until the dialog is closed.
|
|
|
|
val = dlg.ShowModal()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2004-08-09 21:21:16 -04:00
|
|
|
if val == wx.ID_OK:
|
|
|
|
self.log.WriteText("You pressed OK\n")
|
|
|
|
else:
|
|
|
|
self.log.WriteText("You pressed Cancel\n")
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2004-08-09 21:21:16 -04:00
|
|
|
dlg.Destroy()
|
|
|
|
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2004-08-09 21:21:16 -04:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
#---------------------------------------------------------------------------
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
overview = """\
|
|
|
|
wxPython offers quite a few general purpose dialogs for useful data input from
|
|
|
|
the user; they are all based on the wx.Dialog class, which you can also subclass
|
|
|
|
to create custom dialogs to suit your needs.
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
The Dialog class, in addition to dialog-like behaviors, also supports the full
|
|
|
|
wxWindows layout featureset, which means that you can incorporate sizers or
|
|
|
|
layout constraints as needed to achieve the look and feel desired. It even supports
|
|
|
|
context-sensitive help, which is illustrated in this example.
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
The example is very simple; in real world situations, a dialog that had input
|
|
|
|
fields such as this would no doubt be required to deliver those values back to
|
|
|
|
the calling function. The Dialog class supports data retrieval in this manner.
|
|
|
|
<b>However, the data must be retrieved prior to the dialog being destroyed.</b>
|
|
|
|
The example shown here is <i>modal</i>; non-modal dialogs are possible as well.
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
See the documentation for the <code>Dialog</code> class for more details.
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
"""
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
1999-04-29 23:29:54 -04:00
|
|
|
|