##// END OF EJS Templates
Work on the user focused GUI event loop interface....
Brian Granger -
Show More
@@ -42,6 +42,7 b' import __builtin__'
42 42 import os
43 43 import sys
44 44 from pprint import pprint
45 import warnings
45 46
46 47 # Our own
47 48 from IPython.utils import DPyGetOpt
@@ -53,6 +54,7 b' from IPython.core.iplib import InteractiveShell'
53 54 from IPython.core.usage import cmd_line_usage, interactive_usage
54 55 from IPython.utils.genutils import *
55 56
57
56 58 def force_import(modname,force_reload=False):
57 59 if modname in sys.modules and force_reload:
58 60 info("reloading: %s" % modname)
@@ -61,6 +63,16 b' def force_import(modname,force_reload=False):'
61 63 __import__(modname)
62 64
63 65
66 def threaded_shell_warning():
67 msg = """
68
69 The IPython threaded shells and their associated command line
70 arguments (pylab/wthread/gthread/qthread/q4thread) have been
71 deprecated. See the %gui magic for information on the new interface.
72 """
73 warnings.warn(msg, category=DeprecationWarning, stacklevel=1)
74
75
64 76 #-----------------------------------------------------------------------------
65 77 def make_IPython(argv=None,user_ns=None,user_global_ns=None,debug=1,
66 78 rc_override=None,shell_class=InteractiveShell,
@@ -330,6 +342,13 b" object? -> Details about 'object'. ?object also works, ?? prints more."
330 342 IP.magic_magic('-latex')
331 343 sys.exit()
332 344
345 # Display the deprecation warnings about threaded shells
346 if opts_all.pylab == 1: threaded_shell_warning()
347 if opts_all.wthread == 1: threaded_shell_warning()
348 if opts_all.qthread == 1: threaded_shell_warning()
349 if opts_all.q4thread == 1: threaded_shell_warning()
350 if opts_all.gthread == 1: threaded_shell_warning()
351
333 352 # add personal ipythondir to sys.path so that users can put things in
334 353 # there for customization
335 354 sys.path.append(os.path.abspath(opts_all.ipythondir))
@@ -3524,4 +3524,47 b' Defaulting color scheme to \'NoColor\'"""'
3524 3524 print 'Doctest mode is:',
3525 3525 print ['OFF','ON'][dstore.mode]
3526 3526
3527 def magic_gui(self, parameter_s=''):
3528 """Enable or disable IPython GUI event loop integration.
3529
3530 This magic replaces IPython's threaded shells that were activated
3531 using the (pylab/wthread/etc.) command line flags. GUI toolkits
3532 can now be enabled, disabled and swtiched at runtime and keyboard
3533 interrupts should work without any problems. The following toolkits
3534 are supports: wxPython, PyQt4, PyGTK, and Tk::
3535
3536 %gui wx # enable wxPython event loop integration
3537 %gui qt4 # enable PyQt4 event loop integration
3538 %gui gtk # enable PyGTK event loop integration
3539 %gui tk # enable Tk event loop integration
3540 %gui # disable all event loop integration
3541
3542 WARNING: after any of these has been called you can simply create
3543 an application object, but DO NOT start the event loop yourself, as
3544 we have already handled that.
3545
3546 If you want us to create an appropriate application object add the
3547 "-a" flag to your command::
3548
3549 %gui -a wx
3550
3551 This is highly recommended for most users.
3552 """
3553 from IPython.lib import inputhook
3554 if "-a" in parameter_s:
3555 app = True
3556 else:
3557 app = False
3558 if not parameter_s:
3559 inputhook.clear_inputhook()
3560 elif 'wx' in parameter_s:
3561 return inputhook.enable_wx(app)
3562 elif 'qt4' in parameter_s:
3563 return inputhook.enable_qt4(app)
3564 elif 'gtk' in parameter_s:
3565 return inputhook.enable_gtk(app)
3566 elif 'tk' in parameter_s:
3567 return inputhook.enable_tk(app)
3568
3569
3527 3570 # end Magic
@@ -16,6 +16,7 b' Inputhook management for GUI event loop integration.'
16 16 #-----------------------------------------------------------------------------
17 17
18 18 import ctypes
19 import sys
19 20
20 21 #-----------------------------------------------------------------------------
21 22 # Code
@@ -65,7 +66,7 b' class InputHookManager(object):'
65 66 self._reset()
66 67 return original
67 68
68 def enable_wx(self):
69 def enable_wx(self, app=False):
69 70 """Enable event loop integration with wxPython.
70 71
71 72 This methods sets the PyOS_InputHook for wxPython, which allows
@@ -85,6 +86,10 b' class InputHookManager(object):'
85 86 """
86 87 from IPython.lib.inputhookwx import inputhook_wx
87 88 self.set_inputhook(inputhook_wx)
89 if app:
90 import wx
91 app = wx.App(redirect=False, clearSigInt=False)
92 return app
88 93
89 94 def disable_wx(self):
90 95 """Disable event loop integration with wxPython.
@@ -93,7 +98,7 b' class InputHookManager(object):'
93 98 """
94 99 self.clear_inputhook()
95 100
96 def enable_qt4(self):
101 def enable_qt4(self, app=False):
97 102 """Enable event loop integration with PyQt4.
98 103
99 104 This methods sets the PyOS_InputHook for wxPython, which allows
@@ -113,6 +118,10 b' class InputHookManager(object):'
113 118 QtCore.pyqtRestoreInputHook()
114 119 except AttributeError:
115 120 pass
121 if app:
122 from PyQt4 import QtGui
123 app = QtGui.QApplication(sys.argv)
124 return app
116 125
117 126 def disable_qt4(self):
118 127 """Disable event loop integration with PyQt4.
@@ -121,7 +130,7 b' class InputHookManager(object):'
121 130 """
122 131 self.clear_inputhook()
123 132
124 def enable_gtk(self):
133 def enable_gtk(self, app=False):
125 134 """Enable event loop integration with PyGTK.
126 135
127 136 This methods sets the PyOS_InputHook for PyGTK, which allows
@@ -147,7 +156,7 b' class InputHookManager(object):'
147 156 """
148 157 self.clear_inputhook()
149 158
150 def enable_tk(self):
159 def enable_tk(self, app=False):
151 160 # Creating a Tkinter.Tk object sets PyOS_InputHook()
152 161 pass
153 162
General Comments 0
You need to be logged in to leave comments. Login now