comparison 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
comparison
equal deleted inserted replaced
1252:71222a6b4c06 1253:07e0cb1e051d
6 import glib 6 import glib
7 import traceback 7 import traceback
8 import pybInkscape 8 import pybInkscape
9 from tween import scenes_director 9 from tween import scenes_director
10 from domview_ui import domview_ui 10 from domview_ui import domview_ui
11 from data_monitor import data_monitor
11 12
12 # Please refer to 13 # Please refer to
13 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention 14 # http://www.assembla.com/wiki/show/MadButterfly/Inkscape_extention
14 # for the designed document. 15 # for the designed document.
15 16
35 # scene is 10, we will set the scene field as "8-10". 36 # scene is 10, we will set the scene field as "8-10".
36 # - 5. If this scene are filled screne, we will split the existing 37 # - 5. If this scene are filled screne, we will split the existing
37 # scene into two scenes with the same content. 38 # scene into two scenes with the same content.
38 # 39 #
39 40
40 ## \brief Monitor accessing on the dta model.
41 #
42 # This class is a meta-class that monitor data accessing for its instance
43 # classes.
44 #
45 # All methods, of instance classes, who's name is prefixed with 'do' are
46 # monitored. When a monitored method was called, monitor will try to lock
47 # _domview of the object. The method is only called if successfully acquiring
48 # the lock, or return immediately. The lock is released after the calling
49 # returned.
50 #
51 class data_monitor(type):
52 def __new__(mclazz, name, bases, clazz_dict):
53 import os
54
55 debug_level = 0
56 if os.environ.has_key('DATA_MONITOR_DBG'):
57 debug_level = int(os.environ['DATA_MONITOR_DBG'])
58 pass
59
60 def gen_sentinel(name, func):
61 def sentinel(self, *args, **kws):
62 if debug_level >= 1:
63 print 'calling %s' % (name)
64 pass
65 if debug_level >= 2:
66 print ' args: %s' % (repr(args))
67 print ' kws: %s' % (repr(kws))
68 pass
69
70 if not self._domview.lock(): # can not lock
71 if debug_level >= 1:
72 print ' fault to lock'
73 pass
74 return
75
76 try:
77 func(self, *args, **kws)
78 finally:
79 self._domview.unlock()
80 pass
81 pass
82 return sentinel
83
84 for attr_name in clazz_dict:
85 if (not attr_name.startswith('do')) or \
86 (not callable(clazz_dict[attr_name])):
87 continue
88 clazz_dict[attr_name] = \
89 gen_sentinel(attr_name, clazz_dict[attr_name])
90 pass
91
92 clazz = type.__new__(mclazz, name, bases, clazz_dict)
93
94 return clazz
95 pass
96
97 ## \brief MBScene connect GUI and DOM-tree 41 ## \brief MBScene connect GUI and DOM-tree
98 # 42 #
99 # This method accepts user actions and involves domview_ui to update 43 # This method accepts user actions and involves domview_ui to update
100 # data on the document. 44 # data on the document.
101 # 45 #