/[ascend]/trunk/pygtk/canvas/blocktype.py
ViewVC logotype

Contents of /trunk/pygtk/canvas/blocktype.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1961 - (show annotations) (download) (as text)
Tue Nov 18 03:48:21 2008 UTC (13 years, 8 months ago) by jpye
File MIME type: text/x-python
File size: 2262 byte(s)
Working on reattaching ports, but not working yet.
1 import pygtk
2 pygtk.require('2.0')
3 import gtk
4 import ascpy
5
6 class BlockType:
7 """
8 All data associated with the MODEL type that is represented by a block.
9 This includes the actual ASCEND TypeDescription as well as the NOTES that
10 are found to represent the inputs and outputs for this block, as well as
11 some kind of graphical representation(s) for the block. In the canvas-
12 based GUI, there will need to be a Cairo-based represention, for drawing
13 on the canvas, as well as some other form, for creating the icon in the
14 block palette.
15 """
16 # FIXME there is no definition here of the canvas graphical representation,
17 # but there should be.
18
19 def __init__(self, typedesc, notesdb):
20 self.type = typedesc
21 self.notesdb = notesdb
22
23 # FIXME BlockType should know what .a4c file to load in order to access
24 # its type definition, for use in unpickling.
25 self.sourcefile = None
26
27 nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("inline"))
28
29 self.inputs = []
30 self.outputs = []
31 for n in nn:
32 t = n.getText()
33 if t[0:min(len(t),3)]=="in:":
34 self.inputs += [n]
35 elif t[0:min(len(t),4)]=="out:":
36 self.outputs += [n]
37
38 def get_icon(self, width, height):
39 return gtk.gdk.pixbuf_new_from_file_at_size("defaultblock.svg",width,height)
40
41 def __getstate__(self):
42 print "GET STATE ON BLOCKTYPE %s" % self.type.getName()
43 return (str(self.type.getName()),len(self.inputs), len(self.outputs))
44
45 def __setstate__(self, state):
46 print "SET STATE ON BLOCKTYPE"
47 (typename,ninputs,noutputs) = state
48 print "Recreating type '%s' with %d inputs, %d outputs" % (typename,ninputs,noutputs)
49 self.type = None
50 self.notesdb = None
51 self._typename = typename
52 self.inputs = range(ninputs)
53 self.outputs = range(noutputs)
54 print "outputs =", self.outputs
55
56 def reattach_ascend(self,library, notesdb):
57 self.type = library.findType(self._typename)
58
59 nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("inline"))
60
61 self.inputs = []
62 self.outputs = []
63 for n in nn:
64 t = n.getText()
65 if t[0:min(len(t),3)]=="in:":
66 self.inputs += [n]
67 elif t[0:min(len(t),4)]=="out:":
68 self.outputs += [n]
69
70 print "Reattached type '%s', with %d inputs, %d outputs" % (self.type.getName(), len(self.inputs), len(self.outputs))
71

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