The wxGlade local Widgets book

V 0.1b 2009-11-04 Correct filename, add more properties description
V 0.2b 2009-11-21 Added commented code for TextProperty

Introduction

wxGlade is a GUI designer that is used to design and generate code for the wxWidget toolkit. wxGlade has a limited widget choice but have extensions possibilities. First, there is a custom widget button so that you can insert about any wxWidget on your form, there are also templates that you can manage and use as needed and finally, there is support for local 'plug-in' widget.

This document describe howto design and install local plugin widgets. They are well integrated to wxGlade, using the widgets parameters, properties and events interfaces panels. They provide the correct look in the visual design window. In all ways, they have the same 'look and feel' as built-in widgets.

Local widgets installation

This section show you how to install the local widgets. If you have already a local widget, you have just a few steps to install.

Setup the local widgets root directory

Start wxGlade, select View->Preferences... In the preferences window, select the 'Other' tab.menu. The local widget root is in the 'Local widget path' field. Create the directory and enter the path as needed. You should have a widgets.txt file in the directory, create an empty text file if needed.

Move the local widget to the root diretory

Move or copy the new widget directory and his files in the local widget root directory.

Enter the widget in the widgets.txt file

Open the text file with any plain text editor and add a line with the name of the widget directory

More information - local widget directory, files and formats


Directory example: knob Control
"""

Local widget root directory
  |
  |-- widgets.txt
  |
  |-- knob_ctrl
      |
      |-- __.ini__.py
      |-- knob_ctrl.py
      |-- codegen.py
      |-- knob_ctrl.xpm
      |-- perl_codegen.py (optional)
      |-- lisp_codegen.py (optional)
      |-- more worker directories, class and/or modules
"""

Files description

__ini__.py
Load and initialize the local widget
<widget>.py
Widget GUI code. Standard properties and method to connect to wxGlade.
codegen.py
Code generation to write Python, xml file and C++ files
<widget>.xpm
Icon file in XWindows picture map format.
perl_codegen.py
Generate perl code.
lisp_codegen.py
Generate lisp code
class/helper modules
Any module to add functions or class to help streamline the code. Only required for very complex widgets (multi-panels, tool strips, ...)

widgets.txt file

The file is scanned at wxGlade startup. Il you have may local widgets, you can comment the ones you don't need to reduce clutter.

widgets.txt example
# list of widget modules available (one per line, without extension)
# lines starting with a '#' are comments
knob_ctrl  

Icon file

Icons for wxGlade tool panel buttons. Icons for builtin widget are found in the wxGlade/icon directory. We will place the new ones in the local widget subdirectory to help portability.


A simple local widget

Create the first local widget

This will show how easy it can be to create a new widget. For our first local widget we will code the checkListBox. To make things easier, we select the listBox as a starting point as it is very close to the checkListBox. Just a few easy steps:

  1. Copy the list_box directory with all the files from the wxGlade/widget directory to the local widget directory.
  2. Change the local widget directory name from list_box to check_list_box
  3. Change the file name from list_box.py to check_list_box.py
  4. Scan all the source files, find and replace list_box by check_list_box; find and replace also wxListBox by wxCheckListBox
  5. Replace the events by EVT_CHECKED
  6. Add a line in the local widgets.txt file with only check_list_box on the line.

Done! Start wxGlade: you will see the button: 'Custom components'. Create a frame, add a checkListBox, and preview.



Adding a new widget

Select the widget, try to find a similar widget that you can use as a starting point. Enumerate parameters, properties and events. Create the new local widget directory and modules.

The code must:
From now on, the following conventions will apply:

<localDir>
The name of the root directory for the local widget.
<widgetDir>
The directory that contains the local widget modules.
<widget>
Then name of the widget 'python style' ie lower case with underscores
<wxWidget>
The name of the widget as used in wxPython

Declaration

In the <localDir>\widgets.txt file: add a line for <widget>.

The __ini__.py will import the widget modules and icon. The standard is OK for most purposes, importing and initializing modules:

__ini__.py example

def initialize():
    import common
    import codegen
    codegen.initialize()
    if common.use_gui:
        import knob_ctrl
        return knob_ctrl.initialize()
 

Declare the new widget class in the <widget>.py file.

Class declaration
   
class EditKnobCtrl(ManagedBase):
    """\
    Class to handle wxKnobCtrl objects
    """

Base classes

Different base classes are available, depending on the class parameters. You will find them in edit_window.py

