Package vwidget :: Module pydialog
[hide private]
[frames] | no frames]

Source Code for Module vwidget.pydialog

 1   
 2  import os 
 3   
 4  from threading import Thread 
 5   
 6  import gtk 
 7  import vwidget 
 8  import vwidget.main as vw_main 
 9  import vwidget.windows as vw_windows 
10   
11 -class ScriptThread(Thread):
12 - def __init__(self, cobj, locals):
13 Thread.__init__(self) 14 self.setDaemon(True) 15 self.cobj = cobj 16 self.locals = locals
17
18 - def run(self):
19 try: 20 exec(self.cobj, self.locals) 21 except Exception, e: 22 print "Script Error: ",e
23
24 -class PyDialog(vw_windows.VWindow):
25 - def __init__(self, locals=None):
26 dname = os.path.dirname(vwidget.__file__) 27 fname = os.path.join(dname, "pydialog.glade") 28 vw_windows.VWindow.__init__(self, fname, None) 29 if locals == None: 30 locals = {} 31 self.locals = locals
32
33 - def PyDialogRun(self, button):
34 buffer = self.getWidget("PyDialogText").get_buffer() 35 start, end = buffer.get_bounds() 36 script = buffer.get_text(start,end) 37 self.runPython(script)
38
39 - def runPython(self, pystring):
40 """ 41 Extend and over-ride this for any special handling... 42 """ 43 cobj = compile(pystring, "pydialog_exec.py", "exec") 44 sthr = ScriptThread(cobj, self.locals) 45 sthr.start()
46 # FIXME set button insensitive and have ScriptThread take 47 # a reference to the dialog and change it back when run is complete 48