Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/functions.py
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-07-12 21:27:49 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-07-12 21:27:49 (GMT)
commit34c57e25682b368404c37de0a270557cd1b124f8 (patch)
tree2516b8b40debcd7e1b9df404f5bcbaaa40e766e6 /functions.py
parent083f5a865d5c4e3fa95382dc1e8d73d9c69ca96a (diff)
Evaluate function
Diffstat (limited to 'functions.py')
-rw-r--r--functions.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/functions.py b/functions.py
index 996634e..44e6c29 100644
--- a/functions.py
+++ b/functions.py
@@ -46,7 +46,7 @@ class FunctionsList(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.grab_focus()
- self.model = gtk.ListStore(object, str, str)
+ self.model = gtk.ListStore(object, str, str, str)
self.set_model(self.model)
column = gtk.TreeViewColumn()
color_renderer = CellRendererIcon(self)
@@ -69,10 +69,29 @@ class FunctionsList(gtk.TreeView):
column.add_attribute(text_renderer, 'text', 2)
self.set_headers_visible(False)
self.append_column(column)
+ self.evaluating_column = gtk.TreeViewColumn()
+ y_renderer = gtk.CellRendererText()
+ y_renderer.set_property('text', ' = ')
+ self.evaluating_column.pack_start(y_renderer)
+ evaluation_cell = gtk.CellRendererText()
+ self.evaluating_column.pack_start(evaluation_cell)
+ self.evaluating_column.add_attribute(evaluation_cell, 'text', 3)
+ self.append_column(self.evaluating_column)
+ self.evaluating_column.set_visible(False)
self.selection = self.get_selection()
self.selection.set_select_function(self.update_color)
self.updating_color = False
+ def evaluate(self, safe_dict):
+ for func in self.model:
+ if not safe_dict['x']:
+ self.evaluating_column.set_visible(False)
+ return
+ result = eval(func[2].replace('^', '**'),
+ {'__builtins__': {}}, safe_dict)
+ func[3] = str(result)
+ self.evaluating_column.set_visible(True)
+
def set_current_line_color(self, color):
if not self.updating_color:
rows = self.selection.get_selected_rows()
@@ -104,7 +123,7 @@ class FunctionsList(gtk.TreeView):
self.selection.select_iter(self.model.append([XoColor(color + "," +\
color),
"y%d = " % len(self.model),
- "sin(x)"]))
+ "sin(x)", None]))
def remove_function(self):
rows = self.selection.get_selected_rows()