Show More
@@ -32,6 +32,9 b' from IPython.utils.traitlets import Instance' | |||
|
32 | 32 | class __BuiltinUndefined(object): pass |
|
33 | 33 | BuiltinUndefined = __BuiltinUndefined() |
|
34 | 34 | |
|
35 | class __HideBuiltin(object): pass | |
|
36 | HideBuiltin = __HideBuiltin() | |
|
37 | ||
|
35 | 38 | |
|
36 | 39 | class BuiltinTrap(Configurable): |
|
37 | 40 | |
@@ -44,9 +47,10 b' class BuiltinTrap(Configurable):' | |||
|
44 | 47 | # Only turn off the trap when the outermost call to __exit__ is made. |
|
45 | 48 | self._nested_level = 0 |
|
46 | 49 | self.shell = shell |
|
47 | # builtins we always add | |
|
48 | self.auto_builtins = {'exit': Quitter(self.shell, 'exit'), | |
|
49 | 'quit': Quitter(self.shell, 'quit'), | |
|
50 | # builtins we always add - if set to HideBuiltin, they will just | |
|
51 | # be removed instead of being replaced by something else | |
|
52 | self.auto_builtins = {'exit': HideBuiltin, | |
|
53 | 'quit': HideBuiltin, | |
|
50 | 54 | 'get_ipython': self.shell.get_ipython, |
|
51 | 55 | } |
|
52 | 56 | # Recursive reload function |
@@ -78,6 +82,9 b' class BuiltinTrap(Configurable):' | |||
|
78 | 82 | bdict = __builtin__.__dict__ |
|
79 | 83 | orig = bdict.get(key, BuiltinUndefined) |
|
80 | 84 | self._orig_builtins[key] = orig |
|
85 | if value is HideBuiltin: | |
|
86 | del bdict[key] | |
|
87 | else: | |
|
81 | 88 | bdict[key] = value |
|
82 | 89 | |
|
83 | 90 | def remove_builtin(self, key): |
@@ -58,12 +58,16 b' class MainWindow(QtGui.QMainWindow):' | |||
|
58 | 58 | #--------------------------------------------------------------------------- |
|
59 | 59 | |
|
60 | 60 | def closeEvent(self, event): |
|
61 |
""" Reimplemented to prompt the user and close the kernel cleanly |
|
|
61 | """ Reimplemented to prompt the user and close the kernel cleanly, or | |
|
62 | close without prompt only if the exit magic is used. | |
|
62 | 63 | """ |
|
64 | keepkernel = None #Use the prompt by default | |
|
65 | if hasattr(self._frontend,'_keep_kernel_on_exit'): #set by exit magic | |
|
63 | 66 | keepkernel = self._frontend._keep_kernel_on_exit |
|
67 | ||
|
64 | 68 | kernel_manager = self._frontend.kernel_manager |
|
65 | 69 | |
|
66 | if keepkernel is None: | |
|
70 | if keepkernel is None: #show prompt | |
|
67 | 71 | if kernel_manager and kernel_manager.channels_running: |
|
68 | 72 | title = self.window().windowTitle() |
|
69 | 73 | cancel = QtGui.QMessageBox.Cancel |
@@ -106,13 +110,13 b' class MainWindow(QtGui.QMainWindow):' | |||
|
106 | 110 | event.accept() |
|
107 | 111 | else: |
|
108 | 112 | event.ignore() |
|
109 | elif keepkernel: #close console but leave kernel running | |
|
113 | elif keepkernel: #close console but leave kernel running (no prompt) | |
|
110 | 114 | if kernel_manager and kernel_manager.channels_running: |
|
111 | 115 | if not self._existing: |
|
112 | 116 | # I have the kernel: don't quit, just close the window |
|
113 | 117 | self._app.setQuitOnLastWindowClosed(False) |
|
114 | 118 | event.accept() |
|
115 | else: #close console and kernel | |
|
119 | else: #close console and kernel (no prompt) | |
|
116 | 120 | if kernel_manager and kernel_manager.channels_running: |
|
117 | 121 | kernel_manager.shutdown_kernel() |
|
118 | 122 | event.accept() |
@@ -78,7 +78,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||
|
78 | 78 | """A subclass of InteractiveShell for ZMQ.""" |
|
79 | 79 | |
|
80 | 80 | displayhook_class = Type(ZMQDisplayHook) |
|
81 | keepkernel = None | |
|
81 | keepkernel_on_exit = None | |
|
82 | 82 | |
|
83 | 83 | def init_environment(self): |
|
84 | 84 | """Configure the user's environment. |
@@ -112,7 +112,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||
|
112 | 112 | payload = dict( |
|
113 | 113 | source='IPython.zmq.zmqshell.ZMQInteractiveShell.ask_exit', |
|
114 | 114 | exit=True, |
|
115 | keepkernel=self.keepkernel, | |
|
115 | keepkernel=self.keepkernel_on_exit, | |
|
116 | 116 | ) |
|
117 | 117 | self.payload_manager.write_payload(payload) |
|
118 | 118 | |
@@ -571,7 +571,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||
|
571 | 571 | running. Otherwise, it will shutdown without prompting. |
|
572 | 572 | """ |
|
573 | 573 | opts,args = self.parse_options(parameter_s,'k') |
|
574 | self.shell.keepkernel = opts.has_key('k') | |
|
574 | self.shell.keepkernel_on_exit = opts.has_key('k') | |
|
575 | 575 | self.shell.ask_exit() |
|
576 | 576 | |
|
577 | 577 | # Add aliases as magics so all common forms work: exit, quit, Exit, Quit. |
General Comments 0
You need to be logged in to leave comments.
Login now