##// END OF EJS Templates
finish IPShellQt[4] improvements, hijacking mainloop ...
darren.dale -
Show More
@@ -4,7 +4,7 b''
4 All the matplotlib support code was co-developed with John Hunter,
4 All the matplotlib support code was co-developed with John Hunter,
5 matplotlib's author.
5 matplotlib's author.
6
6
7 $Id: Shell.py 2758 2007-09-10 20:56:27Z darren.dale $"""
7 $Id: Shell.py 2760 2007-09-11 17:30:32Z darren.dale $"""
8
8
9 #*****************************************************************************
9 #*****************************************************************************
10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -46,7 +46,6 b' from IPython.ipmaker import make_IPython'
46 from IPython.Magic import Magic
46 from IPython.Magic import Magic
47 from IPython.ipstruct import Struct
47 from IPython.ipstruct import Struct
48
48
49
50 # Globals
49 # Globals
51 # global flag to pass around information about Ctrl-C without exceptions
50 # global flag to pass around information about Ctrl-C without exceptions
52 KBINT = False
51 KBINT = False
@@ -877,7 +876,7 b' class IPShellQt(IPThread):'
877 Python commands can be passed to the thread where they will be executed.
876 Python commands can be passed to the thread where they will be executed.
878 This is implemented by periodically checking for passed code using a
877 This is implemented by periodically checking for passed code using a
879 Qt timer / slot."""
878 Qt timer / slot."""
880
879
881 TIMEOUT = 100 # Millisecond interval between timeouts.
880 TIMEOUT = 100 # Millisecond interval between timeouts.
882
881
883 def __init__(self, argv=None, user_ns=None, user_global_ns=None,
882 def __init__(self, argv=None, user_ns=None, user_global_ns=None,
@@ -885,6 +884,14 b' class IPShellQt(IPThread):'
885
884
886 import qt
885 import qt
887
886
887 def dummy_mainloop(*args, **kwargs):
888 pass
889
890 self.exec_loop = qt.qApp.exec_loop
891
892 qt.qApp.exec_loop = dummy_mainloop
893 qt.QApplication.exec_loop = dummy_mainloop
894
888 # Allows us to use both Tk and QT.
895 # Allows us to use both Tk and QT.
889 self.tk = get_tk()
896 self.tk = get_tk()
890
897
@@ -902,25 +909,25 b' class IPShellQt(IPThread):'
902
909
903 threading.Thread.__init__(self)
910 threading.Thread.__init__(self)
904
911
905 def mainloop(self,sys_exit=0,banner=None):
912 def mainloop(self, sys_exit=0, banner=None):
906
913
907 import qt
914 import qt
908
915
909 self._banner = banner
916 self._banner = banner
910
917
911 if qt.QApplication.startingUp():
918 if qt.QApplication.startingUp():
912 self.qApp = qt.QApplication(sys.argv)
919 a = qt.QApplication(sys.argv)
913
920
914 self.timer = qt.QTimer()
921 self.timer = qt.QTimer()
915 qt.QObject.connect(self.timer,
922 qt.QObject.connect(self.timer,
916 qt.SIGNAL( 'timeout()' ),
923 qt.SIGNAL('timeout()'),
917 self.on_timer)
924 self.on_timer)
918
925
919 self.start()
926 self.start()
920 self.timer.start(self.TIMEOUT, True)
927 self.timer.start(self.TIMEOUT, True)
921 while True:
928 while True:
922 if self.IP._kill: break
929 if self.IP._kill: break
923 qt.qApp.exec_loop()
930 self.exec_loop()
924 self.join()
931 self.join()
925
932
926 def on_timer(self):
933 def on_timer(self):
@@ -929,6 +936,7 b' class IPShellQt(IPThread):'
929 self.timer.start(self.TIMEOUT, True)
936 self.timer.start(self.TIMEOUT, True)
930 return result
937 return result
931
938
939
932 class IPShellQt4(IPThread):
940 class IPShellQt4(IPThread):
933 """Run a Qt event loop in a separate thread.
941 """Run a Qt event loop in a separate thread.
934
942
@@ -942,6 +950,15 b' class IPShellQt4(IPThread):'
942 debug=0, shell_class=MTInteractiveShell):
950 debug=0, shell_class=MTInteractiveShell):
943
951
944 from PyQt4 import QtCore, QtGui
952 from PyQt4 import QtCore, QtGui
953
954 def dummy_mainloop(*args, **kwargs):
955 pass
956
957 self.exec_ = QtGui.qApp.exec_
958
959 QtGui.qApp.exec_ = dummy_mainloop
960 QtGui.QApplication.exec_ = dummy_mainloop
961 QtCore.QCoreApplication.exec_ = dummy_mainloop
945
962
946 # Allows us to use both Tk and QT.
963 # Allows us to use both Tk and QT.
947 self.tk = get_tk()
964 self.tk = get_tk()
@@ -967,7 +984,7 b' class IPShellQt4(IPThread):'
967 self._banner = banner
984 self._banner = banner
968
985
969 if QtGui.QApplication.startingUp():
986 if QtGui.QApplication.startingUp():
970 self.qApp = QtGui.QApplication(sys.argv)
987 a = QtGui.QApplication(sys.argv)
971
988
972 self.timer = QtCore.QTimer()
989 self.timer = QtCore.QTimer()
973 QtCore.QObject.connect(self.timer,
990 QtCore.QObject.connect(self.timer,
@@ -978,7 +995,7 b' class IPShellQt4(IPThread):'
978 self.timer.start(self.TIMEOUT)
995 self.timer.start(self.TIMEOUT)
979 while True:
996 while True:
980 if self.IP._kill: break
997 if self.IP._kill: break
981 QtGui.qApp.exec_()
998 self.exec_()
982 self.join()
999 self.join()
983
1000
984 def on_timer(self):
1001 def on_timer(self):
General Comments 0
You need to be logged in to leave comments. Login now