EditBase
Base class of every window available in the builder.
WindowBase
Extends EditBase with the addition of the common properties available to almost every window: size, background and foreground colors, and font
ManagedBase
Base class for every managed window used by the builder: extends WindowBase with the addition of properties relative to the layout of the window: option, flag, and border
TopLevelBase
Base class for every non-managed window (i.e. Frames and Dialogs).

Builders and code generators

Builders and codes generators are declared in the initialize function of <widget>.py and codegen.py. The standard one will work just fine. Just change the widget names unless you have custom properties handlers.

Again keep the same code in the builder and xml_builder functions in <widget>.py; only change the widget edit class.




Icons

wxGlade icons are used on the toolbox array buttons. They are 21x21 pixels, 256 colors xpm format files; you can use Gimp to format them.

Modify an existing icon or create your own from scratch, then save it as <localDir>/<widget>/<widget>.xpm. Our example would use localWidgets/check_list_box/check_list_box.xpm.

Change the (normally last) line of <widiget>.py to use the current module directory:


Local widget icon - find and load

    import os
    # ... module code

    # Change the last line to find module directory
    # return common.make_object_button('EditCheckListBox', 'icons/list_box.xpm')       
    return common.make_object_button('EditCheckListBox',
                  os.path.join(os.path.dirname(__file__) ,'check_list_box.xpm'))
 


Widget GUI instanciating

The <widget>.create_widget method will create an instance of the widget to use on the designer GUI. Use 'self.widget' for the object name, 'self.parent.widget' as parent and 'self.id' as id. After instanciation, you can add whatever code you need to process properties values. Parameters are handled automatically depending of the base class used in the edit control.

Create widget

    def create_widget(self):
        self.widget = wx.lib.agw.knobctrl.KnobCtrl(self.parent.widget, self.id)
 



Events

All processing is done by wxGlade. Events are defined in the <widget>.py module, 'Edit<widget>' class.  'events' is a class variable that holds the list of events we want to show in wxGlade:

Events declaration
   

    events = ['KC_EVENT_ANGLE_CHANGING','KC_EVENT_ANGLE_CHANGED']
     


Adding properties

wxGlade provides useful tools to manage properties:

Declare properties

The properties declaration will be added in the <widget>.Edit<widget>.__init__

Add the object instance variables to hold the property value.

Add a self.access_function declaration for the property

Add the property to the dictionnary as a property type object.

You can use one of the following standard properties objects; you can find them in the widget_properties.py module:



Common ObjectProperty parameters

Parent
Label
Will be shown on the property panel.
can_disable

Every type handler has a boolean 'can_disable' property'. If True a checkbox will be displayed at the left of the parameter field. If
this checkbox is empty, the input field will be disabled and the property will be deleted from the property dictionnary. Thus we can control code generation in codegen modules. The program can change the status using the toggle_active() method and test it with is_active property.

write_always
If True, the property will be written to the xrc file, even if the can_disable box is unchecked. Default: False
omitter
Blocking key used by activator enabled object, default None.

Working with editors, you can access widgets underlyiing the input fields. For example, to change minimun and maximum value of a SpinProperty, add a line to the display method after the widget property entry is created:
self.property['maxValue'].spin.SetRange(100, 1000)
Be warned that the names can change in a later version so your code won't work anymore.

Common ObjectProperty properties

access_functions[]
This dictionnary will contain for each property name a tuple of the get/set functions.
_original[]
Dictionnary of original property value for each property name.
properties[]
Dictionnary of specific PropertyType for each property name

HiddenProperty

This is a place holder for a property without user interface, ie computed from other values. 'label' is set to None by the property code. The 'HiddenProperty' will provide dummy access functions so you don't have to declare get_value and set_value method in the property dictionnary. Naturally, you can also provide your own get_value and/or set_value methods.
This property type is useful as it is built around the same structures and processing frames as the other properties type. The standard properties services will provide file read/write. And it is easy to switch property type if you ever have to.

TextBoxProperty

This property will let the user input a text. You have the option to allow multi-lines entries. We will use extracts from static_text and shows how to use it, first in the widget module, then in the codegen.py

