A dialog box is similar to a panel, in that it is a window which can be used for placing controls, with the following exceptions:
See also
wx.TopLevelWindow and wx.Window for inherited member functions. Validation of data in controls is covered in Validator Overview.
As an ever greater variety of mobile hardware comes to market, it becomes more imperative for wxPython applications to adapt to these platforms without putting too much burden on the programmer. One area where wxPython can help is in adapting dialogs for the lower resolution screens that inevitably accompany a smaller form factor. wx.Dialog therefore supplies a global wx.DialogLayoutAdapter class that implements automatic scrolling adaptation for most sizer-based custom dialogs.
Many applications should therefore be able to adapt to small displays
with little or no work, as far as dialogs are concerned. By default
this adaptation is off. To switch scrolling adaptation on globally in
your application, call the static function
wx.Dialog.EnableLayoutAdaptation
passing True
. You can also
adjust adaptation on a per-dialog basis by calling
wx.Dialog.SetLayoutAdaptationMode
with one of
wx.DIALOG_ADAPTATION_MODE_DEFAULT
(use the global setting),
wx.DIALOG_ADAPTATION_MODE_ENABLED
or
wx.DIALOG_ADAPTATION_MODE_DISABLED
.
The last two modes override the global adaptation setting. With
adaptation enabled, if the display size is too small for the dialog,
wxPython (or rather the standard adapter class
wx.StandardDialogLayoutAdapter ) will make part of the dialog
scrolling, leaving standard buttons in a non-scrolling part at the
bottom of the dialog. This is done as follows, in
wx.DialogLayoutAdapter.DoLayoutAdaptation
called from within
wx.Dialog.Show
or wx.Dialog.ShowModal
:
wx.Dialog.GetContentWindow
returns a window derived from
wx.BookCtrlBase, the pages are made scrollable and no other
adaptation is done.wx.ID_OK
and wx.ID_CANCEL
.In addition to switching adaptation on and off globally and per
dialog, you can choose how aggressively wxPython will search for
standard buttons by setting
wx.Dialog.SetLayoutAdaptationLevel
. By default, all the steps
described above will be performed but by setting the level to 1, for
example, you can choose to only look for wx.StdDialogButtonSizer.
You can use wx.Dialog.AddMainButtonId
to add identifiers for
buttons that should also be treated as standard buttons for the
non-scrolling area.
You can derive your own class from wx.DialogLayoutAdapter or
wx.StandardDialogLayoutAdapter and call
wx.Dialog.SetLayoutAdapter
, deleting the old object that this
function returns. Override the functions CanDoLayoutAdaptation and
DoLayoutAdaptation to test for adaptation applicability and perform
the adaptation.
You can also override wx.Dialog.CanDoLayoutAdaptation
and
wx.Dialog.DoLayoutAdaptation
in a class derived from
wx.Dialog.
Because adaptation rearranges your sizer and window hierarchy, it is not fool-proof, and may fail in the following situations:
You can help make sure that your dialogs will continue to function after adaptation by:
wx.Dialog.GetContentWindow
to return a book control
if your dialog implements pages: wxPython will then only make the
pages scrollable.Adaptation for wx.PropertySheetDialog is always done by simply
making the pages scrollable, since wx.Dialog.GetContentWindow
returns the dialog’s book control and this is handled by the standard
layout adapter.
wx.adv.Wizard
uses its own CanDoLayoutAdaptation and
DoLayoutAdaptation functions rather than the global adapter: again,
only the wizard pages are made scrollable.