diff -r ccbf96145796 -r 89d76549ba6e caurender.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/caurender.py Thu Dec 30 14:22:05 2010 +0100 @@ -0,0 +1,46 @@ +import Tkinter as tk +from caugrid import Grid + +class Render(object): + def __init__(self, title, width, height): + self.title = title + self.width = width + self.height = height + self.root = tk.Tk(className=title, sync=1) + self.canvas = tk.Canvas(width=self.width, height=self.height, bg="black") + self.canvas.pack(expand=tk.YES, fill=tk.BOTH) + def render(self, grid): + offset = (self.width / 2, self.height / 2) + size = 1 + cell_ids = [] + for pos in grid.cells.iterkeys(): + x = pos[0] + offset[0] + y = pos[1] + offset[1] + cell_id = self.canvas.create_rectangle(x, y, x+size, y+size, + fill="yellow", width=0) + cell_ids.append(cell_id) + self.root.update() + for cell_id in cell_ids: + self.canvas.delete(cell_id) + +import sys +import time +import caumarshal as marshal +import os, stat + +def main(): + filename = sys.argv[1] + print "rendering ", filename + render = Render("hope", 800, 800) + mod_time = 0 + while True: + current = os.stat(filename)[stat.ST_MTIME] + if current > mod_time: + mod_time = current + print "updating render" + grid = marshal.loadGrid(filename) + render.render(grid) + time.sleep(1) + +if __name__ == "__main__": + main()