TextBoxProperty - commented code
    def __init__(self, name, parent, id, label, sizer, pos, property_window,
                 show=True):
        """\
        Class to handle ... objects
        """

        import config
        ManagedBase.__init__(self, name, 'wxStaticText', parent, id, sizer,
                             pos, property_window, show=show)
        #  Declare the local value holder for the parameter
        # we initialise the value to the __init__ parameter                  
        self.label = label
        # code...
       
        # Declare the get and set function
        self.access_functions['label'] = (self.get_label, self.set_label)
        # code...
        # code...
       
        # Create the user interface object: notice the 'multiline' option!
        self.properties['label'] = TextProperty(self, 'label', None,
                                                multiline=True, label=_('label'))
        # more code...
        # ...
               
    def create_widget(self):
        self.widget = StaticText(self.parent.widget, self.id,
                                 self.label.replace('\\n', '\n'))
        # we don't have to provide an creation time value as it
        # is specified in the __init__ parameter.
               
    def create_properties(self):
        ManagedBase.create_properties(self)
        panel = wx.Panel(self.notebook, -1)
        szr = wx.BoxSizer(wx.VERTICAL)
        # Add the property to the property panel
        self.properties['label'].display(panel)
        # code...
        szr.Add(self.properties['label'].panel, 0, wx.EXPAND)
                # code...
       
   
        # The 'get' method         
    def get_label(self): return self.label

    # The 'set' method
    def set_label(self, value):
        value = misc.wxstr(value)
        if not misc.streq(value, self.label):
            self.label = value
            if self.widget:
                self.widget.SetLabel(value.replace('\\n', '\n'))
                if not self.properties['size'].is_active():
                    self.sizer.set_item(self.pos,
                                        size=self.widget.GetBestSize())
 



codegen.py - with comments
class PythonCodeGenerator:
    def get_code(self, obj):
        # Code, code, code...
        # Get property value, add proper quotes
        label = pygen.quote_str(prop.get('label', ''))
                # Code...
               
                # Use the value in the code generator:
        init.append('%s%s = %s(%s, %s, %s%s)\n' %
                    (prefix, obj.name, klass, parent, id, label, style))
                # ...

class CppCodeGenerator:
    def get_code(self, obj):
                # ...code...
        # Get property value, add proper quotes
        label = cppgen.quote_str(prop.get('label', ''))
        # Code....
        # Write the value to the c text
        init = ['%s%s = new %s(%s, %s, %s%s);\n' %
                (prefix, obj.name, obj.klass, parent, id, label, extra) ]
        
        # More code....
 

CheckBoxProperty

Use a check box to set the property value.

SpinProperty

ComboBoxProperty

RadioProperty

CheckListProperty

DialogProperty

FileDialogProperty

FontDialogProperty

This property allows you to manage fonts selection.
Invoke the property creation  prop['font']

ColorDialogProperty

