##// END OF EJS Templates
ipy_leo: 'wb' is now the more 'advanced' workbook
vivainio -
Show More
@@ -52,7 +52,7 b' def all_cells():'
52 return d
52 return d
53
53
54
54
55 class LeoWorkbook:
55 class TrivialLeoWorkbook:
56 """ class to find cells """
56 """ class to find cells """
57 def __getattr__(self, key):
57 def __getattr__(self, key):
58 cells = all_cells()
58 cells = all_cells()
@@ -67,9 +67,61 b' class LeoWorkbook:'
67 else:
67 else:
68 c.setBodyString(p,format_for_leo(val))
68 c.setBodyString(p,format_for_leo(val))
69 def __str__(self):
69 def __str__(self):
70 return "<TrivialLeoWorkbook>"
71 __repr__ = __str__
72
73 ip.user_ns['nodes'] = TrivialLeoWorkbook()
74
75
76 class LeoNode(object):
77 def __init__(self,p):
78 self.p = p.copy()
79
80 def get_h(self): return self.p.headString()
81 def set_h(self,val):
82 print "set head",val
83 c.setHeadString(self.p,val)
84
85 h = property( get_h, set_h)
86
87 def get_b(self): return self.p.bodyString()
88 def set_b(self,val):
89 print "set body",val
90 c.setBodyString(self.p, val)
91
92 b = property(get_b, set_b)
93
94 def set_val(self, val):
95 self.b = pprint.pformat(val)
96
97 val = property(lambda self: ip.ev(self.b.strip()), set_val)
98
99 def set_l(self,val):
100 self.b = '\n'.join(val )
101 l = property(lambda self : IPython.genutils.SList(self.b.splitlines()),
102 set_l)
103
104 def __iter__(self):
105 return (LeoNode(p) for p in self.p.children_iter())
106
107
108 class LeoWorkbook:
109 """ class for 'advanced' node access """
110 def __getattr__(self, key):
111 if key.startswith('_') or key == 'trait_names':
112 raise AttributeError
113 cells = all_cells()
114 p = cells.get(key, None)
115 if p is None:
116 p = add_var(key,None)
117
118 return LeoNode(p)
119
120 def __str__(self):
70 return "<LeoWorkbook>"
121 return "<LeoWorkbook>"
71 __repr__ = __str__
122 __repr__ = __str__
72 ip.user_ns['nodes'] = LeoWorkbook()
123 ip.user_ns['wb'] = LeoWorkbook()
124
73
125
74 _dummyval = object()
126 _dummyval = object()
75 @IPython.generics.complete_object.when_type(LeoWorkbook)
127 @IPython.generics.complete_object.when_type(LeoWorkbook)
@@ -89,8 +141,10 b' def add_var(varname, value = _dummyval):'
89 val = ip.user_ns[varname]
141 val = ip.user_ns[varname]
90 else:
142 else:
91 val = value
143 val = value
92 formatted = format_for_leo(val)
144 if val is not None:
93 c.setBodyString(p2,formatted)
145 formatted = format_for_leo(val)
146 c.setBodyString(p2,formatted)
147 return p2
94
148
95 def add_file(self,fname):
149 def add_file(self,fname):
96 p2 = c.currentPosition().insertAfter()
150 p2 = c.currentPosition().insertAfter()
General Comments 0
You need to be logged in to leave comments. Login now