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