##// END OF EJS Templates
code cleanup: IPShellQt and IPShellQt4
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 2755 2007-09-09 20:10:30Z darren.dale $"""
7 $Id: Shell.py 2756 2007-09-10 18:25:30Z 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>
@@ -877,33 +877,45 b' class IPShellQt(IPThread):'
877 Python commands can be passed to the thread where they will be executed.
877 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
878 This is implemented by periodically checking for passed code using a
879 Qt timer / slot."""
879 Qt timer / slot."""
880
880
881 TIMEOUT = 100 # Millisecond interval between timeouts.
881 TIMEOUT = 100 # Millisecond interval between timeouts.
882
882
883 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
883 def __init__(self, argv=None, user_ns=None, user_global_ns=None,
884 debug=0,shell_class=MTInteractiveShell):
884 debug=0, shell_class=MTInteractiveShell):
885
885
886 import qt
886 import qt
887
887
888 class newQApplication:
888 self.qApp = qt.qApp
889 def __init__( self ):
890 self.QApplication = qt.QApplication
891
892 def __call__( *args, **kwargs ):
893 return qt.qApp
894
889
895 def exec_loop( *args, **kwargs ):
890 class DummyQApp:
891 def __init__(self, *args):
892 self.qApp = qt.qApp
893
894 def exec_loop(*args, **kwargs):
896 pass
895 pass
897
896
897 def __getattr__(self, name):
898 return getattr(self.qApp, name)
899
900 class DummyQApplication:
901 def __init__(self):
902 self.QApplication = qt.QApplication
903
904 def __call__(*args, **kwargs):
905 # mask until module NoneType errors can be fixed
906 # return DummyQApp()
907 return qt.qApp
908
898 def __getattr__( self, name ):
909 def __getattr__( self, name ):
899 return getattr( self.QApplication, name )
910 return getattr(self.QApplication, name)
900
911
901 qt.QApplication = newQApplication()
912 qt.QApplication = DummyQApplication()
902
913
903 # Allows us to use both Tk and QT.
914 # Allows us to use both Tk and QT.
904 self.tk = get_tk()
915 self.tk = get_tk()
905
916
906 self.IP = make_IPython(argv,user_ns=user_ns,
917 self.IP = make_IPython(argv,
918 user_ns=user_ns,
907 user_global_ns=user_global_ns,
919 user_global_ns=user_global_ns,
908 debug=debug,
920 debug=debug,
909 shell_class=shell_class,
921 shell_class=shell_class,
@@ -923,21 +935,26 b' class IPShellQt(IPThread):'
923 self._banner = banner
935 self._banner = banner
924
936
925 if qt.QApplication.startingUp():
937 if qt.QApplication.startingUp():
926 a = qt.QApplication.QApplication(sys.argv)
938 self.qApp = qt.QApplication.QApplication(sys.argv)
939 # mask until module NoneType errors can be fixed
940 # qt.qApp = qt.QApplication()
941
927 self.timer = qt.QTimer()
942 self.timer = qt.QTimer()
928 qt.QObject.connect( self.timer, qt.SIGNAL( 'timeout()' ), self.on_timer )
943 qt.QObject.connect(self.timer,
944 qt.SIGNAL( 'timeout()' ),
945 self.on_timer)
929
946
930 self.start()
947 self.start()
931 self.timer.start( self.TIMEOUT, True )
948 self.timer.start(self.TIMEOUT, True)
932 while True:
949 while True:
933 if self.IP._kill: break
950 if self.IP._kill: break
934 qt.qApp.exec_loop()
951 self.qApp.exec_loop()
935 self.join()
952 self.join()
936
953
937 def on_timer(self):
954 def on_timer(self):
938 update_tk(self.tk)
955 update_tk(self.tk)
939 result = self.IP.runcode()
956 result = self.IP.runcode()
940 self.timer.start( self.TIMEOUT, True )
957 self.timer.start(self.TIMEOUT, True)
941 return result
958 return result
942
959
943
960
@@ -950,30 +967,42 b' class IPShellQt4(IPThread):'
950
967
951 TIMEOUT = 100 # Millisecond interval between timeouts.
968 TIMEOUT = 100 # Millisecond interval between timeouts.
952
969
953 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
970 def __init__(self, argv=None, user_ns=None, user_global_ns=None,
954 debug=0,shell_class=MTInteractiveShell):
971 debug=0, shell_class=MTInteractiveShell):
955
972
956 from PyQt4 import QtCore, QtGui
973 from PyQt4 import QtCore, QtGui
957
974
958 class newQApplication:
975 self.qApp = QtGui.qApp
959 def __init__( self ):
960 self.QApplication = QtGui.QApplication
961
976
962 def __call__( *args, **kwargs ):
977 class DummyQApp:
963 return QtGui.qApp
978 def __init__(self, *args):
979 self.qApp = QtGui.qApp
964
980
965 def exec_loop( *args, **kwargs ):
981 def exec_(*args, **kwargs):
966 pass
982 pass
967
983
968 def __getattr__( self, name ):
984 def __getattr__(self, name):
969 return getattr( self.QApplication, name )
985 return getattr(self.qApp, name)
986
987 class DummyQApplication:
988 def __init__(self, *args):
989 self.QApplication = QtGui.QApplication
990
991 def __call__(*args, **kwargs):
992 # mask until module NoneType errors can be fixed
993 # return DummyQApp()
994 return QtGui.qApp
995
996 def __getattr__(self, name):
997 return getattr(self.QApplication, name)
970
998
971 QtGui.QApplication = newQApplication()
999 QtGui.QApplication = DummyQApplication()
972
1000
973 # Allows us to use both Tk and QT.
1001 # Allows us to use both Tk and QT.
974 self.tk = get_tk()
1002 self.tk = get_tk()
975
1003
976 self.IP = make_IPython(argv,user_ns=user_ns,
1004 self.IP = make_IPython(argv,
1005 user_ns=user_ns,
977 user_global_ns=user_global_ns,
1006 user_global_ns=user_global_ns,
978 debug=debug,
1007 debug=debug,
979 shell_class=shell_class,
1008 shell_class=shell_class,
@@ -986,28 +1015,33 b' class IPShellQt4(IPThread):'
986
1015
987 threading.Thread.__init__(self)
1016 threading.Thread.__init__(self)
988
1017
989 def mainloop(self,sys_exit=0,banner=None):
1018 def mainloop(self, sys_exit=0, banner=None):
990
1019
991 from PyQt4 import QtCore, QtGui
1020 from PyQt4 import QtCore, QtGui
992
1021
993 self._banner = banner
1022 self._banner = banner
994
1023
995 if QtGui.QApplication.startingUp():
1024 if QtGui.QApplication.startingUp():
996 a = QtGui.QApplication.QApplication(sys.argv)
1025 self.qApp = QtGui.QApplication.QApplication(sys.argv)
1026 # mask until module NoneType errors can be fixed
1027 # QtGui.qApp = QtGui.QApplication()
1028
997 self.timer = QtCore.QTimer()
1029 self.timer = QtCore.QTimer()
998 QtCore.QObject.connect( self.timer, QtCore.SIGNAL( 'timeout()' ), self.on_timer )
1030 QtCore.QObject.connect(self.timer,
1031 QtCore.SIGNAL('timeout()'),
1032 self.on_timer)
999
1033
1000 self.start()
1034 self.start()
1001 self.timer.start( self.TIMEOUT )
1035 self.timer.start(self.TIMEOUT)
1002 while True:
1036 while True:
1037 self.qApp.exec_()
1003 if self.IP._kill: break
1038 if self.IP._kill: break
1004 QtGui.qApp.exec_()
1005 self.join()
1039 self.join()
1006
1040
1007 def on_timer(self):
1041 def on_timer(self):
1008 update_tk(self.tk)
1042 update_tk(self.tk)
1009 result = self.IP.runcode()
1043 result = self.IP.runcode()
1010 self.timer.start( self.TIMEOUT )
1044 self.timer.start(self.TIMEOUT)
1011 return result
1045 return result
1012
1046
1013
1047
@@ -1,3 +1,7 b''
1 2007-09-10 Darren Dale <dd55@cornell.edu>
2
3 * Cleanup of IPShellQt and IPShellQt4
4
1 2007-09-09 Fernando Perez <Fernando.Perez@colorado.edu>
5 2007-09-09 Fernando Perez <Fernando.Perez@colorado.edu>
2
6
3 * IPython/FakeModule.py (FakeModule.__init__): further fixes for
7 * IPython/FakeModule.py (FakeModule.__init__): further fixes for
General Comments 0
You need to be logged in to leave comments. Login now