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