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()
|
|
|
|
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,
|
|
|
|
style=wx.DEFAULT_DIALOG_STYLE
|
|
|
|
):
|
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
|
2003-03-25 01:35:27 -05:00
|
|
|
# creation, and then we create the GUI dialog using the Create
|
|
|
|
# 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.
|
2003-12-08 20:23:28 -05:00
|
|
|
self.this = pre.this
|
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
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer.AddSizer(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
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer.AddSizer(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
|
|
|
|
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
|
|
|
if wx.Platform != "__WXMSW__":
|
|
|
|
btn = wx.ContextHelpButton(self)
|
|
|
|
box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
btn = wx.Button(self, wx.ID_OK, " OK ")
|
2003-03-25 01:35:27 -05:00
|
|
|
btn.SetDefault()
|
|
|
|
btn.SetHelpText("The OK button completes the dialog")
|
2003-12-08 20:23:28 -05:00
|
|
|
box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
btn = wx.Button(self, wx.ID_CANCEL, " Cancel ")
|
|
|
|
btn.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)")
|
|
|
|
box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer.Add(box, 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)
|
|
|
|
self.SetAutoLayout(True)
|
|
|
|
sizer.Fit(self)
|
2002-03-13 17:25:56 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
win = TestDialog(frame, -1, "This is a Dialog", size=(350, 200),
|
2003-03-25 01:35:27 -05:00
|
|
|
#style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
|
2003-12-08 20:23:28 -05:00
|
|
|
style = wx.DEFAULT_DIALOG_STYLE
|
2003-03-25 01:35:27 -05:00
|
|
|
)
|
|
|
|
win.CenterOnScreen()
|
1999-04-29 23:29:54 -04:00
|
|
|
val = win.ShowModal()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
if val == wx.ID_OK:
|
1999-04-29 23:29:54 -04:00
|
|
|
log.WriteText("You pressed OK\n")
|
|
|
|
else:
|
|
|
|
log.WriteText("You pressed Cancel\n")
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-10-01 19:28:31 -04:00
|
|
|
win.Destroy()
|
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
|
|
|
|