/[ascend]/branches/mike/pygtk/canvas/blockcanvas.py
ViewVC logotype

Diff of /branches/mike/pygtk/canvas/blockcanvas.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1966 by jpye, Mon Dec 1 07:13:49 2008 UTC revision 1967 by jpye, Mon Dec 1 07:58:58 2008 UTC
# Line 40  class BlockCanvas(Canvas): Line 40  class BlockCanvas(Canvas):
40          return dirty_matrix_items          return dirty_matrix_items
41    
42      def reattach_ascend(self, library, notesdb):      def reattach_ascend(self, library, notesdb):
43          # FIXME still need a way of iterating through these items          """
44            After unpickling a canvas, this method gives a way of reattaching
45            the model to an ASCEND library, by connecting the types named in the
46            pickle with the typenames present in the Library.
47            """
48            # FIXME need to set ASCEND to *load* the missing types if they're not
49            # already in the Library.
50          items = []          items = []
51          for item in self.get_all_items():          for item in self.get_all_items():
52              if not hasattr(item, 'blockinstance'):              if not hasattr(item, 'blockinstance'):
# Line 49  class BlockCanvas(Canvas): Line 55  class BlockCanvas(Canvas):
55              if bi.blocktype.type is None:              if bi.blocktype.type is None:
56                  bi.blocktype.reattach_ascend(library, notesdb)                  bi.blocktype.reattach_ascend(library, notesdb)
57    
58        def __str__(self):
59            """
60            Create ASCEND code corresponding to canvas model, return the
61            code as a string.
62            """
63            s = "\n(* automatically generated model from blocklist.py *)\n";
64            s += "MODEL canvasmodel;\n"
65            for item in self.get_all_items():
66                if not hasattr(item, 'blockinstance'):
67                    continue
68                bi = item.blockinstance
69                s += "\t%s IS_A %s;\n" % (bi.name, bi.blocktype.type.getName())
70    
71            for item in self.get_all_items():
72                if not hasattr(item, 'lineinstance'):
73                    continue
74                li = item.lineinstance
75                s += ("\t%s, %s ARE_THE_SAME;\n" % (li.fromblock.name, li.toblock.name))
76            s += "END canvasmodel;\n";
77            return s
78    
79      def __getstate__(self):      def __getstate__(self):
80            """
81            Placeholder for any special pickling stuff that we want to do with
82            our canvas.
83            """
84          return super(BlockCanvas,self).__getstate__()          return super(BlockCanvas,self).__getstate__()
85    
86      def __setstate__(self, state):      def __setstate__(self, state):
87            """
88            Placeholder for any special pickling stuff that we want to do with
89            our canvas.
90            """
91          super(BlockCanvas,self).__setstate__(state)          super(BlockCanvas,self).__setstate__(state)
92    

Legend:
Removed from v.1966  
changed lines
  Added in v.1967

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