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