Show More
@@ -15,6 +15,7 b' from IPython.external.qt import QtGui' | |||||
15 | from pygments.styles import get_all_styles |
|
15 | from pygments.styles import get_all_styles | |
16 |
|
16 | |||
17 | # Local imports |
|
17 | # Local imports | |
|
18 | from IPython.config.application import boolean_flag | |||
18 | from IPython.core.newapplication import ProfileDir, BaseIPythonApplication |
|
19 | from IPython.core.newapplication import ProfileDir, BaseIPythonApplication | |
19 | from IPython.frontend.qt.console.frontend_widget import FrontendWidget |
|
20 | from IPython.frontend.qt.console.frontend_widget import FrontendWidget | |
20 | from IPython.frontend.qt.console.ipython_widget import IPythonWidget |
|
21 | from IPython.frontend.qt.console.ipython_widget import IPythonWidget | |
@@ -22,7 +23,7 b' from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget' | |||||
22 | from IPython.frontend.qt.console import styles |
|
23 | from IPython.frontend.qt.console import styles | |
23 | from IPython.frontend.qt.kernelmanager import QtKernelManager |
|
24 | from IPython.frontend.qt.kernelmanager import QtKernelManager | |
24 | from IPython.utils.traitlets import ( |
|
25 | from IPython.utils.traitlets import ( | |
25 | Dict, List, Unicode, Int, CaselessStrEnum, Bool, Any |
|
26 | Dict, List, Unicode, Int, CaselessStrEnum, CBool, Any | |
26 | ) |
|
27 | ) | |
27 | from IPython.zmq.ipkernel import ( |
|
28 | from IPython.zmq.ipkernel import ( | |
28 | flags as ipkernel_flags, |
|
29 | flags as ipkernel_flags, | |
@@ -48,7 +49,8 b' class MainWindow(QtGui.QMainWindow):' | |||||
48 | # 'object' interface |
|
49 | # 'object' interface | |
49 | #--------------------------------------------------------------------------- |
|
50 | #--------------------------------------------------------------------------- | |
50 |
|
51 | |||
51 |
def __init__(self, app, frontend, existing=False, may_close=True |
|
52 | def __init__(self, app, frontend, existing=False, may_close=True, | |
|
53 | confirm_exit=True): | |||
52 | """ Create a MainWindow for the specified FrontendWidget. |
|
54 | """ Create a MainWindow for the specified FrontendWidget. | |
53 |
|
55 | |||
54 | The app is passed as an argument to allow for different |
|
56 | The app is passed as an argument to allow for different | |
@@ -67,6 +69,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
67 | else: |
|
69 | else: | |
68 | self._may_close = True |
|
70 | self._may_close = True | |
69 | self._frontend.exit_requested.connect(self.close) |
|
71 | self._frontend.exit_requested.connect(self.close) | |
|
72 | self._confirm_exit = confirm_exit | |||
70 | self.setCentralWidget(frontend) |
|
73 | self.setCentralWidget(frontend) | |
71 |
|
74 | |||
72 | #--------------------------------------------------------------------------- |
|
75 | #--------------------------------------------------------------------------- | |
@@ -86,6 +89,11 b' class MainWindow(QtGui.QMainWindow):' | |||||
86 |
|
89 | |||
87 | kernel_manager = self._frontend.kernel_manager |
|
90 | kernel_manager = self._frontend.kernel_manager | |
88 |
|
91 | |||
|
92 | if keepkernel is None and not self._confirm_exit: | |||
|
93 | # don't prompt, just terminate the kernel if we own it | |||
|
94 | # or leave it alone if we don't | |||
|
95 | keepkernel = not self._existing | |||
|
96 | ||||
89 | if keepkernel is None: #show prompt |
|
97 | if keepkernel is None: #show prompt | |
90 | if kernel_manager and kernel_manager.channels_running: |
|
98 | if kernel_manager and kernel_manager.channels_running: | |
91 | title = self.window().windowTitle() |
|
99 | title = self.window().windowTitle() | |
@@ -154,11 +162,26 b' flags.update({' | |||||
154 | "Use a pure Python kernel instead of an IPython kernel."), |
|
162 | "Use a pure Python kernel instead of an IPython kernel."), | |
155 | 'plain' : ({'ConsoleWidget' : {'kind' : 'plain'}}, |
|
163 | 'plain' : ({'ConsoleWidget' : {'kind' : 'plain'}}, | |
156 | "Disable rich text support."), |
|
164 | "Disable rich text support."), | |
157 | 'gui-completion' : ({'FrontendWidget' : {'gui_completion' : True}}, |
|
|||
158 | "use a GUI widget for tab completion"), |
|
|||
159 | }) |
|
165 | }) | |
160 |
|
166 | flags.update(boolean_flag( | ||
161 | qt_flags = ['existing', 'pure', 'plain', 'gui-completion'] |
|
167 | 'gui-completion', 'ConsoleWidget.gui_completion', | |
|
168 | "use a GUI widget for tab completion", | |||
|
169 | "use plaintext output for completion" | |||
|
170 | )) | |||
|
171 | flags.update(boolean_flag( | |||
|
172 | 'confirm-exit', 'IPythonQtConsoleApp.confirm_exit', | |||
|
173 | """Set to display confirmation dialog on exit. You can always use 'exit' or 'quit', | |||
|
174 | to force a direct exit without any confirmation. | |||
|
175 | """, | |||
|
176 | """Don't prompt the user when exiting. This will terminate the kernel | |||
|
177 | if it is owned by the frontend, and leave it alive if it is external. | |||
|
178 | """ | |||
|
179 | )) | |||
|
180 | # the flags that are specific to the frontend | |||
|
181 | # these must be scrubbed before being passed to the kernel, | |||
|
182 | # or it will raise an error on unrecognized flags | |||
|
183 | qt_flags = ['existing', 'pure', 'plain', 'gui-completion', 'no-gui-completion', | |||
|
184 | 'confirm-exit', 'no-confirm-exit'] | |||
162 |
|
185 | |||
163 | aliases = dict(ipkernel_aliases) |
|
186 | aliases = dict(ipkernel_aliases) | |
164 |
|
187 | |||
@@ -171,7 +194,7 b' aliases.update(dict(' | |||||
171 |
|
194 | |||
172 | plain = 'IPythonQtConsoleApp.plain', |
|
195 | plain = 'IPythonQtConsoleApp.plain', | |
173 | pure = 'IPythonQtConsoleApp.pure', |
|
196 | pure = 'IPythonQtConsoleApp.pure', | |
174 |
gui_completion = ' |
|
197 | gui_completion = 'ConsoleWidget.gui_completion', | |
175 | style = 'IPythonWidget.syntax_style', |
|
198 | style = 'IPythonWidget.syntax_style', | |
176 | stylesheet = 'IPythonQtConsoleApp.stylesheet', |
|
199 | stylesheet = 'IPythonQtConsoleApp.stylesheet', | |
177 | colors = 'ZMQInteractiveShell.colors', |
|
200 | colors = 'ZMQInteractiveShell.colors', | |
@@ -213,15 +236,15 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
213 | stdin_port = Int(0, config=True, |
|
236 | stdin_port = Int(0, config=True, | |
214 | help="set the stdin (XREQ) port [default: random]") |
|
237 | help="set the stdin (XREQ) port [default: random]") | |
215 |
|
238 | |||
216 | existing = Bool(False, config=True, |
|
239 | existing = CBool(False, config=True, | |
217 | help="Whether to connect to an already running Kernel.") |
|
240 | help="Whether to connect to an already running Kernel.") | |
218 |
|
241 | |||
219 | stylesheet = Unicode('', config=True, |
|
242 | stylesheet = Unicode('', config=True, | |
220 | help="path to a custom CSS stylesheet") |
|
243 | help="path to a custom CSS stylesheet") | |
221 |
|
244 | |||
222 | pure = Bool(False, config=True, |
|
245 | pure = CBool(False, config=True, | |
223 | help="Use a pure Python kernel instead of an IPython kernel.") |
|
246 | help="Use a pure Python kernel instead of an IPython kernel.") | |
224 | plain = Bool(False, config=True, |
|
247 | plain = CBool(False, config=True, | |
225 | help="Use a plaintext widget instead of rich text (plain can't print/save).") |
|
248 | help="Use a plaintext widget instead of rich text (plain can't print/save).") | |
226 |
|
249 | |||
227 | def _pure_changed(self, name, old, new): |
|
250 | def _pure_changed(self, name, old, new): | |
@@ -236,6 +259,12 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
236 |
|
259 | |||
237 | _plain_changed = _pure_changed |
|
260 | _plain_changed = _pure_changed | |
238 |
|
261 | |||
|
262 | confirm_exit = CBool(True, config=True, | |||
|
263 | help=""" | |||
|
264 | Set to display confirmation dialog on exit. You can always use 'exit' or 'quit', | |||
|
265 | to force a direct exit without any confirmation.""", | |||
|
266 | ) | |||
|
267 | ||||
239 | # the factory for creating a widget |
|
268 | # the factory for creating a widget | |
240 | widget_factory = Any(RichIPythonWidget) |
|
269 | widget_factory = Any(RichIPythonWidget) | |
241 |
|
270 | |||
@@ -278,7 +307,8 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
278 | local_kernel=local_kernel) |
|
307 | local_kernel=local_kernel) | |
279 | self.widget.kernel_manager = self.kernel_manager |
|
308 | self.widget.kernel_manager = self.kernel_manager | |
280 | self.window = MainWindow(self.app, self.widget, self.existing, |
|
309 | self.window = MainWindow(self.app, self.widget, self.existing, | |
281 |
may_close=local_kernel |
|
310 | may_close=local_kernel, | |
|
311 | confirm_exit=self.confirm_exit) | |||
282 | self.window.setWindowTitle('Python' if self.pure else 'IPython') |
|
312 | self.window.setWindowTitle('Python' if self.pure else 'IPython') | |
283 |
|
313 | |||
284 | def init_colors(self): |
|
314 | def init_colors(self): |
General Comments 0
You need to be logged in to leave comments.
Login now