direct.gui.DirectGuiBase

from direct.gui.DirectGuiBase import DirectGuiBase, DirectGuiWidget, setGuiGridSpacing, toggleGuiGridSnap

Base class for all DirectGui items. Handles composite widgets and command line argument parsing.

Code overview:

  1. Each widget defines a set of options (optiondefs) as a list of tuples of the form ('name', defaultValue, handler). ‘name’ is the name of the option (used during construction of configure) handler can be: None, method, or INITOPT. If a method is specified, it will be called during widget construction (via initialiseoptions), if the Handler is specified as an INITOPT, this is an option that can only be set during widget construction.

  2. defineoptions() is called. defineoption creates:

    self._constructorKeywords = { keyword: [value, useFlag] }

    A dictionary of the keyword options specified as part of the constructor keywords can be of the form ‘component_option’, where component is the name of a widget’s component, a component group or a component alias.

    self._dynamicGroups

    A list of group names for which it is permissible to specify options before components of that group are created. If a widget is a derived class the order of execution would be:

    foo.optiondefs = {}
    foo.defineoptions()
      fooParent()
         fooParent.optiondefs = {}
         fooParent.defineoptions()
    
  3. addoptions() is called. This combines options specified as keywords to the widget constructor (stored in self._constructorKeywords) with the default options (stored in optiondefs). Results are stored in self._optionInfo = { keyword: [default, current, handler] }. If a keyword is of the form ‘component_option’ it is left in the self._constructorKeywords dictionary (for use by component constructors), otherwise it is ‘used’, and deleted from self._constructorKeywords.

    Notes:

    • constructor keywords override the defaults.

    • derived class default values override parent class defaults

    • derived class handler functions override parent class functions

  4. Superclass initialization methods are called (resulting in nested calls to define options (see 2 above)

  5. Widget components are created via calls to createcomponent(). User can specify aliases and groups for each component created.

    Aliases are alternate names for components, e.g. a widget may have a component with a name ‘entryField’, which itself may have a component named ‘entry’, you could add an alias ‘entry’ for the ‘entryField_entry’ These are stored in self.__componentAliases. If an alias is found, all keyword entries which use that alias are expanded to their full form (to avoid conversion later)

    Groups allow option specifications that apply to all members of the group. If a widget has components: ‘text1’, ‘text2’, and ‘text3’ which all belong to the ‘text’ group, they can be all configured with keywords of the form: ‘text_keyword’ (e.g. text_font='comic.rgb'). A component’s group is stored as the fourth element of its entry in self.__componentInfo.

    Note: the widget constructors have access to all remaining keywords in _constructorKeywords (those not transferred to _optionInfo by define/addoptions). If a component defines an alias that applies to one of the keywords, that keyword is replaced with a new keyword with the alias expanded.

    If a keyword (or substituted alias keyword) is used during creation of the component, it is deleted from self._constructorKeywords. If a group keyword applies to the component, that keyword is marked as used, but is not deleted from self._constructorKeywords, in case it applies to another component. If any constructor keywords remain at the end of component construction (and initialisation), an error is raised.

  1. initialiseoptions() is called. This method calls any option handlers to respond to any keyword/default values, then checks to see if any keywords are left unused. If so, an error is raised.

Inheritance diagram

Inheritance diagram of direct.gui.DirectGuiBase

class DirectGuiBase[source]

Bases: DirectObject

Base class of all DirectGUI widgets.

__init__(self)[source]
addoptions(self, optionDefs, optionkeywords)[source]

addoptions(optionDefs) - add option def to option info

bind(self, event, command, extraArgs=[])[source]

Bind the command (which should expect one arg) to the specified event (such as ENTER, EXIT, B1PRESS, B1CLICK, etc.) See DirectGuiGlobals for possible events

cget(self, option)[source]

Get current configuration setting for this option

component(self, name)[source]
components(self)[source]
configure(option=None)[source]

Query or configure the megawidget options.

createcomponent(self, componentName, componentAliases, componentGroup, widgetClass, *widgetArgs, **kw)[source]

Create a component (during construction or later) for this widget.

defineoptions(self, keywords, optionDefs, dynamicGroups=())[source]

defineoptions(keywords, optionDefs, dynamicGroups = {})

destroy(self)[source]
destroycomponent(self, name)[source]
hascomponent(self, component)[source]
initialiseoptions(self, myClass)[source]

Call all initialisation functions to initialize widget options to default of keyword value

isinitoption(self, option)[source]

Is this opition one that can only be specified at construction?

options(self)[source]

Print out a list of available widget options. Does not include subcomponent options.

postInitialiseFunc(self)[source]
unbind(self, event)[source]

Unbind the specified event

class DirectGuiWidget(parent=None, **kw)[source]

Bases: DirectGuiBase, NodePath

__init__(self, parent=None, **kw)[source]
copyOptions(self, other)[source]

Copy other’s options into our self so we look and feel like other

destroy(self)[source]
disableEdit(self)[source]
editStart(self, event)[source]
editStop(self, event)[source]
enableEdit(self)[source]
frameInitialiseFunc(self)[source]
getBounds(self, state=0)[source]
getCenter(self)[source]
getFrameType(self, state=0)[source]
getHeight(self)[source]
getWidth(self)[source]
gridSpacing = 0.05
guiDict = {}
guiDragTask(self, state)[source]
guiEdit = False
guiScaleTask(self, state)[source]
inactiveInitState = 'disabled'
printConfig(self, indent=0)[source]
resetFrameSize(self)[source]
setBorderUvWidth(self)[source]
setBorderWidth(self)[source]
setFrameColor(self)[source]
setFrameSize(self, fClearFrame=0)[source]
setFrameTexture(self)[source]
setFrameVisibleScale(self)[source]
setProp(self, propString, value)[source]

Allows you to set a property like frame[‘text’] = ‘Joe’ in a function instead of an assignment. This is useful for setting properties inside function intervals where must input a function and extraArgs, not an assignment.

setRelief(self, fSetStyle=1)[source]
setState(self)[source]
snapToGrid = 0
taskName(self, idString)[source]
uniqueName(self, idString)[source]
updateFrameStyle(self)[source]
setGuiGridSpacing(spacing)[source]
toggleGuiGridSnap()[source]