Commit 1a7e359b authored by Georg Brandl's avatar Georg Brandl

Remove usage of rexec in tkinter demo.

parent a7e071f0
...@@ -4,7 +4,6 @@ import os ...@@ -4,7 +4,6 @@ import os
import re import re
import sys import sys
import cgi import cgi
import rexec
from xml.parsers import expat from xml.parsers import expat
LEFT, CENTER, RIGHT = "LEFT", "CENTER", "RIGHT" LEFT, CENTER, RIGHT = "LEFT", "CENTER", "RIGHT"
...@@ -33,16 +32,16 @@ class Sheet: ...@@ -33,16 +32,16 @@ class Sheet:
def __init__(self): def __init__(self):
self.cells = {} # {(x, y): cell, ...} self.cells = {} # {(x, y): cell, ...}
self.rexec = rexec.RExec() self.ns = dict(
m = self.rexec.add_module('__main__') cell = self.cellvalue,
m.cell = self.cellvalue cells = self.multicellvalue,
m.cells = self.multicellvalue sum = sum,
m.sum = sum )
def cellvalue(self, x, y): def cellvalue(self, x, y):
cell = self.getcell(x, y) cell = self.getcell(x, y)
if hasattr(cell, 'recalc'): if hasattr(cell, 'recalc'):
return cell.recalc(self.rexec) return cell.recalc(self.ns)
else: else:
return cell return cell
...@@ -144,7 +143,7 @@ class Sheet: ...@@ -144,7 +143,7 @@ class Sheet:
self.reset() self.reset()
for cell in self.cells.values(): for cell in self.cells.values():
if hasattr(cell, 'recalc'): if hasattr(cell, 'recalc'):
cell.recalc(self.rexec) cell.recalc(self.ns)
def display(self): def display(self):
maxx, maxy = self.getsize() maxx, maxy = self.getsize()
...@@ -164,7 +163,7 @@ class Sheet: ...@@ -164,7 +163,7 @@ class Sheet:
if x <= 0 or y <= 0: if x <= 0 or y <= 0:
continue continue
if hasattr(cell, 'recalc'): if hasattr(cell, 'recalc'):
cell.recalc(self.rexec) cell.recalc(self.ns)
if hasattr(cell, 'format'): if hasattr(cell, 'format'):
text, alignment = cell.format() text, alignment = cell.format()
assert isinstance(text, str) assert isinstance(text, str)
...@@ -317,7 +316,7 @@ class BaseCell: ...@@ -317,7 +316,7 @@ class BaseCell:
Subclasses may but needn't provide the following APIs: Subclasses may but needn't provide the following APIs:
cell.reset() -- prepare for recalculation cell.reset() -- prepare for recalculation
cell.recalc(rexec) -> value -- recalculate formula cell.recalc(ns) -> value -- recalculate formula
cell.format() -> (value, alignment) -- return formatted value cell.format() -> (value, alignment) -- return formatted value
cell.xml() -> string -- return XML cell.xml() -> string -- return XML
""" """
...@@ -331,7 +330,7 @@ class NumericCell(BaseCell): ...@@ -331,7 +330,7 @@ class NumericCell(BaseCell):
self.fmt = fmt self.fmt = fmt
self.alignment = alignment self.alignment = alignment
def recalc(self, rexec): def recalc(self, ns):
return self.value return self.value
def format(self): def format(self):
...@@ -372,7 +371,7 @@ class StringCell(BaseCell): ...@@ -372,7 +371,7 @@ class StringCell(BaseCell):
self.fmt = fmt self.fmt = fmt
self.alignment = alignment self.alignment = alignment
def recalc(self, rexec): def recalc(self, ns):
return self.text return self.text
def format(self): def format(self):
...@@ -398,13 +397,11 @@ class FormulaCell(BaseCell): ...@@ -398,13 +397,11 @@ class FormulaCell(BaseCell):
def reset(self): def reset(self):
self.value = None self.value = None
def recalc(self, rexec): def recalc(self, ns):
if self.value is None: if self.value is None:
try: try:
# A hack to evaluate expressions using true division # A hack to evaluate expressions using true division
rexec.r_exec("from __future__ import division\n" + self.value = eval(self.translated, ns)
"__value__ = eval(%s)" % repr(self.translated))
self.value = rexec.r_eval("__value__")
except: except:
exc = sys.exc_info()[0] exc = sys.exc_info()[0]
if hasattr(exc, "__name__"): if hasattr(exc, "__name__"):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment