From 2d6c2c5c6d62d186d0d6379b1a9467352704c5ed Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 20 Nov 2015 17:42:18 +0100 Subject: [PATCH] Remove dependency on tkpanels and tkwidgets modules when building .p3d package --- direct/src/actor/Actor.py | 6 ++- direct/src/directnotify/DirectNotify.py | 9 +++-- .../extensions_native/CInterval_extensions.py | 36 +++++++++-------- .../extensions_native/NodePath_extensions.py | 15 +++++-- direct/src/fsm/ClassicFSM.py | 5 ++- direct/src/interval/Interval.py | 40 +++++++++---------- direct/src/showbase/PythonUtil.py | 5 ++- direct/src/showbase/ShowBaseGlobal.py | 5 ++- direct/src/task/Task.py | 5 ++- 9 files changed, 78 insertions(+), 48 deletions(-) diff --git a/direct/src/actor/Actor.py b/direct/src/actor/Actor.py index d5fcaa8ee4..233768a5d3 100644 --- a/direct/src/actor/Actor.py +++ b/direct/src/actor/Actor.py @@ -1534,8 +1534,10 @@ class Actor(DirectObject, NodePath): # actions def animPanel(self): - from direct.showbase import TkGlobal - from direct.tkpanels import AnimPanel + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + AnimPanel = importlib.import_module('direct.tkpanels.AnimPanel') return AnimPanel.AnimPanel(self) def stop(self, animName=None, partName=None): diff --git a/direct/src/directnotify/DirectNotify.py b/direct/src/directnotify/DirectNotify.py index d61420e3f5..2d3fb5ab19 100644 --- a/direct/src/directnotify/DirectNotify.py +++ b/direct/src/directnotify/DirectNotify.py @@ -111,10 +111,13 @@ class DirectNotify: category.setWarning(1) category.setInfo(1) category.setDebug(1) - + def popupControls(self, tl = None): - from direct.tkpanels import NotifyPanel + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + NotifyPanel = importlib.import_module('direct.tkpanels.NotifyPanel') NotifyPanel.NotifyPanel(self, tl) - + def giveNotify(self,cls): cls.notify = self.newCategory(cls.__name__) diff --git a/direct/src/extensions_native/CInterval_extensions.py b/direct/src/extensions_native/CInterval_extensions.py index 34c7a781cc..a6f9241d81 100644 --- a/direct/src/extensions_native/CInterval_extensions.py +++ b/direct/src/extensions_native/CInterval_extensions.py @@ -58,13 +58,17 @@ def popupControls(self, tl = None): """ Popup control panel for interval. """ - from direct.showbase.TkGlobal import Toplevel, Frame, Button, LEFT, X, Pmw import math - from direct.tkwidgets import EntryScale + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + EntryScale = importlib.import_module('direct.tkwidgets.EntryScale') + Tkinter = importlib.import_module('Tkinter') + if tl == None: - tl = Toplevel() + tl = Tkinter.Toplevel() tl.title('Interval Controls') - outerFrame = Frame(tl) + outerFrame = Tkinter.Frame(tl) def entryScaleCommand(t, s=self): s.setT(t) s.pause() @@ -73,8 +77,8 @@ def popupControls(self, tl = None): min = 0, max = math.floor(self.getDuration() * 100) / 100, command = entryScaleCommand) es.set(self.getT(), fCommand = 0) - es.pack(expand = 1, fill = X) - bf = Frame(outerFrame) + es.pack(expand = 1, fill = Tkinter.X) + bf = Tkinter.Frame(outerFrame) # Jump to start and end def toStart(s=self, es=es): s.setT(0.0) @@ -82,23 +86,23 @@ def popupControls(self, tl = None): def toEnd(s=self): s.setT(s.getDuration()) s.pause() - jumpToStart = Button(bf, text = '<<', command = toStart) + jumpToStart = Tkinter.Button(bf, text = '<<', command = toStart) # Stop/play buttons def doPlay(s=self, es=es): s.resume(es.get()) - stop = Button(bf, text = 'Stop', + stop = Tkinter.Button(bf, text = 'Stop', command = lambda s=self: s.pause()) - play = Button( + play = Tkinter.Button( bf, text = 'Play', command = doPlay) - jumpToEnd = Button(bf, text = '>>', command = toEnd) - jumpToStart.pack(side = LEFT, expand = 1, fill = X) - play.pack(side = LEFT, expand = 1, fill = X) - stop.pack(side = LEFT, expand = 1, fill = X) - jumpToEnd.pack(side = LEFT, expand = 1, fill = X) - bf.pack(expand = 1, fill = X) - outerFrame.pack(expand = 1, fill = X) + jumpToEnd = Tkinter.Button(bf, text = '>>', command = toEnd) + jumpToStart.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + play.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + stop.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + jumpToEnd.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + bf.pack(expand = 1, fill = Tkinter.X) + outerFrame.pack(expand = 1, fill = Tkinter.X) # Add function to update slider during setT calls def update(t, es=es): es.set(t, fCommand = 0) diff --git a/direct/src/extensions_native/NodePath_extensions.py b/direct/src/extensions_native/NodePath_extensions.py index 7b17dc34f6..56adf16aea 100644 --- a/direct/src/extensions_native/NodePath_extensions.py +++ b/direct/src/extensions_native/NodePath_extensions.py @@ -1079,7 +1079,10 @@ del lerpScaleXYZ ##################################################################### def place(self): base.startDirect(fWantTk = 1) - from direct.tkpanels import Placer + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + Placer = importlib.import_module('direct.tkpanels.Placer') return Placer.place(self) Dtool_funcToMethod(place, NodePath) @@ -1087,7 +1090,10 @@ del place ##################################################################### def explore(self): base.startDirect(fWantTk = 1) - from direct.tkwidgets import SceneGraphExplorer + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + SceneGraphExplorer = importlib.import_module('direct.tkwidgets.SceneGraphExplorer') return SceneGraphExplorer.explore(self) Dtool_funcToMethod(explore, NodePath) @@ -1095,7 +1101,10 @@ del explore ##################################################################### def rgbPanel(self, cb = None): base.startTk() - from direct.tkwidgets import Slider + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + Slider = importlib.import_module('direct.tkwidgets.Slider') return Slider.rgbPanel(self, cb) Dtool_funcToMethod(rgbPanel, NodePath) diff --git a/direct/src/fsm/ClassicFSM.py b/direct/src/fsm/ClassicFSM.py index 880a249e2e..98191166ab 100644 --- a/direct/src/fsm/ClassicFSM.py +++ b/direct/src/fsm/ClassicFSM.py @@ -369,7 +369,10 @@ class ClassicFSM(DirectObject): return 0 def view(self): - from direct.tkpanels import FSMInspector + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + FSMInspector = importlib.import_module('direct.tkpanels.FSMInspector') FSMInspector.FSMInspector(self) def isInternalStateInFlux(self): diff --git a/direct/src/interval/Interval.py b/direct/src/interval/Interval.py index 0907c6d6a0..5b413f5ad9 100644 --- a/direct/src/interval/Interval.py +++ b/direct/src/interval/Interval.py @@ -443,16 +443,16 @@ class Interval(DirectObject): """ Popup control panel for interval. """ - from direct.showbase import TkGlobal - import math - # I moved this here because Toontown does not ship Tk - from Tkinter import Toplevel, Frame, Button, LEFT, X - import Pmw - from direct.tkwidgets import EntryScale + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + EntryScale = importlib.import_module('direct.tkwidgets.EntryScale') + Tkinter = importlib.import_module('Tkinter') + if tl == None: - tl = Toplevel() + tl = Tkinter.Toplevel() tl.title('Interval Controls') - outerFrame = Frame(tl) + outerFrame = Tkinter.Frame(tl) def entryScaleCommand(t, s=self): s.setT(t) s.pause() @@ -461,8 +461,8 @@ class Interval(DirectObject): min = 0, max = math.floor(self.getDuration() * 100) / 100, command = entryScaleCommand) es.set(self.getT(), fCommand = 0) - es.pack(expand = 1, fill = X) - bf = Frame(outerFrame) + es.pack(expand = 1, fill = Tkinter.X) + bf = Tkinter.Frame(outerFrame) # Jump to start and end def toStart(s=self, es=es): s.clearToInitial() @@ -472,23 +472,23 @@ class Interval(DirectObject): s.setT(s.getDuration()) es.set(s.getDuration(), fCommand = 0) s.pause() - jumpToStart = Button(bf, text = '<<', command = toStart) + jumpToStart = Tkinter.Button(bf, text = '<<', command = toStart) # Stop/play buttons def doPlay(s=self, es=es): s.resume(es.get()) - stop = Button(bf, text = 'Stop', + stop = Tkinter.Button(bf, text = 'Stop', command = lambda s=self: s.pause()) - play = Button( + play = Tkinter.Button( bf, text = 'Play', command = doPlay) - jumpToEnd = Button(bf, text = '>>', command = toEnd) - jumpToStart.pack(side = LEFT, expand = 1, fill = X) - play.pack(side = LEFT, expand = 1, fill = X) - stop.pack(side = LEFT, expand = 1, fill = X) - jumpToEnd.pack(side = LEFT, expand = 1, fill = X) - bf.pack(expand = 1, fill = X) - outerFrame.pack(expand = 1, fill = X) + jumpToEnd = Tkinter.Button(bf, text = '>>', command = toEnd) + jumpToStart.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + play.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + stop.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + jumpToEnd.pack(side = Tkinter.LEFT, expand = 1, fill = Tkinter.X) + bf.pack(expand = 1, fill = Tkinter.X) + outerFrame.pack(expand = 1, fill = Tkinter.X) # Add function to update slider during setT calls def update(t, es=es): es.set(t, fCommand = 0) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index ccd4de8800..ffe6869094 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -327,7 +327,10 @@ def adjust(command = None, dim = 1, parent = None, **kw): 10.0 """ # Make sure we enable Tk - from direct.tkwidgets import Valuator + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + Valuator = importlib.import_module('direct.tkwidgets.Valuator') # Set command if specified if command: kw['command'] = lambda x: apply(command, x) diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index 0722580019..451f411f15 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -14,7 +14,10 @@ assert base directNotify.setDconfigLevels() def inspect(anObject): - from direct.tkpanels import Inspector + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + Inspector = importlib.import_module('direct.tkpanels.Inspector') return Inspector.inspect(anObject) import __builtin__ diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 54458f0d2c..6d8f38acbd 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -583,7 +583,10 @@ class TaskManager: return numFound def popupControls(self): - from direct.tkpanels import TaskManagerPanel + # Don't use a regular import, to prevent ModuleFinder from picking + # it up as a dependency when building a .p3d package. + import importlib + TaskManagerPanel = importlib.import_module('direct.tkpanels.TaskManagerPanel') return TaskManagerPanel.TaskManagerPanel(self) def getProfileSession(self, name=None):