|
|
@@ -97,48 +97,48 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
self._hookDict = {}
|
|
|
# To avoid doing things redundantly during initialisation
|
|
|
self.fInit = 1
|
|
|
- # Mapping from each megawidget option to a list of information
|
|
|
- # about the option
|
|
|
- # - default value
|
|
|
- # - current value
|
|
|
- # - function to call when the option is initialised in the
|
|
|
- # call to initialiseoptions() in the constructor or
|
|
|
- # modified via configure(). If this is INITOPT, the
|
|
|
- # option is an initialisation option (an option that can
|
|
|
- # be set by the call to the constructor but can not be
|
|
|
- # used with configure).
|
|
|
- # This mapping is not initialised here, but in the call to
|
|
|
- # defineoptions() which precedes construction of this base class.
|
|
|
- #
|
|
|
- # self._optionInfo = {}
|
|
|
-
|
|
|
- # Mapping from each component name to a tuple of information
|
|
|
- # about the component.
|
|
|
- # - component widget instance
|
|
|
- # - configure function of widget instance
|
|
|
- # - the class of the widget (Frame, EntryField, etc)
|
|
|
- # - cget function of widget instance
|
|
|
- # - the name of the component group of this component, if any
|
|
|
- self.__componentInfo = {}
|
|
|
-
|
|
|
- # Mapping from alias names to the names of components or
|
|
|
- # sub-components.
|
|
|
- self.__componentAliases = {}
|
|
|
-
|
|
|
- # Contains information about the keywords provided to the
|
|
|
- # constructor. It is a mapping from the keyword to a tuple
|
|
|
- # containing:
|
|
|
- # - value of keyword
|
|
|
- # - a boolean indicating if the keyword has been used.
|
|
|
- # A keyword is used if, during the construction of a megawidget,
|
|
|
- # - it is defined in a call to defineoptions() or addoptions(), or
|
|
|
- # - it references, by name, a component of the megawidget, or
|
|
|
- # - it references, by group, at least one component
|
|
|
- # At the end of megawidget construction, a call is made to
|
|
|
- # initialiseoptions() which reports an error if there are
|
|
|
- # unused options given to the constructor.
|
|
|
- #
|
|
|
- # self._constructorKeywords = {}
|
|
|
+ # Mapping from each megawidget option to a list of information
|
|
|
+ # about the option
|
|
|
+ # - default value
|
|
|
+ # - current value
|
|
|
+ # - function to call when the option is initialised in the
|
|
|
+ # call to initialiseoptions() in the constructor or
|
|
|
+ # modified via configure(). If this is INITOPT, the
|
|
|
+ # option is an initialisation option (an option that can
|
|
|
+ # be set by the call to the constructor but can not be
|
|
|
+ # used with configure).
|
|
|
+ # This mapping is not initialised here, but in the call to
|
|
|
+ # defineoptions() which precedes construction of this base class.
|
|
|
+ #
|
|
|
+ # self._optionInfo = {}
|
|
|
+
|
|
|
+ # Mapping from each component name to a tuple of information
|
|
|
+ # about the component.
|
|
|
+ # - component widget instance
|
|
|
+ # - configure function of widget instance
|
|
|
+ # - the class of the widget (Frame, EntryField, etc)
|
|
|
+ # - cget function of widget instance
|
|
|
+ # - the name of the component group of this component, if any
|
|
|
+ self.__componentInfo = {}
|
|
|
+
|
|
|
+ # Mapping from alias names to the names of components or
|
|
|
+ # sub-components.
|
|
|
+ self.__componentAliases = {}
|
|
|
+
|
|
|
+ # Contains information about the keywords provided to the
|
|
|
+ # constructor. It is a mapping from the keyword to a tuple
|
|
|
+ # containing:
|
|
|
+ # - value of keyword
|
|
|
+ # - a boolean indicating if the keyword has been used.
|
|
|
+ # A keyword is used if, during the construction of a megawidget,
|
|
|
+ # - it is defined in a call to defineoptions() or addoptions(), or
|
|
|
+ # - it references, by name, a component of the megawidget, or
|
|
|
+ # - it references, by group, at least one component
|
|
|
+ # At the end of megawidget construction, a call is made to
|
|
|
+ # initialiseoptions() which reports an error if there are
|
|
|
+ # unused options given to the constructor.
|
|
|
+ #
|
|
|
+ # self._constructorKeywords = {}
|
|
|
|
|
|
# List of dynamic component groups. If a group is included in
|
|
|
# this list, then it not an error if a keyword argument for
|
|
|
@@ -153,10 +153,10 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
|
|
|
def defineoptions(self, keywords, optionDefs, dynamicGroups = ()):
|
|
|
""" defineoptions(keywords, optionDefs, dynamicGroups = {}) """
|
|
|
- # Create options, providing the default value and the method
|
|
|
- # to call when the value is changed. If any option created by
|
|
|
- # base classes has the same name as one in <optionDefs>, the
|
|
|
- # base class's value and function will be overriden.
|
|
|
+ # Create options, providing the default value and the method
|
|
|
+ # to call when the value is changed. If any option created by
|
|
|
+ # base classes has the same name as one in <optionDefs>, the
|
|
|
+ # base class's value and function will be overriden.
|
|
|
|
|
|
# keywords is a dictionary of keyword/value pairs from the constructor
|
|
|
# optionDefs is a dictionary of default options for the widget
|
|
|
@@ -164,15 +164,15 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
# specify options even though no components of this group have
|
|
|
# been created
|
|
|
|
|
|
- # This should be called before the constructor of the base
|
|
|
- # class, so that default values defined in the derived class
|
|
|
- # override those in the base class.
|
|
|
- if not hasattr(self, '_constructorKeywords'):
|
|
|
- tmp = {}
|
|
|
- for option, value in keywords.items():
|
|
|
- tmp[option] = [value, 0]
|
|
|
+ # This should be called before the constructor of the base
|
|
|
+ # class, so that default values defined in the derived class
|
|
|
+ # override those in the base class.
|
|
|
+ if not hasattr(self, '_constructorKeywords'):
|
|
|
+ tmp = {}
|
|
|
+ for option, value in keywords.items():
|
|
|
+ tmp[option] = [value, 0]
|
|
|
self._constructorKeywords = tmp
|
|
|
- self._optionInfo = {}
|
|
|
+ self._optionInfo = {}
|
|
|
# Initialize dictionary of dynamic groups
|
|
|
if not hasattr(self, '_dynamicGroups'):
|
|
|
self._dynamicGroups = ()
|
|
|
@@ -182,19 +182,19 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
|
|
|
def addoptions(self, optionDefs):
|
|
|
""" addoptions(optionDefs) - add option def to option info """
|
|
|
- # Add additional options, providing the default value and the
|
|
|
- # method to call when the value is changed. See
|
|
|
- # "defineoptions" for more details
|
|
|
+ # Add additional options, providing the default value and the
|
|
|
+ # method to call when the value is changed. See
|
|
|
+ # "defineoptions" for more details
|
|
|
|
|
|
- # optimisations:
|
|
|
- optionInfo = self._optionInfo
|
|
|
- optionInfo_has_key = optionInfo.has_key
|
|
|
- keywords = self._constructorKeywords
|
|
|
- keywords_has_key = keywords.has_key
|
|
|
- FUNCTION = _OPT_FUNCTION
|
|
|
+ # optimisations:
|
|
|
+ optionInfo = self._optionInfo
|
|
|
+ optionInfo_has_key = optionInfo.has_key
|
|
|
+ keywords = self._constructorKeywords
|
|
|
+ keywords_has_key = keywords.has_key
|
|
|
+ FUNCTION = _OPT_FUNCTION
|
|
|
|
|
|
- for name, default, function in optionDefs:
|
|
|
- if '_' not in name:
|
|
|
+ for name, default, function in optionDefs:
|
|
|
+ if '_' not in name:
|
|
|
# The option will already exist if it has been defined
|
|
|
# in a derived class. In this case, do not override the
|
|
|
# default value of the option or the callback function
|
|
|
@@ -212,13 +212,13 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
elif optionInfo[name][FUNCTION] is None:
|
|
|
# Only override function if not defined by derived class
|
|
|
optionInfo[name][FUNCTION] = function
|
|
|
- else:
|
|
|
- # This option is of the form "component_option". If this is
|
|
|
- # not already defined in self._constructorKeywords add it.
|
|
|
- # This allows a derived class to override the default value
|
|
|
- # of an option of a component of a base class.
|
|
|
- if not keywords_has_key(name):
|
|
|
- keywords[name] = [default, 0]
|
|
|
+ else:
|
|
|
+ # This option is of the form "component_option". If this is
|
|
|
+ # not already defined in self._constructorKeywords add it.
|
|
|
+ # This allows a derived class to override the default value
|
|
|
+ # of an option of a component of a base class.
|
|
|
+ if not keywords_has_key(name):
|
|
|
+ keywords[name] = [default, 0]
|
|
|
|
|
|
def initialiseoptions(self, myClass):
|
|
|
"""
|
|
|
@@ -227,36 +227,36 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
"""
|
|
|
# This is to make sure this method class is only called by
|
|
|
# the most specific class in the class hierarchy
|
|
|
- if self.__class__ is myClass:
|
|
|
- # Call the configuration callback function for every option.
|
|
|
- FUNCTION = _OPT_FUNCTION
|
|
|
+ if self.__class__ is myClass:
|
|
|
+ # Call the configuration callback function for every option.
|
|
|
+ FUNCTION = _OPT_FUNCTION
|
|
|
self.fInit = 1
|
|
|
- for info in self._optionInfo.values():
|
|
|
- func = info[FUNCTION]
|
|
|
- if func is not None and func is not INITOPT:
|
|
|
- func()
|
|
|
+ for info in self._optionInfo.values():
|
|
|
+ func = info[FUNCTION]
|
|
|
+ if func is not None and func is not INITOPT:
|
|
|
+ func()
|
|
|
self.fInit = 0
|
|
|
|
|
|
# Now check if anything is left over
|
|
|
- unusedOptions = []
|
|
|
- keywords = self._constructorKeywords
|
|
|
- for name in keywords.keys():
|
|
|
- used = keywords[name][1]
|
|
|
- if not used:
|
|
|
+ unusedOptions = []
|
|
|
+ keywords = self._constructorKeywords
|
|
|
+ for name in keywords.keys():
|
|
|
+ used = keywords[name][1]
|
|
|
+ if not used:
|
|
|
# This keyword argument has not been used. If it
|
|
|
# does not refer to a dynamic group, mark it as
|
|
|
# unused.
|
|
|
index = string.find(name, '_')
|
|
|
if index < 0 or name[:index] not in self._dynamicGroups:
|
|
|
unusedOptions.append(name)
|
|
|
- self._constructorKeywords = {}
|
|
|
- if len(unusedOptions) > 0:
|
|
|
- if len(unusedOptions) == 1:
|
|
|
- text = 'Unknown option "'
|
|
|
- else:
|
|
|
- text = 'Unknown options "'
|
|
|
- raise KeyError, text + string.join(unusedOptions, ', ') + \
|
|
|
- '" for ' + myClass.__name__
|
|
|
+ self._constructorKeywords = {}
|
|
|
+ if len(unusedOptions) > 0:
|
|
|
+ if len(unusedOptions) == 1:
|
|
|
+ text = 'Unknown option "'
|
|
|
+ else:
|
|
|
+ text = 'Unknown options "'
|
|
|
+ raise KeyError, text + string.join(unusedOptions, ', ') + \
|
|
|
+ '" for ' + myClass.__name__
|
|
|
# Can now call post init func
|
|
|
self.postInitialiseFunc()
|
|
|
|
|
|
@@ -268,7 +268,7 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
isinitoption(option)
|
|
|
Is this opition one that can only be specified at construction?
|
|
|
"""
|
|
|
- return self._optionInfo[option][_OPT_FUNCTION] is INITOPT
|
|
|
+ return self._optionInfo[option][_OPT_FUNCTION] is INITOPT
|
|
|
|
|
|
def options(self):
|
|
|
"""
|
|
|
@@ -276,155 +276,155 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
Print out a list of available widget options.
|
|
|
Does not include subcomponent options.
|
|
|
"""
|
|
|
- options = []
|
|
|
- if hasattr(self, '_optionInfo'):
|
|
|
- for option, info in self._optionInfo.items():
|
|
|
- isinit = info[_OPT_FUNCTION] is INITOPT
|
|
|
- default = info[_OPT_DEFAULT]
|
|
|
- options.append((option, default, isinit))
|
|
|
- options.sort()
|
|
|
- return options
|
|
|
+ options = []
|
|
|
+ if hasattr(self, '_optionInfo'):
|
|
|
+ for option, info in self._optionInfo.items():
|
|
|
+ isinit = info[_OPT_FUNCTION] is INITOPT
|
|
|
+ default = info[_OPT_DEFAULT]
|
|
|
+ options.append((option, default, isinit))
|
|
|
+ options.sort()
|
|
|
+ return options
|
|
|
|
|
|
def configure(self, option=None, **kw):
|
|
|
"""
|
|
|
configure(option = None)
|
|
|
- Query or configure the megawidget options.
|
|
|
+ Query or configure the megawidget options.
|
|
|
"""
|
|
|
- #
|
|
|
- # If not empty, *kw* is a dictionary giving new
|
|
|
- # values for some of the options of this gui item
|
|
|
- # For options defined for this widget, set
|
|
|
- # the value of the option to the new value and call the
|
|
|
- # configuration callback function, if any.
|
|
|
- #
|
|
|
- # If *option* is None, return all gui item configuration
|
|
|
- # options and settings. Options are returned as standard 3
|
|
|
- # element tuples
|
|
|
- #
|
|
|
- # If *option* is a string, return the 3 element tuple for the
|
|
|
- # given configuration option.
|
|
|
+ #
|
|
|
+ # If not empty, *kw* is a dictionary giving new
|
|
|
+ # values for some of the options of this gui item
|
|
|
+ # For options defined for this widget, set
|
|
|
+ # the value of the option to the new value and call the
|
|
|
+ # configuration callback function, if any.
|
|
|
+ #
|
|
|
+ # If *option* is None, return all gui item configuration
|
|
|
+ # options and settings. Options are returned as standard 3
|
|
|
+ # element tuples
|
|
|
+ #
|
|
|
+ # If *option* is a string, return the 3 element tuple for the
|
|
|
+ # given configuration option.
|
|
|
|
|
|
- # First, deal with the option queries.
|
|
|
- if len(kw) == 0:
|
|
|
- # This configure call is querying the values of one or all options.
|
|
|
- # Return 3-tuples:
|
|
|
- # (optionName, default, value)
|
|
|
- if option is None:
|
|
|
- rtn = {}
|
|
|
- for option, config in self._optionInfo.items():
|
|
|
- rtn[option] = (option,
|
|
|
+ # First, deal with the option queries.
|
|
|
+ if len(kw) == 0:
|
|
|
+ # This configure call is querying the values of one or all options.
|
|
|
+ # Return 3-tuples:
|
|
|
+ # (optionName, default, value)
|
|
|
+ if option is None:
|
|
|
+ rtn = {}
|
|
|
+ for option, config in self._optionInfo.items():
|
|
|
+ rtn[option] = (option,
|
|
|
config[_OPT_DEFAULT],
|
|
|
config[_OPT_VALUE])
|
|
|
- return rtn
|
|
|
- else:
|
|
|
- config = self._optionInfo[option]
|
|
|
- return (option, config[_OPT_DEFAULT], config[_OPT_VALUE])
|
|
|
+ return rtn
|
|
|
+ else:
|
|
|
+ config = self._optionInfo[option]
|
|
|
+ return (option, config[_OPT_DEFAULT], config[_OPT_VALUE])
|
|
|
|
|
|
- # optimizations:
|
|
|
- optionInfo = self._optionInfo
|
|
|
- optionInfo_has_key = optionInfo.has_key
|
|
|
- componentInfo = self.__componentInfo
|
|
|
- componentInfo_has_key = componentInfo.has_key
|
|
|
- componentAliases = self.__componentAliases
|
|
|
- componentAliases_has_key = componentAliases.has_key
|
|
|
- VALUE = _OPT_VALUE
|
|
|
- FUNCTION = _OPT_FUNCTION
|
|
|
+ # optimizations:
|
|
|
+ optionInfo = self._optionInfo
|
|
|
+ optionInfo_has_key = optionInfo.has_key
|
|
|
+ componentInfo = self.__componentInfo
|
|
|
+ componentInfo_has_key = componentInfo.has_key
|
|
|
+ componentAliases = self.__componentAliases
|
|
|
+ componentAliases_has_key = componentAliases.has_key
|
|
|
+ VALUE = _OPT_VALUE
|
|
|
+ FUNCTION = _OPT_FUNCTION
|
|
|
|
|
|
- # This will contain a list of options in *kw* which
|
|
|
- # are known to this gui item.
|
|
|
- directOptions = []
|
|
|
+ # This will contain a list of options in *kw* which
|
|
|
+ # are known to this gui item.
|
|
|
+ directOptions = []
|
|
|
|
|
|
- # This will contain information about the options in
|
|
|
- # *kw* of the form <component>_<option>, where
|
|
|
- # <component> is a component of this megawidget. It is a
|
|
|
- # dictionary whose keys are the configure method of each
|
|
|
- # component and whose values are a dictionary of options and
|
|
|
- # values for the component.
|
|
|
- indirectOptions = {}
|
|
|
- indirectOptions_has_key = indirectOptions.has_key
|
|
|
-
|
|
|
- for option, value in kw.items():
|
|
|
- if optionInfo_has_key(option):
|
|
|
- # This is one of the options of this gui item.
|
|
|
- # Check it is an initialisation option.
|
|
|
- if optionInfo[option][FUNCTION] is INITOPT:
|
|
|
+ # This will contain information about the options in
|
|
|
+ # *kw* of the form <component>_<option>, where
|
|
|
+ # <component> is a component of this megawidget. It is a
|
|
|
+ # dictionary whose keys are the configure method of each
|
|
|
+ # component and whose values are a dictionary of options and
|
|
|
+ # values for the component.
|
|
|
+ indirectOptions = {}
|
|
|
+ indirectOptions_has_key = indirectOptions.has_key
|
|
|
+
|
|
|
+ for option, value in kw.items():
|
|
|
+ if optionInfo_has_key(option):
|
|
|
+ # This is one of the options of this gui item.
|
|
|
+ # Check it is an initialisation option.
|
|
|
+ if optionInfo[option][FUNCTION] is INITOPT:
|
|
|
print 'Cannot configure initialisation option "' \
|
|
|
+ option + '" for ' + self.__class__.__name__
|
|
|
break
|
|
|
- #raise KeyError, \
|
|
|
- # 'Cannot configure initialisation option "' \
|
|
|
- # + option + '" for ' + self.__class__.__name__
|
|
|
- optionInfo[option][VALUE] = value
|
|
|
- directOptions.append(option)
|
|
|
+ #raise KeyError, \
|
|
|
+ # 'Cannot configure initialisation option "' \
|
|
|
+ # + option + '" for ' + self.__class__.__name__
|
|
|
+ optionInfo[option][VALUE] = value
|
|
|
+ directOptions.append(option)
|
|
|
else:
|
|
|
- index = string.find(option, '_')
|
|
|
- if index >= 0:
|
|
|
- # This option may be of the form <component>_<option>.
|
|
|
+ index = string.find(option, '_')
|
|
|
+ if index >= 0:
|
|
|
+ # This option may be of the form <component>_<option>.
|
|
|
# e.g. if alias ('efEntry', 'entryField_entry')
|
|
|
# and option = efEntry_width
|
|
|
# component = efEntry, componentOption = width
|
|
|
- component = option[:index]
|
|
|
- componentOption = option[(index + 1):]
|
|
|
+ component = option[:index]
|
|
|
+ componentOption = option[(index + 1):]
|
|
|
|
|
|
- # Expand component alias
|
|
|
- if componentAliases_has_key(component):
|
|
|
+ # Expand component alias
|
|
|
+ if componentAliases_has_key(component):
|
|
|
# component = entryField, subcomponent = entry
|
|
|
- component, subComponent = componentAliases[component]
|
|
|
- if subComponent is not None:
|
|
|
+ component, subComponent = componentAliases[component]
|
|
|
+ if subComponent is not None:
|
|
|
# componentOption becomes entry_width
|
|
|
- componentOption = subComponent + '_' \
|
|
|
- + componentOption
|
|
|
+ componentOption = subComponent + '_' \
|
|
|
+ + componentOption
|
|
|
|
|
|
- # Expand option string to write on error
|
|
|
+ # Expand option string to write on error
|
|
|
# option = entryField_entry_width
|
|
|
- option = component + '_' + componentOption
|
|
|
+ option = component + '_' + componentOption
|
|
|
|
|
|
# Does this component exist
|
|
|
- if componentInfo_has_key(component):
|
|
|
- # Get the configure func for the named component
|
|
|
+ if componentInfo_has_key(component):
|
|
|
+ # Get the configure func for the named component
|
|
|
# component = entryField
|
|
|
- componentConfigFuncs = [componentInfo[component][1]]
|
|
|
- else:
|
|
|
- # Check if this is a group name and configure all
|
|
|
- # components in the group.
|
|
|
- componentConfigFuncs = []
|
|
|
+ componentConfigFuncs = [componentInfo[component][1]]
|
|
|
+ else:
|
|
|
+ # Check if this is a group name and configure all
|
|
|
+ # components in the group.
|
|
|
+ componentConfigFuncs = []
|
|
|
# For each component
|
|
|
- for info in componentInfo.values():
|
|
|
+ for info in componentInfo.values():
|
|
|
# Check if it is a member of this group
|
|
|
- if info[4] == component:
|
|
|
+ if info[4] == component:
|
|
|
# Yes, append its config func
|
|
|
- componentConfigFuncs.append(info[1])
|
|
|
+ componentConfigFuncs.append(info[1])
|
|
|
|
|
|
if len(componentConfigFuncs) == 0 and \
|
|
|
component not in self._dynamicGroups:
|
|
|
- raise KeyError, 'Unknown option "' + option + \
|
|
|
- '" for ' + self.__class__.__name__
|
|
|
-
|
|
|
- # Add the configure method(s) (may be more than
|
|
|
- # one if this is configuring a component group)
|
|
|
- # and option/value to dictionary.
|
|
|
- for componentConfigFunc in componentConfigFuncs:
|
|
|
- if not indirectOptions_has_key(componentConfigFunc):
|
|
|
- indirectOptions[componentConfigFunc] = {}
|
|
|
+ raise KeyError, 'Unknown option "' + option + \
|
|
|
+ '" for ' + self.__class__.__name__
|
|
|
+
|
|
|
+ # Add the configure method(s) (may be more than
|
|
|
+ # one if this is configuring a component group)
|
|
|
+ # and option/value to dictionary.
|
|
|
+ for componentConfigFunc in componentConfigFuncs:
|
|
|
+ if not indirectOptions_has_key(componentConfigFunc):
|
|
|
+ indirectOptions[componentConfigFunc] = {}
|
|
|
# Create a dictionary of keyword/values keyed
|
|
|
# on configuration function
|
|
|
- indirectOptions[componentConfigFunc][componentOption] \
|
|
|
- = value
|
|
|
- else:
|
|
|
- raise KeyError, 'Unknown option "' + option + \
|
|
|
- '" for ' + self.__class__.__name__
|
|
|
+ indirectOptions[componentConfigFunc][componentOption] \
|
|
|
+ = value
|
|
|
+ else:
|
|
|
+ raise KeyError, 'Unknown option "' + option + \
|
|
|
+ '" for ' + self.__class__.__name__
|
|
|
|
|
|
- # Call the configure methods for any components.
|
|
|
+ # Call the configure methods for any components.
|
|
|
# Pass in the dictionary of keyword/values created above
|
|
|
- map(apply, indirectOptions.keys(),
|
|
|
- ((),) * len(indirectOptions), indirectOptions.values())
|
|
|
+ map(apply, indirectOptions.keys(),
|
|
|
+ ((),) * len(indirectOptions), indirectOptions.values())
|
|
|
|
|
|
- # Call the configuration callback function for each option.
|
|
|
- for option in directOptions:
|
|
|
- info = optionInfo[option]
|
|
|
- func = info[_OPT_FUNCTION]
|
|
|
- if func is not None:
|
|
|
- func()
|
|
|
+ # Call the configuration callback function for each option.
|
|
|
+ for option in directOptions:
|
|
|
+ info = optionInfo[option]
|
|
|
+ func = info[_OPT_FUNCTION]
|
|
|
+ if func is not None:
|
|
|
+ func()
|
|
|
|
|
|
# Allow index style references
|
|
|
def __setitem__(self, key, value):
|
|
|
@@ -433,111 +433,111 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
def cget(self, option):
|
|
|
"""
|
|
|
cget(option)
|
|
|
- Get current configuration setting for this option
|
|
|
+ Get current configuration setting for this option
|
|
|
"""
|
|
|
- # Return the value of an option, for example myWidget['font'].
|
|
|
- if self._optionInfo.has_key(option):
|
|
|
- return self._optionInfo[option][_OPT_VALUE]
|
|
|
- else:
|
|
|
- index = string.find(option, '_')
|
|
|
- if index >= 0:
|
|
|
- component = option[:index]
|
|
|
- componentOption = option[(index + 1):]
|
|
|
-
|
|
|
- # Expand component alias
|
|
|
- if self.__componentAliases.has_key(component):
|
|
|
- component, subComponent = self.__componentAliases[
|
|
|
+ # Return the value of an option, for example myWidget['font'].
|
|
|
+ if self._optionInfo.has_key(option):
|
|
|
+ return self._optionInfo[option][_OPT_VALUE]
|
|
|
+ else:
|
|
|
+ index = string.find(option, '_')
|
|
|
+ if index >= 0:
|
|
|
+ component = option[:index]
|
|
|
+ componentOption = option[(index + 1):]
|
|
|
+
|
|
|
+ # Expand component alias
|
|
|
+ if self.__componentAliases.has_key(component):
|
|
|
+ component, subComponent = self.__componentAliases[
|
|
|
component]
|
|
|
- if subComponent is not None:
|
|
|
- componentOption = subComponent + '_' + componentOption
|
|
|
-
|
|
|
- # Expand option string to write on error
|
|
|
- option = component + '_' + componentOption
|
|
|
-
|
|
|
- if self.__componentInfo.has_key(component):
|
|
|
- # Call cget on the component.
|
|
|
- componentCget = self.__componentInfo[component][3]
|
|
|
- return componentCget(componentOption)
|
|
|
- else:
|
|
|
- # If this is a group name, call cget for one of
|
|
|
- # the components in the group.
|
|
|
- for info in self.__componentInfo.values():
|
|
|
- if info[4] == component:
|
|
|
- componentCget = info[3]
|
|
|
- return componentCget(componentOption)
|
|
|
+ if subComponent is not None:
|
|
|
+ componentOption = subComponent + '_' + componentOption
|
|
|
+
|
|
|
+ # Expand option string to write on error
|
|
|
+ option = component + '_' + componentOption
|
|
|
+
|
|
|
+ if self.__componentInfo.has_key(component):
|
|
|
+ # Call cget on the component.
|
|
|
+ componentCget = self.__componentInfo[component][3]
|
|
|
+ return componentCget(componentOption)
|
|
|
+ else:
|
|
|
+ # If this is a group name, call cget for one of
|
|
|
+ # the components in the group.
|
|
|
+ for info in self.__componentInfo.values():
|
|
|
+ if info[4] == component:
|
|
|
+ componentCget = info[3]
|
|
|
+ return componentCget(componentOption)
|
|
|
|
|
|
# Option not found
|
|
|
- raise KeyError, 'Unknown option "' + option + \
|
|
|
- '" for ' + self.__class__.__name__
|
|
|
+ raise KeyError, 'Unknown option "' + option + \
|
|
|
+ '" for ' + self.__class__.__name__
|
|
|
|
|
|
# Allow index style refererences
|
|
|
__getitem__ = cget
|
|
|
|
|
|
def createcomponent(self, componentName, componentAliases, componentGroup,
|
|
|
widgetClass, *widgetArgs, **kw):
|
|
|
- """
|
|
|
+ """
|
|
|
Create a component (during construction or later) for this widget.
|
|
|
"""
|
|
|
# Check for invalid component name
|
|
|
- if '_' in componentName:
|
|
|
- raise ValueError, \
|
|
|
+ if '_' in componentName:
|
|
|
+ raise ValueError, \
|
|
|
'Component name "%s" must not contain "_"' % componentName
|
|
|
|
|
|
# Get construction keywords
|
|
|
- if hasattr(self, '_constructorKeywords'):
|
|
|
- keywords = self._constructorKeywords
|
|
|
- else:
|
|
|
- keywords = {}
|
|
|
-
|
|
|
- for alias, component in componentAliases:
|
|
|
- # Create aliases to the component and its sub-components.
|
|
|
- index = string.find(component, '_')
|
|
|
- if index < 0:
|
|
|
+ if hasattr(self, '_constructorKeywords'):
|
|
|
+ keywords = self._constructorKeywords
|
|
|
+ else:
|
|
|
+ keywords = {}
|
|
|
+
|
|
|
+ for alias, component in componentAliases:
|
|
|
+ # Create aliases to the component and its sub-components.
|
|
|
+ index = string.find(component, '_')
|
|
|
+ if index < 0:
|
|
|
# Just a shorter name for one of this widget's components
|
|
|
- self.__componentAliases[alias] = (component, None)
|
|
|
- else:
|
|
|
+ self.__componentAliases[alias] = (component, None)
|
|
|
+ else:
|
|
|
# An alias for a component of one of this widget's components
|
|
|
- mainComponent = component[:index]
|
|
|
- subComponent = component[(index + 1):]
|
|
|
- self.__componentAliases[alias] = (mainComponent, subComponent)
|
|
|
-
|
|
|
- # Remove aliases from the constructor keyword arguments by
|
|
|
- # replacing any keyword arguments that begin with *alias*
|
|
|
- # with corresponding keys beginning with *component*.
|
|
|
- alias = alias + '_'
|
|
|
- aliasLen = len(alias)
|
|
|
- for option in keywords.keys():
|
|
|
- if len(option) > aliasLen and option[:aliasLen] == alias:
|
|
|
- newkey = component + '_' + option[aliasLen:]
|
|
|
- keywords[newkey] = keywords[option]
|
|
|
- del keywords[option]
|
|
|
+ mainComponent = component[:index]
|
|
|
+ subComponent = component[(index + 1):]
|
|
|
+ self.__componentAliases[alias] = (mainComponent, subComponent)
|
|
|
+
|
|
|
+ # Remove aliases from the constructor keyword arguments by
|
|
|
+ # replacing any keyword arguments that begin with *alias*
|
|
|
+ # with corresponding keys beginning with *component*.
|
|
|
+ alias = alias + '_'
|
|
|
+ aliasLen = len(alias)
|
|
|
+ for option in keywords.keys():
|
|
|
+ if len(option) > aliasLen and option[:aliasLen] == alias:
|
|
|
+ newkey = component + '_' + option[aliasLen:]
|
|
|
+ keywords[newkey] = keywords[option]
|
|
|
+ del keywords[option]
|
|
|
|
|
|
# Find any keyword arguments for this component
|
|
|
- componentPrefix = componentName + '_'
|
|
|
- nameLen = len(componentPrefix)
|
|
|
- for option in keywords.keys():
|
|
|
- if len(option) > nameLen and option[:nameLen] == componentPrefix:
|
|
|
- # The keyword argument refers to this component, so add
|
|
|
- # this to the options to use when constructing the widget.
|
|
|
- kw[option[nameLen:]] = keywords[option][0]
|
|
|
+ componentPrefix = componentName + '_'
|
|
|
+ nameLen = len(componentPrefix)
|
|
|
+ for option in keywords.keys():
|
|
|
+ if len(option) > nameLen and option[:nameLen] == componentPrefix:
|
|
|
+ # The keyword argument refers to this component, so add
|
|
|
+ # this to the options to use when constructing the widget.
|
|
|
+ kw[option[nameLen:]] = keywords[option][0]
|
|
|
# And delete it from main construction keywords
|
|
|
- del keywords[option]
|
|
|
- else:
|
|
|
- # Check if this keyword argument refers to the group
|
|
|
- # of this component. If so, add this to the options
|
|
|
- # to use when constructing the widget. Mark the
|
|
|
- # keyword argument as being used, but do not remove it
|
|
|
- # since it may be required when creating another
|
|
|
- # component.
|
|
|
- index = string.find(option, '_')
|
|
|
- if index >= 0 and componentGroup == option[:index]:
|
|
|
- rest = option[(index + 1):]
|
|
|
- kw[rest] = keywords[option][0]
|
|
|
- keywords[option][1] = 1
|
|
|
+ del keywords[option]
|
|
|
+ else:
|
|
|
+ # Check if this keyword argument refers to the group
|
|
|
+ # of this component. If so, add this to the options
|
|
|
+ # to use when constructing the widget. Mark the
|
|
|
+ # keyword argument as being used, but do not remove it
|
|
|
+ # since it may be required when creating another
|
|
|
+ # component.
|
|
|
+ index = string.find(option, '_')
|
|
|
+ if index >= 0 and componentGroup == option[:index]:
|
|
|
+ rest = option[(index + 1):]
|
|
|
+ kw[rest] = keywords[option][0]
|
|
|
+ keywords[option][1] = 1
|
|
|
|
|
|
# Return None if no widget class is specified
|
|
|
- if widgetClass is None:
|
|
|
- return None
|
|
|
+ if widgetClass is None:
|
|
|
+ return None
|
|
|
# Get arguments for widget constructor
|
|
|
if len(widgetArgs) == 1 and type(widgetArgs[0]) == types.TupleType:
|
|
|
# Arguments to the constructor can be specified as either
|
|
|
@@ -545,63 +545,63 @@ class DirectGuiBase(PandaObject.PandaObject):
|
|
|
# single tuple argument.
|
|
|
widgetArgs = widgetArgs[0]
|
|
|
# Create the widget
|
|
|
- widget = apply(widgetClass, widgetArgs, kw)
|
|
|
- componentClass = widget.__class__.__name__
|
|
|
- self.__componentInfo[componentName] = (widget, widget.configure,
|
|
|
- componentClass, widget.cget, componentGroup)
|
|
|
- return widget
|
|
|
+ widget = apply(widgetClass, widgetArgs, kw)
|
|
|
+ componentClass = widget.__class__.__name__
|
|
|
+ self.__componentInfo[componentName] = (widget, widget.configure,
|
|
|
+ componentClass, widget.cget, componentGroup)
|
|
|
+ return widget
|
|
|
|
|
|
def component(self, name):
|
|
|
- # Return a component widget of the megawidget given the
|
|
|
- # component's name
|
|
|
- # This allows the user of a megawidget to access and configure
|
|
|
- # widget components directly.
|
|
|
-
|
|
|
- # Find the main component and any subcomponents
|
|
|
- index = string.find(name, '_')
|
|
|
- if index < 0:
|
|
|
- component = name
|
|
|
- remainingComponents = None
|
|
|
- else:
|
|
|
- component = name[:index]
|
|
|
- remainingComponents = name[(index + 1):]
|
|
|
-
|
|
|
- # Expand component alias
|
|
|
+ # Return a component widget of the megawidget given the
|
|
|
+ # component's name
|
|
|
+ # This allows the user of a megawidget to access and configure
|
|
|
+ # widget components directly.
|
|
|
+
|
|
|
+ # Find the main component and any subcomponents
|
|
|
+ index = string.find(name, '_')
|
|
|
+ if index < 0:
|
|
|
+ component = name
|
|
|
+ remainingComponents = None
|
|
|
+ else:
|
|
|
+ component = name[:index]
|
|
|
+ remainingComponents = name[(index + 1):]
|
|
|
+
|
|
|
+ # Expand component alias
|
|
|
# Example entry which is an alias for entryField_entry
|
|
|
- if self.__componentAliases.has_key(component):
|
|
|
+ if self.__componentAliases.has_key(component):
|
|
|
# component = entryField, subComponent = entry
|
|
|
- component, subComponent = self.__componentAliases[component]
|
|
|
- if subComponent is not None:
|
|
|
- if remainingComponents is None:
|
|
|
+ component, subComponent = self.__componentAliases[component]
|
|
|
+ if subComponent is not None:
|
|
|
+ if remainingComponents is None:
|
|
|
# remainingComponents = entry
|
|
|
- remainingComponents = subComponent
|
|
|
- else:
|
|
|
- remainingComponents = subComponent + '_' \
|
|
|
- + remainingComponents
|
|
|
+ remainingComponents = subComponent
|
|
|
+ else:
|
|
|
+ remainingComponents = subComponent + '_' \
|
|
|
+ + remainingComponents
|
|
|
# Get the component from __componentInfo dictionary
|
|
|
- widget = self.__componentInfo[component][0]
|
|
|
- if remainingComponents is None:
|
|
|
+ widget = self.__componentInfo[component][0]
|
|
|
+ if remainingComponents is None:
|
|
|
# Not looking for subcomponent
|
|
|
- return widget
|
|
|
- else:
|
|
|
+ return widget
|
|
|
+ else:
|
|
|
# Recursive call on subcomponent
|
|
|
- return widget.component(remainingComponents)
|
|
|
+ return widget.component(remainingComponents)
|
|
|
|
|
|
def components(self):
|
|
|
- # Return a list of all components.
|
|
|
- names = self.__componentInfo.keys()
|
|
|
- names.sort()
|
|
|
- return names
|
|
|
+ # Return a list of all components.
|
|
|
+ names = self.__componentInfo.keys()
|
|
|
+ names.sort()
|
|
|
+ return names
|
|
|
|
|
|
def hascomponent(self, component):
|
|
|
return component in self.__componentInfo.keys()
|
|
|
|
|
|
def destroycomponent(self, name):
|
|
|
- # Remove a megawidget component.
|
|
|
- # This command is for use by megawidget designers to destroy a
|
|
|
- # megawidget component.
|
|
|
- self.__componentInfo[name][0].destroy()
|
|
|
- del self.__componentInfo[name]
|
|
|
+ # Remove a megawidget component.
|
|
|
+ # This command is for use by megawidget designers to destroy a
|
|
|
+ # megawidget component.
|
|
|
+ self.__componentInfo[name][0].destroy()
|
|
|
+ del self.__componentInfo[name]
|
|
|
|
|
|
def destroy(self):
|
|
|
# Clean out any hooks
|