Returns either the name of a system context color or the name of a color. You must transform it to an actual color to display the widget in wxGlade but keep in  the code generators.
If you use a ColorDialog with the parameter can_disable=True, the class will reset the property to the default value when the property is disabled, i.e. check box unchecked. To use it:
The user selected value is a string that can represent a system color (wx.SYS_COLOUR_BTNFACE) or a string representation of a hex value of the RGB channel (#000000 = black). (As of this writing wxGlade does not support Alpha channel). This is the value written to file and used to generate the code.

To display this color, we convert it to a wx.colour object that we can use in SetObjectColour methods. wxGlade provide the misc.string_to_color functon that returns a wx.object. We must use this format for the self._original value as it is used in the wxGlade functions.

The ColorDialogProperty will capitalize the property name and add 'Set' before and 'Colour' after the name so 'tags' will become SetTagsColour method. If the method use two capital letters (SetFirstGradientColour), just assign the proper name to the ColorDialogProperty name in create_widget:

 
Adding a color property - widget commented code
   
   
    def __init__(self, name, parent, id, sizer, pos, property_window,
                 show=True):
        import config
        ManagedBase.__init__(self, name, 'wxKnobCtrl', parent, id,
                             sizer, pos, property_window, show=show)
        # code.......
        # ...
        # Declare the local value holder for the parameter
        self.color1='wxSYS_COLOUR_BTNFACE'
       
        # ...
        # Declare the get and set function and create a user interface object
        self.access_functions['FirstGradient']=(self.get_color1, self.set_color1)
        self.properties['FirstGradient']=ColorDialogProperty(self, 'FirstGradient', can_disable=True, label=_('Color 1'))
       
        # ...
    # Helper function for color management     
    def to_color(self, colorName):
        """From system color name or hex color string
        returns wxColor object """

        wColorName=colorName.strip()
        if wColorName in ColorDialogProperty.str_to_colors:
            return wx.SystemSettings_GetColour(ColorDialogProperty.str_to_colors[wColorName])
        else:
            try:
                return misc.string_to_color(wColorName)
            except:
                return None
           
    def create_widget(self):
        self.widget = wx.lib.agw.knobctrl.KnobCtrl(self.parent.widget,
                                                                                        self.id)
        # ...
        # We must create synonyms for methods with multiple Capital letters
        # as ColorProperty will capitallze some names
        self.widget.SetFirstgradientColour=self.widget.SetFirstGradientColour
       
        # As we want the original value we memorize it right after widget creation
        # This will provide automatic value rollback when the checkbox is unchecked
        self._original['FirstGradient']=self.widget.GetFirstGradientColour()

        # ...
        # Apply any value read from a xrc file
        if self.properties['FirstGradient'].is_active():
            self.widget.SetFirstGradientColour(self.to_color(self.color1))
           
           
    def create_properties(self):
        ManagedBase.create_properties(self)
        panel = wx.ScrolledWindow(self.notebook, -1, style=wx.TAB_TRAVERSAL)
        szr = wx.BoxSizer(wx.VERTICAL)

        # ...
        # Add the property to the property grid panel
        self.properties['FirstGradient'].display(panel)

        # ...
        # add the property field to the sizer
        szr.Add(self.properties['FirstGradient'].panel, 0, wx.EXPAND)

    # ...
    # add the get property and set property method    
    def get_color1(self):
        return self.color1
   
    def set_color1(self, value):
        new_color=self.to_color(value)
        if new_color:
            self.color1=value
            if self.widget:
                self.widget.SetFirstGradientColour(new_color)
        else:
            self.properties['FirstGradient'].set_value(self.color1)            


Color property generate python and c++ - codegen.py

class PythonCodeGenerator():
        # code.....
    def get_code(self, obj):
        # code....
        #  Read the selected value and output a color code or a system color name
        color1=prop.get('FirstGradient')
        if color1 is not None:
            sysColIdx=getattr(wx, color1[2:], None)
            if color1[0:12]=='wxSYS_COLOUR' and sysColIdx is not None:
                colorCode=('wx.SystemSettings_GetColour(wx.%s)' %
                           color1[2:])
            else:
                colorCode=('wx.Colour(%s, %s, %s)' %
                           tuple([int(color1[i:i+2], 16) for i in range(1, 7, 2)]))
            props_buf.append('self.%s.SetFirstGradientColour(%s)\n' %
                             (obj.name, colorCode))

        # ...

class CppCodeGenerator:
    # ,,,
       
    def get_code(self, obj):
        """\
        generates C++ code for wxKnobCtrl objects.
        """

        # ...
        # Read the selected value and output a color code or a system color name
        color1=prop.get('FirstGradient')
        if color1 is not None:
            sysColIdx=getattr(wx, color1[2:], None)
            if color1[0:12]=='wxSYS_COLOUR' and sysColIdx is not None:
                colorCode=('wxSystemSettings_GetColour(wx%s)' %
                           color1[2:])
            else:
                colorCode=('wxColour(%s, %s, %s)' %
                           tuple([int(color1[i:i+2], 16) for i in range(1, 7, 2)]))
            props_buf.append('%s->SetFirstGradientColour(%s)\n' %
                             (obj.name, colorCode))
       
 

GridProperty

Grid Property is  used when you need to input tabular values like the  arguments table for the custom widget, fields in the status bar, grid columns list, etc... It provides 'Apply', 'Add', 'Insert' and 'Remove' buttons, columns headers and multiple selection.
The grid property supports four columns input type: string, int, float and bool with defined constants. It exposes 'can_add', 'can_remove' and 'can_insert' properties to enable/disable those buttons.

We can have an example in the frame.py module, class EditStatusBar:

Commented code from EditStatusBar

# code ...


class EditStatusBar(EditBase):

    # code...
  
    def __init__(self, parent, property_window):
        EditBase.__init__(self, parent.name + '_statusbar',
                          'wxStatusBar', parent, id, property_window,
                          custom_class=False, show=False)

        # code...
        # create value holder
        self.fields = [ [self.name, "-1"] ] # list of 2-lists label, size
                                            # for the statusbar fields
        self.access_functions['fields'] = (self.get_fields, self.set_fields)
        prop = self.properties['fields'] = GridProperty(
            self, 'fields', None,
            [("Text", GridProperty.STRING), ("Size", GridProperty.INT)])
   
        # code...

        # fields custom writer...

    def create_widget(self):
        self.widget = wx.StatusBar(self.parent.widget, wx.NewId())
        wx.EVT_LEFT_DOWN(self.widget, self.on_set_focus)
   
        # we use the local value when we create the wxGlade widget

        self.set_fields(self.fields)
        if self.parent.widget: self.parent.widget.SetStatusBar(self.widget)

    def create_properties(self):
        # code...
        # link property to properties panel
        prop = self.properties['fields']
        prop.display(page)
        sizer = page.GetSizer()

        # code...
   
        # Add to the sizer

        sizer.Add(prop.panel, 1, wx.ALL|wx.EXPAND, 3)
   
        # code...



    # set/get property

    def set_fields(self, values):
        # values is a list of lists
        self.fields = []
        if self.widget: self.widget.SetFieldsCount(len(values))
        for i in range(len(values)):
            try: v = int(values[i][1])
            except: v = 0
            s = misc.wxstr(values[i][0])
            self.fields.append([s, str(v)])
            if self.widget: self.widget.SetStatusText(s, i)
        if self.widget:
            self.widget.SetStatusWidths([int(i[1]) for i in self.fields])

    def get_fields(self):
        return self.fields

    # code...

    # code...
    # code...

  
# end of class EditStatusBar
      

ChoicesProperty

This property type will allow the user to load a list of selectable value. It is used in comboBox, listBox, radioBox. It is a GridProperty subclassed to handle choices.

Most of the time, there is also a selection value field to preset to the selection value. Choices and selection are different properties but work together.

 The following is taken from the list_box widget:


Choices property - commented code from list_box widget

# import the propertyType

from ChoicesProperty import *

class EditListBox(ManagedBase):
    ...
  
    def __init__(self....):

        # ...code...
        # Create a value holder
        self.choices = choices
        # properties
        # ChoicesProperty subclasses GridProperty: see widget_properties.py
        self.access_functions['choices'] = (self.get_choices, self.set_choices)
        self.properties['choices'] = ChoicesProperty(self, 'choices', None,
                                                     [(_('Label'),
                                                       GridProperty.STRING)],
                                                     len(choices), label=_('choices'))

        # ...code...

    def create_widget(self):
        # Actually use the value when we create the GUI widget:
        self.widget = wx.ListBox(self.parent.widget, self.id,
                                choices=self.choices)

        # ...code...

    def create_properties(self):
        ManagedBase.create_properties(self)
        panel = wx.ScrolledWindow(self.notebook, -1, style=wx.TAB_TRAVERSAL)
        szr = wx.BoxSizer(wx.VERTICAL)
        # Link the property type to the wxGlade properties panel
        self.properties['choices'].display(panel)

        # ...code...
        # Add the Choice selector to the wxGlade properties panel
        ch = self.properties['choices'].panel
        ch.SetSize((ch.GetSize()[0]-20, 200))
        szr.Add(self.properties['choices'].panel, 1, wx.ALL|wx.EXPAND, 5)
        panel.SetAutoLayout(True)
        panel.SetSizer(szr)
        szr.Fit(panel)

        # Add scroll bar and adjust sizes
        w, h = panel.GetSize()
        from math import ceil
        panel.SetScrollbars(5, 5, int(ceil(w/5.0)), int(ceil(h/5.0)))
        self.notebook.AddPage(panel, 'Widget')
        self.properties['choices'].set_col_sizes([-1])
       
        # ...code...


    def get_property_handler(self, prop_name):
        # ChoicesProperty uses a custom property handler      
        # found in ChoicesProperty.py
        if prop_name == 'choices':
            return ChoicesHandler(self)
        return ManagedBase.get_property_handler(self, prop_name)

        # ...code...


    # get/set methods
    def get_choices(self):
        return zip(self.choices)

    def set_choices(self, values):
        self.choices = [ misc.wxstr(v[0]) for v in values ]
        self.properties['selection'].set_range(0, len(self.choices)-1)
        if self.widget:
            self.widget.Clear()
            for c in self.choices: self.widget.Append(c)
            if not self.properties['size'].is_active():
                self.sizer.set_item(self.pos, size=self.widget.GetBestSize())
            self.widget.SetSelection(
                int(self.properties['selection'].get_value()))

        # ...code...

# end of class EditListBox

        # ...code...




commented code for choice - codegen.py
# THIS PROGRAM COMES WITH NO WARRANTY

# We will need the special choice handler: import it
from ChoicesCodeHandler import *


class PythonCodeGenerator:
    def get_code(self, obj):

        # ...
        # Find user selected choices
        choices = prop.get('choices', [])

        # ...
        # Format string and output code
        choices = ', '.join([pygen.quote_str(c) for c in choices])

        # ...
        init.append('self.%s = %s(%s, %s, choices=[%s]%s)\n' %
                    (obj.name, klass, parent, id, choices, style))
        # ...
        # ...

# end of class PythonCodeGenerator

# We must create a custom xrc generator to process the interaction
# of 'choices' and 'selection'
def xrc_code_generator(obj):
    xrcgen = common.code_writers['XRC']
    class ListBoxXrcObject(xrcgen.DefaultXrcObject):
        def write_property(self, name, val, outfile, tabs):
            if name == 'choices':
                xrc_write_choices_property(self, outfile, tabs)
            elif name == 'selection':
                choices = self.properties['choices']
                if choices:
                    xrcgen.DefaultXrcObject.write_property(self, name, val,
                                                           outfile, tabs)
            else:
                xrcgen.DefaultXrcObject.write_property(self, name, val,
                                                       outfile, tabs)

    # end of class ListBoxXrcObject

    return ListBoxXrcObject(obj)


class CppCodeGenerator:
    def get_code(self, obj):
        """\
        generates the C++ code for wxListBox objects
        """

        # ...
        # Get the values
        choices = prop.get('choices', [])

        # ...
        # build the choice array
        ch_arr = '{\n        %s\n    };\n' % \
                 ',\n        '.join([cppgen.quote_str(c) for c in choices])

        # ...
        # Generate c++ code
        if number:
            init.append('const wxString %s_choices[] = %s' % (obj.name, ch_arr))
        else:
            init.append('const wxString *%s_choices = NULL;\n' % obj.name)
        init.append('%s = new %s(%s, %s, wxDefaultPosition, wxDefaultSize, '
                    '%s, %s_choices, %s);\n' % \
                    (obj.name, obj.klass, parent, id, number, obj.name, style))
        # ...

# end of class CppCodeGenerator


# We must declare the custom property handler for each generator:
def initialize():
    common.class_names['EditListBox'] = 'wxListBox'

    pygen = common.code_writers.get("python")
    if pygen:
        pygen.add_widget_handler('wxListBox', PythonCodeGenerator())
        pygen.add_property_handler('choices', ChoicesCodeHandler)
    xrcgen = common.code_writers.get("XRC")
    if xrcgen:
        xrcgen.add_widget_handler('wxListBox', xrc_code_generator)
        xrcgen.add_property_handler('choices', ChoicesCodeHandler)
    cppgen = common.code_writers.get('C++')
    if cppgen:
        cppgen.add_widget_handler('wxListBox', CppCodeGenerator())
        cppgen.add_property_handler('choices', ChoicesCodeHandler)
 



Technical reference

Widget classes using properties

The following widgets use properties. Read the code to get a better understanding of how to do it.

widget_properties.py reference

 
 
widget_properties
index
c:\program files\wxglade\source\wxglade-0.6.3\widget_properties.py

# widget_properties.py: classes to handle the various properties of the widgets
# (name, size, color, etc.)
# $Id: widget_properties.py,v 1.65 2007/08/07 12:21:56 agriggio Exp $

# Copyright (c) 2002-2007 Alberto Griggio <agriggio@users.sourceforge.net>
# License: MIT (see license.txt)
# THIS PROGRAM COMES WITH NO WARRANTY

 
Modules
       
common
misc
wx

 
Classes
       
Property
CheckBoxProperty
CheckListProperty
ComboBoxProperty(Property, _activator)
DialogProperty(Property, _activator)
ColorDialogProperty
FileDialogProperty
FontDialogProperty
GridProperty
HiddenProperty
RadioProperty(Property, _activator)
SpinProperty(Property, _activator)
TextProperty(Property, _activator)
 
class CheckBoxProperty(Property)
    Properties whose values can be changed by one checkbox. 
  Methods defined here:
__init__(self, owner, name, parent=None, label=None, write_always=False)
bind_event(self, function)
display(self, parent)
Actually builds the check box to set the value of the property
interactively
get_value(self)
set_value(self, val)
write(self, outfile, tabs)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed
 
class CheckListProperty(Property)
    Properties whose values can be changed by a list of checkboxes. 
  Methods defined here:
__init__(self, owner, name, parent=None, labels=None, writer=None, tooltips=None)
@type labels: list of strings
@param labels: list of names of the labels of the checkboxes; a
label that begins with the string "#section#" is used as the
title of a static box that encloses the checkboxes that
follow
@type tooltips: tuple of strings
@param tooltips: a list of strings to be displayed as the tool-tips for
the properties
bind_event(self, function)
display(self, parent)
Actually builds the list of checkboxes to set the value of the property
interactively
get_value(self)
prepare_value(self, old_val)
turns a string of tokens separated by '|' into a list of
boolean values
set_value(self, value)
write(self, outfile, tabs)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed
 
class ColorDialogProperty(DialogProperty)
    
Method resolution order:
ColorDialogProperty
DialogProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, parent=None, can_disable=True, label=None)
display_dialog(self, event)
toggle_active(self, active)

