Updates to cluster code to allow cluster object to execute commands

Changed the use of the builtins class
This commit is contained in:
Mark Mine 2002-12-12 17:33:20 +00:00
parent c5eeb2098f
commit 864e7edf9a
12 changed files with 60 additions and 62 deletions

View File

@ -105,21 +105,21 @@ class ClusterClient(DirectObject.DirectObject):
return rootName
def selectNodePath(self, nodePath):
self.cmd(self.getNodePathFindCmd(nodePath) + '.select()', 0)
self(self.getNodePathFindCmd(nodePath) + '.select()', 0)
def deselectNodePath(self, nodePath):
self.cmd(self.getNodePathFindCmd(nodePath) + '.deselect()', 0)
self(self.getNodePathFindCmd(nodePath) + '.deselect()', 0)
def loadModel(self, nodePath):
pass
def cmd(self, commandString, fLocally = 1):
def __call__(self, commandString, fLocally = 1):
# Execute remotely
for server in self.serverList:
server.sendCommandString(commandString)
if fLocally:
# Execute locally
exec( commandString, globals() )
exec( commandString, __builtins__ )
def exit(self):
# Execute remotely
@ -349,9 +349,9 @@ class DummyClusterClient(DirectObject.DirectObject):
def __init__(self):
pass
def cmd(self, commandString, fLocally = 1):
def __call__(self, commandString, fLocally = 1):
if fLocally:
# Execute locally
exec( commandString, globals() )
exec( commandString, __builtins__ )

View File

