/[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 2005 - (hide annotations) (download) (as text)
Mon Apr 20 08:39:46 2009 UTC (9 years, 6 months ago) by jpye
Original Path: trunk/pygtk/canvas/blockcanvas.py
File MIME type: text/x-python
File size: 2607 byte(s)
Started work on exposing model parameters to canvas GUI.
Updated header/comment formatting in type_descio.h.
Fixed some warnings in error.c.
A bug still exists error_reporter_tree_start that is causing problems with the
canvas-based GUI.
Added Info class to canvas code, for output of debug information via GUI.
Added a few missing types of gtksourceview langdef.
1 jpye 1942 from gaphas import Canvas
2 jpye 1968 from gaphas.item import Line
3 jpye 1942
4     class BlockCanvas(Canvas):
5 jpye 1961 def update_constraints(self, items):
6     """
7     Update constraints. Also variables may be marked as dirty before the
8     constraint solver kicks in.
9     """
10     # request solving of external constraints associated with dirty items
11     request_resolve = self._solver.request_resolve
12     for item in items:
13 jpye 1970 if hasattr(item,'ports'):
14     for p in item._ports:
15     if hasattr(p,"point"):
16     request_resolve(p.point.x)
17     request_resolve(p.point.y)
18 jpye 1942
19 jpye 1961 super(BlockCanvas,self).update_constraints(items)
20 jpye 1942
21 jpye 1961 def reattach_ascend(self, library, notesdb):
22 jpye 1967 """
23     After unpickling a canvas, this method gives a way of reattaching
24     the model to an ASCEND library, by connecting the types named in the
25     pickle with the typenames present in the Library.
26     """
27     # FIXME need to set ASCEND to *load* the missing types if they're not
28     # already in the Library.
29 jpye 1959 items = []
30 jpye 1961 for item in self.get_all_items():
31     if not hasattr(item, 'blockinstance'):
32 jpye 1959 continue
33 jpye 1961 bi = item.blockinstance
34     if bi.blocktype.type is None:
35     bi.blocktype.reattach_ascend(library, notesdb)
36 jpye 1954
37 jpye 1967 def __str__(self):
38     """
39     Create ASCEND code corresponding to canvas model, return the
40     code as a string.
41     """
42 jpye 2005
43     # FIXME it should be possible to perform this function at an
44     # application layer, without using routines from Gaphas...
45    
46 jpye 1967 s = "\n(* automatically generated model from blocklist.py *)\n";
47     s += "MODEL canvasmodel;\n"
48 jpye 2005
49     # Add blocks to the model via IS_A statements
50 jpye 1967 for item in self.get_all_items():
51     if not hasattr(item, 'blockinstance'):
52     continue
53 jpye 1968 s += str(item.blockinstance)
54 jpye 1967
55 jpye 2005 # Add LINES as ARE_THE_SAME statements
56 jpye 1973 for line in self.get_all_items():
57     if not isinstance(line, Line):
58 jpye 1967 continue
59 jpye 1979 s += str(line.lineinstance)
60 jpye 2005
61     # Set PARAMETERS using the ON_LOAD METHOD.
62     p = ""
63     for item in self.get_all_items():
64     if not hasattr(item, 'blockinstance'):
65     continue
66     n = item.blockinstance.name
67     for k,v in item.blockinstance.params.iteritems():
68     p += "\tFIX %s.%s;\n" % (n,v.name)
69     p += "\t%s.%s := %f;\n" % (n,v.name,v.value)
70     if not p == "":
71     s += "METHODS\nMETHOD on_load;\n";
72     s += p
73     s += "END on_load;\n"
74    
75 jpye 1967 s += "END canvasmodel;\n";
76     return s
77    
78 jpye 1965 def __getstate__(self):
79 jpye 1967 """
80     Placeholder for any special pickling stuff that we want to do with
81     our canvas.
82     """
83 jpye 1965 return super(BlockCanvas,self).__getstate__()
84 jpye 1959
85 jpye 1965 def __setstate__(self, state):
86 jpye 1967 """
87     Placeholder for any special pickling stuff that we want to do with
88     our canvas.
89     """
90 jpye 1965 super(BlockCanvas,self).__setstate__(state)
91    

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