Saturday, March 21, 2009

Turtle Fileview

A fileviewer for Turtle Art using the programmable Python brick

The Python brick code
def myblock(lc,x):
text=lc.heap.pop(-1)
if x==0:
dialog = gtk.FileChooserDialog("Load...", None, \
gtk.FILE_CHOOSER_ACTION_OPEN, \
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
fname = None
response = dialog.run()
if response == gtk.RESPONSE_OK:
fname = dialog.get_filename()
dialog.destroy()
f = open(fname, "r")
f.seek(0)
text = f.read()
f.close()
text="".join([z for z in text if ord(z)>0])
lc.heap.append(text)
lc.heap.append(text[int(x*500):int((x+1)*500)])
The file selection dialog box


Output screen, viewing a py file

Labels: , ,

0 Comments:

Post a Comment

<< Home