WxPython

From Solipsis

Here are just some random notes about WxPython.

Table of contents

Internationalization, Localization

Setup is done using the wx.Locale class :

>>> import wx
>>> locale = wx.Locale()
>>> locale.Init2()
True
>>> wx.GetTranslation("Close")
u'Fermer'
>>> wx.GetTranslation("Cancel")
u'Annuler'
>>> wx.GetTranslation("File")
u'File'
>>>

wxPython comes with a catalog for built-in controls and dialogs. It is automatically loaded by wx.Locale.

XrcResourceFiles are also compatible with localization. Strings in XRC files are automatically passed to the translation mechanism.

To add a catalog, use locale.AddCatalog and optionally locale.AddCatalogPathPrefix.

Sizing and resizing

Calling window.SetSizeHintsSz(window.GetBestSize()) on every window is a good idea: it will prevent resizing to sizes too small.

A FlexGridSizer as root element of a window or dialog allows to have autogrowable rows or columns, so that the window contents don't stay small if the user enlarges the window. For inner controls, use the wxEXPAND (or wxGROW) flag so that they follow suit when the containing window is resized. The "ratio" parameter controls relative sizing of elements in a sizer.

Sleep functions

The various wx Sleep functions (wx.MilliSleep, etc.) look like they completely invalidate the normal event loop behaviour, e.g. all idle events are suspended. Thus they must be avoided.

Useful tools

The following tools are useful:

  • xrced, normally bundled with wxPython
  • wxglade, but it seems a bit buggy especially with latest wxPythonGTK2 releases
  • wxdemo shows nice examples of many wxWidgets
  • wxrc can extract strings from xrc files and put them in files looking like C source code, enabling other tools to extract them and put them in po files (...). As of now, it must be compiled by hand from the wxWidgets source tree.
  • poedit

WxPython and Twisted

See this example !

Documentation

related web sites