FILENAME: autoObjectWidgets.tcl
AUTHOR: theerik@github
DESCRIPTION: AutoObject is a base class used to create auto-assembling objects using a descriptor array. AutoObjectWidgets defines a set of plugins that allow autoObjects to have an autogenerated GUI representation, allowing examination and manipulation of each field. Widget classes are designed as mixin classes, allowing them to be attached to many common data types.
Common widgets provided include:
Copyright 2015-18, Erik N. Johnson
This software is distributed under the MIT 3-clause license.
This package documentation is auto-generated with Pycco: https://pycco-docs.github.io/pycco/
Use "pycco filename" to re-generate HTML documentation in ./docs .
All widgets intended for use with AutoObject fields must support the following canonical methods:
All classes should be declared in the ::AutoObject:: namespace, as below. N.B. that the widgets rely on the value of the object being in the canonical variable MyValue. If this does not hold for your class, you will need to recreate any widgets to work with the difference.
The initial widgets all use the validate method and tie it to the validatecommand option of the widget. This allows the objects to catch the update of the widget contents as they happen and reflect them into the underlying object variables.
Default widget for common use. Simple entry field. Expects the value to be stored in the canonical AutoObject name MyValue. N.B. that if your base class stores its data in a different place, you will need to use a different widget.
oo::class create ::AutoObject::autoEntry {
method createWidget {wname args} {
my variable MyValue
my variable MyWidget
set MyWidget [ttk::entry $wname \
-textvariable [self namespace]::MyValue \
-validate focusout \
-validatecommand [list [self] validate] \
-width 12 \
{*}$args]
oo::objdefine [self] forward widget $MyWidget
if {[self next] ne {}} {next {*}$args}
return $MyWidget
}
method validate {} {
my variable MyWidget
set curVal [$MyWidget get]
my set $curVal
return true
}
}
Most commonly used with data that's got an enum_mix mixed in. Basic setup done here; note the call to "next", which calls the base class's method - the enum_mix class populates the pick list and handles the housekeeping. Other classes may choose to use it differently.
oo::class create ::AutoObject::autoCombobox {
method createWidget {wname args} {
my variable MyValue
my variable MyWidget
set ns [info object namespace [info object class [self object]]]
upvar ${ns}::defArray defArray
set MyWidget [ttk::combobox $wname {*}$args]
$wname set $MyValue
oo::objdefine [self] forward widget $MyWidget
if {[self next] ne {}} {next {*}$args}
return $MyWidget
}
method validate {} {
my variable MyWidget
set curVal [$MyWidget get]
my set $curVal
return true
}
}
oo::class create ::AutoObject::autoLabel {
method createWidget {wname args} {
my variable MyValue
my variable MyWidget
set MyWidget [ttk::label $wname -textvariable \
[self namespace]::MyValue {*}$args]
oo::objdefine [self] forward widget $MyWidget
if {[self next] ne {}} {next {*}$args}
return $MyWidget
}
}
Non-widget for reserved fields and other fields that for whatever reason should not be displayed in the GUI.
oo::class create ::AutoObject::autoNone {
method createWidget {wname args} {
my variable MyWidget
set MyWidget ""
return $MyWidget
}
}