Data and other attributes defined here:
colors_to_str = {0: 'wxSYS_COLOUR_SCROLLBAR', 1: 'wxSYS_COLOUR_DESKTOP', 2: 'wxSYS_COLOUR_ACTIVECAPTION', 3: 'wxSYS_COLOUR_INACTIVECAPTION', 4: 'wxSYS_COLOUR_MENU', 5: 'wxSYS_COLOUR_WINDOW', 6: 'wxSYS_COLOUR_WINDOWFRAME', 7: 'wxSYS_COLOUR_MENUTEXT', 8: 'wxSYS_COLOUR_WINDOWTEXT', 9: 'wxSYS_COLOUR_CAPTIONTEXT', ...}
dialog = [None]
str_to_colors = {'wxSYS_COLOUR_3DDKSHADOW': 21, 'wxSYS_COLOUR_3DFACE': 15, 'wxSYS_COLOUR_3DHIGHLIGHT': 20, 'wxSYS_COLOUR_3DHILIGHT': 20, 'wxSYS_COLOUR_3DLIGHT': 22, 'wxSYS_COLOUR_3DSHADOW': 16, 'wxSYS_COLOUR_ACTIVEBORDER': 10, 'wxSYS_COLOUR_ACTIVECAPTION': 2, 'wxSYS_COLOUR_APPWORKSPACE': 12, 'wxSYS_COLOUR_BACKGROUND': 1, ...}

