formatting
This commit is contained in:
parent
f66d4151fc
commit
64a75159c6
|
|
@ -19,7 +19,7 @@ class DirectCheckButton(DirectButton):
|
|||
# state can have a different text/geom/image
|
||||
# State transitions happen automatically based upon mouse interaction
|
||||
# Responds to click event and calls command if None
|
||||
|
||||
|
||||
self.colors = None
|
||||
optiondefs = (
|
||||
('indicatorValue', 0, self.setIndicatorValue),
|
||||
|
|
@ -46,25 +46,25 @@ class DirectCheckButton(DirectButton):
|
|||
text = ('X', 'X'),
|
||||
relief = self['boxRelief'],
|
||||
)
|
||||
|
||||
|
||||
# Call option initialization functions
|
||||
self.initialiseoptions(DirectCheckButton)
|
||||
# After initialization with X giving it the correct size, put back space
|
||||
# After initialization with X giving it the correct size, put back space
|
||||
if self['boxImage'] == None:
|
||||
self.indicator['text'] = (' ', '*')
|
||||
self.indicator['text_pos'] = (0,-.2)
|
||||
self.indicator['text_pos'] = (0, -.2)
|
||||
else:
|
||||
self.indicator['text'] = (' ', ' ')
|
||||
if self['boxImageColor'] != None and self['boxImage'] != None:
|
||||
self.colors = [VBase4(0,0,0,0), self['boxImageColor']]
|
||||
self.component('indicator')['image_color'] = VBase4(0,0,0,0)
|
||||
|
||||
self.colors = [VBase4(0, 0, 0, 0), self['boxImageColor']]
|
||||
self.component('indicator')['image_color'] = VBase4(0, 0, 0, 0)
|
||||
|
||||
# Override the resetFrameSize of DirectGuiWidget inorder to provide space for label
|
||||
def resetFrameSize(self):
|
||||
self.setFrameSize(fClearFrame = 1)
|
||||
|
||||
|
||||
def setFrameSize(self, fClearFrame = 0):
|
||||
|
||||
|
||||
if self['frameSize']:
|
||||
# Use user specified bounds
|
||||
self.bounds = self['frameSize']
|
||||
|
|
@ -125,7 +125,7 @@ class DirectCheckButton(DirectButton):
|
|||
(frameType != PGFrameStyle.TFlat)):
|
||||
bw = self['borderWidth']
|
||||
else:
|
||||
bw = (0,0)
|
||||
bw = (0, 0)
|
||||
# Set frame to new dimensions
|
||||
self.guiItem.setFrame(
|
||||
self.bounds[0] - bw[0],
|
||||
|
|
@ -137,7 +137,7 @@ class DirectCheckButton(DirectButton):
|
|||
if not self.indicator['pos']:
|
||||
bbounds = self.bounds
|
||||
lbounds = self.indicator.bounds
|
||||
newpos = [0,0,0]
|
||||
newpos = [0, 0, 0]
|
||||
|
||||
if self['boxPlacement'] == 'left': #left
|
||||
newpos[0] += bbounds[0]-lbounds[0] + self['boxBorder'] + ibw[0]
|
||||
|
|
@ -154,18 +154,18 @@ class DirectCheckButton(DirectButton):
|
|||
else: #below
|
||||
newpos[2] += bbounds[2]-lbounds[2] + self['boxBorder'] + ibw[1]
|
||||
|
||||
self.indicator.setPos(newpos[0],newpos[1],newpos[2])
|
||||
self.indicator.setPos(newpos[0], newpos[1], newpos[2])
|
||||
|
||||
|
||||
|
||||
def commandFunc(self, event):
|
||||
self['indicatorValue'] = 1 - self['indicatorValue']
|
||||
if self.colors != None:
|
||||
self.component('indicator')['image_color'] = self.colors[self['indicatorValue']]
|
||||
|
||||
|
||||
if self['command']:
|
||||
# Pass any extra args to command
|
||||
apply(self['command'], [self['indicatorValue']] + self['extraArgs'])
|
||||
|
||||
|
||||
def setIndicatorValue(self):
|
||||
self.component('indicator').guiItem.setState(self['indicatorValue'])
|
||||
if self.colors != None:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from DirectButton import *
|
|||
|
||||
def findDialog(uniqueName):
|
||||
"""findPanel(string uniqueName)
|
||||
|
||||
|
||||
Returns the panel whose uniqueName is given. This is mainly
|
||||
useful for debugging, to get a pointer to the current onscreen
|
||||
panel of a particular type.
|
||||
|
|
@ -48,7 +48,7 @@ class DirectDialog(DirectFrame):
|
|||
buttonImageList List of images to show on each button
|
||||
buttonValueList List of values sent to dialog command for
|
||||
each button. If value is [] then the
|
||||
ordinal rank of the button is used as
|
||||
ordinal rank of the button is used as
|
||||
its value
|
||||
buttonHotKeyList List of hotkeys to bind to each button.
|
||||
Typing hotkey is equivalent to pressing
|
||||
|
|
@ -64,7 +64,7 @@ class DirectDialog(DirectFrame):
|
|||
midPad Extra space added between text/buttons
|
||||
sidePad Extra space added to either side of
|
||||
text/buttons
|
||||
buttonPadSF Scale factor used to expand/contract
|
||||
buttonPadSF Scale factor used to expand/contract
|
||||
button horizontal spacing
|
||||
command Callback command used when a button is
|
||||
pressed. Value supplied to command
|
||||
|
|
@ -75,7 +75,7 @@ class DirectDialog(DirectFrame):
|
|||
Values of None are substituted for lists that are shorter
|
||||
than the max length
|
||||
"""
|
||||
|
||||
|
||||
# Inherits from DirectFrame
|
||||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
|
|
@ -95,8 +95,8 @@ class DirectDialog(DirectFrame):
|
|||
('buttonImageList', [], INITOPT),
|
||||
('buttonValueList', [], INITOPT),
|
||||
('buttonHotKeyList', [], INITOPT),
|
||||
('button_borderWidth',(.01,.01), None),
|
||||
('button_pad', (.01,.01), None),
|
||||
('button_borderWidth', (.01, .01), None),
|
||||
('button_pad', (.01, .01), None),
|
||||
('button_relief', RAISED, None),
|
||||
('button_text_scale', 0.06, None),
|
||||
('buttonSize', None, INITOPT),
|
||||
|
|
@ -126,7 +126,7 @@ class DirectDialog(DirectFrame):
|
|||
# Store this panel in our map of all open panels.
|
||||
DirectDialog.AllDialogs[self['dialogName']] = self
|
||||
DirectDialog.PanelIndex += 1
|
||||
|
||||
|
||||
# Determine number of buttons
|
||||
self.numButtons = max(len(self['buttonTextList']),
|
||||
len(self['buttonGeomList']),
|
||||
|
|
@ -186,9 +186,9 @@ class DirectDialog(DirectFrame):
|
|||
extraArgs = [value])
|
||||
self.bind('press-' + key + '-', self.buttonCommand,
|
||||
extraArgs = [value])
|
||||
|
||||
|
||||
else:
|
||||
button.bind('press-' + hotKey + '-',self.buttonCommand,
|
||||
button.bind('press-' + hotKey + '-', self.buttonCommand,
|
||||
extraArgs = [value])
|
||||
self.bind('press-' + hotKey + '-', self.buttonCommand,
|
||||
extraArgs = [value])
|
||||
|
|
@ -247,7 +247,7 @@ class DirectDialog(DirectFrame):
|
|||
bt += bpad[1]
|
||||
# Now resize buttons to match largest
|
||||
for button in self.buttonList:
|
||||
button['frameSize'] = (bl,br,bb,bt)
|
||||
button['frameSize'] = (bl, br, bb, bt)
|
||||
# Must compensate for scale
|
||||
scale = self['button_scale']
|
||||
# Can either be a Vec3 or a tuple of 3 values
|
||||
|
|
@ -283,7 +283,7 @@ class DirectDialog(DirectFrame):
|
|||
bl = br = bb = bt = 0
|
||||
bPos = 0
|
||||
bMax = 0
|
||||
bpad = (0,0)
|
||||
bpad = (0, 0)
|
||||
bHeight = bWidth = 0
|
||||
# Resize frame to fit text and buttons
|
||||
l = min(bPos + bl, l) - pad[0]
|
||||
|
|
@ -296,7 +296,7 @@ class DirectDialog(DirectFrame):
|
|||
t = t + self['topPad'] + pad[1]
|
||||
self['image_scale'] = (r - l, 1, t - b)
|
||||
# Center frame about text and buttons
|
||||
self['image_pos'] = ((l+r)*0.5, 0.0,(b+t)*0.5)
|
||||
self['image_pos'] = ((l+r)*0.5, 0.0, (b+t)*0.5)
|
||||
self.resetFrameSize()
|
||||
|
||||
def show(self):
|
||||
|
|
@ -316,7 +316,7 @@ class DirectDialog(DirectFrame):
|
|||
def setMessage(self, message):
|
||||
self['text'] = message
|
||||
self.configureDialog()
|
||||
|
||||
|
||||
def cleanup(self):
|
||||
# Remove this panel out of the AllDialogs list
|
||||
uniqueName = self['dialogName']
|
||||
|
|
@ -348,7 +348,7 @@ class OkCancelDialog(DirectDialog):
|
|||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('buttonTextList', ['OK','Cancel'], INITOPT),
|
||||
('buttonValueList', [DIALOG_OK,DIALOG_CANCEL], INITOPT),
|
||||
('buttonValueList', [DIALOG_OK, DIALOG_CANCEL], INITOPT),
|
||||
)
|
||||
# Merge keyword options with default options
|
||||
self.defineoptions(kw, optiondefs)
|
||||
|
|
@ -361,7 +361,7 @@ class YesNoDialog(DirectDialog):
|
|||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('buttonTextList', ['Yes', 'No'], INITOPT),
|
||||
('buttonValueList', [DIALOG_YES,DIALOG_NO], INITOPT),
|
||||
('buttonValueList', [DIALOG_YES, DIALOG_NO], INITOPT),
|
||||
)
|
||||
# Merge keyword options with default options
|
||||
self.defineoptions(kw, optiondefs)
|
||||
|
|
@ -374,7 +374,7 @@ class YesNoCancelDialog(DirectDialog):
|
|||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('buttonTextList', ['Yes', 'No', 'Cancel'], INITOPT),
|
||||
('buttonValueList', [DIALOG_YES,DIALOG_NO,DIALOG_CANCEL],
|
||||
('buttonValueList', [DIALOG_YES, DIALOG_NO, DIALOG_CANCEL],
|
||||
INITOPT),
|
||||
)
|
||||
# Merge keyword options with default options
|
||||
|
|
@ -388,7 +388,7 @@ class RetryCancelDialog(DirectDialog):
|
|||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('buttonTextList', ['Retry','Cancel'], INITOPT),
|
||||
('buttonValueList', [DIALOG_RETRY,DIALOG_CANCEL], INITOPT),
|
||||
('buttonValueList', [DIALOG_RETRY, DIALOG_CANCEL], INITOPT),
|
||||
)
|
||||
# Merge keyword options with default options
|
||||
self.defineoptions(kw, optiondefs)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class DirectEntry(DirectFrame):
|
|||
"""
|
||||
|
||||
directWtext = ConfigVariableBool('direct-wtext', 1)
|
||||
|
||||
|
||||
def __init__(self, parent = None, **kw):
|
||||
# Inherits from DirectFrame
|
||||
# A Direct Frame can have:
|
||||
|
|
@ -48,9 +48,9 @@ class DirectEntry(DirectFrame):
|
|||
('extraArgs', [], None),
|
||||
# commands to be called when focus is gained or lost
|
||||
('focusInCommand', None, None),
|
||||
('focusInExtraArgs',[], None),
|
||||
('focusOutCommand',None, None),
|
||||
('focusOutExtraArgs',[], None),
|
||||
('focusInExtraArgs', [], None),
|
||||
('focusOutCommand', None, None),
|
||||
('focusOutExtraArgs', [], None),
|
||||
# Sounds to be used for button events
|
||||
('rolloverSound', getDefaultRolloverSound(), self.setRolloverSound),
|
||||
('clickSound', getDefaultClickSound(), self.setClickSound),
|
||||
|
|
@ -64,7 +64,7 @@ class DirectEntry(DirectFrame):
|
|||
if self['entryFont'] == None:
|
||||
font = getDefaultFont()
|
||||
else:
|
||||
font = self['entryFont']
|
||||
font = self['entryFont']
|
||||
|
||||
# Create Text Node Component
|
||||
self.onscreenText = self.createcomponent(
|
||||
|
|
@ -146,11 +146,11 @@ class DirectEntry(DirectFrame):
|
|||
def focusInCommandFunc(self):
|
||||
if self['focusInCommand']:
|
||||
apply(self['focusInCommand'], self['focusInExtraArgs'])
|
||||
|
||||
|
||||
def focusOutCommandFunc(self):
|
||||
if self['focusOutCommand']:
|
||||
apply(self['focusOutCommand'], self['focusOutExtraArgs'])
|
||||
|
||||
|
||||
def set(self, text):
|
||||
self.unicodeText = isinstance(text, types.UnicodeType)
|
||||
if self.unicodeText:
|
||||
|
|
@ -164,7 +164,7 @@ class DirectEntry(DirectFrame):
|
|||
# return an 8-bit string. This will be encoded if
|
||||
# necessary, according to Panda's default encoding.
|
||||
return self.guiItem.getText()
|
||||
|
||||
|
||||
if self.unicodeText:
|
||||
return self.guiItem.getWtext()
|
||||
else:
|
||||
|
|
@ -187,7 +187,7 @@ class DirectEntry(DirectFrame):
|
|||
self.guiItem.setCursorPosition(len(self.get()) + pos)
|
||||
else:
|
||||
self.guiItem.setCursorPosition(pos)
|
||||
|
||||
|
||||
def enterText(self, text):
|
||||
""" sets the entry's text, and moves the cursor to the end """
|
||||
self.set(text)
|
||||
|
|
@ -215,7 +215,7 @@ class DirectEntry(DirectFrame):
|
|||
|
||||
bottom = -0.3 * lineHeight - (lineHeight * (numLines - 1))
|
||||
top = lineHeight
|
||||
|
||||
|
||||
self.ll.set(left, 0.0, bottom)
|
||||
self.ur.set(right, 0.0, top)
|
||||
self.ll = mat.xformPoint(self.ll)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ Code Overview:
|
|||
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:
|
||||
|
|
@ -156,7 +156,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
# 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
|
||||
# dynamicGroups is a tuple of component groups for which you can
|
||||
|
|
@ -178,20 +178,20 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
self._dynamicGroups = self._dynamicGroups + tuple(dynamicGroups)
|
||||
# Reconcile command line and default options
|
||||
self.addoptions(optionDefs)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
# 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:
|
||||
# The option will already exist if it has been defined
|
||||
|
|
@ -218,10 +218,10 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
# of an option of a component of a base class.
|
||||
if not keywords_has_key(name):
|
||||
keywords[name] = [default, 0]
|
||||
|
||||
|
||||
def initialiseoptions(self, myClass):
|
||||
"""
|
||||
Call all initialisation functions to initialize widget
|
||||
Call all initialisation functions to initialize widget
|
||||
options to default of keyword value
|
||||
"""
|
||||
# This is to make sure this method class is only called by
|
||||
|
|
@ -262,13 +262,13 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
def postInitialiseFunc(self):
|
||||
for func in self.postInitialiseFuncList:
|
||||
func()
|
||||
|
||||
|
||||
def isinitoption(self, option):
|
||||
"""
|
||||
Is this opition one that can only be specified at construction?
|
||||
"""
|
||||
return self._optionInfo[option][_OPT_FUNCTION] is INITOPT
|
||||
|
||||
|
||||
def options(self):
|
||||
"""
|
||||
Print out a list of available widget options.
|
||||
|
|
@ -282,7 +282,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
options.append((option, default, isinit))
|
||||
options.sort()
|
||||
return options
|
||||
|
||||
|
||||
def configure(self, option=None, **kw):
|
||||
"""
|
||||
configure(option = None)
|
||||
|
|
@ -301,7 +301,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
#
|
||||
# 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.
|
||||
|
|
@ -317,7 +317,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
else:
|
||||
config = self._optionInfo[option]
|
||||
return (option, config[_OPT_DEFAULT], config[_OPT_VALUE])
|
||||
|
||||
|
||||
# optimizations:
|
||||
optionInfo = self._optionInfo
|
||||
optionInfo_has_key = optionInfo.has_key
|
||||
|
|
@ -327,11 +327,11 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
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 information about the options in
|
||||
# *kw* of the form <component>_<option>, where
|
||||
# <component> is a component of this megawidget. It is a
|
||||
|
|
@ -343,7 +343,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
|
||||
for option, value in kw.items():
|
||||
if optionInfo_has_key(option):
|
||||
# This is one of the options of this gui item.
|
||||
# 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 "' \
|
||||
|
|
@ -416,23 +416,23 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
# Pass in the dictionary of keyword/values created above
|
||||
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()
|
||||
|
||||
|
||||
# Allow index style references
|
||||
def __setitem__(self, key, value):
|
||||
apply(self.configure, (), {key: value})
|
||||
|
||||
|
||||
def cget(self, option):
|
||||
"""
|
||||
Get current configuration setting for this option
|
||||
"""
|
||||
# Return the value of an option, for example myWidget['font'].
|
||||
# Return the value of an option, for example myWidget['font'].
|
||||
if self._optionInfo.has_key(option):
|
||||
return self._optionInfo[option][_OPT_VALUE]
|
||||
else:
|
||||
|
|
@ -466,10 +466,10 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
# Option not found
|
||||
raise KeyError, 'Unknown option "' + option + \
|
||||
'" for ' + self.__class__.__name__
|
||||
|
||||
|
||||
# Allow index style refererences
|
||||
__getitem__ = cget
|
||||
|
||||
|
||||
def createcomponent(self, componentName, componentAliases, componentGroup,
|
||||
widgetClass, *widgetArgs, **kw):
|
||||
"""
|
||||
|
|
@ -479,7 +479,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
if '_' in componentName:
|
||||
raise ValueError, \
|
||||
'Component name "%s" must not contain "_"' % componentName
|
||||
|
||||
|
||||
# Get construction keywords
|
||||
if hasattr(self, '_constructorKeywords'):
|
||||
keywords = self._constructorKeywords
|
||||
|
|
@ -515,7 +515,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
|
||||
# First, walk through the option list looking for arguments
|
||||
# than refer to this component's group.
|
||||
|
||||
|
||||
for option in keywords.keys():
|
||||
# Check if this keyword argument refers to the group
|
||||
# of this component. If so, add this to the options
|
||||
|
|
@ -534,7 +534,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
# this component specifically by name. These are more
|
||||
# specific than the group arguments, above; we walk through
|
||||
# the list afterwards so they will override.
|
||||
|
||||
|
||||
for option in keywords.keys():
|
||||
if len(option) > nameLen and option[:nameLen] == componentPrefix:
|
||||
# The keyword argument refers to this component, so add
|
||||
|
|
@ -617,7 +617,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
del self._optionInfo
|
||||
del self.__componentInfo
|
||||
del self.postInitialiseFuncList
|
||||
|
||||
|
||||
def bind(self, event, command, extraArgs = []):
|
||||
"""
|
||||
Bind the command (which should expect one arg) to the specified
|
||||
|
|
@ -627,7 +627,7 @@ class DirectGuiBase(DirectObject.DirectObject):
|
|||
# Need to tack on gui item specific id
|
||||
gEvent = event + self.guiId
|
||||
self.accept(gEvent, command, extraArgs = extraArgs)
|
||||
|
||||
|
||||
def unbind(self, event):
|
||||
"""
|
||||
Unbind the specified event
|
||||
|
|
@ -681,12 +681,12 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
('state', NORMAL, self.setState),
|
||||
# Widget's frame characteristics
|
||||
('relief', FLAT, self.setRelief),
|
||||
('borderWidth', (.1,.1), self.setBorderWidth),
|
||||
('borderWidth', (.1, .1), self.setBorderWidth),
|
||||
('frameSize', None, self.setFrameSize),
|
||||
('frameColor', (.8,.8,.8,1), self.setFrameColor),
|
||||
('frameColor', (.8, .8, .8, 1), self.setFrameColor),
|
||||
('frameTexture', None, self.setFrameTexture),
|
||||
('frameVisibleScale', (1,1), self.setFrameVisibleScale),
|
||||
('pad', (0,0), self.resetFrameSize),
|
||||
('frameVisibleScale', (1, 1), self.setFrameVisibleScale),
|
||||
('pad', (0, 0), self.resetFrameSize),
|
||||
# Override button id (beware! your name may not be unique!)
|
||||
('guiId', None, INITOPT),
|
||||
# Initial pos/scale of the widget
|
||||
|
|
@ -779,7 +779,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
|
||||
# Update frame when everything has been initialized
|
||||
self.postInitialiseFuncList.append(self.frameInitialiseFunc)
|
||||
|
||||
|
||||
# Call option initialization functions
|
||||
self.initialiseoptions(DirectGuiWidget)
|
||||
|
||||
|
|
@ -806,7 +806,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
#mb = base.mouseWatcherNode.getModifierButtons()
|
||||
#mb.removeButton(KeyboardButton.control())
|
||||
#base.mouseWatcherNode.setModifierButtons(mb)
|
||||
|
||||
|
||||
def editStart(self, event):
|
||||
taskMgr.remove('guiEditTask')
|
||||
vWidget2render2d = self.getPos(render2d)
|
||||
|
|
@ -859,15 +859,15 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
def resetFrameSize(self):
|
||||
if not self.fInit:
|
||||
self.setFrameSize(fClearFrame = 1)
|
||||
|
||||
|
||||
def setFrameSize(self, fClearFrame = 0):
|
||||
# Use ready state to determine frame Type
|
||||
frameType = self.getFrameType()
|
||||
if self['frameSize']:
|
||||
# Use user specified bounds
|
||||
self.bounds = self['frameSize']
|
||||
#print "%s bounds = %s" % (self.getName(),self.bounds)
|
||||
bw = (0,0)
|
||||
#print "%s bounds = %s" % (self.getName(), self.bounds)
|
||||
bw = (0, 0)
|
||||
|
||||
else:
|
||||
if fClearFrame and (frameType != PGFrameStyle.TNone):
|
||||
|
|
@ -886,7 +886,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
(frameType != PGFrameStyle.TFlat)):
|
||||
bw = self['borderWidth']
|
||||
else:
|
||||
bw = (0,0)
|
||||
bw = (0, 0)
|
||||
|
||||
# Set frame to new dimensions
|
||||
self.guiItem.setFrame(
|
||||
|
|
@ -906,19 +906,19 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
return self.bounds
|
||||
|
||||
def getWidth(self):
|
||||
return self.bounds[1] - self.bounds[0]
|
||||
|
||||
return self.bounds[1] - self.bounds[0]
|
||||
|
||||
def getHeight(self):
|
||||
return self.bounds[3] - self.bounds[2]
|
||||
|
||||
def getCenter(self):
|
||||
x = self.bounds[0] + (self.bounds[1] - self.bounds[0])/2.0
|
||||
y = self.bounds[2] + (self.bounds[3] - self.bounds[2])/2.0
|
||||
return (x,y)
|
||||
return (x, y)
|
||||
|
||||
def getFrameType(self, state = 0):
|
||||
return self.frameStyle[state].getType()
|
||||
|
||||
|
||||
def updateFrameStyle(self):
|
||||
if not self.fInit:
|
||||
for i in range(self['numStates']):
|
||||
|
|
@ -1011,7 +1011,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
del self.guiItem
|
||||
# Call superclass destruction method (clears out hooks)
|
||||
DirectGuiBase.destroy(self)
|
||||
|
||||
|
||||
def printConfig(self, indent = 0):
|
||||
space = ' ' * indent
|
||||
print space + self.guiId, '-', self.__class__.__name__
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ if __name__ == "__main__":
|
|||
# Get a handle on the geometry for the rollover state
|
||||
rolloverSmiley = db.component('geom2')
|
||||
rolloverSmiley.setScale(db.component('geom0').getScale()[0])
|
||||
rolloverSmiley.lerpScale(.1,.1,.1, 1.0, blendType = 'easeInOut',
|
||||
rolloverSmiley.lerpScale(.1, .1, .1, 1.0, blendType = 'easeInOut',
|
||||
task = 'shrink')
|
||||
|
||||
def expand(db):
|
||||
|
|
@ -28,7 +28,7 @@ if __name__ == "__main__":
|
|||
taskMgr.remove('shrink')
|
||||
taskMgr.remove('expand')
|
||||
db.component('geom0').setScale(db.component('geom2').getScale()[0])
|
||||
db.component('geom0').lerpScale(1,1,1, 1, blendType = 'easeInOut',
|
||||
db.component('geom0').lerpScale(1, 1, 1, 1, blendType = 'easeInOut',
|
||||
task = 'expand')
|
||||
db.component('geom2').clearColor()
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ if __name__ == "__main__":
|
|||
db.component('geom0').setScale(db.component('geom2').getScale()[0])
|
||||
db.component('geom1').setScale(db.component('geom2').getScale()[0])
|
||||
db['text2_text'] = 'Ouch!'
|
||||
db['geom2_color'] = Vec4(1,0,0,1)
|
||||
db['geom2_color'] = Vec4(1, 0, 0, 1)
|
||||
newX = -1.0 + random() * 2.0
|
||||
newZ = -1.0 + random() * 2.0
|
||||
db.lerpPos(Point3(newX, 0, newZ), 1.0, task = 'runAway',
|
||||
|
|
@ -59,7 +59,7 @@ if __name__ == "__main__":
|
|||
text = ('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'),
|
||||
scale = .15, relief = 'raised',
|
||||
# Here we set an option for a component of the button
|
||||
geom1_color = Vec4(1,0,0,1),
|
||||
geom1_color = Vec4(1, 0, 0, 1),
|
||||
# Here is an example of a component group option
|
||||
text_pos = (.6, -.8),
|
||||
# Set audio characteristics
|
||||
|
|
@ -80,7 +80,7 @@ if __name__ == "__main__":
|
|||
db.bind(B3PRESS, lambda x, db = db: db.place())
|
||||
|
||||
dbArray.append(db)
|
||||
|
||||
|
||||
# To get rid of button and clear out hooks call:
|
||||
# db.destroy()
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ if __name__ == "__main__":
|
|||
fancyDialog = YesNoDialog(text = 'Testing Direct Dialog',
|
||||
geom = smiley,
|
||||
geom_scale = .1,
|
||||
geom_pos = (-0.3,0,0),
|
||||
geom_pos = (-0.3, 0, 0),
|
||||
command = printDialogValue)
|
||||
|
||||
customDialog = DirectDialog(text = 'Pick a number',
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ class DirectOptionMenu(DirectButton):
|
|||
# Amount of padding to place around popup button indicator
|
||||
('popupMarkerBorder', (.1, .1), None),
|
||||
# Background color to use to highlight popup menu items
|
||||
('highlightColor', (.5,.5,.5,1),None),
|
||||
('highlightColor', (.5, .5, .5, 1), None),
|
||||
# Alignment to use for text on popup menu button
|
||||
# Changing this breaks button layout
|
||||
('text_align', TextNode.ALeft, None),
|
||||
# Remove press effect because it looks a bit funny
|
||||
# Remove press effect because it looks a bit funny
|
||||
('pressEffect', 0, INITOPT),
|
||||
)
|
||||
# Merge keyword options with default options
|
||||
|
|
@ -47,7 +47,7 @@ class DirectOptionMenu(DirectButton):
|
|||
self.popupMarker.bind(B1RELEASE, self.selectHighlightedIndex)
|
||||
# Make popup marker have the same click sound
|
||||
self.popupMarker.guiItem.setSound(
|
||||
B1PRESS + self.popupMarker.guiId,self['clickSound'])
|
||||
B1PRESS + self.popupMarker.guiId, self['clickSound'])
|
||||
# This is created when you set the menu's items
|
||||
self.popupMenu = None
|
||||
self.selectedIndex = None
|
||||
|
|
@ -56,7 +56,7 @@ class DirectOptionMenu(DirectButton):
|
|||
self.cancelFrame = self.createcomponent(
|
||||
'cancelframe', (), None,
|
||||
DirectFrame, (self,),
|
||||
frameSize = (-1,1,-1,1),
|
||||
frameSize = (-1, 1, -1, 1),
|
||||
relief = None,
|
||||
state = 'normal')
|
||||
# Make sure this is on top of all the other widgets
|
||||
|
|
@ -130,11 +130,11 @@ class DirectOptionMenu(DirectButton):
|
|||
item.bind(B1RELEASE, self.hidePopupMenu)
|
||||
# Highlight background when mouse is in item
|
||||
item.bind(WITHIN,
|
||||
lambda x,i=i,item=item:self._highlightItem(item, i))
|
||||
lambda x, i=i, item=item:self._highlightItem(item, i))
|
||||
# Restore specified color upon exiting
|
||||
fc = item['frameColor']
|
||||
item.bind(WITHOUT,
|
||||
lambda x,item=item,fc=fc: self._unhighlightItem(item,fc))
|
||||
lambda x, item=item, fc=fc: self._unhighlightItem(item, fc))
|
||||
# Set popup menu frame size to encompass all items
|
||||
f = self.component('popupMenu')
|
||||
f['frameSize'] = (0, self.maxWidth, -self.maxHeight * itemIndex, 0)
|
||||
|
|
@ -145,7 +145,7 @@ class DirectOptionMenu(DirectButton):
|
|||
else:
|
||||
# No initial item specified, just use first item
|
||||
self.set(0, fCommand = 0)
|
||||
|
||||
|
||||
# Position popup Marker to the right of the button
|
||||
pm = self.popupMarker
|
||||
pmw = (pm.getWidth() * pm.getScale()[0] +
|
||||
|
|
@ -175,7 +175,7 @@ class DirectOptionMenu(DirectButton):
|
|||
# Show the menu
|
||||
self.popupMenu.show()
|
||||
# Make sure its at the right scale
|
||||
self.popupMenu.setScale(self, VBase3(1))
|
||||
self.popupMenu.setScale(self, VBase3(1))
|
||||
# Compute bounds
|
||||
b = self.getBounds()
|
||||
fb = self.popupMenu.getBounds()
|
||||
|
|
@ -205,8 +205,8 @@ class DirectOptionMenu(DirectButton):
|
|||
# Also display cancel frame to catch clicks outside of the popup
|
||||
self.cancelFrame.show()
|
||||
# Position and scale cancel frame to fill entire window
|
||||
self.cancelFrame.setPos(render2d,0,0,0)
|
||||
self.cancelFrame.setScale(render2d,1,1,1)
|
||||
self.cancelFrame.setPos(render2d, 0, 0, 0)
|
||||
self.cancelFrame.setScale(render2d, 1, 1, 1)
|
||||
|
||||
def hidePopupMenu(self, event = None):
|
||||
""" Put away popup and cancel frame """
|
||||
|
|
@ -259,7 +259,7 @@ class DirectOptionMenu(DirectButton):
|
|||
def get(self):
|
||||
""" Get currently selected item """
|
||||
return self['items'][self.selectedIndex]
|
||||
|
||||
|
||||
def commandFunc(self, event):
|
||||
"""
|
||||
Override popup menu button's command func
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from DirectGuiBase import _OPT_VALUE
|
|||
|
||||
"""
|
||||
import DirectScrollBar
|
||||
d = DirectScrollBar(borderWidth=(0,0))
|
||||
d = DirectScrollBar(borderWidth=(0, 0))
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ class DirectScrollBar(DirectFrame):
|
|||
# Define type of DirectGuiWidget
|
||||
('pgFunc', PGSliderBar, None),
|
||||
('state', NORMAL, None),
|
||||
('frameColor', (0.6,0.6,0.6,1), None),
|
||||
('frameColor', (0.6, 0.6, 0.6, 1), None),
|
||||
|
||||
('range', (0, 1), self.setRange),
|
||||
('value', 0, self.__setValue),
|
||||
|
|
@ -36,12 +36,12 @@ class DirectScrollBar(DirectFrame):
|
|||
if kw.get('orientation') == VERTICAL:
|
||||
# These are the default options for a vertical layout.
|
||||
optiondefs += (
|
||||
('frameSize', (-0.04,0.04,-0.5,0.5), None),
|
||||
('frameSize', (-0.04, 0.04, -0.5, 0.5), None),
|
||||
)
|
||||
else:
|
||||
# These are the default options for a horizontal layout.
|
||||
optiondefs += (
|
||||
('frameSize', (-0.5,0.5,-0.04,0.04), None),
|
||||
('frameSize', (-0.5, 0.5, -0.04, 0.04), None),
|
||||
)
|
||||
|
||||
# Merge keyword options with default options
|
||||
|
|
@ -72,7 +72,7 @@ class DirectScrollBar(DirectFrame):
|
|||
|
||||
# Call option initialization functions
|
||||
self.initialiseoptions(DirectScrollBar)
|
||||
|
||||
|
||||
def setRange(self):
|
||||
# Try to preserve the value across a setRange call.
|
||||
v = self['value']
|
||||
|
|
@ -126,4 +126,4 @@ class DirectScrollBar(DirectFrame):
|
|||
|
||||
if self['command']:
|
||||
apply(self['command'], self['extraArgs'])
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from DirectScrollBar import *
|
|||
|
||||
"""
|
||||
import DirectScrolledFrame
|
||||
d = DirectScrolledFrame(borderWidth=(0,0))
|
||||
d = DirectScrolledFrame(borderWidth=(0, 0))
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -23,9 +23,9 @@ class DirectScrolledFrame(DirectFrame):
|
|||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('pgFunc', PGScrollFrame, None),
|
||||
('frameSize', (-0.5,0.5,-0.5,0.5), None),
|
||||
|
||||
('canvasSize', (-1,1,-1,1), self.setCanvasSize),
|
||||
('frameSize', (-0.5, 0.5, -0.5, 0.5), None),
|
||||
|
||||
('canvasSize', (-1, 1, -1, 1), self.setCanvasSize),
|
||||
('manageScrollBars', 1, self.setManageScrollBars),
|
||||
('autoHideScrollBars', 1, self.setAutoHideScrollBars),
|
||||
('scrollBarWidth', 0.08, None),
|
||||
|
|
@ -82,11 +82,11 @@ class DirectScrolledFrame(DirectFrame):
|
|||
def commandFunc(self):
|
||||
if self['command']:
|
||||
apply(self['command'], self['extraArgs'])
|
||||
|
||||
|
||||
def destroy(self):
|
||||
# Destroy children of the canvas
|
||||
for child in self.canvas.getChildrenAsList():
|
||||
childGui = self.guiDict.get(child.getName())
|
||||
if childGui: childGui.destroy()
|
||||
DirectFrame.destroy(self)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class DirectScrolledList(DirectFrame):
|
|||
kw['items'] = kw['items'][:]
|
||||
|
||||
self.nextItemID = 10
|
||||
|
||||
|
||||
# Inherits from DirectFrame
|
||||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
|
|
@ -100,13 +100,13 @@ class DirectScrolledList(DirectFrame):
|
|||
for item in self["items"]:
|
||||
if item.__class__.__name__ != 'str':
|
||||
item.reparentTo(self.itemFrame)
|
||||
|
||||
|
||||
self.initialiseoptions(DirectScrolledList)
|
||||
self.recordMaxHeight()
|
||||
#if len(self["items"]) > 0:
|
||||
# self.scrollTo(0)
|
||||
self.scrollTo(0)
|
||||
|
||||
|
||||
def setForceHeight(self):
|
||||
assert self.notify.debugStateCall(self)
|
||||
self.forceHeight = self["forceHeight"]
|
||||
|
|
@ -120,7 +120,7 @@ class DirectScrolledList(DirectFrame):
|
|||
for item in self["items"]:
|
||||
if item.__class__.__name__ != 'str':
|
||||
self.maxHeight = max(self.maxHeight, item.getHeight())
|
||||
|
||||
|
||||
def setScrollSpeed(self):
|
||||
assert self.notify.debugStateCall(self)
|
||||
# Items per second to move
|
||||
|
|
@ -149,13 +149,13 @@ class DirectScrolledList(DirectFrame):
|
|||
|
||||
def scrollBy(self, delta):
|
||||
assert self.notify.debugStateCall(self)
|
||||
# print "scrollBy[",delta,"]"
|
||||
# print "scrollBy[", delta,"]"
|
||||
return self.scrollTo(self.index + delta)
|
||||
|
||||
def getItemIndexForItemID(self, itemID):
|
||||
assert self.notify.debugStateCall(self)
|
||||
#for i in range(len(self["items"])):
|
||||
# print "buttontext[",i,"]",self["items"][i]["text"]
|
||||
# print "buttontext[", i,"]", self["items"][i]["text"]
|
||||
|
||||
if(len(self["items"])==0):
|
||||
return 0
|
||||
|
|
@ -177,7 +177,7 @@ class DirectScrolledList(DirectFrame):
|
|||
def scrollTo(self, index, centered=0):
|
||||
""" scrolls list so selected index is at top, or centered in box"""
|
||||
assert self.notify.debugStateCall(self)
|
||||
# print "scrollTo[",index,"] called, len(self[items])=",len(self["items"])," self[numItemsVisible]=",self["numItemsVisible"]
|
||||
# print "scrollTo[", index,"] called, len(self[items])=", len(self["items"])," self[numItemsVisible]=", self["numItemsVisible"]
|
||||
|
||||
numItemsVisible=self["numItemsVisible"]
|
||||
numItemsTotal = len(self["items"])
|
||||
|
|
@ -202,7 +202,7 @@ class DirectScrolledList(DirectFrame):
|
|||
ret = 0
|
||||
elif (self.index >= (numItemsTotal - numItemsVisible)):
|
||||
self.index = numItemsTotal - numItemsVisible
|
||||
# print "at list end, ",len(self["items"])," ",self["numItemsVisible"]
|
||||
# print "at list end, ", len(self["items"])," ", self["numItemsVisible"]
|
||||
self.incButton['state'] = DISABLED
|
||||
self.decButton['state'] = NORMAL
|
||||
ret = 0
|
||||
|
|
@ -211,18 +211,18 @@ class DirectScrolledList(DirectFrame):
|
|||
self.decButton['state'] = NORMAL
|
||||
ret = 1
|
||||
|
||||
# print "self.index set to ",self.index
|
||||
# print "self.index set to ", self.index
|
||||
|
||||
# Hide them all
|
||||
for item in self["items"]:
|
||||
if item.__class__.__name__ != 'str':
|
||||
item.hide()
|
||||
|
||||
# Then show the ones in range, and stack their positions
|
||||
|
||||
# Then show the ones in range, and stack their positions
|
||||
upperRange = min(numItemsTotal, numItemsVisible)
|
||||
for i in range(self.index, self.index + upperRange):
|
||||
item = self["items"][i]
|
||||
#print "stacking buttontext[",i,"]",self["items"][i]["text"]
|
||||
#print "stacking buttontext[", i,"]", self["items"][i]["text"]
|
||||
# If the item is a 'str', then it has not been created (scrolled list is 'as needed')
|
||||
# Therefore, use the the function given to make it or just make it a frame
|
||||
if item.__class__.__name__ == 'str':
|
||||
|
|
@ -234,15 +234,15 @@ class DirectScrolledList(DirectFrame):
|
|||
text_align = self['itemsAlign'],
|
||||
text_wordwrap = self['itemsWordwrap'],
|
||||
relief = None)
|
||||
#print "str stacking buttontext[",i,"]",self["items"][i]["text"]
|
||||
#print "str stacking buttontext[", i,"]", self["items"][i]["text"]
|
||||
# Then add the newly formed item back into the normal item list
|
||||
self["items"][i] = item
|
||||
item.reparentTo(self.itemFrame)
|
||||
self.recordMaxHeight()
|
||||
|
||||
|
||||
item.show()
|
||||
item.setPos(0,0, -(i-self.index) * self.maxHeight)
|
||||
|
||||
item.setPos(0, 0, -(i-self.index) * self.maxHeight)
|
||||
|
||||
if self['command']:
|
||||
# Pass any extra args to command
|
||||
apply(self['command'], self['extraArgs'])
|
||||
|
|
@ -282,7 +282,7 @@ class DirectScrolledList(DirectFrame):
|
|||
return Task.cont
|
||||
else:
|
||||
return Task.done
|
||||
|
||||
|
||||
def __incButtonDown(self, event):
|
||||
assert self.notify.debugStateCall(self)
|
||||
task = Task.Task(self.__scrollByTask)
|
||||
|
|
@ -291,7 +291,7 @@ class DirectScrolledList(DirectFrame):
|
|||
task.delta = 1
|
||||
self.scrollBy(task.delta)
|
||||
taskMgr.add(task, self.taskName("scroll"))
|
||||
|
||||
|
||||
|
||||
def __decButtonDown(self, event):
|
||||
assert self.notify.debugStateCall(self)
|
||||
|
|
@ -341,7 +341,7 @@ class DirectScrolledList(DirectFrame):
|
|||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def refresh(self):
|
||||
"""
|
||||
Update the list - useful when adding or deleting items
|
||||
|
|
@ -351,7 +351,7 @@ class DirectScrolledList(DirectFrame):
|
|||
self.recordMaxHeight()
|
||||
#print "refresh called"
|
||||
self.scrollTo(self.index)
|
||||
|
||||
|
||||
def getSelectedIndex(self):
|
||||
assert self.notify.debugStateCall(self)
|
||||
return self.index
|
||||
|
|
@ -359,7 +359,7 @@ class DirectScrolledList(DirectFrame):
|
|||
def getSelectedText(self):
|
||||
assert self.notify.debugStateCall(self)
|
||||
return self['items'][self.index]['text']
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
|
@ -370,7 +370,7 @@ def makeButton(itemName, itemNum, *extraArgs):
|
|||
print itemName, itemNum
|
||||
return DirectButton(text = itemName,
|
||||
relief = RAISED,
|
||||
frameSize = (-3.5,3.5,-0.2,0.8),
|
||||
frameSize = (-3.5, 3.5, -0.2, 0.8),
|
||||
scale = 0.85,
|
||||
command = buttonCommand)
|
||||
|
||||
|
|
@ -380,13 +380,13 @@ s = scrollList = DirectScrolledList(
|
|||
# Use the default dialog box image as the background
|
||||
image = getDefaultDialogGeom(),
|
||||
# Scale it to fit around everyting
|
||||
image_scale = (0.7,1,.8),
|
||||
image_scale = (0.7, 1, .8),
|
||||
# Give it a label
|
||||
text = "Scrolled List Example",
|
||||
text_scale = 0.06,
|
||||
text_align = TextNode.ACenter,
|
||||
text_pos = (0,0.3),
|
||||
text_fg = (0,0,0,1),
|
||||
text_pos = (0, 0.3),
|
||||
text_fg = (0, 0, 0, 1),
|
||||
# inc and dec are DirectButtons
|
||||
# They can contain a combination of text, geometry and images
|
||||
# Just a simple text one for now
|
||||
|
|
@ -401,7 +401,7 @@ s = scrollList = DirectScrolledList(
|
|||
decButton_scale = 0.1,
|
||||
# each item is a button with text on it
|
||||
numItemsVisible = 4,
|
||||
itemMakeFunction = makeButton,
|
||||
itemMakeFunction = makeButton,
|
||||
items = ['Able', 'Baker', 'Charlie', 'Delta', 'Echo', 'Foxtrot',
|
||||
'Golf', 'Hotel', 'India', 'Juliet', 'Kilo', 'Lima'],
|
||||
# itemFrame is a DirectFrame
|
||||
|
|
@ -409,7 +409,7 @@ s = scrollList = DirectScrolledList(
|
|||
# to eveything else
|
||||
itemFrame_pos = (0, 0, 0.06),
|
||||
itemFrame_scale = 0.1,
|
||||
itemFrame_frameSize = (-3.1,3.1,-3.3,0.8),
|
||||
itemFrame_frameSize = (-3.1, 3.1, -3.3, 0.8),
|
||||
itemFrame_relief = GROOVE,
|
||||
)
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from DirectGuiBase import _OPT_VALUE
|
|||
|
||||
"""
|
||||
import DirectSlider
|
||||
d = DirectSlider(borderWidth=(0,0))
|
||||
d = DirectSlider(borderWidth=(0, 0))
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ class DirectSlider(DirectFrame):
|
|||
# Define type of DirectGuiWidget
|
||||
('pgFunc', PGSliderBar, None),
|
||||
('state', NORMAL, None),
|
||||
('frameColor', (0.6,0.6,0.6,1), None),
|
||||
('frameColor', (0.6, 0.6, 0.6, 1), None),
|
||||
|
||||
('range', (0, 1), self.setRange),
|
||||
('value', 0, self.__setValue),
|
||||
|
|
@ -33,14 +33,14 @@ class DirectSlider(DirectFrame):
|
|||
if kw.get('orientation') == VERTICAL:
|
||||
# These are the default options for a vertical layout.
|
||||
optiondefs += (
|
||||
('frameSize', (-0.08,0.08,-1,1), None),
|
||||
('frameVisibleScale', (0.25,1), None),
|
||||
('frameSize', (-0.08, 0.08, -1, 1), None),
|
||||
('frameVisibleScale', (0.25, 1), None),
|
||||
)
|
||||
else:
|
||||
# These are the default options for a horizontal layout.
|
||||
optiondefs += (
|
||||
('frameSize', (-1,1,-0.08,0.08), None),
|
||||
('frameVisibleScale', (1,0.25), None),
|
||||
('frameSize', (-1, 1, -0.08, 0.08), None),
|
||||
('frameVisibleScale', (1, 0.25), None),
|
||||
)
|
||||
|
||||
# Merge keyword options with default options
|
||||
|
|
@ -57,9 +57,9 @@ class DirectSlider(DirectFrame):
|
|||
# Compute a default frameSize for the thumb.
|
||||
f = self['frameSize']
|
||||
if self['orientation'] == HORIZONTAL:
|
||||
self.thumb['frameSize'] = (f[0]*0.05,f[1]*0.05,f[2],f[3])
|
||||
self.thumb['frameSize'] = (f[0]*0.05, f[1]*0.05, f[2], f[3])
|
||||
else:
|
||||
self.thumb['frameSize'] = (f[0],f[1],f[2]*0.05,f[3]*0.05)
|
||||
self.thumb['frameSize'] = (f[0], f[1], f[2]*0.05, f[3]*0.05)
|
||||
|
||||
self.guiItem.setThumbButton(self.thumb.guiItem)
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ class DirectSlider(DirectFrame):
|
|||
|
||||
# Call option initialization functions
|
||||
self.initialiseoptions(DirectSlider)
|
||||
|
||||
|
||||
def setRange(self):
|
||||
# Try to preserve the value across a setRange call.
|
||||
v = self['value']
|
||||
|
|
@ -110,6 +110,6 @@ class DirectSlider(DirectFrame):
|
|||
def commandFunc(self):
|
||||
# Store the updated value in self['value']
|
||||
self._optionInfo['value'][_OPT_VALUE] = self.guiItem.getValue()
|
||||
|
||||
|
||||
if self['command']:
|
||||
apply(self['command'], self['extraArgs'])
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from DirectFrame import *
|
|||
|
||||
"""
|
||||
import DirectWaitBar
|
||||
d = DirectWaitBar(borderWidth=(0,0))
|
||||
d = DirectWaitBar(borderWidth=(0, 0))
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -20,18 +20,18 @@ class DirectWaitBar(DirectFrame):
|
|||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('pgFunc', PGWaitBar, None),
|
||||
('frameSize', (-1,1,-0.08,0.08), None),
|
||||
('borderWidth', (0,0), None),
|
||||
('frameSize', (-1, 1, -0.08, 0.08), None),
|
||||
('borderWidth', (0, 0), None),
|
||||
('range', 100, self.setRange),
|
||||
('value', 0, self.setValue),
|
||||
('barBorderWidth', (0,0), self.setBarBorderWidth),
|
||||
('barColor', (1,0,0,1), self.setBarColor),
|
||||
('barBorderWidth', (0, 0), self.setBarBorderWidth),
|
||||
('barColor', (1, 0, 0, 1), self.setBarColor),
|
||||
('barRelief', FLAT, self.setBarRelief),
|
||||
('sortOrder', NO_FADE_SORT_INDEX, None),
|
||||
)
|
||||
if kw.has_key('text'):
|
||||
textoptiondefs = (
|
||||
('text_pos', (0,-0.025), None),
|
||||
('text_pos', (0, -0.025), None),
|
||||
('text_scale', 0.1, None)
|
||||
)
|
||||
else:
|
||||
|
|
@ -48,7 +48,7 @@ class DirectWaitBar(DirectFrame):
|
|||
def destroy(self):
|
||||
del self.barStyle
|
||||
DirectFrame.destroy(self)
|
||||
|
||||
|
||||
def setRange(self):
|
||||
self.guiItem.setRange(self['range'])
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ class DirectWaitBar(DirectFrame):
|
|||
|
||||
def updateBarStyle(self):
|
||||
if not self.fInit:
|
||||
self.guiItem.setBarStyle(self.barStyle)
|
||||
self.guiItem.setBarStyle(self.barStyle)
|
||||
|
||||
def setBarRelief(self):
|
||||
self.barStyle.setType(self['barRelief'])
|
||||
|
|
@ -95,4 +95,4 @@ class DirectWaitBar(DirectFrame):
|
|||
if count > self['range']:
|
||||
count = self['range']
|
||||
self.update(count)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class OnscreenGeom(DirectObject, NodePath):
|
|||
This maybe a 3-tuple of floats or a vector.
|
||||
y should be zero
|
||||
|
||||
hpr: the h,p,r of the geometry on the screen.
|
||||
hpr: the h, p, r of the geometry on the screen.
|
||||
This maybe a 3-tuple of floats or a vector.
|
||||
|
||||
scale: the size of the geometry. This may either be a single
|
||||
|
|
@ -106,7 +106,7 @@ class OnscreenGeom(DirectObject, NodePath):
|
|||
|
||||
def getGeom(self):
|
||||
return self
|
||||
|
||||
|
||||
def configure(self, option=None, **kw):
|
||||
for option, value in kw.items():
|
||||
# Use option string to access setter function
|
||||
|
|
@ -118,7 +118,7 @@ class OnscreenGeom(DirectObject, NodePath):
|
|||
(setter == self.setScale)) and
|
||||
(isinstance(value, types.TupleType) or
|
||||
isinstance(value, types.ListType))):
|
||||
apply(setter,value)
|
||||
apply(setter, value)
|
||||
else:
|
||||
setter(value)
|
||||
except AttributeError:
|
||||
|
|
@ -127,7 +127,7 @@ class OnscreenGeom(DirectObject, NodePath):
|
|||
# Allow index style references
|
||||
def __setitem__(self, key, value):
|
||||
apply(self.configure, (), {key: value})
|
||||
|
||||
|
||||
def cget(self, option):
|
||||
# Get current configuration setting.
|
||||
# This is for compatability with DirectGui functions
|
||||
|
|
@ -136,6 +136,6 @@ class OnscreenGeom(DirectObject, NodePath):
|
|||
|
||||
# Allow index style refererences
|
||||
__getitem__ = cget
|
||||
|
||||
|
||||
def destroy(self):
|
||||
self.removeNode()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class OnscreenImage(DirectObject, NodePath):
|
|||
This maybe a 3-tuple of floats or a vector.
|
||||
y should be zero
|
||||
|
||||
hpr: the h,p,r of the geometry on the screen.
|
||||
hpr: the h, p, r of the geometry on the screen.
|
||||
This maybe a 3-tuple of floats or a vector.
|
||||
|
||||
scale: the size of the geometry. This may either be a single
|
||||
|
|
@ -123,7 +123,7 @@ class OnscreenImage(DirectObject, NodePath):
|
|||
|
||||
def getImage(self):
|
||||
return self
|
||||
|
||||
|
||||
def configure(self, option=None, **kw):
|
||||
for option, value in kw.items():
|
||||
# Use option string to access setter function
|
||||
|
|
@ -135,7 +135,7 @@ class OnscreenImage(DirectObject, NodePath):
|
|||
(setter == self.setScale)) and
|
||||
(isinstance(value, types.TupleType) or
|
||||
isinstance(value, types.ListType))):
|
||||
apply(setter,value)
|
||||
apply(setter, value)
|
||||
else:
|
||||
setter(value)
|
||||
except AttributeError:
|
||||
|
|
@ -144,7 +144,7 @@ class OnscreenImage(DirectObject, NodePath):
|
|||
# Allow index style references
|
||||
def __setitem__(self, key, value):
|
||||
apply(self.configure, (), {key: value})
|
||||
|
||||
|
||||
def cget(self, option):
|
||||
# Get current configuration setting.
|
||||
# This is for compatability with DirectGui functions
|
||||
|
|
@ -153,6 +153,6 @@ class OnscreenImage(DirectObject, NodePath):
|
|||
|
||||
# Allow index style refererences
|
||||
__getitem__ = cget
|
||||
|
||||
|
||||
def destroy(self):
|
||||
self.removeNode()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class OnscreenText(DirectObject, NodePath):
|
|||
fg = None,
|
||||
bg = None,
|
||||
shadow = None,
|
||||
shadowOffset = (0.04,0.04),
|
||||
shadowOffset = (0.04, 0.04),
|
||||
frame = None,
|
||||
align = None,
|
||||
wordwrap = None,
|
||||
|
|
@ -152,7 +152,7 @@ class OnscreenText(DirectObject, NodePath):
|
|||
raise ValueError
|
||||
|
||||
if not isinstance(scale, types.TupleType):
|
||||
# If the scale is already a tuple, it's a 2-d (x,y) scale.
|
||||
# If the scale is already a tuple, it's a 2-d (x, y) scale.
|
||||
# Otherwise, it's a uniform scale--make it a tuple.
|
||||
scale = (scale, scale)
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ class OnscreenText(DirectObject, NodePath):
|
|||
|
||||
if font == None:
|
||||
font = DirectGuiGlobals.getDefaultFont()
|
||||
|
||||
|
||||
textNode.setFont(font)
|
||||
textNode.setTextColor(fg[0], fg[1], fg[2], fg[3])
|
||||
textNode.setAlign(align)
|
||||
|
|
@ -213,12 +213,12 @@ class OnscreenText(DirectObject, NodePath):
|
|||
# If we aren't going to change the text later, we can
|
||||
# throw away the TextNode.
|
||||
self.textNode = textNode.generate()
|
||||
|
||||
|
||||
self.isClean = 0
|
||||
|
||||
# Set ourselves up as the NodePath that points to this node.
|
||||
self.assign(parent.attachNewNode(self.textNode, sort))
|
||||
|
||||
|
||||
def cleanup(self):
|
||||
self.textNode = None
|
||||
if self.isClean == 0:
|
||||
|
|
@ -282,7 +282,7 @@ class OnscreenText(DirectObject, NodePath):
|
|||
|
||||
def setY(self, y):
|
||||
self.setPos(self.pos[0], y)
|
||||
|
||||
|
||||
def setPos(self, x, y):
|
||||
"""setPos(self, float, float)
|
||||
Position the onscreen text in 2d screen space
|
||||
|
|
@ -302,7 +302,7 @@ class OnscreenText(DirectObject, NodePath):
|
|||
|
||||
def getRoll(self):
|
||||
return self.roll
|
||||
|
||||
|
||||
def setScale(self, sx, sy = None):
|
||||
"""setScale(self, float, float)
|
||||
Scale the text in 2d space. You may specify either a single
|
||||
|
|
@ -320,21 +320,21 @@ class OnscreenText(DirectObject, NodePath):
|
|||
|
||||
def updateTransformMat(self):
|
||||
mat = (
|
||||
Mat4.scaleMat(self.scale[0],1,self.scale[1]) *
|
||||
Mat4.rotateMat(self.roll, Vec3(0,-1,0)) *
|
||||
Mat4.scaleMat(self.scale[0], 1, self.scale[1]) *
|
||||
Mat4.rotateMat(self.roll, Vec3(0, -1, 0)) *
|
||||
Mat4.translateMat(self.pos[0], 0, self.pos[1])
|
||||
)
|
||||
self.textNode.setTransform(mat)
|
||||
|
||||
def getScale(self):
|
||||
return self.scale
|
||||
|
||||
|
||||
def setWordwrap(self, wordwrap):
|
||||
if wordwrap:
|
||||
self.textNode.setWordwrap(wordwrap)
|
||||
else:
|
||||
self.textNode.clearWordwrap()
|
||||
|
||||
|
||||
def setFg(self, fg):
|
||||
self.textNode.setTextColor(fg[0], fg[1], fg[2], fg[3])
|
||||
|
||||
|
|
@ -385,7 +385,7 @@ class OnscreenText(DirectObject, NodePath):
|
|||
# Allow index style references
|
||||
def __setitem__(self, key, value):
|
||||
apply(self.configure, (), {key: value})
|
||||
|
||||
|
||||
def cget(self, option):
|
||||
# Get current configuration setting.
|
||||
# This is for compatability with DirectGui functions
|
||||
|
|
@ -397,4 +397,4 @@ class OnscreenText(DirectObject, NodePath):
|
|||
|
||||
# Allow index style refererences
|
||||
__getitem__ = cget
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class FunctionInterval(Interval.Interval):
|
|||
del kw['openEnded']
|
||||
if kw.has_key('extraArgs'):
|
||||
del kw['extraArgs']
|
||||
|
||||
|
||||
# Record instance variables
|
||||
self.function = function
|
||||
# Create a unique name for the interval if necessary
|
||||
|
|
@ -50,7 +50,7 @@ class FunctionInterval(Interval.Interval):
|
|||
# Event, Accept, Ignore intervals default to openEnded = 0
|
||||
# Parent, Pos, Hpr, etc intervals default to openEnded = 1
|
||||
Interval.Interval.__init__(self, name, duration = 0.0, openEnded = openEnded)
|
||||
|
||||
|
||||
def privInstant(self):
|
||||
# Evaluate the function
|
||||
self.function(*self.extraArgs, **self.kw)
|
||||
|
|
@ -231,7 +231,7 @@ class HprScaleInterval(FunctionInterval):
|
|||
if other:
|
||||
np.setHprScale(other, hpr, scale)
|
||||
else:
|
||||
np.setHprScale(hpr, scale)
|
||||
np.setHprScale(hpr, scale)
|
||||
# Determine name
|
||||
if (name == None):
|
||||
name = ('HprScale-%d' %
|
||||
|
|
@ -254,7 +254,7 @@ class PosHprScaleInterval(FunctionInterval):
|
|||
if other:
|
||||
np.setPosHprScale(other, pos, hpr, scale)
|
||||
else:
|
||||
np.setPosHprScale(pos, hpr, scale)
|
||||
np.setPosHprScale(pos, hpr, scale)
|
||||
# Determine name
|
||||
if (name == None):
|
||||
name = ('PosHprScale-%d' %
|
||||
|
|
@ -354,11 +354,11 @@ def printTrackStart():
|
|||
|
||||
i1 = Func(printStart)
|
||||
# Just to take time
|
||||
i2 = LerpPosInterval(camera, 2.0, Point3(0,10,5))
|
||||
i2 = LerpPosInterval(camera, 2.0, Point3(0, 10, 5))
|
||||
# This will be relative to end of camera move
|
||||
i3 = FunctionInterval(printPreviousEnd)
|
||||
# Just to take time
|
||||
i4 = LerpPosInterval(camera, 2.0, Point3(0,0,5))
|
||||
i4 = LerpPosInterval(camera, 2.0, Point3(0, 0, 5))
|
||||
# This will be relative to the start of the camera move
|
||||
i5 = FunctionInterval(printPreviousStart)
|
||||
# This will be relative to track start
|
||||
|
|
@ -385,23 +385,23 @@ donald.loadAnims({"steer":"phase_6/models/char/donald-wheel-wheel"})
|
|||
donald.reparentTo(render)
|
||||
|
||||
|
||||
seq = Sequence(Func(donald.setPos, 0,0,0),
|
||||
seq = Sequence(Func(donald.setPos, 0, 0, 0),
|
||||
donald.actorInterval('steer', duration=1.0),
|
||||
donald.posInterval(1, Point3(0,0,1)),
|
||||
donald.posInterval(1, Point3(0, 0, 1)),
|
||||
Parallel(donald.actorInterval('steer', duration=1.0),
|
||||
donald.posInterval(1, Point3(0,0,0)),
|
||||
donald.posInterval(1, Point3(0, 0, 0)),
|
||||
),
|
||||
Wait(1.0),
|
||||
Func(base.toggleWireframe),
|
||||
Wait(1.0),
|
||||
Parallel(donald.actorInterval('steer', duration=1.0),
|
||||
donald.posInterval(1, Point3(0,0,-1)),
|
||||
Sequence(donald.hprInterval(1, Vec3(180,0,0)),
|
||||
donald.hprInterval(1, Vec3(0,0,0)),
|
||||
donald.posInterval(1, Point3(0, 0, -1)),
|
||||
Sequence(donald.hprInterval(1, Vec3(180, 0, 0)),
|
||||
donald.hprInterval(1, Vec3(0, 0, 0)),
|
||||
),
|
||||
),
|
||||
Func(base.toggleWireframe),
|
||||
Func(messenger.send, 'hello'),
|
||||
Func(base.toggleWireframe),
|
||||
Func(messenger.send, 'hello'),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class Interval(DirectObject):
|
|||
# breaks looping intervals. The interval code should properly
|
||||
# handle t values outside the proper range.
|
||||
#t = min(max(t, 0.0), self.getDuration())
|
||||
|
||||
|
||||
state = self.getState()
|
||||
if state == CInterval.SInitial:
|
||||
self.privInitialize(t)
|
||||
|
|
@ -98,7 +98,7 @@ class Interval(DirectObject):
|
|||
else:
|
||||
self.notify.error("Invalid state: %s" % (state))
|
||||
self.privPostEvent()
|
||||
|
||||
|
||||
def getT(self):
|
||||
return self.currT
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ class Interval(DirectObject):
|
|||
|
||||
def resumeUntil(self, endT):
|
||||
duration = self.getDuration()
|
||||
|
||||
|
||||
if endT < 0 or endT >= duration:
|
||||
self.__endT = duration
|
||||
self.__endTAtEnd = 1
|
||||
|
|
@ -137,7 +137,7 @@ class Interval(DirectObject):
|
|||
self.setupResume()
|
||||
if not self.isPlaying():
|
||||
self.__spawnTask()
|
||||
|
||||
|
||||
def finish(self):
|
||||
state = self.getState()
|
||||
if state == CInterval.SInitial:
|
||||
|
|
@ -146,7 +146,7 @@ class Interval(DirectObject):
|
|||
self.privFinalize()
|
||||
self.privPostEvent()
|
||||
self.__removeTask()
|
||||
|
||||
|
||||
def clearToInitial(self):
|
||||
# This method resets the interval's internal state to the
|
||||
# initial state, abandoning any parts of the interval that
|
||||
|
|
@ -237,7 +237,7 @@ class Interval(DirectObject):
|
|||
|
||||
def setupPlay(self, startT, endT, playRate, doLoop):
|
||||
duration = self.getDuration()
|
||||
|
||||
|
||||
if startT <= 0:
|
||||
self.__startT = 0
|
||||
self.__startTAtStart = 1
|
||||
|
|
@ -247,7 +247,7 @@ class Interval(DirectObject):
|
|||
else:
|
||||
self.__startT = startT
|
||||
self.__startTAtStart = 0
|
||||
|
||||
|
||||
if endT < 0 or endT >= duration:
|
||||
self.__endT = duration
|
||||
self.__endTAtEnd = 1
|
||||
|
|
@ -275,7 +275,7 @@ class Interval(DirectObject):
|
|||
|
||||
if self.__endTAtEnd:
|
||||
self.__endT = self.getDuration()
|
||||
|
||||
|
||||
if t < self.__endT:
|
||||
# In the middle of the interval, not a problem.
|
||||
if self.isStopped():
|
||||
|
|
@ -386,7 +386,7 @@ class Interval(DirectObject):
|
|||
tl = Toplevel()
|
||||
tl.title('Interval Controls')
|
||||
outerFrame = Frame(tl)
|
||||
def entryScaleCommand(t,s=self):
|
||||
def entryScaleCommand(t, s=self):
|
||||
s.setT(t)
|
||||
s.pause()
|
||||
self.es = es = EntryScale.EntryScale(
|
||||
|
|
@ -409,7 +409,7 @@ class Interval(DirectObject):
|
|||
# Stop/play buttons
|
||||
def doPlay(s=self, es=es):
|
||||
s.resume(es.get())
|
||||
|
||||
|
||||
stop = Button(bf, text = 'Stop',
|
||||
command = lambda s=self: s.pause())
|
||||
play = Button(
|
||||
|
|
@ -423,7 +423,7 @@ class Interval(DirectObject):
|
|||
bf.pack(expand = 1, fill = X)
|
||||
outerFrame.pack(expand = 1, fill = X)
|
||||
# Add function to update slider during setT calls
|
||||
def update(t,es=es):
|
||||
def update(t, es=es):
|
||||
es.set(t, fCommand = 0)
|
||||
if not hasattr(self, "setTHooks"):
|
||||
self.setTHooks = []
|
||||
|
|
|
|||
|
|
@ -19,16 +19,16 @@ class IntervalManager(CIntervalManager):
|
|||
# "constructing" a Python wrapper around the global
|
||||
# CIntervalManager object.
|
||||
##self.cObj = CIntervalManager.getGlobalPtr()
|
||||
##Dtool_BarrowThisRefrence(self,self.cObj)
|
||||
##self.dd = self
|
||||
##Dtool_BarrowThisRefrence(self, self.cObj)
|
||||
##self.dd = self
|
||||
if globalPtr:
|
||||
self.cObj = CIntervalManager.getGlobalPtr()
|
||||
Dtool_BarrowThisRefrence(self,self.cObj)
|
||||
Dtool_BarrowThisRefrence(self, self.cObj)
|
||||
self.dd = self
|
||||
else:
|
||||
CIntervalManager.__init__(self)
|
||||
CIntervalManager.__init__(self)
|
||||
self.eventQueue = EventQueue()
|
||||
self.MyEventmanager = EventManager.EventManager(self.eventQueue)
|
||||
self.MyEventmanager = EventManager.EventManager(self.eventQueue)
|
||||
self.setEventQueue(self.eventQueue)
|
||||
self.ivals = []
|
||||
self.removedIvals = {}
|
||||
|
|
@ -50,14 +50,14 @@ class IntervalManager(CIntervalManager):
|
|||
self.MyEventmanager = EventManager.EventManager(self.eventQueue)
|
||||
self.setEventQueue(self.eventQueue)
|
||||
self.ivals = []
|
||||
self.removedIvals = {}
|
||||
|
||||
|
||||
self.removedIvals = {}
|
||||
|
||||
|
||||
|
||||
def addInterval(self, interval):
|
||||
index = self.addCInterval(interval, 1)
|
||||
self.__storeInterval(interval, index)
|
||||
|
||||
|
||||
def removeInterval(self, interval):
|
||||
index = self.findCInterval(interval.getName())
|
||||
if index >= 0:
|
||||
|
|
@ -73,7 +73,7 @@ class IntervalManager(CIntervalManager):
|
|||
return None
|
||||
|
||||
def finishIntervalsMatching(self, pattern):
|
||||
count = 0
|
||||
count = 0
|
||||
maxIndex = self.getMaxIndex()
|
||||
for index in range(maxIndex):
|
||||
ival = self.getCInterval(index)
|
||||
|
|
@ -90,7 +90,7 @@ class IntervalManager(CIntervalManager):
|
|||
ival.finish()
|
||||
|
||||
return count
|
||||
|
||||
|
||||
|
||||
def step(self):
|
||||
# This method should be called once per frame to perform all
|
||||
|
|
@ -134,8 +134,8 @@ class IntervalManager(CIntervalManager):
|
|||
# these immediately, rather than waiting for the global event
|
||||
# queue to be serviced (which might not be till next frame).
|
||||
self.MyEventmanager.doEvents()
|
||||
|
||||
|
||||
|
||||
|
||||
def __storeInterval(self, interval, index):
|
||||
while index >= len(self.ivals):
|
||||
self.ivals.append(None)
|
||||
|
|
|
|||
|
|
@ -6,30 +6,30 @@ if __name__ == "__main__":
|
|||
from direct.actor.Actor import *
|
||||
|
||||
from direct.directutil import Mopath
|
||||
|
||||
|
||||
boat = loader.loadModel('models/misc/smiley')
|
||||
boat.reparentTo(render)
|
||||
|
||||
|
||||
donald = Actor()
|
||||
donald.loadModel("phase_6/models/char/donald-wheel-1000")
|
||||
donald.loadAnims({"steer":"phase_6/models/char/donald-wheel-wheel"})
|
||||
donald.reparentTo(boat)
|
||||
|
||||
|
||||
dock = loader.loadModel('models/misc/smiley')
|
||||
dock.reparentTo(render)
|
||||
|
||||
|
||||
sound = loader.loadSfx('phase_6/audio/sfx/SZ_DD_waterlap.mp3')
|
||||
foghorn = loader.loadSfx('phase_6/audio/sfx/SZ_DD_foghorn.mp3')
|
||||
|
||||
|
||||
mp = Mopath.Mopath()
|
||||
mp.loadFile(Filename('phase_6/paths/dd-e-w'))
|
||||
|
||||
|
||||
# Set up the boat
|
||||
boatMopath = MopathInterval(mp, boat, 'boatpath')
|
||||
boatTrack = Track([boatMopath], 'boattrack')
|
||||
BOAT_START = boatTrack.getIntervalStartTime('boatpath')
|
||||
BOAT_END = boatTrack.getIntervalEndTime('boatpath')
|
||||
|
||||
|
||||
# This will create an anim interval that is posed every frame
|
||||
donaldSteerInterval = ActorInterval(donald, 'steer')
|
||||
# This will create an anim interval that is started at t = 0 and then
|
||||
|
|
@ -37,12 +37,12 @@ if __name__ == "__main__":
|
|||
donaldLoopInterval = ActorInterval(donald, 'steer', loop=1, duration = 10.0)
|
||||
donaldSteerTrack = Track([donaldSteerInterval, donaldLoopInterval],
|
||||
name = 'steerTrack')
|
||||
|
||||
|
||||
# Make the dock lerp up so that it's up when the boat reaches the end of
|
||||
# its mopath
|
||||
dockLerp = LerpPosHprInterval(dock, 5.0,
|
||||
pos=Point3(0, 0, -5),
|
||||
hpr=Vec3(0, 0, 0),
|
||||
dockLerp = LerpPosHprInterval(dock, 5.0,
|
||||
pos=Point3(0, 0, -5),
|
||||
hpr=Vec3(0, 0, 0),
|
||||
name='dock-lerp')
|
||||
# We need the dock's state to be defined before the lerp
|
||||
dockPos = PosHprInterval(dock, dock.getPos(), dock.getHpr(), 1.0, 'dockpos')
|
||||
|
|
@ -52,58 +52,58 @@ if __name__ == "__main__":
|
|||
dockTrack = Track([dockLerp2, dockPos, dockLerp], 'docktrack')
|
||||
dockTrack.setIntervalStartTime('dock-lerp', dockUpTime)
|
||||
dockTrack.setIntervalStartTime('hpr-lerp', BOAT_START)
|
||||
|
||||
|
||||
# Start the water sound 5 seconds after the boat starts moving
|
||||
waterStartTime = BOAT_START + 5.0
|
||||
waterSound = SoundInterval(sound, name='watersound')
|
||||
soundTrack = Track([waterSound], 'soundtrack')
|
||||
soundTrack.setIntervalStartTime('watersound', waterStartTime)
|
||||
|
||||
|
||||
# Throw an event when the water track ends
|
||||
eventTime = soundTrack.getIntervalEndTime('watersound')
|
||||
waterDone = EventInterval('water-is-done')
|
||||
waterEventTrack = Track([waterDone])
|
||||
waterEventTrack.setIntervalStartTime('water-is-done', eventTime)
|
||||
|
||||
|
||||
def handleWaterDone():
|
||||
print 'water is done'
|
||||
|
||||
|
||||
# Interval can handle its own event
|
||||
messenger.accept('water-is-done', waterDone, handleWaterDone)
|
||||
|
||||
|
||||
foghornStartTime = BOAT_START + 4.0
|
||||
foghornSound = SoundInterval(foghorn, name='foghorn')
|
||||
soundTrack2 = Track([(foghornStartTime, foghornSound)], 'soundtrack2')
|
||||
|
||||
|
||||
mtrack = MultiTrack([boatTrack, dockTrack, soundTrack, soundTrack2, waterEventTrack,
|
||||
donaldSteerTrack])
|
||||
# Print out MultiTrack parameters
|
||||
print(mtrack)
|
||||
|
||||
|
||||
### Using lambdas and functions ###
|
||||
# Using a lambda
|
||||
i1 = FunctionInterval(lambda: base.transitions.fadeOut())
|
||||
i2 = FunctionInterval(lambda: base.transitions.fadeIn())
|
||||
|
||||
|
||||
def caughtIt():
|
||||
print 'Caught here-is-an-event'
|
||||
|
||||
|
||||
class DummyAcceptor(DirectObject):
|
||||
pass
|
||||
|
||||
|
||||
da = DummyAcceptor()
|
||||
i3 = AcceptInterval(da, 'here-is-an-event', caughtIt)
|
||||
|
||||
|
||||
i4 = EventInterval('here-is-an-event')
|
||||
|
||||
|
||||
i5 = IgnoreInterval(da, 'here-is-an-event')
|
||||
|
||||
|
||||
# Using a function
|
||||
def printDone():
|
||||
print 'done'
|
||||
|
||||
|
||||
i6 = FunctionInterval(printDone)
|
||||
|
||||
|
||||
# Create track
|
||||
t1 = Track([
|
||||
# Fade out
|
||||
|
|
@ -120,53 +120,53 @@ if __name__ == "__main__":
|
|||
(7.0, i4),
|
||||
# Print done
|
||||
(8.0, i6)], name = 'demo')
|
||||
|
||||
|
||||
print(t1)
|
||||
|
||||
|
||||
### Specifying interval start times during track construction ###
|
||||
# Interval start time can be specified relative to three different points:
|
||||
# PREVIOUS_END
|
||||
# PREVIOUS_START
|
||||
# TRACK_START
|
||||
|
||||
|
||||
startTime = 0.0
|
||||
def printStart():
|
||||
global startTime
|
||||
startTime = globalClock.getFrameTime()
|
||||
print 'Start'
|
||||
|
||||
|
||||
def printPreviousStart():
|
||||
global startTime
|
||||
currTime = globalClock.getFrameTime()
|
||||
print 'PREVIOUS_END %0.2f' % (currTime - startTime)
|
||||
|
||||
|
||||
def printPreviousEnd():
|
||||
global startTime
|
||||
currTime = globalClock.getFrameTime()
|
||||
print 'PREVIOUS_END %0.2f' % (currTime - startTime)
|
||||
|
||||
|
||||
def printTrackStart():
|
||||
global startTime
|
||||
currTime = globalClock.getFrameTime()
|
||||
print 'TRACK_START %0.2f' % (currTime - startTime)
|
||||
|
||||
def printArguments(a,b,c):
|
||||
print 'My args were %d, %d, %d' % (a,b,c)
|
||||
|
||||
|
||||
def printArguments(a, b, c):
|
||||
print 'My args were %d, %d, %d' % (a, b, c)
|
||||
|
||||
i1 = FunctionInterval(printStart)
|
||||
# Just to take time
|
||||
i2 = LerpPosInterval(camera, 2.0, Point3(0,10,5))
|
||||
i2 = LerpPosInterval(camera, 2.0, Point3(0, 10, 5))
|
||||
# This will be relative to end of camera move
|
||||
i3 = FunctionInterval(printPreviousEnd)
|
||||
# Just to take time
|
||||
i4 = LerpPosInterval(camera, 2.0, Point3(0,0,5))
|
||||
i4 = LerpPosInterval(camera, 2.0, Point3(0, 0, 5))
|
||||
# This will be relative to the start of the camera move
|
||||
i5 = FunctionInterval(printPreviousStart)
|
||||
# This will be relative to track start
|
||||
i6 = FunctionInterval(printTrackStart)
|
||||
# This will print some arguments
|
||||
# This will be relative to track start
|
||||
i7 = FunctionInterval(printArguments, extraArgs = [1,10,100])
|
||||
i7 = FunctionInterval(printArguments, extraArgs = [1, 10, 100])
|
||||
# Create the track, if you don't specify offset type in tuple it defaults to
|
||||
# relative to TRACK_START (first entry below)
|
||||
t2 = Track([(0.0, i1), # i1 start at t = 0, duration = 0.0
|
||||
|
|
@ -177,20 +177,20 @@ if __name__ == "__main__":
|
|||
(10.0, i6, TRACK_START), # i6 start at t = 10, duration = 0.0
|
||||
(12.0, i7)], # i7 start at t = 12, duration = 0.0
|
||||
name = 'startTimeDemo')
|
||||
|
||||
|
||||
print(t2)
|
||||
|
||||
|
||||
# Play tracks
|
||||
# mtrack.play()
|
||||
# t1.play()
|
||||
# t2.play()
|
||||
|
||||
|
||||
|
||||
|
||||
def test(n):
|
||||
lerps = []
|
||||
for i in range(n):
|
||||
lerps.append(LerpPosHprInterval(dock, 5.0,
|
||||
pos=Point3(0, 0, -5),
|
||||
lerps.append(LerpPosHprInterval(dock, 5.0,
|
||||
pos=Point3(0, 0, -5),
|
||||
hpr=Vec3(0, 0, 0),
|
||||
startPos=dock.getPos(),
|
||||
startHpr=dock.getHpr(),
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ def doTest():
|
|||
smiley = loader.loadModel('models/misc/smiley')
|
||||
smiley.reparentTo(render)
|
||||
|
||||
pi = ProjectileInterval(smiley, startPos=Point3(0,0,0),
|
||||
endZ = -10, wayPoint=Point3(10,0,0),
|
||||
pi = ProjectileInterval(smiley, startPos=Point3(0, 0, 0),
|
||||
endZ = -10, wayPoint=Point3(10, 0, 0),
|
||||
timeToWayPoint=3)
|
||||
pi.loop()
|
||||
return pi
|
||||
|
|
|
|||
Loading…
Reference in New Issue