diff --git a/direct/src/directtools/DirectSession.py b/direct/src/directtools/DirectSession.py index 0aef23030c..dd70015875 100644 --- a/direct/src/directtools/DirectSession.py +++ b/direct/src/directtools/DirectSession.py @@ -35,7 +35,7 @@ class DirectSession(PandaObject): self.drList = DisplayRegionList() self.iRayList = map(lambda x: x.iRay, self.drList) self.dr = self.drList[0] - self.camera = self.dr.cam + self.camera = base.cameraList[0] self.iRay = self.dr.iRay self.cameraControl = DirectCameraControl() diff --git a/direct/src/gui/DirectButton.py b/direct/src/gui/DirectButton.py index cfc69cf67d..2536fea0ea 100644 --- a/direct/src/gui/DirectButton.py +++ b/direct/src/gui/DirectButton.py @@ -4,6 +4,7 @@ from PGTop import * from PGButton import * from PGItem import * from PGFrameStyle import * +import types import __builtin__ NORMAL = 'normal' @@ -26,7 +27,9 @@ __builtin__.guiTop = aspect2d.attachNewNode(PGTop('DirectGuiTop')) guiTop.node().setMouseWatcher(base.mouseWatcher.node()) class DirectGuiObject(PandaObject): - def __init__(self, optiondefs, **kw): + def __init__(self, optiondefs, dynamicGroups, **kw): + # Default id of all gui object, subclasses should override this + self.guiId = 'guiObject' # Mapping from each megawidget option to a list of information # about the option # - default value @@ -51,6 +54,10 @@ class DirectGuiObject(PandaObject): # - 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: @@ -65,9 +72,16 @@ class DirectGuiObject(PandaObject): # unused options given to the constructor. # # self._constructorKeywords = {} - self.defineoptions(kw, optiondefs) + + # List of dynamic component groups. If a group is included in + # this list, then it not an error if a keyword argument for + # the group is given to the constructor or to configure(), but + # no components with this group have been created. + # self._dynamicGroups = () + + self.defineoptions(kw, optiondefs, dynamicGroups) - def defineoptions(self, keywords, optionDefs): + def defineoptions(self, 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 , the @@ -79,9 +93,14 @@ class DirectGuiObject(PandaObject): if not hasattr(self, '_constructorKeywords'): tmp = {} for option, value in keywords.items(): - tmp[option] = value + tmp[option] = [value, 0] self._constructorKeywords = tmp self._optionInfo = {} + # Initialize dictionary of dynamic groups + if not hasattr(self, '_dynamicGroups'): + self._dynamicGroups = () + self._dynamicGroups = self._dynamicGroups + tuple(dynamicGroups) + # Reconcile command line and default options self.addoptions(optionDefs) def addoptions(self, optionDefs): @@ -105,7 +124,7 @@ class DirectGuiObject(PandaObject): if not optionInfo_has_key(name): if keywords_has_key(name): # Overridden by keyword, use keyword value - value = keywords[name] + value = keywords[name][0] optionInfo[name] = [default, value, function] del keywords[name] else: @@ -127,8 +146,15 @@ class DirectGuiObject(PandaObject): unusedOptions = [] keywords = self._constructorKeywords for name in keywords.keys(): - # This keyword argument has not been used. - unusedOptions.append(name) + print name + 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: @@ -195,6 +221,8 @@ class DirectGuiObject(PandaObject): 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 @@ -227,17 +255,38 @@ class DirectGuiObject(PandaObject): # This option may be of the form _