##// END OF EJS Templates
qt4agg matplotlib backend support for pylab...
vivainio -
Show More
@@ -4,7 +4,7 b''
4 4 All the matplotlib support code was co-developed with John Hunter,
5 5 matplotlib's author.
6 6
7 $Id: Shell.py 1327 2006-05-25 03:33:58Z fperez $"""
7 $Id: Shell.py 1384 2006-06-29 20:04:37Z vivainio $"""
8 8
9 9 #*****************************************************************************
10 10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -847,6 +847,81 b' class IPShellQt(threading.Thread):'
847 847 self.timer.start( self.TIMEOUT, True )
848 848 return result
849 849
850
851 class IPShellQt4(threading.Thread):
852 """Run a Qt event loop in a separate thread.
853
854 Python commands can be passed to the thread where they will be executed.
855 This is implemented by periodically checking for passed code using a
856 Qt timer / slot."""
857
858 TIMEOUT = 100 # Millisecond interval between timeouts.
859
860 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
861 debug=0,shell_class=MTInteractiveShell):
862
863 from PyQt4 import QtCore, QtGui
864
865 class newQApplication:
866 def __init__( self ):
867 self.QApplication = QtGui.QApplication
868
869 def __call__( *args, **kwargs ):
870 return QtGui.qApp
871
872 def exec_loop( *args, **kwargs ):
873 pass
874
875 def __getattr__( self, name ):
876 return getattr( self.QApplication, name )
877
878 QtGui.QApplication = newQApplication()
879
880 # Allows us to use both Tk and QT.
881 self.tk = get_tk()
882
883 self.IP = make_IPython(argv,user_ns=user_ns,
884 user_global_ns=user_global_ns,
885 debug=debug,
886 shell_class=shell_class,
887 on_kill=[QtGui.qApp.exit])
888
889 # HACK: slot for banner in self; it will be passed to the mainloop
890 # method only and .run() needs it. The actual value will be set by
891 # .mainloop().
892 self._banner = None
893
894 threading.Thread.__init__(self)
895
896 def run(self):
897 self.IP.mainloop(self._banner)
898 self.IP.kill()
899
900 def mainloop(self,sys_exit=0,banner=None):
901
902 from PyQt4 import QtCore, QtGui
903
904 self._banner = banner
905
906 if QtGui.QApplication.startingUp():
907 a = QtGui.QApplication.QApplication(sys.argv)
908 self.timer = QtCore.QTimer()
909 QtCore.QObject.connect( self.timer, QtCore.SIGNAL( 'timeout()' ), self.on_timer )
910
911 self.start()
912 self.timer.start( self.TIMEOUT )
913 while True:
914 if self.IP._kill: break
915 QtGui.qApp.exec_()
916 self.join()
917
918 def on_timer(self):
919 update_tk(self.tk)
920 result = self.IP.runcode()
921 self.timer.start( self.TIMEOUT )
922 return result
923
924
850 925 # A set of matplotlib public IPython shell classes, for single-threaded
851 926 # (Tk* and FLTK* backends) and multithreaded (GTK* and WX* backends) use.
852 927 class IPShellMatplotlib(IPShell):
@@ -887,6 +962,15 b' class IPShellMatplotlibQt(IPShellQt):'
887 962 IPShellQt.__init__(self,argv,user_ns,user_global_ns,debug,
888 963 shell_class=MatplotlibMTShell)
889 964
965 class IPShellMatplotlibQt4(IPShellQt4):
966 """Subclass IPShellQt4 with MatplotlibMTShell as the internal shell.
967
968 Multi-threaded class, meant for the Qt4* backends."""
969
970 def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1):
971 IPShellQt4.__init__(self,argv,user_ns,user_global_ns,debug,
972 shell_class=MatplotlibMTShell)
973
890 974 #-----------------------------------------------------------------------------
891 975 # Factory functions to actually start the proper thread-aware shell
892 976
@@ -907,6 +991,8 b' def _matplotlib_shell_class():'
907 991 sh_class = IPShellMatplotlibGTK
908 992 elif backend.startswith('WX'):
909 993 sh_class = IPShellMatplotlibWX
994 elif backend.startswith('Qt4'):
995 sh_class = IPShellMatplotlibQt4
910 996 elif backend.startswith('Qt'):
911 997 sh_class = IPShellMatplotlibQt
912 998 else:
@@ -935,6 +1021,8 b' def start(user_ns = None):'
935 1021 shell = IPShellGTK
936 1022 elif arg1.endswith( '-qthread' ):
937 1023 shell = IPShellQt
1024 elif arg1.endswith( '-q4thread' ):
1025 shell = IPShellQt4
938 1026 elif arg1.endswith('-wthread'):
939 1027 shell = IPShellWX
940 1028 elif arg1.endswith('-pylab'):
@@ -6,7 +6,7 b' Requires Python 2.1 or better.'
6 6
7 7 This file contains the main make_IPython() starter function.
8 8
9 $Id: ipmaker.py 1355 2006-06-07 16:56:50Z vivainio $"""
9 $Id: ipmaker.py 1384 2006-06-29 20:04:37Z vivainio $"""
10 10
11 11 #*****************************************************************************
12 12 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -170,7 +170,7 b" object? -> Details about 'object'. ?object also works, ?? prints more."
170 170 # The "ignore" option is a kludge so that Emacs buffers don't crash, since
171 171 # the 'C-c !' command in emacs automatically appends a -i option at the end.
172 172 cmdline_only = ('help ignore|i ipythondir=s Version upgrade '
173 'gthread! qthread! wthread! pylab! tk!')
173 'gthread! qthread! q4thread! wthread! pylab! tk!')
174 174
175 175 # Build the actual name list to be used by DPyGetOpt
176 176 opts_names = qw(cmdline_opts) + qw(cmdline_only)
@@ -221,6 +221,7 b" object? -> Details about 'object'. ?object also works, ?? prints more."
221 221 system_verbose = 0,
222 222 gthread = 0,
223 223 qthread = 0,
224 q4thread = 0,
224 225 wthread = 0,
225 226 pylab = 0,
226 227 tk = 0,
@@ -1,3 +1,8 b''
1 2006-06-29 Ville Vainio <vivainio@gmail.com>
2
3 * ipmaker.py, Shell.py: qt4agg matplotlib backend support for pylab
4 mode, patch contributed by Darren Dale. NEEDS TESTING!
5
1 6 2006-06-28 Walter Doerwald <walter@livinglogic.de>
2 7
3 8 * IPython/Extensions/ibrowse.py: Give the ibrowse cursor row
General Comments 0
You need to be logged in to leave comments. Login now