work on demo.py: sample running

This commit is contained in:
Alexander Mordvintsev 2011-08-21 07:54:54 +00:00
parent 0de8ed1099
commit 67cbcd2fa6

View File

@ -3,6 +3,7 @@ from ScrolledText import ScrolledText
from glob import glob from glob import glob
from common import splitfn from common import splitfn
import webbrowser import webbrowser
from subprocess import Popen
#from IPython.Shell import IPShellEmbed #from IPython.Shell import IPShellEmbed
#ipshell = IPShellEmbed() #ipshell = IPShellEmbed()
@ -70,15 +71,19 @@ class App:
self.samples[name] = fn self.samples[name] = fn
demos_lb.bind('<<ListboxSelect>>', self.on_demo_select) demos_lb.bind('<<ListboxSelect>>', self.on_demo_select)
self.text = text = ScrolledText(right, font=('arial', 12, 'normal'), width = 30, wrap='word') self.cmd_entry = cmd_entry = tk.Entry(right)
text.pack(fill='both', expand=1) run_btn = tk.Button(right, command=self.on_run, text='Run', width=8)
self.linker = linker = LinkManager(text, self.on_link)
self.text = text = ScrolledText(right, font=('arial', 12, 'normal'), width = 30, wrap='word')
self.linker = linker = LinkManager(text, self.on_link)
self.text.tag_config("header1", font=('arial', 14, 'bold')) self.text.tag_config("header1", font=('arial', 14, 'bold'))
self.text.tag_config("header2", font=('arial', 12, 'bold')) self.text.tag_config("header2", font=('arial', 12, 'bold'))
text.config(state='disabled') text.config(state='disabled')
text.pack(fill='both', expand=1, side=tk.BOTTOM)
cmd_entry.pack(fill='x', side='left' , expand=1)
run_btn.pack()
def on_link(self, url): def on_link(self, url):
print url print url
webbrowser.open(url) webbrowser.open(url)
@ -89,13 +94,16 @@ class App:
loc = {} loc = {}
execfile(fn, loc) execfile(fn, loc)
descr = loc.get('__doc__', 'no-description') descr = loc.get('__doc__', 'no-description')
self.linker.reset() self.linker.reset()
self.text.config(state='normal') self.text.config(state='normal')
self.text.delete(1.0, tk.END) self.text.delete(1.0, tk.END)
self.format_text(descr) self.format_text(descr)
self.text.config(state='disabled') self.text.config(state='disabled')
self.cmd_entry.delete(0, tk.END)
self.cmd_entry.insert(0, fn)
def format_text(self, s): def format_text(self, s):
text = self.text text = self.text
lines = s.splitlines() lines = s.splitlines()
@ -129,6 +137,11 @@ class App:
else: else:
text.tag_add(tag_proc, match_index, end_index) text.tag_add(tag_proc, match_index, end_index)
def on_run(self):
cmd = self.cmd_entry.get()
print 'running:', cmd
Popen(cmd, shell=True)
def run(self): def run(self):
tk.mainloop() tk.mainloop()