ItclObjectx¶
-
class
decida.ItclObjectx.
ItclObjectx
¶ synopsis:
Base class to provide configuration option capability.
ItclObjectx is modeled after the [incr Tcl] configuration paradigm. Each derived class can add a number of configuration options. These options are class attributes which are treated specially. An instance of the derived class is configured when created, and can be reconfigured after creation. The configuration/reconfiguration causes a call-back (if specified) to be called. The type of the configuration is also checked with the established type.
ItclObjectx also provides message, warning, error, and fatal methods, which print messages and react in different ways.
adding options:
- derived classes use the _add_options protected method to add configuration options. The argument to _add_options is a dictionary with the option name as the index, and a list of default configuration option value and callback as the value of the dictionary index.
example: (from PlotBase derived-class constructor)
def __init__(self) : ItclObjectx.__init__(self) self._add_options({ "plot_background" : ["GhostWhite", self._config_plot_background_callback], "legend_background" : ["AntiqueWhite2", self._config_legend_background_callback], "colors" : [colors, None], })
public methods:
indexing:
- <instance>[“<config_option>”] returns the value of the configuration option named <config_option>
- <instance>[“<config_option>”]=<value> sets the value of the configuration option named <config_option> to <value>. If the configuration option callback returns false, the option is set back to the previous value.
-
config_options
()¶ return configuration option names.
results:
- Returns list of configuration option names, in no particular order.
-
cshow
(key=None)¶ show all configuration option values.
arguments:
key (str, default=None)
configuration option key.results:
- if key is not specified, display all configuration option values. if key is specified,
- if key is specified, display its current configuration value.
-
error
(*args)¶ print error message, raise exception, exit.
arguments:
*args (tuple of str)
message or parts of message to print.results:
- print “error”, the class, the method, and the joined argument list.
- raise a RuntimeError taken out
- exit
-
fatal
(*args)¶ print fatal error message, raise exception, exit.
arguments:
*args (tuple of str)
message or parts of message to print.results:
- print “error”, the class, the method, and the joined argument list.
- raise a RuntimeError taken out
- exit
-
message
(*args)¶ print message.
arguments:
*args (tuple of str)
message or parts of message to print.results:
- print the class, the method, and the joined argument list.
-
warning
(*args)¶ print warning message.
arguments:
*args (tuple of str)
message or parts of message to print.results:
- print “warning”, the class, the method, and the joined argument list.
-
was_configured
(key)¶ return true if configuration option was configured.
arguments:
key (str)
configuration option keyresults:
- return True if configuration option was configured, or False if it was never configured.