Show More
@@ -45,6 +45,7 b' class InputHookManager(object):' | |||
|
45 | 45 | self._current_gui = None |
|
46 | 46 | |
|
47 | 47 | def _hijack_wx(self): |
|
48 | """Hijack the wx mainloop so a user calling it won't cause badness.""" | |
|
48 | 49 | import wx |
|
49 | 50 | if hasattr(wx, '_core_'): core = getattr(wx, '_core_') |
|
50 | 51 | elif hasattr(wx, '_core'): core = getattr(wx, '_core') |
@@ -54,6 +55,7 b' class InputHookManager(object):' | |||
|
54 | 55 | return orig_mainloop |
|
55 | 56 | |
|
56 | 57 | def _hijack_qt4(self): |
|
58 | """Hijack the qt4 mainloop so a user calling it won't cause badness.""" | |
|
57 | 59 | from PyQt4 import QtGui, QtCore |
|
58 | 60 | orig_mainloop = QtGui.qApp.exec_ |
|
59 | 61 | QtGui.qApp.exec_ = _dummy_mainloop |
@@ -62,6 +64,7 b' class InputHookManager(object):' | |||
|
62 | 64 | return orig_mainloop |
|
63 | 65 | |
|
64 | 66 | def _hijack_gtk(self): |
|
67 | """Hijack the gtk mainloop so a user calling it won't cause badness.""" | |
|
65 | 68 | import gtk |
|
66 | 69 | orig_mainloop = gtk.main |
|
67 | 70 | gtk.mainloop = _dummy_mainloop |
@@ -69,23 +72,21 b' class InputHookManager(object):' | |||
|
69 | 72 | return orig_mainloop |
|
70 | 73 | |
|
71 | 74 | def _hijack_tk(self): |
|
75 | """Hijack the tk mainloop so a user calling it won't cause badness.""" | |
|
72 | 76 | import Tkinter |
|
73 | 77 | Tkinter.Misc.mainloop = _dummy_mainloop |
|
74 | 78 | Tkinter.mainloop = _dummy_mainloop |
|
75 | 79 | |
|
76 | 80 | def get_pyos_inputhook(self): |
|
77 | """Return the current PyOS_InputHook as a ctypes.c_void_p. | |
|
78 | """ | |
|
81 | """Return the current PyOS_InputHook as a ctypes.c_void_p.""" | |
|
79 | 82 | return ctypes.c_void_p.in_dll(ctypes.pythonapi,"PyOS_InputHook") |
|
80 | 83 | |
|
81 | 84 | def get_pyos_inputhook_as_func(self): |
|
82 | """Return the current PyOS_InputHook as a ctypes.PYFUNCYPE. | |
|
83 | """ | |
|
85 | """Return the current PyOS_InputHook as a ctypes.PYFUNCYPE.""" | |
|
84 | 86 | return self.PYFUNC.in_dll(ctypes.pythonapi,"PyOS_InputHook") |
|
85 | 87 | |
|
86 | 88 | def set_inputhook(self, callback): |
|
87 | """Set PyOS_InputHook to callback and return the previous one. | |
|
88 | """ | |
|
89 | """Set PyOS_InputHook to callback and return the previous one.""" | |
|
89 | 90 | self._callback = callback |
|
90 | 91 | self._callback_pyfunctype = self.PYFUNC(callback) |
|
91 | 92 | pyos_inputhook_ptr = self.get_pyos_inputhook() |
@@ -96,8 +97,7 b' class InputHookManager(object):' | |||
|
96 | 97 | return original |
|
97 | 98 | |
|
98 | 99 | def clear_inputhook(self): |
|
99 | """Set PyOS_InputHook to NULL and return the previous one. | |
|
100 | """ | |
|
100 | """Set PyOS_InputHook to NULL and return the previous one.""" | |
|
101 | 101 | pyos_inputhook_ptr = self.get_pyos_inputhook() |
|
102 | 102 | original = self.get_pyos_inputhook_as_func() |
|
103 | 103 | pyos_inputhook_ptr.value = ctypes.c_void_p(None).value |
@@ -107,6 +107,11 b' class InputHookManager(object):' | |||
|
107 | 107 | def clear_app_refs(self, gui=None): |
|
108 | 108 | """Clear IPython's internal reference to an application instance. |
|
109 | 109 | |
|
110 | Whenever we create an app for a user on qt4 or wx, we hold a | |
|
111 | reference to the app. This is needed because in some cases bad things | |
|
112 | can happen if a user doesn't hold a reference themselves. This | |
|
113 | method is provided to clear the references we are holding. | |
|
114 | ||
|
110 | 115 | Parameters |
|
111 | 116 | ---------- |
|
112 | 117 | gui : None or str |
@@ -129,20 +134,20 b' class InputHookManager(object):' | |||
|
129 | 134 | |
|
130 | 135 | Notes |
|
131 | 136 | ----- |
|
132 | This methods sets the PyOS_InputHook for wxPython, which allows | |
|
137 | This methods sets the ``PyOS_InputHook`` for wxPython, which allows | |
|
133 | 138 | the wxPython to integrate with terminal based applications like |
|
134 | 139 | IPython. |
|
135 | ||
|
136 | Once this has been called, you can use wx interactively by doing:: | |
|
137 | ||
|
138 |
|
|
|
139 |
|
|
|
140 | ||
|
140 | ||
|
141 | If ``app`` is True, we create an :class:`wx.App` as follows:: | |
|
142 | ||
|
143 | import wx | |
|
144 | app = wx.App(redirect=False, clearSigInt=False) | |
|
145 | ||
|
141 | 146 | Both options this constructor are important for things to work |
|
142 | 147 | properly in an interactive context. |
|
143 | ||
|
144 | But, *don't start the event loop*. That is handled automatically by | |
|
145 | PyOS_InputHook. | |
|
148 | ||
|
149 | But, we first check to see if an application has already been | |
|
150 | created. If so, we simply return that instance. | |
|
146 | 151 | """ |
|
147 | 152 | from IPython.lib.inputhookwx import inputhook_wx |
|
148 | 153 | self.set_inputhook(inputhook_wx) |
@@ -158,7 +163,7 b' class InputHookManager(object):' | |||
|
158 | 163 | |
|
159 | 164 | def disable_wx(self): |
|
160 | 165 | """Disable event loop integration with wxPython. |
|
161 | ||
|
166 | ||
|
162 | 167 | This merely sets PyOS_InputHook to NULL. |
|
163 | 168 | """ |
|
164 | 169 | self.clear_inputhook() |
@@ -173,13 +178,17 b' class InputHookManager(object):' | |||
|
173 | 178 | |
|
174 | 179 | Notes |
|
175 | 180 | ----- |
|
176 |
This methods sets the PyOS_InputHook for |
|
|
181 | This methods sets the PyOS_InputHook for PyQt4, which allows | |
|
177 | 182 | the PyQt4 to integrate with terminal based applications like |
|
178 | 183 | IPython. |
|
179 | ||
|
180 | Once this has been called, you can simply create a QApplication and | |
|
181 | use it. But, *don't start the event loop*. That is handled | |
|
182 | automatically by PyOS_InputHook. | |
|
184 | ||
|
185 | If ``app`` is True, we create an :class:`QApplication` as follows:: | |
|
186 | ||
|
187 | from PyQt4 import QtCore | |
|
188 | app = QtGui.QApplication(sys.argv) | |
|
189 | ||
|
190 | But, we first check to see if an application has already been | |
|
191 | created. If so, we simply return that instance. | |
|
183 | 192 | """ |
|
184 | 193 | from PyQt4 import QtCore |
|
185 | 194 | # PyQt4 has had this since 4.3.1. In version 4.2, PyOS_InputHook |
@@ -202,7 +211,7 b' class InputHookManager(object):' | |||
|
202 | 211 | |
|
203 | 212 | def disable_qt4(self): |
|
204 | 213 | """Disable event loop integration with PyQt4. |
|
205 | ||
|
214 | ||
|
206 | 215 | This merely sets PyOS_InputHook to NULL. |
|
207 | 216 | """ |
|
208 | 217 | self.clear_inputhook() |
@@ -213,17 +222,14 b' class InputHookManager(object):' | |||
|
213 | 222 | Parameters |
|
214 | 223 | ---------- |
|
215 | 224 | app : bool |
|
216 | Create a running application object or not. | |
|
225 | Create a running application object or not. Because gtk does't | |
|
226 | have an app class, this does nothing. | |
|
217 | 227 | |
|
218 | 228 | Notes |
|
219 | 229 | ----- |
|
220 | 230 | This methods sets the PyOS_InputHook for PyGTK, which allows |
|
221 | 231 | the PyGTK to integrate with terminal based applications like |
|
222 | 232 | IPython. |
|
223 | ||
|
224 | Once this has been called, you can simple create PyGTK objects and | |
|
225 | use them. But, *don't start the event loop*. That is handled | |
|
226 | automatically by PyOS_InputHook. | |
|
227 | 233 | """ |
|
228 | 234 | import gtk |
|
229 | 235 | try: |
General Comments 0
You need to be logged in to leave comments.
Login now