Package: wxWize
What? Why?wxWize is a GUI builder library that supplements wxPython.
wxPython is very powerful and very flexible, but creating windows,
sizers and events can be a bit cumbersone.This is where wxWize comes in, providing a simple way of creating
sophisticated wxPython designs in fewer lines of code, with vastly
improved readability, and without sacrifising any of the expressive
power of programmatic GUI building.It’s a shallow wrapper, intended to be easily picked up by anyone
who’s written wxPython applications before. Things are called the same
as in wxPython/wxWidgets where possible.Once frames and dialogs are created, wxWize steps out of the way, and
the wxPython objects are all yours. You use them exactly the same as
you’ve always done, using familiar methods like Bind, SetValue,
GetValue, SetBackgroundColour etc.How?wxWize uses the Pythonwithstatement to express object nesting.Sizers and windows are integrated in a single hierarchy, meaning that
you no longer need to type in all those sizer.Add calls – wxWize
does that for you, based on relative positions in the
with-statement hierarchy.parentandidparameters are gone as required parameters for
controls. parent is computed from the hierarchy position. They can
still be set where needed using named parameters.Installation$ pip install wxWizeOr copy wize.py to your site-packages directory.UsageSizersUse the with statement to create sizers.  Sizers and windows that are
created within the scope of the with-statement, become children of the
sizer, and automatically added.Simple windowsTo create a wx.Window control, use the identically named wize class.
The __init__ parameters are the same as for the wxPython object, except for this:There are only a 1-2 (or an occasional 3) positional
parameters.parent,id,pos,sizeandstylehave been relegated to keyword-only.parentcan and should be
omitted entirely (except for the top-level item).flagandproportionparameters
provide parent sizer Add arguments.x,y,xspanandyspanprovide additional parent sizer Add
arguments, for when the parent sizer is a GridBagSizer.EVT_*parameters provide an event binding
shorthand.initorclsare useful for subclassing.Container windowsFor windows that can have sub-windows (wize.Frame, wize.Dialog, wize.Panel,
wize.StaticBox), use the with statement and nest other windows or sizers
below it.If needed, a BoxSizer is created automatically and passed to
SetSizer. Use  theorientparameter
to set the direction.If there is only one child and that child is a sizer, then
no BoxSizer is created and the child is used instead.Interfacing with ordinary wxPython codewx.Frame/wx.Dialog implemented with wxWizeWhen implementing the whole of a top-level window using wxWize,
define the wxWize hierarchy (of nested with-statements) in the
__init__ of your wx.Frame/wx.Dialog subclass. Use
theinitparameter for the top-level call to
wize.Frame/wize.Dialog.Nesting a wxWize hierarchy within an existing structureWhen implementing only a part of the frame/dialog using wxWize,provide aparentargument to the top-level wxWize
object, and the object returned fromwith .. aswill be ready to put into a sizer in your own plain wxPython code.Nesting an wxPython windowwxPython objects - windows and sizers - can be inserted into a
wxWize hierarchy using ordinary Sizer.Add method calls - using thewith .. asvalue from e.g. a wize.BoxSizer or wize.GridSizer.
The wize.Parent function returns a suitable parent value for
windows.For windows, an alternative is to create a wize.Window with
awparameter, and sizer parameters (flag,proportion)
as needed. Then, wxWize handles the sizer Add.  So you’d write e.g.:my_win=CreateWindowSomeOtherWay(parent=wize.Parent(),...)wize.Window(w=my_win,flag=wx.EXPAND,proportion=1)Nesting a wxPython sizerThere’s no similar setup for inserting a sizer. But you can alwaysGetting at the wxPython objectsThe sizers and windows created are ordinary wx.Sizer and wx.Window
objects.with wize. as *variable*binds the
wrapped  wxPython object tovariable.All the wxWize classes are intended to be used in a Python with
statement.   The value bound withwith .. asis the
wrapped wxPython object, a wx.Window or a wx.Sizer.For simple objects with no sub-objects – StaticText, TextCtrl,
Choice etc. – the with statement can be omitted. In that case, to get
at the wrapped wxPython object, use thewxproperty.E.g. instead of writing:withwize.BoxSizer(wx.HORIZONTAL):withwize.StaticText(u'Enter name: '):passwithwize.TextCtrl()asname_input:passyou can write, to the same effect:withwize.BoxSizer(wx.HORIZONTAL):wize.StaticText(u'Enter name: ')name_input=wize.TextCtrl().wxMenusJust like the with statement and indentation is used to place controls into the sizer
hierarchy, the with statement and indentation can be used to create
menus and submenus. See the example indemo_pallette.py.Start with awize.MenuBarorwize.PopupMenuat the top level. Nested within
that, usewize.MenuItem’s to create simple menu entries, andwize.Menu’s to
create submenus.For an application-global menu bar, usewize.MenuBar, with the main
frame of application as the parent. That is to say, either nestwize.MenuBarwithin awize.Frame, or provide thewx.Framein theparentparameter. The immediate children must bewize.Menu’s, not
MenuItem’s.For a pop-up menu, usewize.PopupMenuas the top-level item, nestingwize.MenuItemandwize.Menuobjects as desired.wize.MenuCheckandwize.MenuRadioare shortcuts forwize.MenuItemwith parameters to create a menu item with a checkbox
or a radio button.Also there’swize.MenuSeparatorwhich adds a separator line between
menu items.Specific featuresEVT_* bindingBind an event callback by using the event name as a named parameter,
with the callback as its value. I.e.EVT_FOO=self.OnFoois a shorthand for.Bind(wx.EVT_FOO, self.OnFoo).Mixing in a window not created using wxWizeIf for whatever reason you don’t want wxWize to create a window, but
you still wxWize to handle the sizers, then create the window yourself
and pass it to thewparameter. wxWize will then use the
w-value you provided instead of creating a new window.You can do this even if there’s no precise wxWize equivalent to thetype of window created. Use a superclass such as wize.Window or wize.Panel
instead.Automatic wx.ALL if border>0Ifborderis set, and none of the border flags
(wx.TOP,wx.BOTTOM,wx.LEFT,wx.RIGHT) are set, then wx.ALL is assumed.fgcolour, bgcolour and toolTipPass afgcolour,bgcolourortoolTipparameter as a shorthand
for.SetForegroundColour,.SetBackgroundColouror.SetToolTip.wx.EXPAND and proportion=1 for sizers and panelsSizers and panels haveflag=wx.EXPANDas the default. (Controls haveflag=0.)
Additionally, panels have proportion=1 as the default.wx.EXPAND and proportion>0 help sizers and panels be neutral
intermediaries: If you e.g have a ListCtrl on a Frame, and you change
that to be a ListCtrl on a Panel on a Frame, then the ListCtrl will
resize with the frame if it did before.Panels include wize.Panel and wize.SplitterWindow.Changing defaults with DefaultThe Default classmethod temporarily changes the default value of one or
more attributes. It’s a with-statement expression, and takes keyword
parameters which are the new defaults for the class for anything
created within the scope of the with statement.For example, to revert the default flag value for a BoxSizer back to 0,
instead of wx.EXPAND, do this:withwize.BoxSizer.Default(flag=0):....GridBagSizer positioningGrid position in a GridBagSizer is set using
separatexandyparameters (which become
the position=wx.GBPosition(y,x) argument to wx.GridBagSizer.Add). To span over
more than one square, there’sxspanandyspan(which become the wx.GBSpan(yspan,xspan)
argument to wx.GridBagSizer.Add).If bothxandyare omitted, then the
item is placed to the right of the previous item, or just below. The
value of theorientattribute determines which one:
wx.HORIZONTAL, and it’s to the right, wx.VERTICAL, and it’s below.One or both ofxandycan be
omitted, in which case the previous value is reused. Or, the
previous value plus one.  That happens if a new x value is provided
that isn’t larger than the previous one, then y is incremented, and
similarly, if the new y value is provided that isn’t larger than the
previous one, then x is incremented.This is perhaps better shown by example:withwize.GridBagSizer():wize.StaticText("First",x=0,y=0)# (x=0, y=0)wize.StaticText("Second",x=1)# (x=1, y=0)wize.StaticText("Third",x=0)# (x=0, y=1)wize.StaticText("Fourth",x=1)# (x=1, y=1)wize.StaticText("Fifth",x=1)# (x=1, y=2)Although only the line number y=0 is explicitly given, “Third” and
“Fifth” are moved to a new line, because the x value isn’t to the
right of the previous x value.Note that this could also have been written like this:withwize.GridBagSizer(wx.HORIZONTAL):wize.StaticText("First")# (x=0, y=0) is the defaultwize.StaticText("Second")# (x=1, y=0)wize.StaticText("Third",x=0)# (x=0, y=1)wize.StaticText("Fourth")# (x=1, y=1)wize.StaticText("Fifth",x=1)# (x=1, y=2)StaticBoxThe wize.StaticBox control combines wx.StaticBox and wx.StaticBoxSizer
into one.StaticLineThe default sizer flag is wx.EXPAND.  A new parameter, ‘thickness’,
sets the size to (-1,self.thickness) if the style is wx.LI_HORIZONTAL,
or (self.thickness,-1) if wx.LI_VERTICAL. In combination, that means
that e.g. within a BoxSizer(wx.VERTICAL)wize.StaticLine(3,wx.LI_HORIZONTAL)or, since wx.LI_HORIZONTAL is already the default, shortened to:wize.StaticLine(3)puts a 3 pixels high line horisontal line across the full width.SplitterWindowSplitterWindow(wx.HORIZONTAL)puts the two nested windows side by side
with a resizing sash between.SplitterWindow(wx.VERTICAL)puts the two
nested windows on top of one another. (Don’t callSplitVerticallyorSplitHorizontally, it’s automatic.)The default of sashGravity=0.5 makes the subwindows equal sized, and
the default of minimumPaneSize=1 ensures that the second subwindow
doesn’t disappear unexpectedly. (Use minimumPaneSize=0 to restore the
wxWidgets default behaviour that a double
click on the sash hides the second window.)FourWaySplittersashPosition=(hfraction,vfraction)sizes the subpanels using fractions in the 0..1 range,
for consistency with sashPosition for SplitterWindow.Properties HSplit and VSplit are an alternative to sashPosition that uses integers in the
range 0..10000 instead, for consistency with the SetHSplit and SetVSplit methods of FourWaySplitter.SubclassingWhen defining a new subclass of a wxPython class, the new subclass
does not have an implementation in wxWize. The obvious fix is to
create a such a class, a wize.Control subclass to wrap your
wx.Control subclass.That’s not at all hard to do.  If you look in wize.py, you can see how
it’s done for the standard controls and do something similar.But there are other options: For wx.Frame and wx.Dialog subclasses,
define the wxWize object hierarchy by using nested with’s in
__init__. For the root of the with-hierarchy, use a wize.Frame or wize.Dialog
with init=self.Finally there’scls, which is an option, if the
subclass __init__ parameter list is identical to the parent
__init__.Subclassing withinitTheinitparameter provides a way to use wxWize from
within the __init__ of a wxPython window subclass. It goes like this:Instead of calling parent __init__ from within the subclass
__init__, create a wxWize object usinginit=selfinstead. Now wxWize will call the parent __init__ with the same
parameters it would otherwise have used to create a new object.Subclassing withclsIf the subclass __init__ takes the same parameters as the parent
class, then you can use an existing wxWize-class
withcls=MyNewSubclass. Theclsparameter
tells wxWize to create the window using this class instead of the normal wxPython class.Isolating withIsolatewxWize uses global state to track the current wxWize
parent.withIsolate():temporarily sets the wxWize
parent to None, so that objects created in the context do not become linked into the
current hierarchy, but stand on their own.List of classesClass namePositional parametersBoxSizerorientButtonlabelCheckBoxlabelChoicechoicesComboBoxvalue, choicesCommandLinkButtonmainLabel, noteControlwDatePickerCtrldtDialogtitleFileBrowseButtonFlexGridSizerrowsFourWaySplittersashPositionFrametitleGaugerangeGradientButtonlabel, bitmapGridGridBagSizerIsolateLabelBookagwStyleListBoxchoicesListCtrlMaskedNumCtrlvalueMaskedTextCtrlvalueMenulabelMenuBarparentMenuChecktext, callbackMenuItemtext, callbackMenuRadiotext, callbackMenuSeparatortext, callbackNotebookPagetextPanelproportionPopupMenuparentPropertyGridRadioButtonlabelScrolledPanelScrolledWindowSearchCtrlShellSpacersizeSpinCtrlmin, max, initialSplitterWindoworient, minimumPaneSizeStaticBoxlabel, orientStaticLinethickness, styleStaticTextlabelStdDialogButtonSizerTextCtrlvalueTopLevelWindowtitleWindowwParameters not in the wxWidgets docsThe wxPython/wxWidgets documentation for creating objects can be
used with wxWize as well, since all the documented __init__
parameters are available.Here’s an overview of the additional parameters that are specific to wxWize:Parameter nameDescriptionwPre-created wxPython object.clsSubclass of the wrapped wxPython class to use.initinit=self if using wxWize to initialise the parent class in __init__proportionSizer Add parameter.flagSizer Add parameter.borderSizer Add parameter.orientPanels and top-level windows can also take this BoxSizer parameter.fgcolourTriggers a SetForegroundColour method call.fgcolourTriggers a SetBackgroundColour method call.toolTipTriggers a SetToolTipString method call.xGridBagSizer column number.yGridBagSizer row number.xspanGridBagSizer column span.yspanGridBagSizer row span.orientLayout of children, wx.VERTICAL or wx.HORIZONTALcallbackEVT_MENU action for MenuItem’sthicknessStaticLine line width.InterpClass_args*args for Shell to pass to InterpClassInterpClass_kwargs**kwargs for Shell to pass to InterpClasssashGravitySplitterWindow.SetSashGravity parameterminimumPaneSizeSplitterWindow.SetMinimumPaneSize parameterEVT_*Set an event callback.