##// END OF EJS Templates
add confirm_exit option to qtconsole to suppress exit dialog
MinRK -
Show More
@@ -15,6 +15,7 b' from IPython.external.qt import QtGui'
15 15 from pygments.styles import get_all_styles
16 16
17 17 # Local imports
18 from IPython.config.application import boolean_flag
18 19 from IPython.core.newapplication import ProfileDir, BaseIPythonApplication
19 20 from IPython.frontend.qt.console.frontend_widget import FrontendWidget
20 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 23 from IPython.frontend.qt.console import styles
23 24 from IPython.frontend.qt.kernelmanager import QtKernelManager
24 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 28 from IPython.zmq.ipkernel import (
28 29 flags as ipkernel_flags,
@@ -48,7 +49,8 b' class MainWindow(QtGui.QMainWindow):'
48 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 54 """ Create a MainWindow for the specified FrontendWidget.
53 55
54 56 The app is passed as an argument to allow for different
@@ -67,6 +69,7 b' class MainWindow(QtGui.QMainWindow):'
67 69 else:
68 70 self._may_close = True
69 71 self._frontend.exit_requested.connect(self.close)
72 self._confirm_exit = confirm_exit
70 73 self.setCentralWidget(frontend)
71 74
72 75 #---------------------------------------------------------------------------
@@ -86,6 +89,11 b' class MainWindow(QtGui.QMainWindow):'
86 89
87 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 97 if keepkernel is None: #show prompt
90 98 if kernel_manager and kernel_manager.channels_running:
91 99 title = self.window().windowTitle()
@@ -154,11 +162,26 b' flags.update({'
154 162 "Use a pure Python kernel instead of an IPython kernel."),
155 163 'plain' : ({'ConsoleWidget' : {'kind' : 'plain'}},
156 164 "Disable rich text support."),
157 'gui-completion' : ({'FrontendWidget' : {'gui_completion' : True}},
158 "use a GUI widget for tab completion"),
159 165 })
160
161 qt_flags = ['existing', 'pure', 'plain', 'gui-completion']
166 flags.update(boolean_flag(
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 186 aliases = dict(ipkernel_aliases)
164 187
@@ -171,7 +194,7 b' aliases.update(dict('
171 194
172 195 plain = 'IPythonQtConsoleApp.plain',
173 196 pure = 'IPythonQtConsoleApp.pure',
174 gui_completion = 'FrontendWidget.gui_completion',
197 gui_completion = 'ConsoleWidget.gui_completion',
175 198 style = 'IPythonWidget.syntax_style',
176 199 stylesheet = 'IPythonQtConsoleApp.stylesheet',
177 200 colors = 'ZMQInteractiveShell.colors',
@@ -213,15 +236,15 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
213 236 stdin_port = Int(0, config=True,
214 237 help="set the stdin (XREQ) port [default: random]")
215 238
216 existing = Bool(False, config=True,
239 existing = CBool(False, config=True,
217 240 help="Whether to connect to an already running Kernel.")
218 241
219 242 stylesheet = Unicode('', config=True,
220 243 help="path to a custom CSS stylesheet")
221 244
222 pure = Bool(False, config=True,
245 pure = CBool(False, config=True,
223 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 248 help="Use a plaintext widget instead of rich text (plain can't print/save).")
226 249
227 250 def _pure_changed(self, name, old, new):
@@ -236,6 +259,12 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
236 259
237 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 268 # the factory for creating a widget
240 269 widget_factory = Any(RichIPythonWidget)
241 270
@@ -278,7 +307,8 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
278 307 local_kernel=local_kernel)
279 308 self.widget.kernel_manager = self.kernel_manager
280 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 312 self.window.setWindowTitle('Python' if self.pure else 'IPython')
283 313
284 314 def init_colors(self):
General Comments 0
You need to be logged in to leave comments. Login now