Show More
@@ -1,7 +1,7 b'' | |||||
1 | #!/usr/bin/python |
|
1 | #!/usr/bin/python | |
2 | # -*- coding: iso-8859-15 -*- |
|
2 | # -*- coding: iso-8859-15 -*- | |
3 | ''' |
|
3 | ''' | |
4 | Provides IPython WX console widget. |
|
4 | Provides IPython WX console widgets. | |
5 |
|
5 | |||
6 | @author: Laurent Dufrechou |
|
6 | @author: Laurent Dufrechou | |
7 | laurent.dufrechou _at_ gmail.com |
|
7 | laurent.dufrechou _at_ gmail.com | |
@@ -33,7 +33,6 b' import sys' | |||||
33 | import os |
|
33 | import os | |
34 | import locale |
|
34 | import locale | |
35 | import time |
|
35 | import time | |
36 | #from ThreadEx import Thread |
|
|||
37 | from StringIO import StringIO |
|
36 | from StringIO import StringIO | |
38 | try: |
|
37 | try: | |
39 | import IPython |
|
38 | import IPython | |
@@ -41,11 +40,11 b' except Exception,e:' | |||||
41 | raise "Error importing IPython (%s)" % str(e) |
|
40 | raise "Error importing IPython (%s)" % str(e) | |
42 |
|
41 | |||
43 |
|
42 | |||
44 |
from |
|
43 | from non_blocking_ip_shell import * | |
45 |
|
44 | |||
46 |
class Wx |
|
45 | class WxNonBlockingIPShell(NonBlockingIPShell): | |
47 | ''' |
|
46 | ''' | |
48 |
An |
|
47 | An NonBlockingIPShell Thread that is WX dependent. | |
49 | Thus it permits direct interaction with a WX GUI without OnIdle event state machine trick... |
|
48 | Thus it permits direct interaction with a WX GUI without OnIdle event state machine trick... | |
50 | ''' |
|
49 | ''' | |
51 | def __init__(self,wx_instance, |
|
50 | def __init__(self,wx_instance, | |
@@ -54,7 +53,7 b' class WxIterableIPShell(IterableIPShell):' | |||||
54 | exit_handler=None,time_loop = 0.1): |
|
53 | exit_handler=None,time_loop = 0.1): | |
55 |
|
54 | |||
56 | user_ns['addGUIShortcut'] = self.addGUIShortcut |
|
55 | user_ns['addGUIShortcut'] = self.addGUIShortcut | |
57 |
|
|
56 | NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns, | |
58 | cin, cout, cerr, |
|
57 | cin, cout, cerr, | |
59 | exit_handler,time_loop) |
|
58 | exit_handler,time_loop) | |
60 |
|
59 | |||
@@ -464,8 +463,10 b' class WxIPythonViewPanel(wx.Panel):' | |||||
464 | I've choosed to derivate from a wx.Panel because it seems to be ore usefull |
|
463 | I've choosed to derivate from a wx.Panel because it seems to be ore usefull | |
465 | Any idea to make it more 'genric' welcomed. |
|
464 | Any idea to make it more 'genric' welcomed. | |
466 | ''' |
|
465 | ''' | |
467 | def __init__(self,parent,exit_handler=None,intro=None, |
|
466 | def __init__(self, parent, exit_handler=None, intro=None, | |
468 |
background_color="BLACK",add_button_handler=None |
|
467 | background_color="BLACK", add_button_handler=None, | |
|
468 | wx_ip_shell=None, | |||
|
469 | ): | |||
469 | ''' |
|
470 | ''' | |
470 | Initialize. |
|
471 | Initialize. | |
471 | Instanciate an IPython thread. |
|
472 | Instanciate an IPython thread. | |
@@ -480,7 +481,10 b' class WxIPythonViewPanel(wx.Panel):' | |||||
480 | self.add_button_handler = add_button_handler |
|
481 | self.add_button_handler = add_button_handler | |
481 | self.exit_handler = exit_handler |
|
482 | self.exit_handler = exit_handler | |
482 |
|
483 | |||
483 | self.IP = WxIterableIPShell(self, |
|
484 | if wx_ip_shell is not None: | |
|
485 | self.IP = wx_ip_shell | |||
|
486 | else: | |||
|
487 | self.IP = WxNonBlockingIPShell(self, | |||
484 | cout=self.cout,cerr=self.cout, |
|
488 | cout=self.cout,cerr=self.cout, | |
485 | exit_handler = exit_handler, |
|
489 | exit_handler = exit_handler, | |
486 | time_loop = 0.1) |
|
490 | time_loop = 0.1) | |
@@ -526,7 +530,7 b' class WxIPythonViewPanel(wx.Panel):' | |||||
526 | # 'SHOW_PROMPT'] |
|
530 | # 'SHOW_PROMPT'] | |
527 |
|
531 | |||
528 | self.cur_state = 'IDLE' |
|
532 | self.cur_state = 'IDLE' | |
529 |
|
|
533 | self.pager_state = 'DONE' | |
530 | #wx.CallAfter(self.runStateMachine) |
|
534 | #wx.CallAfter(self.runStateMachine) | |
531 |
|
535 | |||
532 | # This creates a new Event class and a EVT binder function |
|
536 | # This creates a new Event class and a EVT binder function | |
@@ -578,9 +582,9 b' class WxIPythonViewPanel(wx.Panel):' | |||||
578 | if rv: rv = rv.strip('\n') |
|
582 | if rv: rv = rv.strip('\n') | |
579 | self.text_ctrl.showReturned(rv) |
|
583 | self.text_ctrl.showReturned(rv) | |
580 | self.cout.truncate(0) |
|
584 | self.cout.truncate(0) | |
581 |
|
|
585 | self.IP.initHistoryIndex() | |
582 |
|
|
586 | self.cur_state = 'IDLE' | |
583 |
|
587 | |||
584 | ## def runStateMachine(self,event): |
|
588 | ## def runStateMachine(self,event): | |
585 | ## #print >>sys.__stdout__,"state:",self.cur_state |
|
589 | ## #print >>sys.__stdout__,"state:",self.cur_state | |
586 | ## self.updateStatusTracker(self.cur_state) |
|
590 | ## self.updateStatusTracker(self.cur_state) | |
@@ -598,8 +602,8 b' class WxIPythonViewPanel(wx.Panel):' | |||||
598 | ## self.doc = self.IP.getDocText() |
|
602 | ## self.doc = self.IP.getDocText() | |
599 | ## if self.doc: |
|
603 | ## if self.doc: | |
600 | ## self.pager_state = 'INIT' |
|
604 | ## self.pager_state = 'INIT' | |
601 |
## |
|
605 | ## self.cur_state = 'SHOW_DOC' | |
602 |
## |
|
606 | ## #if self.button: | |
603 | ## #self.IP.doExecute('print "cool"')#self.button['func']) |
|
607 | ## #self.IP.doExecute('print "cool"')#self.button['func']) | |
604 | ## #self.updateHistoryTracker(self.text_ctrl.getCurrentLine()) |
|
608 | ## #self.updateHistoryTracker(self.text_ctrl.getCurrentLine()) | |
605 | ## |
|
609 | ## |
@@ -23,7 +23,7 b' import os' | |||||
23 | import locale |
|
23 | import locale | |
24 | import time |
|
24 | import time | |
25 | import pydoc,__builtin__,site |
|
25 | import pydoc,__builtin__,site | |
26 |
from |
|
26 | from thread_ex import ThreadEx | |
27 | from StringIO import StringIO |
|
27 | from StringIO import StringIO | |
28 |
|
28 | |||
29 | try: |
|
29 | try: | |
@@ -57,13 +57,13 b' class _Helper(object):' | |||||
57 | return pydoc.help(*args, **kwds) |
|
57 | return pydoc.help(*args, **kwds) | |
58 |
|
58 | |||
59 |
|
59 | |||
60 |
class |
|
60 | class NonBlockingIPShell(ThreadEx): | |
61 | ''' |
|
61 | ''' | |
62 | Create an IPython instance inside a dedicated thread. |
|
62 | Create an IPython instance inside a dedicated thread. | |
63 | Does not start a blocking event loop, instead allow single iterations. |
|
63 | Does not start a blocking event loop, instead allow single iterations. | |
64 | This allows embedding in any GUI without blockage. |
|
64 | This allows embedding in any GUI without blockage. | |
65 | The thread is a slave one, in that it doesn't interact directly with the GUI. |
|
65 | The thread is a slave one, in that it doesn't interact directly with the GUI. | |
66 |
Note Thread class |
|
66 | Note ThreadEx class supports asynchroneous function call | |
67 | via raise_exc() |
|
67 | via raise_exc() | |
68 | ''' |
|
68 | ''' | |
69 |
|
69 | |||
@@ -89,7 +89,7 b' class IterableIPShell(Thread):' | |||||
89 | @param time_loop: Define the sleep time between two thread's loop |
|
89 | @param time_loop: Define the sleep time between two thread's loop | |
90 | @type int |
|
90 | @type int | |
91 | ''' |
|
91 | ''' | |
92 | Thread.__init__(self) |
|
92 | ThreadEx.__init__(self) | |
93 |
|
93 | |||
94 | #first we redefine in/out/error functions of IPython |
|
94 | #first we redefine in/out/error functions of IPython | |
95 | if cin: |
|
95 | if cin: |
@@ -1,3 +1,8 b'' | |||||
|
1 | """ | |||
|
2 | Thread subclass that can deal with asynchronously function calls via | |||
|
3 | raise_exc. | |||
|
4 | """ | |||
|
5 | ||||
1 | import threading |
|
6 | import threading | |
2 | import inspect |
|
7 | import inspect | |
3 | import ctypes |
|
8 | import ctypes | |
@@ -17,7 +22,7 b' def _async_raise(tid, exctype):' | |||||
17 | raise SystemError("PyThreadState_SetAsyncExc failed") |
|
22 | raise SystemError("PyThreadState_SetAsyncExc failed") | |
18 |
|
23 | |||
19 |
|
24 | |||
20 | class Thread(threading.Thread): |
|
25 | class ThreadEx(threading.Thread): | |
21 | def _get_my_tid(self): |
|
26 | def _get_my_tid(self): | |
22 | """determines this (self's) thread id""" |
|
27 | """determines this (self's) thread id""" | |
23 | if not self.isAlive(): |
|
28 | if not self.isAlive(): |
General Comments 0
You need to be logged in to leave comments.
Login now