Mercurial > MadButterfly
annotate pyink/data_monitor.py @ 1341:599b606c4669
Start to implement HTML5/CSS3 exporter
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 07 Feb 2011 21:54:03 +0800 |
parents | cfbc0f3e54e3 |
children |
rev | line source |
---|---|
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1 import os |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2 |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
3 ## \brief Monitor accessing on the dta model. |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
4 # |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
5 # This class is a meta-class that monitor data accessing for its instance |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
6 # classes. |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
7 # |
1254
0cb5979549be
Add more doc for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
8 # It is a monitor with a small modification. The calling would be |
0cb5979549be
Add more doc for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
9 # rejected when the domview_ui was locked. It will not waiting for a |
0cb5979549be
Add more doc for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
10 # lock. |
0cb5979549be
Add more doc for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
11 # |
0cb5979549be
Add more doc for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
12 # \see http://en.wikipedia.org/wiki/Monitor_%28synchronization%29 |
0cb5979549be
Add more doc for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1253
diff
changeset
|
13 # |
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
14 # All methods, of instance classes, who's name is prefixed with 'do' are |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
15 # monitored. When a monitored method was called, monitor will try to lock |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
16 # _domview of the object. The method is only called if successfully acquiring |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
17 # the lock, or return immediately. The lock is released after the calling |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
18 # returned. |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
19 # |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
20 class data_monitor(type): |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
21 def __new__(mclazz, name, bases, clazz_dict): |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
22 debug_level = 0 |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
23 if os.environ.has_key('DATA_MONITOR_DBG'): |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
24 debug_level = int(os.environ['DATA_MONITOR_DBG']) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
25 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
26 |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
27 def gen_sentinel(func_name, func): |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
28 def sentinel(self, *args, **kws): |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
29 if debug_level >= 1: |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
30 print 'calling %s.%s' % (name, func_name) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
31 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
32 if debug_level >= 2: |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
33 print ' args: %s' % (repr(args)) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
34 print ' kws: %s' % (repr(kws)) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
35 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
36 |
1265
ca301f6abef7
Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents:
1254
diff
changeset
|
37 if not self._locker.lock(): # can not lock |
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
38 if debug_level >= 1: |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
39 print ' fault to lock' |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
40 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
41 return |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
42 |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
43 try: |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
44 func(self, *args, **kws) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
45 finally: |
1265
ca301f6abef7
Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
wycc
parents:
1254
diff
changeset
|
46 self._locker.unlock() |
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
47 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
48 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
49 return sentinel |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
50 |
1307
cfbc0f3e54e3
Add supporting for programmer defined prefix for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1265
diff
changeset
|
51 monitor_prefix = 'do' |
cfbc0f3e54e3
Add supporting for programmer defined prefix for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1265
diff
changeset
|
52 if clazz_dict.has_key('__data_monitor_prefix__'): |
cfbc0f3e54e3
Add supporting for programmer defined prefix for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1265
diff
changeset
|
53 monitor_prefix = clazz_dict['__data_monitor_prefix__'] |
cfbc0f3e54e3
Add supporting for programmer defined prefix for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1265
diff
changeset
|
54 pass |
cfbc0f3e54e3
Add supporting for programmer defined prefix for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1265
diff
changeset
|
55 |
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
56 for attr_name in clazz_dict: |
1307
cfbc0f3e54e3
Add supporting for programmer defined prefix for data_monitor
Thinker K.F. Li <thinker@codemud.net>
parents:
1265
diff
changeset
|
57 if (not attr_name.startswith(monitor_prefix)) or \ |
1253
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
58 (not callable(clazz_dict[attr_name])): |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
59 continue |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
60 clazz_dict[attr_name] = \ |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
61 gen_sentinel(attr_name, clazz_dict[attr_name]) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
62 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
63 |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
64 clazz = type.__new__(mclazz, name, bases, clazz_dict) |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
65 |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
66 return clazz |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
67 pass |
07e0cb1e051d
Add class consistency_checker for domview_ui.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
68 |