@ -23,6 +23,10 @@ CLUSTER_SERVER_PORT = 1970
CLUSTER_DAEMON_PORT = 8001
# Precede command string with ! to tell server to execute command string
# NOTE: Had to stick with the import __builtin__ scheme, at startup,
# __builtins__ is a module, not a dictionary, like it is inside of a module
# Note, this startup string obviates the need to set any cluster related
# config variables in the client Configrc files
SERVER_STARTUP_STRING = (
'!bash ppython -c ' +
'"import __builtin__; ' +

View File

@ -55,7 +55,7 @@ class ClusterServer(DirectObject.DirectObject):
# Send verification of startup to client
self.daemon = DirectD()
# These must be passed in as bootstrap arguments and stored in
# the __builtin__ namespace
# the __builtins__ namespace
try:
clusterDaemonClient
except NameError:
@ -202,7 +202,7 @@ class ClusterServer(DirectObject.DirectObject):
""" Handle arbitrary command string from client """
command = self.msgHandler.parseCommandStringDatagram(dgi)
try:
exec( command, globals() )
exec( command, __builtins__ )
except:
pass

View File

@ -112,7 +112,7 @@ class DirectManipulationControl(PandaObject):
direct.selected.highlightAll()
self.objectHandles.showAllHandles()
if direct.clusterMode == 'client':
direct.cluster.cmd(
cluster(
'direct.manipulationControl.objectHandles.showAllHandles()')
self.objectHandles.hideGuides()
# Restart followSelectedNodePath task
@ -180,9 +180,9 @@ class DirectManipulationControl(PandaObject):
self.objectHandles.showHandle(self.constraint)
if direct.clusterMode == 'client':
oh = 'direct.manipulationControl.objectHandles'
direct.cluster.cmd(oh + '.showGuides()', 0)
direct.cluster.cmd(oh + '.hideAllHandles()', 0)
direct.cluster.cmd(oh + ('.showHandle("%s")'% self.constraint))
cluster(oh + '.showGuides()', 0)
cluster(oh + '.hideAllHandles()', 0)
cluster(oh + ('.showHandle("%s")'% self.constraint), 0)
# Record relationship between selected nodes and widget
direct.selected.getWrtAll()
# hide the bbox of the selected objects during interaction

View File

@ -3,7 +3,6 @@ from DirectGlobals import *
from DirectUtil import *
from DirectGeometry import *
from DirectSelection import *
import __builtin__
# MRM: To do: handle broken node paths in selected and deselected dicts
class DirectNodePath(NodePath):
@ -48,7 +47,7 @@ class SelectedNodePaths(PandaObject):
def reset(self):
self.selectedDict = {}
self.deselectedDict = {}
__builtin__.last = self.last = None
__builtins__["last"] = self.last = None
def select(self, nodePath, fMultiSelect = 0):
""" Select the specified node path. Multiselect as required """
@ -82,10 +81,10 @@ class SelectedNodePaths(PandaObject):
# Add it to the selected dictionary
self.selectedDict[dnp.id()] = dnp
# And update last
__builtin__.last = self.last = dnp
__builtins__["last"] = self.last = dnp
# Update cluster servers if this is a cluster client
if direct.clusterMode == 'client':
direct.cluster.selectNodePath(dnp)
cluster.selectNodePath(dnp)
return dnp
def deselect(self, nodePath):
@ -106,7 +105,7 @@ class SelectedNodePaths(PandaObject):
messenger.send('DIRECT_deselectedNodePath', [dnp])
# Update cluster servers if this is a cluster client
if direct.clusterMode == 'client':
direct.cluster.deselectNodePath(dnp)
cluster.deselectNodePath(dnp)
return dnp
def getSelectedAsList(self):
@ -188,7 +187,7 @@ class SelectedNodePaths(PandaObject):
selected = self.last
if selected:
selected.remove()
__builtin__.last = self.last = None
__builtins__["last"] = self.last = None
def removeAll(self):
# Remove all selected nodePaths from the Scene Graph

View File

@ -17,14 +17,13 @@ import SceneGraphExplorer
import OnscreenText
import types
import string
import __builtin__
class DirectSession(PandaObject):
def __init__(self):
# Establish a global pointer to the direct object early on
# so dependant classes can access it in their code
__builtin__.direct = self
__builtins__["direct"] = self
# These come early since they are used later on
self.group = render.attachNewNode('DIRECT')
# Set priority to 100 so it always is textured
@ -186,7 +185,7 @@ class DirectSession(PandaObject):
self.cluster = ClusterServer(base.cameraList[0], base.camList[0])
else:
self.cluster = DummyClusterClient()
__builtin__.cluster = self.cluster
__builtins__['cluster'] = self.cluster
def enable(self):
# Make sure old tasks are shut down
@ -408,7 +407,7 @@ class DirectSession(PandaObject):
if self.clusterMode == 'client':
if input in ('v','b','l','p', 'r', 'shift-r', 's', 't',
'shift-a', 'w'):
self.cluster.cmd('messenger.send("%s")' % input,0)
self.cluster('messenger.send("%s")' % input,0)
def getModifiers(self, input, base):
modifiers = DIRECT_NO_MOD
@ -990,7 +989,7 @@ class DisplayRegionContext:
(self.nearHeight*0.5) * self.mouseY)
# Create one
__builtin__.direct = base.direct = DirectSession()
__builtins__['direct'] = base.direct = DirectSession()

View File

@ -17,10 +17,10 @@ import os
import getopt
import sys
import whrandom
import __builtin__
visualizeZones = base.config.GetBool("visualize-zones", 0)
dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna"))
fUseCVS = base.config.GetBool("level-editor-use-cvs", 1)
# Colors used by all color menus
DEFAULT_COLORS = [
@ -205,7 +205,7 @@ try:
except NameError:
print "Loading LevelEditor for hoods: ", hoods
# DNAStorage instance for storing level DNA info
__builtin__.DNASTORE = DNASTORE = DNAStorage()
__builtins__["DNASTORE"] = DNASTORE = DNAStorage()
# Load the generic storage files
loadDNAFile(DNASTORE, 'phase_4/dna/storage.dna', CSDefault, 1)
loadDNAFile(DNASTORE, 'phase_5/dna/storage_town.dna', CSDefault, 1)
@ -234,7 +234,7 @@ except NameError:
loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL.dna', CSDefault, 1)
loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL_sz.dna', CSDefault, 1)
loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL_town.dna', CSDefault, 1)
__builtin__.dnaLoaded = 1
__builtins__["dnaLoaded"] = 1
# Precompute class types for type comparisons
DNA_CORNICE = DNACornice.getClassType()
@ -2476,7 +2476,8 @@ class LevelEditor(NodePath, PandaObject):
self.reset(fDeleteToplevel = 1, fCreateToplevel = 0,
fUpdateExplorer = 0)
# Now load in new file
self.cvsUpdate(filename)
if fUseCVS:
self.cvsUpdate(filename)
node = loadDNAFile(DNASTORE, Filename.fromOsSpecific(filename).cStr(), CSDefault, 1)
if node.getNumParents() == 1:
# If the node already has a parent arc when it's loaded, we must

View File

@ -22,10 +22,9 @@ import Loader
import time
import FSM
import State
import __builtin__
__builtin__.FADE_SORT_INDEX = 1000
__builtin__.NO_FADE_SORT_INDEX = 2000
__builtins__["FADE_SORT_INDEX"] = 1000
__builtins__["NO_FADE_SORT_INDEX"] = 2000
class ShowBase:
@ -138,22 +137,22 @@ class ShowBase:
self.AppHasAudioFocus = 1
__builtin__.base = self
__builtin__.render2d = self.render2d
__builtin__.aspect2d = self.aspect2d
__builtin__.render = self.render
__builtin__.hidden = self.hidden
__builtin__.camera = self.camera
__builtin__.loader = self.loader
__builtin__.taskMgr = self.taskMgr
__builtin__.eventMgr = self.eventMgr
__builtin__.messenger = self.messenger
__builtin__.config = self.config
__builtin__.run = self.run
__builtin__.ostream = Notify.out()
__builtin__.directNotify = directNotify
__builtin__.globalClock = ClockObject.getGlobalClock()
__builtin__.vfs = vfs
__builtins__["base"] = self
__builtins__["render2d"] = self.render2d
__builtins__["aspect2d"] = self.aspect2d
__builtins__["render"] = self.render
__builtins__["hidden"] = self.hidden
__builtins__["camera"] = self.camera
__builtins__["loader"] = self.loader
__builtins__["taskMgr"] = self.taskMgr
__builtins__["eventMgr"] = self.eventMgr
__builtins__["messenger"] = self.messenger
__builtins__["config"] = self.config
__builtins__["run"] = self.run
__builtins__["ostream"] = Notify.out()
__builtins__["directNotify"] = directNotify
__builtins__["globalClock"] = ClockObject.getGlobalClock()
__builtins__["vfs"] = vfs
# Transition effects (fade, iris, etc)
import Transitions
@ -166,7 +165,7 @@ class ShowBase:
import DirectSession
direct.enable()
else:
__builtin__.direct = self.direct = None
__builtins__["direct"] = self.direct = None
self.restart()

View File

@ -12,6 +12,5 @@ def inspect(anObject):
import Inspector
return Inspector.inspect(anObject)
import __builtin__
__builtin__.inspect = inspect
__builtins__["inspect"] = inspect

View File

@ -2,8 +2,7 @@
from Tkinter import *
import Pmw
import __builtin__
__builtin__.tkroot = Pmw.initialise()
__builtins__["tkroot"] = Pmw.initialise()
def tkloop(self):
# Do all the tkinter events waiting on this frame

View File

@ -21,5 +21,4 @@ def newimport(*args, **kw):
return result
# Replace the builtin import with our new import
import __builtin__
__builtin__.__import__ = newimport
__builtins__["__import__"] = newimport

View File

@ -15,7 +15,6 @@ import EntryScale
import VectorWidgets
import sys, string
import ProgressBar
import __builtin__
"""
TO FIX:
@ -24,19 +23,19 @@ Radiobutton ordering change
# Create toplevel widget dictionary
try:
__builtin__.widgetDict
except AttributeError:
__builtin__.widgetDict = {}
__builtins__["widgetDict"]
except KeyError:
__builtins__["widgetDict"] = {}
# Create toplevel variable dictionary
try:
__builtin__.variableDict
except AttributeError:
__builtin__.variableDict = {}
__builtins__["variableDict"]
except KeyError:
__builtins__["variableDict"] = {}
def resetWidgetDict():
__builtin__.widgetDict = {}
__builtins__["widgetDict"] = {}
def resetVariableDict():
__builtin__.variableDict = {}
__builtins__["variableDict"] = {}
# Inherit from MegaWidget instead of Toplevel so you can pass in a toplevel
# to use as a container if you wish. If no toplevel passed in, create one