Methods inherited from DialogProperty:
bind_event(self, function)
display(self, parent)
Actually builds the panel (with the text ctrl and the button to display
the dialog) to set the value of the property interactively
get_value(self)
on_char(self, event)
set_value(self, value)
write(self, dest_file=None, tabs=0)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
 
class ComboBoxProperty(Property, _activator)
    Properties whose values can be changed with a combobox. 
 
Method resolution order:
ComboBoxProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, choices, parent=None, label=None, can_disable=False, enabled=False, write_always=False)
bind_event(self, function)
display(self, parent)
Actually builds the check box to set the value of the property
interactively
get_value(self)
set_value(self, val)
write(self, outfile, tabs)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
toggle_active(self, active)
 
class DialogProperty(Property, _activator)
    Property which selection is made through a dialog, which must provide a
get_value method. 
 
Method resolution order:
DialogProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, parent, dialog, can_disable=False, enabled=False, label=None)
bind_event(self, function)
display(self, parent)
Actually builds the panel (with the text ctrl and the button to display
the dialog) to set the value of the property interactively
display_dialog(self, event)
get_value(self)
on_char(self, event)
set_value(self, value)
toggle_active(self, active)
write(self, dest_file=None, tabs=0)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
 
class FileDialogProperty(DialogProperty)
    
