summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Smith <bruce@nanorex.com>2009-03-07 23:21:05 +0000
committerBruce Smith <bruce@nanorex.com>2009-03-07 23:21:05 +0000
commit813aed65fc0c2792560b96267adcad3bf5b7004a (patch)
tree8373489c38ea5fae4421df6264cda20f7773e2cf
parentb002b6fa65853c17fc9d9c7070b73f4db084a151 (diff)
downloadnanoengineer-813aed65fc0c2792560b96267adcad3bf5b7004a.tar.gz
nanoengineer-813aed65fc0c2792560b96267adcad3bf5b7004a.zip
fix AssertionError caused by delegating GraphicsMode
-rwxr-xr-xcad/src/command_support/Command.py6
-rw-r--r--cad/src/command_support/GraphicsMode_API.py63
-rwxr-xr-xcad/src/commands/BuildAtoms/BuildAtoms_Command.py5
-rwxr-xr-xcad/src/commands/Fuse/FuseChunks_Command.py10
-rwxr-xr-xcad/src/commands/Move/Move_Command.py8
-rwxr-xr-xcad/src/commands/Select/Select_Command.py8
-rwxr-xr-xcad/src/commands/SelectAtoms/SelectAtoms_Command.py3
-rwxr-xr-xcad/src/commands/SelectChunks/SelectChunks_Command.py5
-rw-r--r--cad/src/commands/TestGraphics/TestGraphics_Command.py46
-rwxr-xr-xcad/src/exprs/Highlightable.py8
-rwxr-xr-xcad/src/graphics/widgets/GLPane.py6
11 files changed, 90 insertions, 78 deletions
diff --git a/cad/src/command_support/Command.py b/cad/src/command_support/Command.py
index 101eaa4bc..0b153c025 100755
--- a/cad/src/command_support/Command.py
+++ b/cad/src/command_support/Command.py
@@ -47,7 +47,7 @@ from model.jigs import Jig
# this is used only for cmenu making
# TODO: probably it should be factored into a method on the object being tested
-from command_support.GraphicsMode_API import GraphicsMode_API
+from command_support.GraphicsMode_API import GraphicsMode_interface
from command_support.baseCommand import baseCommand
@@ -1002,7 +1002,7 @@ class Command(basicCommand):
# Each Command subclass must override this class constant with the
# most abstract GraphicsMode subclass which they are able to work with.
# In concrete Command subclasses, it must be a subclass of
- # GraphicsMode_API, whose constructor takes a single argument,
+ # GraphicsMode_interface, whose constructor takes a single argument,
# which will be the command instance.
#
# Command subclasses which inherit (say) SomeCommand can also define
@@ -1032,7 +1032,7 @@ class Command(basicCommand):
def _create_GraphicsMode(self):
GM_class = self.GraphicsMode_class
# maybe: let caller pass something to replace this?
- assert issubclass(GM_class, GraphicsMode_API)
+ assert issubclass(GM_class, GraphicsMode_interface)
args = [self] # the command is the only ordinary init argument
kws = {} # TODO: let subclasses add kws to this
diff --git a/cad/src/command_support/GraphicsMode_API.py b/cad/src/command_support/GraphicsMode_API.py
index 2f88b393b..9262d65e4 100644
--- a/cad/src/command_support/GraphicsMode_API.py
+++ b/cad/src/command_support/GraphicsMode_API.py
@@ -1,9 +1,9 @@
-# Copyright 2004-2008 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
GraphicsMode_API.py -- API class for whatever is used as a GraphicsMode
@version: $Id$
-@copyright: 2004-2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
History:
@@ -28,10 +28,63 @@ TODO:
See the TODO comment in module GraphicsMode.
"""
-class GraphicsMode_API(object):
+class GraphicsMode_interface(object): #bruce 090307
"""
- API class and abstract superclass for all GraphicsMode objects,
- including nullGraphicsMode; used for isinstance tests
+ This can be used in isinstance/issubclass assertions,
+ and inherited by classes which intend to delegate to an actual GraphicsMode
+ (such as Delegating_GraphicsMode) and which therefore don't want
+ to inherit the default method implementations in GraphicsMode_API.
+ """
+ pass
+
+# ==
+
+class Delegating_GraphicsMode(GraphicsMode_interface): #bruce 090307
+ """
+ Abstract class for GraphicsModes which delegate almost everything
+ to their parentGraphicsMode.
+ """
+ # implem note: We can't use idlelib.Delegator to help implement this class,
+ # since the delegate needs to be dynamic.
+
+ def __init__(self, command):
+ self.command = command
+ return
+
+ def __get_parentGraphicsMode(self): #bruce 081223 [copied from GraphicsMode]
+ # review: does it need to check whether the following exists?
+ return self.command.parentCommand.graphicsMode
+
+ parentGraphicsMode = property(__get_parentGraphicsMode)
+ # use this when you need to wrap a method, then delegate explicitly
+ # (but rely on __getattr__ instead, when you can delegate directly)
+
+ def __getattr__(self, attr):
+ if self.command.parentCommand:
+ if self.command.parentCommand.graphicsMode: # aka parentGraphicsMode
+ return getattr(self.command.parentCommand.graphicsMode, attr)
+ # may raise AttributeError
+ else:
+ # parentCommand has no graphicsMode [never yet seen]
+ print "%r has no graphicsMode!" % self.command.parentCommand
+ raise AttributeError, attr
+ pass
+ else:
+ # self.command has no parentCommand [never yet seen]
+ print "%r has no parentCommand!" % self.command
+ raise AttributeError, attr
+ pass
+ pass
+
+# ==
+
+class GraphicsMode_API(GraphicsMode_interface):
+ """
+ API class and abstract superclass for most GraphicsMode objects,
+ including nullGraphicsMode.
+
+ @note: for isinstance/issubclass tests, and fully-delegating GraphicsModes,
+ use GraphicsMode_interface instead.
"""
# GraphicsMode-specific attribute null values
diff --git a/cad/src/commands/BuildAtoms/BuildAtoms_Command.py b/cad/src/commands/BuildAtoms/BuildAtoms_Command.py
index a0e5b5b71..7a62d2f80 100755
--- a/cad/src/commands/BuildAtoms/BuildAtoms_Command.py
+++ b/cad/src/commands/BuildAtoms/BuildAtoms_Command.py
@@ -1,9 +1,9 @@
-# Copyright 2004-2008 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
BuildAtoms_Command.py
@version: $Id$
-@copyright: 2004-2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
The 'Command' part of the BuildAtoms Mode (BuildAtoms_Command and
BuildAtoms_basicGraphicsMode are the two split classes of the old
@@ -40,7 +40,6 @@ from utilities.prefs_constants import keepBondsDuringTransmute_prefs_key
from commands.BuildAtoms.BuildAtomsPropertyManager import BuildAtomsPropertyManager
from commands.SelectAtoms.SelectAtoms_Command import SelectAtoms_Command
-from command_support.GraphicsMode_API import GraphicsMode_API
from commands.BuildAtoms.BuildAtoms_GraphicsMode import BuildAtoms_GraphicsMode
from ne1_ui.toolbars.Ui_BuildAtomsFlyout import BuildAtomsFlyout
diff --git a/cad/src/commands/Fuse/FuseChunks_Command.py b/cad/src/commands/Fuse/FuseChunks_Command.py
index f4c0e5aa8..e921be118 100755
--- a/cad/src/commands/Fuse/FuseChunks_Command.py
+++ b/cad/src/commands/Fuse/FuseChunks_Command.py
@@ -1,10 +1,10 @@
-# Copyright 2004-2007 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
FuseChunks_Command.py
@author: Mark
@version: $Id$
-@copyright: 2004-2007 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
History:
Originally by Mark as class 'fuseChunksMode'.
@@ -41,7 +41,7 @@ FUSEATOMS = 'Fuse overlapping atoms'
from commands.Fuse.FuseChunks_GraphicsMode import FuseChunks_GraphicsMode
from commands.Fuse.FuseChunks_GraphicsMode import Translate_in_FuseChunks_GraphicsMode
from commands.Fuse.FuseChunks_GraphicsMode import Rotate_in_FuseChunks_GraphicsMode
-from command_support.GraphicsMode_API import GraphicsMode_API
+from command_support.GraphicsMode_API import GraphicsMode_interface
from ne1_ui.toolbars.Ui_FuseFlyout import FuseFlyout
@@ -83,7 +83,7 @@ class FuseChunks_Command(Move_Command, fusechunksBase):
def _create_GraphicsMode(self):
GM_class = self.GraphicsMode_class
- assert issubclass(GM_class, GraphicsMode_API)
+ assert issubclass(GM_class, GraphicsMode_interface)
args = [self]
kws = {}
self.graphicsMode = GM_class(*args, **kws)
@@ -441,4 +441,4 @@ class FuseChunks_Command(Move_Command, fusechunksBase):
# This must be done before win_update(), or it will try to draw the
# overlapping atoms again, which generates errors.
- self.w.win_update() \ No newline at end of file
+ self.w.win_update()
diff --git a/cad/src/commands/Move/Move_Command.py b/cad/src/commands/Move/Move_Command.py
index 4c64847c6..538650144 100755
--- a/cad/src/commands/Move/Move_Command.py
+++ b/cad/src/commands/Move/Move_Command.py
@@ -1,4 +1,4 @@
-# Copyright 2004-2008 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
Move_Command.py
@@ -14,7 +14,7 @@ For example:
to override them).
@version: $Id$
-@copyright: 2004-2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
History:
@@ -30,7 +30,7 @@ import foundation.env as env
import math
from commands.Move.MovePropertyManager import MovePropertyManager
from commands.SelectChunks.SelectChunks_Command import SelectChunks_Command
-from command_support.GraphicsMode_API import GraphicsMode_API
+from command_support.GraphicsMode_API import GraphicsMode_interface
from geometry.BoundingBox import BBox
from utilities.Log import redmsg
from geometry.VQT import V, Q
@@ -414,7 +414,7 @@ class Move_Command(SelectChunks_Command):
def _create_GraphicsMode(self):
GM_class = self.GraphicsMode_class
- assert issubclass(GM_class, GraphicsMode_API)
+ assert issubclass(GM_class, GraphicsMode_interface)
args = [self]
kws = {}
self.graphicsMode = GM_class(*args, **kws)
diff --git a/cad/src/commands/Select/Select_Command.py b/cad/src/commands/Select/Select_Command.py
index 73320e432..dc27c616b 100755
--- a/cad/src/commands/Select/Select_Command.py
+++ b/cad/src/commands/Select/Select_Command.py
@@ -1,4 +1,4 @@
-# Copyright 2004-2007 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
Select_Command.py
@@ -14,7 +14,7 @@ For example:
to override them).
@version: $Id$
-@copyright: 2004-2007 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
TODO:
@@ -31,7 +31,7 @@ Ninad & Bruce 2007-12-13: Created new Command and GraphicsMode classes from
from command_support.Command import basicCommand
from commands.Select.Select_GraphicsMode import Select_GraphicsMode
-from command_support.GraphicsMode_API import GraphicsMode_API
+from command_support.GraphicsMode_API import GraphicsMode_interface
class Select_basicCommand(basicCommand):
"""
@@ -216,7 +216,7 @@ class Select_Command(Select_basicCommand):
def _create_GraphicsMode(self):
GM_class = self.GraphicsMode_class
- assert issubclass(GM_class, GraphicsMode_API)
+ assert issubclass(GM_class, GraphicsMode_interface)
args = [self]
kws = {}
self.graphicsMode = GM_class(*args, **kws)
diff --git a/cad/src/commands/SelectAtoms/SelectAtoms_Command.py b/cad/src/commands/SelectAtoms/SelectAtoms_Command.py
index cda5dd88d..0257e672c 100755
--- a/cad/src/commands/SelectAtoms/SelectAtoms_Command.py
+++ b/cad/src/commands/SelectAtoms/SelectAtoms_Command.py
@@ -33,7 +33,6 @@ from utilities.debug import print_compact_traceback
from utilities.debug import reload_once_per_event
from commands.Select.Select_Command import Select_Command
-from command_support.GraphicsMode_API import GraphicsMode_API
from commands.SelectAtoms.SelectAtoms_GraphicsMode import SelectAtoms_GraphicsMode
_superclass = Select_Command
@@ -158,4 +157,4 @@ class SelectAtoms_Command(Select_Command):
@see: SelectAtoms_GraphicsMode.drag_selected_atom()
"""
self.graphicsMode.drag_selected_atom(a, delta,
- computeBaggage = computeBaggage) \ No newline at end of file
+ computeBaggage = computeBaggage)
diff --git a/cad/src/commands/SelectChunks/SelectChunks_Command.py b/cad/src/commands/SelectChunks/SelectChunks_Command.py
index f6b01cc75..097d33962 100755
--- a/cad/src/commands/SelectChunks/SelectChunks_Command.py
+++ b/cad/src/commands/SelectChunks/SelectChunks_Command.py
@@ -1,4 +1,4 @@
-# Copyright 2004-2008 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
SelectChunks_Command.py
@@ -14,7 +14,7 @@ For example:
to override them).
@version: $Id$
-@copyright: 2004-2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
TODO:
@@ -30,7 +30,6 @@ Ninad & Bruce 2007-12-13: Created new Command and GraphicsMode classes from
"""
from commands.Select.Select_Command import Select_Command
from commands.SelectChunks.SelectChunks_GraphicsMode import SelectChunks_GraphicsMode
-from command_support.GraphicsMode_API import GraphicsMode_API
from utilities.Comparison import same_vals
from model.chem import Atom
diff --git a/cad/src/commands/TestGraphics/TestGraphics_Command.py b/cad/src/commands/TestGraphics/TestGraphics_Command.py
index ac22ed62b..6fe7efe31 100644
--- a/cad/src/commands/TestGraphics/TestGraphics_Command.py
+++ b/cad/src/commands/TestGraphics/TestGraphics_Command.py
@@ -15,7 +15,7 @@ import time # for time.time (wall clock time)
# NE1 imports
from command_support.Command import Command
-##from command_support.GraphicsMode import GraphicsMode
+from command_support.GraphicsMode_API import Delegating_GraphicsMode
from commands.TestGraphics.TestGraphics_PropertyManager import TestGraphics_PropertyManager
@@ -53,50 +53,12 @@ last_time = time.time()
# == GraphicsMode part
-## _superclass_GM = GraphicsMode # not used as of 081223
-
-class TestGraphics_GraphicsMode(object):
+class TestGraphics_GraphicsMode(Delegating_GraphicsMode):
"""
Graphics mode for TestGraphics command.
"""
-
- # ==
-
# new feature, bruce 090306: delegate almost everything to
- # parentGraphicsMode. (We can't use idlelib.Delegator since
- # the delegate needs to be dynamic.)
-
- def __init__(self, command):
- self.command = command
- return
-
- def __get_parentGraphicsMode(self): #bruce 081223 [copied from GraphicsMode]
- # review: does it need to check whether the following exists?
- return self.command.parentCommand.graphicsMode
-
- parentGraphicsMode = property(__get_parentGraphicsMode)
- # use this when you need to wrap a method, then delegate explicitly
- # (but rely on __getattr__ instead, when you can delegate directly)
-
- def __getattr__(self, attr):
- if self.command.parentCommand:
- if self.command.parentCommand.graphicsMode: # aka parentGraphicsMode
- return getattr(self.command.parentCommand.graphicsMode, attr)
- # May raise AttributeError
- else:
- # parentCommand has no graphicsMode [never yet seen]
- print "%r has no graphicsMode!" % self.command.parentCommand
- raise AttributeError, attr
- pass
- else:
- # self.command has no parentCommand [never yet seen]
- print "%r has no parentCommand!" % self.command
- raise AttributeError, attr
- pass
-
- # (end of delegation section)
-
- # ==
+ # parentGraphicsMode, via our new superclass Delegating_GraphicsMode.
if 0:
# this can be enabled by individual developers if desired (debug_pref?)
@@ -201,7 +163,7 @@ class TestGraphics_GraphicsMode(object):
# == Command part
-class TestGraphics_Command(Command):
+class TestGraphics_Command(Command):
"""
"""
diff --git a/cad/src/exprs/Highlightable.py b/cad/src/exprs/Highlightable.py
index 38547bcb1..5ca102962 100755
--- a/cad/src/exprs/Highlightable.py
+++ b/cad/src/exprs/Highlightable.py
@@ -1,10 +1,10 @@
-# Copyright 2006-2008 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2006-2009 Nanorex, Inc. See LICENSE file for details.
"""
Highlightable.py - general-purpose expr for mouse-responsive drawable objects
@author: Bruce
@version: $Id$
-@copyright: 2006-2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2006-2009 Nanorex, Inc. See LICENSE file for details.
This will start out as just a straight port of class Highlightable from cad/src/testdraw.py,
with the same limitations in API and implem (e.g. it won't work inside display lists).
@@ -1157,8 +1157,8 @@ def _setup_UNKNOWN_SELOBJ_on_graphicsMode(graphicsMode): #061218, revised 071010
## assert isinstance(graphicsMode, anyGraphicsMode)
#
# bruce 071028 reinstating it in a harmless form:
- from command_support.GraphicsMode_API import GraphicsMode_API
- assert isinstance(graphicsMode, GraphicsMode_API)
+ from command_support.GraphicsMode_API import GraphicsMode_interface
+ assert isinstance(graphicsMode, GraphicsMode_interface)
if not hasattr(graphicsMode, 'UNKNOWN_SELOBJ'):
# note: this means each graphicsMode ends up with a unique UNKNOWN_SELOBJ,
diff --git a/cad/src/graphics/widgets/GLPane.py b/cad/src/graphics/widgets/GLPane.py
index a280eba53..585a2fe05 100755
--- a/cad/src/graphics/widgets/GLPane.py
+++ b/cad/src/graphics/widgets/GLPane.py
@@ -53,7 +53,7 @@ import sys
from OpenGL.GL import GL_STENCIL_BITS
from OpenGL.GL import glGetInteger
-from command_support.GraphicsMode_API import GraphicsMode_API # for isinstance assertion
+from command_support.GraphicsMode_API import GraphicsMode_interface # for isinstance assertion
import foundation.env as env
@@ -151,7 +151,7 @@ class GLPane(
* several "point of view" attributes (some might be inherited
from superclass GLPane_minimal)
- * graphicsMode - an instance of GraphicsMode_API
+ * graphicsMode - an instance of GraphicsMode_interface
"""
# Note: classes GLPane and ThumbView still share lots of code,
# which ought to be merged into their common superclass GLPane_minimal.
@@ -473,7 +473,7 @@ class GLPane(
res = self.assy.commandSequencer.currentCommand.graphicsMode
# don't go through commandSequencer.graphicsMode,
# maybe that attr is not needed
- assert isinstance(res, GraphicsMode_API)
+ assert isinstance(res, GraphicsMode_interface)
return res
graphicsMode = property( _get_graphicsMode)