From 864e7edf9a3f94b63451f533e98b615b5dcb45b9 Mon Sep 17 00:00:00 2001 From: Mark Mine Date: Thu, 12 Dec 2002 17:33:20 +0000 Subject: [PATCH] Updates to cluster code to allow cluster object to execute commands Changed the use of the builtins class --- direct/src/cluster/ClusterClient.py | 12 +++--- direct/src/cluster/ClusterMsgs.py | 4 ++ direct/src/cluster/ClusterServer.py | 4 +- direct/src/directtools/DirectManipulation.py | 8 ++-- direct/src/directtools/DirectSelection.py | 11 +++--- direct/src/directtools/DirectSession.py | 9 ++--- direct/src/leveleditor/LevelEditor.py | 9 +++-- direct/src/showbase/ShowBase.py | 39 ++++++++++---------- direct/src/showbase/ShowBaseGlobal.py | 3 +- direct/src/showbase/TkGlobal.py | 3 +- direct/src/showbase/VerboseImport.py | 3 +- direct/src/tkwidgets/AppShell.py | 17 ++++----- 12 files changed, 60 insertions(+), 62 deletions(-) diff --git a/direct/src/cluster/ClusterClient.py b/direct/src/cluster/ClusterClient.py index a2e5e09a45..4ce1a12644 100644 --- a/direct/src/cluster/ClusterClient.py +++ b/direct/src/cluster/ClusterClient.py @@ -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__ ) diff --git a/direct/src/cluster/ClusterMsgs.py b/direct/src/cluster/ClusterMsgs.py index ae8c8a212e..b1c9c01194 100644 --- a/direct/src/cluster/ClusterMsgs.py +++ b/direct/src/cluster/ClusterMsgs.py @@ -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__; ' + diff --git a/direct/src/cluster/ClusterServer.py b/direct/src/cluster/ClusterServer.py index 4fc9393cd4..f74acf977b 100644 --- a/direct/src/cluster/ClusterServer.py +++ b/direct/src/cluster/ClusterServer.py @@ -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 diff --git a/direct/src/directtools/DirectManipulation.py b/direct/src/directtools/DirectManipulation.py index 7b521706f9..b7416f1897 100644 --- a/direct/src/directtools/DirectManipulation.py +++ b/direct/src/directtools/DirectManipulation.py @@ -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 diff --git a/direct/src/directtools/DirectSelection.py b/direct/src/directtools/DirectSelection.py index 9be499a4d0..7f7c0a4809 100644 --- a/direct/src/directtools/DirectSelection.py +++ b/direct/src/directtools/DirectSelection.py @@ -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 diff --git a/direct/src/directtools/DirectSession.py b/direct/src/directtools/DirectSession.py index f7453b2e24..ef6793c099 100644 --- a/direct/src/directtools/DirectSession.py +++ b/direct/src/directtools/DirectSession.py @@ -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() diff --git a/direct/src/leveleditor/LevelEditor.py b/direct/src/leveleditor/LevelEditor.py index 04f27d6421..d1de50fa49 100644 --- a/direct/src/leveleditor/LevelEditor.py +++ b/direct/src/leveleditor/LevelEditor.py @@ -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 diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index f9c7f14bdc..1e9b407ed5 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -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() diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index 8007ff22b7..c973034534 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -12,6 +12,5 @@ def inspect(anObject): import Inspector return Inspector.inspect(anObject) -import __builtin__ -__builtin__.inspect = inspect +__builtins__["inspect"] = inspect diff --git a/direct/src/showbase/TkGlobal.py b/direct/src/showbase/TkGlobal.py index 04e160e14e..45a65f607d 100644 --- a/direct/src/showbase/TkGlobal.py +++ b/direct/src/showbase/TkGlobal.py @@ -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 diff --git a/direct/src/showbase/VerboseImport.py b/direct/src/showbase/VerboseImport.py index d0f45f4dc4..c92d5e9757 100644 --- a/direct/src/showbase/VerboseImport.py +++ b/direct/src/showbase/VerboseImport.py @@ -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 diff --git a/direct/src/tkwidgets/AppShell.py b/direct/src/tkwidgets/AppShell.py index 07409201b8..226dac2c01 100644 --- a/direct/src/tkwidgets/AppShell.py +++ b/direct/src/tkwidgets/AppShell.py @@ -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