/[ascend]/branches/mike/pygtk/canvas/blockcanvas.py
ViewVC logotype

Annotation of /branches/mike/pygtk/canvas/blockcanvas.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1966 - (hide annotations) (download) (as text)
Mon Dec 1 07:13:49 2008 UTC (9 years, 8 months ago) by jpye
Original Path: trunk/pygtk/canvas/blockcanvas.py
File MIME type: text/x-python
File size: 1664 byte(s)
Icon palette uses custom SVGs as specified in MODEL NOTES.
Added icons for out simple test models.
1 jpye 1942 from gaphas import Canvas
2    
3     class BlockCanvas(Canvas):
4 jpye 1961 def update_constraints(self, items):
5     """
6     Update constraints. Also variables may be marked as dirty before the
7     constraint solver kicks in.
8     """
9     # request solving of external constraints associated with dirty items
10     request_resolve = self._solver.request_resolve
11     for item in items:
12     if hasattr(item,'ports'):
13     for p in item.ports:
14     request_resolve(p.x)
15     request_resolve(p.y)
16 jpye 1942
17 jpye 1961 super(BlockCanvas,self).update_constraints(items)
18 jpye 1942
19 jpye 1961 def _normalize(self, items):
20     """
21     Correct offset of ports due to movement of left-side handles.
22     """
23     dirty_matrix_items = set()
24     for item in items:
25     if not hasattr(item, 'ports'):
26     continue
27     handles = item.handles()
28     ports = item.ports
29     if not handles or not ports:
30     continue
31     x, y = map(float, handles[0].pos)
32     # Dirty marking is done by the superclass' method
33     if x:
34     for p in ports:
35     p.x._value -= x
36     if y:
37     for p in ports:
38     p.y._value -= y
39     dirty_matrix_items.update(super(BlockCanvas, self)._normalize(items))
40     return dirty_matrix_items
41 jpye 1942
42 jpye 1961 def reattach_ascend(self, library, notesdb):
43 jpye 1959 # FIXME still need a way of iterating through these items
44     items = []
45 jpye 1961 for item in self.get_all_items():
46     if not hasattr(item, 'blockinstance'):
47 jpye 1959 continue
48 jpye 1961 bi = item.blockinstance
49     if bi.blocktype.type is None:
50     bi.blocktype.reattach_ascend(library, notesdb)
51 jpye 1954
52 jpye 1965 def __getstate__(self):
53     return super(BlockCanvas,self).__getstate__()
54 jpye 1959
55 jpye 1965 def __setstate__(self, state):
56     super(BlockCanvas,self).__setstate__(state)
57    

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22