Method resolution order:
FileDialogProperty
DialogProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, parent=None, wildcard=u'All Files|*', message=u'Choose a file', can_disable=True, style=0, label=None)

Data and other attributes defined here:
FileDialog = <class widget_properties.FileDialog at 0x03AC1D80>
dialog = [None]

Methods inherited from DialogProperty:
bind_event(self, function)
display(self, parent)
Actually builds the panel (with the text ctrl and the button to display
the dialog) to set the value of the property interactively
display_dialog(self, event)
get_value(self)
on_char(self, event)
set_value(self, value)
toggle_active(self, active)
write(self, dest_file=None, tabs=0)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
 
class FontDialogProperty(DialogProperty)
    
Method resolution order:
FontDialogProperty
DialogProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, parent=None, can_disable=True, label=None)
display_dialog(self, event)
toggle_active(self, active)
write(self, outfile=None, tabs=0)

Data and other attributes defined here:
dialog = [None]
font_families_from = {70: 'default', 71: 'decorative', 72: 'roman', 73: 'script', 74: 'swiss', 75: 'modern', 76: 'teletype'}
font_families_to = {'decorative': 71, 'default': 70, 'modern': 75, 'roman': 72, 'script': 73, 'swiss': 74, 'teletype': 76}
font_styles_from = {90: 'normal', 93: 'italic', 94: 'slant'}
font_styles_to = {'italic': 93, 'normal': 90, 'slant': 94}
font_weights_from = {90: 'normal', 91: 'light', 92: 'bold'}
font_weights_to = {'bold': 92, 'light': 91, 'normal': 90}

