diff pyink/MBScene.py @ 1253:07e0cb1e051d

Add class consistency_checker for domview_ui. - consistency_checker is to check consistency of the DOM-tree associated with a domview_ui. - It is so closed to domview_ui, so it may access private variables. - But, it uses public interface of domview_ui if possible. - consistency_checker is not integrated to domview_ui for separating functions of consistency checking from the domview_ui. It collects relative logic into a place and setups a boundary from others.
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 11 Jan 2011 11:43:32 +0800
parents fb5ad43c13eb
children a8e01435e84e
line wrap: on
line diff
--- a/pyink/MBScene.py	Tue Jan 11 10:36:39 2011 +0800
+++ b/pyink/MBScene.py	Tue Jan 11 11:43:32 2011 +0800
@@ -8,6 +8,7 @@
 import pybInkscape
 from tween import scenes_director
 from domview_ui import domview_ui
+from data_monitor import data_monitor
 
 # Please refer to
 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention
@@ -37,63 +38,6 @@
 #       scene into two scenes with the same content.
 #
 
-## \brief Monitor accessing on the dta model.
-#
-# This class is a meta-class that monitor data accessing for its instance
-# classes.
-#
-# All methods, of instance classes, who's name is prefixed with 'do' are
-# monitored.  When a monitored method was called, monitor will try to lock
-# _domview of the object.  The method is only called if successfully acquiring
-# the lock, or return immediately.  The lock is released after the calling
-# returned.
-#
-class data_monitor(type):
-    def __new__(mclazz, name, bases, clazz_dict):
-	import os
-
-	debug_level = 0
-	if os.environ.has_key('DATA_MONITOR_DBG'):
-	    debug_level = int(os.environ['DATA_MONITOR_DBG'])
-	    pass
-	
-	def gen_sentinel(name, func):
-	    def sentinel(self, *args, **kws):
-		if debug_level >= 1:
-		    print 'calling %s' % (name)
-		    pass
-		if debug_level >= 2:
-		    print '    args: %s' % (repr(args))
-		    print '    kws:  %s' % (repr(kws))
-		    pass
-		
-		if not self._domview.lock(): # can not lock
-		    if debug_level >= 1:
-			print '  fault to lock'
-			pass
-		    return
-		
-		try:
-		    func(self, *args, **kws)
-		finally:
-		    self._domview.unlock()
-		    pass
-		pass
-	    return sentinel
-
-	for attr_name in clazz_dict:
-	    if (not attr_name.startswith('do')) or \
-		    (not callable(clazz_dict[attr_name])):
-		continue
-	    clazz_dict[attr_name] = \
-		gen_sentinel(attr_name, clazz_dict[attr_name])
-	    pass
-	
-	clazz = type.__new__(mclazz, name, bases, clazz_dict)
-	
-	return clazz
-    pass
-
 ## \brief MBScene connect GUI and DOM-tree
 #
 # This method accepts user actions and involves domview_ui to update