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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1966 - (show annotations) (download) (as text)
Mon Dec 1 07:13:49 2008 UTC (14 years, 9 months ago) by jpye
File MIME type: text/x-python
File size: 2509 byte(s)
Icon palette uses custom SVGs as specified in MODEL NOTES.
Added icons for out simple test models.
1 import pygtk
2 pygtk.require('2.0')
3 import gtk
4 import ascpy
5 import os.path
6
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 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 def get_icon(self, width, height):
47 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
52 def __getstate__(self):
53 print "GET STATE ON BLOCKTYPE %s" % self.type.getName()
54 return (str(self.type.getName()),len(self.inputs), len(self.outputs))
55
56 def __setstate__(self, state):
57 print "SET STATE ON BLOCKTYPE"
58 (typename,ninputs,noutputs) = state
59 print "Recreating type '%s' with %d inputs, %d outputs" % (typename,ninputs,noutputs)
60 self.type = None
61 self.notesdb = None
62 self._typename = typename
63 self.inputs = range(ninputs)
64 self.outputs = range(noutputs)
65 print "outputs =", self.outputs
66
67 def reattach_ascend(self,library, notesdb):
68 self.type = library.findType(self._typename)
69
70 nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("inline"))
71
72 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

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