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 | |||
@@ -465,7 +464,9 b' class WxIPythonViewPanel(wx.Panel):' | |||||
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) |
@@ -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