Methods inherited from DialogProperty:
bind_event(self, function)
display(self, parent)
Actually builds the panel (with the text ctrl and the button to display
the dialog) to set the value of the property interactively
get_value(self)
on_char(self, event)
set_value(self, value)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
 
class GridProperty(Property)
    Property whose values are modified through a wxGrid table. 
  Methods defined here:
__init__(self, owner, name, parent, cols, rows=1, can_add=True, can_remove=True, can_insert=True, label=None)
add_row(self, event)
bind_event(self, function)
display(self, parent)
Actually builds the grid to set the value of the property
interactively
get_value(self)
insert_row(self, event)
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed
on_select_cell(self, event)
remove_row(self, event)
set_col_sizes(self, sizes)
sets the width of the columns.
sizes is a list of integers with the size of each column: a value of 0
stands for a default size, while -1 means to expand the column to fit
the available space (at most one column can have size -1)
set_value(self, values)

Data and other attributes defined here:
BOOL = 3
FLOAT = 2
INT = 1
STRING = 0
col_format = [<function <lambda> at 0x03ADA970>, <function <lambda> at 0x03ADA9B0>, <function <lambda> at 0x03ADA9F0>, <function <lambda> at 0x03ADAA30>]

Methods inherited from Property:
write(self, outfile=None, tabs=0)
Writes the xml code for this property onto the given file.
 
class HiddenProperty(Property)
    Properties not associated to any control, i.e. not editable by the user. 
  Methods defined here:
__init__(self, owner, name, value=None, label=None)
bind_event(self, function)
get_value(self)
set_value(self, val)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed
write(self, outfile=None, tabs=0)
Writes the xml code for this property onto the given file.
 
class Property
    A class to handle a single property of a widget. 
  Methods defined here:
__init__(self, owner, name, parent, getter=None, setter=None, label=None)
Access to the property is made through the getter and setter functions,
which are invoked also in the default event handler. If they are None,
they default to owner[name][0] and owner[name][1]
bind_event(self, function)
sets the default event handler for this property.
get_value(self)
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed
set_value(self, value)
write(self, outfile=None, tabs=0)
Writes the xml code for this property onto the given file.
 
class RadioProperty(Property, _activator)
    properties controlled by a series of radio buttons. 
 
Method resolution order:
RadioProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, parent, choices, can_disable=False, enabled=False, columns=1, label=None)
bind_event(self, function)
display(self, parent)
Actually builds the radio box to set the value of the property
interactively
get_str_value(self)
get_value(self)
set_str_value(self, value)
set_value(self, value)
write(self, outfile, tabs)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
toggle_active(self, active)
 
class SpinProperty(Property, _activator)
    Properties associated to a spin control. 
 
Method resolution order:
SpinProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, parent=None, can_disable=False, r=None, enabled=False, immediate=False, label=None)
bind_event(self, function)
display(self, parent)
Actually builds the spin control to set the value of the property
interactively
get_value(self)
set_range(self, min_v, max_v)
set_value(self, value)
write(self, outfile, tabs)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
toggle_active(self, active)
 
class TextProperty(Property, _activator)
    Properties associated to a text control. 
 
Method resolution order:
TextProperty
Property
_activator

Methods defined here:
__init__(self, owner, name, parent=None, can_disable=False, enabled=False, readonly=False, multiline=False, label=None)
bind_event(self, function)
display(self, parent)
Actually builds the text control to set the value of the property
interactively
get_value(self)
on_char(self, event)
set_value(self, value)
write(self, outfile, tabs)

Methods inherited from Property:
on_change_val(self, event, first=[True])
Event handler called to notify owner that the value of the Property
has changed

Methods inherited from _activator:
is_active(self)
toggle_active(self, active)


Licence

This document is provided by Laurent Marcoux under the Creative Commons 3.0 Attribution/Share Alike Licence

Code highlight by GeSHi Generic Syntax Highlighter

Most code examples are from wxGlade, under MIT licence:
Copyright (c) 2002-2007 Alberto Griggio  <agriggio@users.sourceforge.net>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.