1 |
from gaphas import Canvas |
2 |
|
3 |
class BlockCanvas(Canvas): |
4 |
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 |
|
17 |
super(BlockCanvas,self).update_constraints(items) |
18 |
|
19 |
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 |
|
42 |
def reattach_ascend(self, library, notesdb): |
43 |
# FIXME still need a way of iterating through these items |
44 |
items = [] |
45 |
for item in self.get_all_items(): |
46 |
if not hasattr(item, 'blockinstance'): |
47 |
continue |
48 |
bi = item.blockinstance |
49 |
if bi.blocktype.type is None: |
50 |
bi.blocktype.reattach_ascend(library, notesdb) |
51 |
|
52 |
def __getstate__(self): |
53 |
return super(BlockCanvas,self).__getstate__() |
54 |
|
55 |
def __setstate__(self, state): |
56 |
super(BlockCanvas,self).__setstate__(state) |
57 |
|