Show More
@@ -1,165 +1,183 b'' | |||||
1 | # Get the config being loaded so we can set attributes on it |
|
1 | # Get the config being loaded so we can set attributes on it | |
2 | c = get_config() |
|
2 | c = get_config() | |
3 |
|
3 | |||
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | # Application-level options |
|
5 | # Application-level options | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | # c.TerminalIPythonApp.display_banner = True |
|
8 | # c.TerminalIPythonApp.display_banner = True | |
9 |
|
9 | |||
10 | # c.TerminalIPythonApp.classic = False |
|
10 | # c.TerminalIPythonApp.classic = False | |
11 |
|
11 | |||
12 | # c.TerminalIPythonApp.nosep = True |
|
12 | # c.TerminalIPythonApp.nosep = True | |
13 |
|
13 | |||
14 | # If you still use multiple versions of IPytho on the same machine, |
|
14 | # If you still use multiple versions of IPytho on the same machine, | |
15 | # set this to True to suppress warnings about old configuration files |
|
15 | # set this to True to suppress warnings about old configuration files | |
16 | # c.TerminalIPythonApp.ignore_old_config = False |
|
16 | # c.TerminalIPythonApp.ignore_old_config = False | |
17 |
|
17 | |||
18 | # Set this to determine the detail of what is logged at startup. |
|
18 | # Set this to determine the detail of what is logged at startup. | |
19 | # The default is 30 and possible values are 0,10,20,30,40,50. |
|
19 | # The default is 30 and possible values are 0,10,20,30,40,50. | |
20 | # c.Application.log_level = 20 |
|
20 | # c.Application.log_level = 20 | |
21 |
|
21 | |||
22 | # This should be a list of importable Python modules that have an |
|
22 | # This should be a list of importable Python modules that have an | |
23 | # load_ipython_extension(ip) method. This method gets called when the extension |
|
23 | # load_ipython_extension(ip) method. This method gets called when the extension | |
24 | # is loaded. You can put your extensions anywhere they can be imported |
|
24 | # is loaded. You can put your extensions anywhere they can be imported | |
25 | # but we add the extensions subdir of the ipython directory to sys.path |
|
25 | # but we add the extensions subdir of the ipython directory to sys.path | |
26 | # during extension loading, so you can put them there as well. |
|
26 | # during extension loading, so you can put them there as well. | |
27 | # c.InteractiveShellApp.extensions = [ |
|
27 | # c.InteractiveShellApp.extensions = [ | |
28 | # 'myextension' |
|
28 | # 'myextension' | |
29 | # ] |
|
29 | # ] | |
30 |
|
30 | |||
31 | # These lines are run in IPython in the user's namespace after extensions |
|
31 | # These lines are run in IPython in the user's namespace after extensions | |
32 | # are loaded. They can contain full IPython syntax with magics etc. |
|
32 | # are loaded. They can contain full IPython syntax with magics etc. | |
33 | # c.InteractiveShellApp.exec_lines = [ |
|
33 | # c.InteractiveShellApp.exec_lines = [ | |
34 | # 'import numpy', |
|
34 | # 'import numpy', | |
35 | # 'a = 10; b = 20', |
|
35 | # 'a = 10; b = 20', | |
36 | # '1/0' |
|
36 | # '1/0' | |
37 | # ] |
|
37 | # ] | |
38 |
|
38 | |||
39 | # These files are run in IPython in the user's namespace. Files with a .py |
|
39 | # These files are run in IPython in the user's namespace. Files with a .py | |
40 | # extension need to be pure Python. Files with a .ipy extension can have |
|
40 | # extension need to be pure Python. Files with a .ipy extension can have | |
41 | # custom IPython syntax (like magics, etc.). |
|
41 | # custom IPython syntax (like magics, etc.). | |
42 | # These files need to be in the cwd, the ipython_dir or be absolute paths. |
|
42 | # These files need to be in the cwd, the ipython_dir or be absolute paths. | |
43 | # c.InteractiveShellApp.exec_files = [ |
|
43 | # c.InteractiveShellApp.exec_files = [ | |
44 | # 'mycode.py', |
|
44 | # 'mycode.py', | |
45 | # 'fancy.ipy' |
|
45 | # 'fancy.ipy' | |
46 | # ] |
|
46 | # ] | |
47 |
|
47 | |||
48 | #----------------------------------------------------------------------------- |
|
48 | #----------------------------------------------------------------------------- | |
49 | # InteractiveShell options |
|
49 | # InteractiveShell options | |
50 | #----------------------------------------------------------------------------- |
|
50 | #----------------------------------------------------------------------------- | |
51 |
|
51 | |||
52 | # c.InteractiveShell.autocall = 1 |
|
52 | # c.InteractiveShell.autocall = 1 | |
53 |
|
53 | |||
54 | # c.TerminalInteractiveShell.autoedit_syntax = False |
|
54 | # c.TerminalInteractiveShell.autoedit_syntax = False | |
55 |
|
55 | |||
56 | # c.InteractiveShell.autoindent = True |
|
56 | # c.InteractiveShell.autoindent = True | |
57 |
|
57 | |||
58 | # c.InteractiveShell.automagic = False |
|
58 | # c.InteractiveShell.automagic = False | |
59 |
|
59 | |||
60 | # c.TerminalInteractiveShell.banner1 = 'This if for overriding the default IPython banner' |
|
60 | # c.TerminalInteractiveShell.banner1 = 'This if for overriding the default IPython banner' | |
61 |
|
61 | |||
62 | # c.TerminalInteractiveShell.banner2 = "This is for extra banner text" |
|
62 | # c.TerminalInteractiveShell.banner2 = "This is for extra banner text" | |
63 |
|
63 | |||
64 | # c.InteractiveShell.cache_size = 1000 |
|
64 | # c.InteractiveShell.cache_size = 1000 | |
65 |
|
65 | |||
66 | # c.InteractiveShell.colors = 'LightBG' |
|
66 | # c.InteractiveShell.colors = 'LightBG' | |
67 |
|
67 | |||
68 | # c.InteractiveShell.color_info = True |
|
68 | # c.InteractiveShell.color_info = True | |
69 |
|
69 | |||
70 | # c.TerminalInteractiveShell.confirm_exit = True |
|
70 | # c.TerminalInteractiveShell.confirm_exit = True | |
71 |
|
71 | |||
72 | # c.InteractiveShell.deep_reload = False |
|
72 | # c.InteractiveShell.deep_reload = False | |
73 |
|
73 | |||
74 | # c.TerminalInteractiveShell.editor = 'nano' |
|
74 | # c.TerminalInteractiveShell.editor = 'nano' | |
75 |
|
75 | |||
76 | # c.InteractiveShell.logstart = True |
|
76 | # c.InteractiveShell.logstart = True | |
77 |
|
77 | |||
78 | # c.InteractiveShell.logfile = u'ipython_log.py' |
|
78 | # c.InteractiveShell.logfile = u'ipython_log.py' | |
79 |
|
79 | |||
80 | # c.InteractiveShell.logappend = u'mylog.py' |
|
80 | # c.InteractiveShell.logappend = u'mylog.py' | |
81 |
|
81 | |||
82 | # c.InteractiveShell.object_info_string_level = 0 |
|
82 | # c.InteractiveShell.object_info_string_level = 0 | |
83 |
|
83 | |||
84 | # c.TerminalInteractiveShell.pager = 'less' |
|
84 | # c.TerminalInteractiveShell.pager = 'less' | |
85 |
|
85 | |||
86 | # c.InteractiveShell.pdb = False |
|
86 | # c.InteractiveShell.pdb = False | |
87 |
|
87 | |||
88 | # c.InteractiveShell.prompt_in1 = 'In [\#]: ' |
|
88 | # c.InteractiveShell.prompt_in1 = 'In [\#]: ' | |
89 | # c.InteractiveShell.prompt_in2 = ' .\D.: ' |
|
89 | # c.InteractiveShell.prompt_in2 = ' .\D.: ' | |
90 | # c.InteractiveShell.prompt_out = 'Out[\#]: ' |
|
90 | # c.InteractiveShell.prompt_out = 'Out[\#]: ' | |
91 | # c.InteractiveShell.prompts_pad_left = True |
|
91 | # c.InteractiveShell.prompts_pad_left = True | |
92 |
|
92 | |||
93 | # c.InteractiveShell.quiet = False |
|
93 | # c.InteractiveShell.quiet = False | |
94 |
|
94 | |||
95 | # c.InteractiveShell.history_length = 10000 |
|
95 | # c.InteractiveShell.history_length = 10000 | |
96 |
|
96 | |||
97 | # Readline |
|
97 | # Readline | |
98 | # c.InteractiveShell.readline_use = True |
|
98 | # c.InteractiveShell.readline_use = True | |
99 |
|
99 | |||
100 | # be careful with meta-key ('\M-<x>') bindings, because |
|
100 | # be careful with meta-key ('\M-<x>') bindings, because | |
101 | # they conflict with 8-bit encodings (e.g. UTF8) |
|
101 | # they conflict with 8-bit encodings (e.g. UTF8) | |
102 |
|
102 | |||
103 | # c.InteractiveShell.readline_parse_and_bind = [ |
|
103 | # c.InteractiveShell.readline_parse_and_bind = [ | |
104 | # 'tab: complete', |
|
104 | # 'tab: complete', | |
105 | # '"\C-l": possible-completions', |
|
105 | # '"\C-l": possible-completions', | |
106 | # 'set show-all-if-ambiguous on', |
|
106 | # 'set show-all-if-ambiguous on', | |
107 | # '"\C-o": tab-insert', |
|
107 | # '"\C-o": tab-insert', | |
108 | # '"\C-r": reverse-search-history', |
|
108 | # '"\C-r": reverse-search-history', | |
109 | # '"\C-s": forward-search-history', |
|
109 | # '"\C-s": forward-search-history', | |
110 | # '"\C-p": history-search-backward', |
|
110 | # '"\C-p": history-search-backward', | |
111 | # '"\C-n": history-search-forward', |
|
111 | # '"\C-n": history-search-forward', | |
112 | # '"\e[A": history-search-backward', |
|
112 | # '"\e[A": history-search-backward', | |
113 | # '"\e[B": history-search-forward', |
|
113 | # '"\e[B": history-search-forward', | |
114 | # '"\C-k": kill-line', |
|
114 | # '"\C-k": kill-line', | |
115 | # '"\C-u": unix-line-discard', |
|
115 | # '"\C-u": unix-line-discard', | |
116 | # ] |
|
116 | # ] | |
117 | # c.InteractiveShell.readline_remove_delims = '-/~' |
|
117 | # c.InteractiveShell.readline_remove_delims = '-/~' | |
118 | # c.InteractiveShell.readline_merge_completions = True |
|
118 | # c.InteractiveShell.readline_merge_completions = True | |
119 | # c.InteractiveShell.readline_omit__names = 0 |
|
119 | # c.InteractiveShell.readline_omit__names = 0 | |
120 |
|
120 | |||
121 | # c.TerminalInteractiveShell.screen_length = 0 |
|
121 | # c.TerminalInteractiveShell.screen_length = 0 | |
122 |
|
122 | |||
123 | # c.InteractiveShell.separate_in = '\n' |
|
123 | # c.InteractiveShell.separate_in = '\n' | |
124 | # c.InteractiveShell.separate_out = '' |
|
124 | # c.InteractiveShell.separate_out = '' | |
125 | # c.InteractiveShell.separate_out2 = '' |
|
125 | # c.InteractiveShell.separate_out2 = '' | |
126 |
|
126 | |||
127 | # c.TerminalInteractiveShell.term_title = False |
|
127 | # c.TerminalInteractiveShell.term_title = False | |
128 |
|
128 | |||
129 | # c.InteractiveShell.wildcards_case_sensitive = True |
|
129 | # c.InteractiveShell.wildcards_case_sensitive = True | |
130 |
|
130 | |||
131 | # c.InteractiveShell.xmode = 'Context' |
|
131 | # c.InteractiveShell.xmode = 'Context' | |
132 |
|
132 | |||
133 | #----------------------------------------------------------------------------- |
|
133 | #----------------------------------------------------------------------------- | |
134 | # Formatter and display options |
|
134 | # Formatter and display options | |
135 | #----------------------------------------------------------------------------- |
|
135 | #----------------------------------------------------------------------------- | |
136 |
|
136 | |||
137 | # c.PlainTextFormatter.pprint = True |
|
137 | # c.PlainTextFormatter.pprint = True | |
138 |
|
138 | |||
139 | #----------------------------------------------------------------------------- |
|
139 | #----------------------------------------------------------------------------- | |
140 | # PrefilterManager options |
|
140 | # PrefilterManager options | |
141 | #----------------------------------------------------------------------------- |
|
141 | #----------------------------------------------------------------------------- | |
142 |
|
142 | |||
143 | # c.PrefilterManager.multi_line_specials = True |
|
143 | # c.PrefilterManager.multi_line_specials = True | |
144 |
|
144 | |||
145 | #----------------------------------------------------------------------------- |
|
145 | #----------------------------------------------------------------------------- | |
146 | # AliasManager options |
|
146 | # AliasManager options | |
147 | #----------------------------------------------------------------------------- |
|
147 | #----------------------------------------------------------------------------- | |
148 |
|
148 | |||
149 | # Do this to disable all defaults |
|
149 | # Do this to disable all defaults | |
150 | # c.AliasManager.default_aliases = [] |
|
150 | # c.AliasManager.default_aliases = [] | |
151 |
|
151 | |||
152 | # c.AliasManager.user_aliases = [ |
|
152 | # c.AliasManager.user_aliases = [ | |
153 | # ('foo', 'echo Hi') |
|
153 | # ('foo', 'echo Hi') | |
154 | # ] |
|
154 | # ] | |
155 |
|
155 | |||
156 | #----------------------------------------------------------------------------- |
|
156 | #----------------------------------------------------------------------------- | |
157 | # HistoryManager options |
|
157 | # HistoryManager options | |
158 | #----------------------------------------------------------------------------- |
|
158 | #----------------------------------------------------------------------------- | |
159 |
|
159 | |||
160 | # Enable logging output as well as input to the database. |
|
160 | # Enable logging output as well as input to the database. | |
161 | # c.HistoryManager.db_log_output = False |
|
161 | # c.HistoryManager.db_log_output = False | |
162 |
|
162 | |||
163 | # Only write to the database every n commands - this can save disk |
|
163 | # Only write to the database every n commands - this can save disk | |
164 | # access (and hence power) over the default of writing on every command. |
|
164 | # access (and hence power) over the default of writing on every command. | |
165 | # c.HistoryManager.db_cache_size = 0 |
|
165 | # c.HistoryManager.db_cache_size = 0 | |
|
166 | ||||
|
167 | #----------------------------------------------------------------------------- | |||
|
168 | # QtConsole configuration | |||
|
169 | #----------------------------------------------------------------------------- | |||
|
170 | ||||
|
171 | # set the preferred font and font size: | |||
|
172 | # c.ConsoleWidget.font_family = "Anonymous Pro" | |||
|
173 | # c.ConsoleWidget.font_size = 10 | |||
|
174 | ||||
|
175 | # set the syntax-highlighting style: | |||
|
176 | # c.IPythonWidget.syntax_style = 'perldoc' | |||
|
177 | ||||
|
178 | # Configure the prompts: | |||
|
179 | # c.IPythonWidget.in_prompt = 'In [<span class="in-prompt-number">%i</span>]: ' | |||
|
180 | # c.IPythonWidget.out_prompt = 'Out[<span class="out-prompt-number">%i</span>]: ' | |||
|
181 | ||||
|
182 | # set the editor - this must be a *GUI* editor, like notepad/gedit/TextMate | |||
|
183 | # c.IPythonWidget.editor = 'mate -w' |
@@ -1,372 +1,372 b'' | |||||
1 | """ A minimal application using the Qt console-style IPython frontend. |
|
1 | """ A minimal application using the Qt console-style IPython frontend. | |
2 | """ |
|
2 | """ | |
3 |
|
3 | |||
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | # Imports |
|
5 | # Imports | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | # stdlib imports |
|
8 | # stdlib imports | |
9 | import os |
|
9 | import os | |
10 | import signal |
|
10 | import signal | |
11 | import sys |
|
11 | import sys | |
12 |
|
12 | |||
13 | # System library imports |
|
13 | # System library imports | |
14 | from IPython.external.qt import QtGui |
|
14 | 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.core.newapplication import ProfileDir, BaseIPythonApplication |
|
18 | from IPython.core.newapplication import ProfileDir, BaseIPythonApplication | |
19 | from IPython.frontend.qt.console.frontend_widget import FrontendWidget |
|
19 | from IPython.frontend.qt.console.frontend_widget import FrontendWidget | |
20 | from IPython.frontend.qt.console.ipython_widget import IPythonWidget |
|
20 | from IPython.frontend.qt.console.ipython_widget import IPythonWidget | |
21 | from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget |
|
21 | from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget | |
22 | from IPython.frontend.qt.console import styles |
|
22 | from IPython.frontend.qt.console import styles | |
23 | from IPython.frontend.qt.kernelmanager import QtKernelManager |
|
23 | from IPython.frontend.qt.kernelmanager import QtKernelManager | |
24 | from IPython.utils.traitlets import ( |
|
24 | from IPython.utils.traitlets import ( | |
25 | Dict, List, Unicode, Int, CaselessStrEnum, Bool, Any |
|
25 | Dict, List, Unicode, Int, CaselessStrEnum, Bool, Any | |
26 | ) |
|
26 | ) | |
27 | from IPython.zmq.ipkernel import ( |
|
27 | from IPython.zmq.ipkernel import ( | |
28 | flags as ipkernel_flags, |
|
28 | flags as ipkernel_flags, | |
29 | aliases as ipkernel_aliases, |
|
29 | aliases as ipkernel_aliases, | |
30 | IPKernelApp |
|
30 | IPKernelApp | |
31 | ) |
|
31 | ) | |
32 | from IPython.zmq.zmqshell import ZMQInteractiveShell |
|
32 | from IPython.zmq.zmqshell import ZMQInteractiveShell | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
36 | # Network Constants |
|
36 | # Network Constants | |
37 | #----------------------------------------------------------------------------- |
|
37 | #----------------------------------------------------------------------------- | |
38 |
|
38 | |||
39 | from IPython.utils.localinterfaces import LOCALHOST, LOCAL_IPS |
|
39 | from IPython.utils.localinterfaces import LOCALHOST, LOCAL_IPS | |
40 |
|
40 | |||
41 | #----------------------------------------------------------------------------- |
|
41 | #----------------------------------------------------------------------------- | |
42 | # Classes |
|
42 | # Classes | |
43 | #----------------------------------------------------------------------------- |
|
43 | #----------------------------------------------------------------------------- | |
44 |
|
44 | |||
45 | class MainWindow(QtGui.QMainWindow): |
|
45 | class MainWindow(QtGui.QMainWindow): | |
46 |
|
46 | |||
47 | #--------------------------------------------------------------------------- |
|
47 | #--------------------------------------------------------------------------- | |
48 | # 'object' interface |
|
48 | # 'object' interface | |
49 | #--------------------------------------------------------------------------- |
|
49 | #--------------------------------------------------------------------------- | |
50 |
|
50 | |||
51 | def __init__(self, app, frontend, existing=False, may_close=True): |
|
51 | def __init__(self, app, frontend, existing=False, may_close=True): | |
52 | """ Create a MainWindow for the specified FrontendWidget. |
|
52 | """ Create a MainWindow for the specified FrontendWidget. | |
53 |
|
53 | |||
54 | The app is passed as an argument to allow for different |
|
54 | The app is passed as an argument to allow for different | |
55 | closing behavior depending on whether we are the Kernel's parent. |
|
55 | closing behavior depending on whether we are the Kernel's parent. | |
56 |
|
56 | |||
57 | If existing is True, then this Console does not own the Kernel. |
|
57 | If existing is True, then this Console does not own the Kernel. | |
58 |
|
58 | |||
59 | If may_close is True, then this Console is permitted to close the kernel |
|
59 | If may_close is True, then this Console is permitted to close the kernel | |
60 | """ |
|
60 | """ | |
61 | super(MainWindow, self).__init__() |
|
61 | super(MainWindow, self).__init__() | |
62 | self._app = app |
|
62 | self._app = app | |
63 | self._frontend = frontend |
|
63 | self._frontend = frontend | |
64 | self._existing = existing |
|
64 | self._existing = existing | |
65 | if existing: |
|
65 | if existing: | |
66 | self._may_close = may_close |
|
66 | self._may_close = may_close | |
67 | else: |
|
67 | else: | |
68 | self._may_close = True |
|
68 | self._may_close = True | |
69 | self._frontend.exit_requested.connect(self.close) |
|
69 | self._frontend.exit_requested.connect(self.close) | |
70 | self.setCentralWidget(frontend) |
|
70 | self.setCentralWidget(frontend) | |
71 |
|
71 | |||
72 | #--------------------------------------------------------------------------- |
|
72 | #--------------------------------------------------------------------------- | |
73 | # QWidget interface |
|
73 | # QWidget interface | |
74 | #--------------------------------------------------------------------------- |
|
74 | #--------------------------------------------------------------------------- | |
75 |
|
75 | |||
76 | def closeEvent(self, event): |
|
76 | def closeEvent(self, event): | |
77 | """ Close the window and the kernel (if necessary). |
|
77 | """ Close the window and the kernel (if necessary). | |
78 |
|
78 | |||
79 | This will prompt the user if they are finished with the kernel, and if |
|
79 | This will prompt the user if they are finished with the kernel, and if | |
80 | so, closes the kernel cleanly. Alternatively, if the exit magic is used, |
|
80 | so, closes the kernel cleanly. Alternatively, if the exit magic is used, | |
81 | it closes without prompt. |
|
81 | it closes without prompt. | |
82 | """ |
|
82 | """ | |
83 | keepkernel = None #Use the prompt by default |
|
83 | keepkernel = None #Use the prompt by default | |
84 | if hasattr(self._frontend,'_keep_kernel_on_exit'): #set by exit magic |
|
84 | if hasattr(self._frontend,'_keep_kernel_on_exit'): #set by exit magic | |
85 | keepkernel = self._frontend._keep_kernel_on_exit |
|
85 | keepkernel = self._frontend._keep_kernel_on_exit | |
86 |
|
86 | |||
87 | kernel_manager = self._frontend.kernel_manager |
|
87 | kernel_manager = self._frontend.kernel_manager | |
88 |
|
88 | |||
89 | if keepkernel is None: #show prompt |
|
89 | if keepkernel is None: #show prompt | |
90 | if kernel_manager and kernel_manager.channels_running: |
|
90 | if kernel_manager and kernel_manager.channels_running: | |
91 | title = self.window().windowTitle() |
|
91 | title = self.window().windowTitle() | |
92 | cancel = QtGui.QMessageBox.Cancel |
|
92 | cancel = QtGui.QMessageBox.Cancel | |
93 | okay = QtGui.QMessageBox.Ok |
|
93 | okay = QtGui.QMessageBox.Ok | |
94 | if self._may_close: |
|
94 | if self._may_close: | |
95 | msg = "You are closing this Console window." |
|
95 | msg = "You are closing this Console window." | |
96 | info = "Would you like to quit the Kernel and all attached Consoles as well?" |
|
96 | info = "Would you like to quit the Kernel and all attached Consoles as well?" | |
97 | justthis = QtGui.QPushButton("&No, just this Console", self) |
|
97 | justthis = QtGui.QPushButton("&No, just this Console", self) | |
98 | justthis.setShortcut('N') |
|
98 | justthis.setShortcut('N') | |
99 | closeall = QtGui.QPushButton("&Yes, quit everything", self) |
|
99 | closeall = QtGui.QPushButton("&Yes, quit everything", self) | |
100 | closeall.setShortcut('Y') |
|
100 | closeall.setShortcut('Y') | |
101 | box = QtGui.QMessageBox(QtGui.QMessageBox.Question, |
|
101 | box = QtGui.QMessageBox(QtGui.QMessageBox.Question, | |
102 | title, msg) |
|
102 | title, msg) | |
103 | box.setInformativeText(info) |
|
103 | box.setInformativeText(info) | |
104 | box.addButton(cancel) |
|
104 | box.addButton(cancel) | |
105 | box.addButton(justthis, QtGui.QMessageBox.NoRole) |
|
105 | box.addButton(justthis, QtGui.QMessageBox.NoRole) | |
106 | box.addButton(closeall, QtGui.QMessageBox.YesRole) |
|
106 | box.addButton(closeall, QtGui.QMessageBox.YesRole) | |
107 | box.setDefaultButton(closeall) |
|
107 | box.setDefaultButton(closeall) | |
108 | box.setEscapeButton(cancel) |
|
108 | box.setEscapeButton(cancel) | |
109 | reply = box.exec_() |
|
109 | reply = box.exec_() | |
110 | if reply == 1: # close All |
|
110 | if reply == 1: # close All | |
111 | kernel_manager.shutdown_kernel() |
|
111 | kernel_manager.shutdown_kernel() | |
112 | #kernel_manager.stop_channels() |
|
112 | #kernel_manager.stop_channels() | |
113 | event.accept() |
|
113 | event.accept() | |
114 | elif reply == 0: # close Console |
|
114 | elif reply == 0: # close Console | |
115 | if not self._existing: |
|
115 | if not self._existing: | |
116 | # Have kernel: don't quit, just close the window |
|
116 | # Have kernel: don't quit, just close the window | |
117 | self._app.setQuitOnLastWindowClosed(False) |
|
117 | self._app.setQuitOnLastWindowClosed(False) | |
118 | self.deleteLater() |
|
118 | self.deleteLater() | |
119 | event.accept() |
|
119 | event.accept() | |
120 | else: |
|
120 | else: | |
121 | event.ignore() |
|
121 | event.ignore() | |
122 | else: |
|
122 | else: | |
123 | reply = QtGui.QMessageBox.question(self, title, |
|
123 | reply = QtGui.QMessageBox.question(self, title, | |
124 | "Are you sure you want to close this Console?"+ |
|
124 | "Are you sure you want to close this Console?"+ | |
125 | "\nThe Kernel and other Consoles will remain active.", |
|
125 | "\nThe Kernel and other Consoles will remain active.", | |
126 | okay|cancel, |
|
126 | okay|cancel, | |
127 | defaultButton=okay |
|
127 | defaultButton=okay | |
128 | ) |
|
128 | ) | |
129 | if reply == okay: |
|
129 | if reply == okay: | |
130 | event.accept() |
|
130 | event.accept() | |
131 | else: |
|
131 | else: | |
132 | event.ignore() |
|
132 | event.ignore() | |
133 | elif keepkernel: #close console but leave kernel running (no prompt) |
|
133 | elif keepkernel: #close console but leave kernel running (no prompt) | |
134 | if kernel_manager and kernel_manager.channels_running: |
|
134 | if kernel_manager and kernel_manager.channels_running: | |
135 | if not self._existing: |
|
135 | if not self._existing: | |
136 | # I have the kernel: don't quit, just close the window |
|
136 | # I have the kernel: don't quit, just close the window | |
137 | self._app.setQuitOnLastWindowClosed(False) |
|
137 | self._app.setQuitOnLastWindowClosed(False) | |
138 | event.accept() |
|
138 | event.accept() | |
139 | else: #close console and kernel (no prompt) |
|
139 | else: #close console and kernel (no prompt) | |
140 | if kernel_manager and kernel_manager.channels_running: |
|
140 | if kernel_manager and kernel_manager.channels_running: | |
141 | kernel_manager.shutdown_kernel() |
|
141 | kernel_manager.shutdown_kernel() | |
142 | event.accept() |
|
142 | event.accept() | |
143 |
|
143 | |||
144 | #----------------------------------------------------------------------------- |
|
144 | #----------------------------------------------------------------------------- | |
145 | # Aliases and Flags |
|
145 | # Aliases and Flags | |
146 | #----------------------------------------------------------------------------- |
|
146 | #----------------------------------------------------------------------------- | |
147 |
|
147 | |||
148 | flags = dict(ipkernel_flags) |
|
148 | flags = dict(ipkernel_flags) | |
149 |
|
149 | |||
150 | flags.update({ |
|
150 | flags.update({ | |
151 | 'existing' : ({'IPythonQtConsoleApp' : {'existing' : True}}, |
|
151 | 'existing' : ({'IPythonQtConsoleApp' : {'existing' : True}}, | |
152 | "Connect to an existing kernel."), |
|
152 | "Connect to an existing kernel."), | |
153 | 'pure' : ({'IPythonQtConsoleApp' : {'pure' : True}}, |
|
153 | 'pure' : ({'IPythonQtConsoleApp' : {'pure' : True}}, | |
154 | "Use a pure Python kernel instead of an IPython kernel."), |
|
154 | "Use a pure Python kernel instead of an IPython kernel."), | |
155 | 'plain' : ({'ConsoleWidget' : {'kind' : 'plain'}}, |
|
155 | 'plain' : ({'ConsoleWidget' : {'kind' : 'plain'}}, | |
156 | "Disable rich text support."), |
|
156 | "Disable rich text support."), | |
157 | 'gui-completion' : ({'FrontendWidget' : {'gui_completion' : True}}, |
|
157 | 'gui-completion' : ({'FrontendWidget' : {'gui_completion' : True}}, | |
158 | "use a GUI widget for tab completion"), |
|
158 | "use a GUI widget for tab completion"), | |
159 | }) |
|
159 | }) | |
160 |
|
160 | |||
161 | qt_flags = ['existing', 'pure', 'plain', 'gui-completion'] |
|
161 | qt_flags = ['existing', 'pure', 'plain', 'gui-completion'] | |
162 |
|
162 | |||
163 | aliases = dict(ipkernel_aliases) |
|
163 | aliases = dict(ipkernel_aliases) | |
164 |
|
164 | |||
165 | aliases.update(dict( |
|
165 | aliases.update(dict( | |
166 | hb = 'IPythonQtConsoleApp.hb_port', |
|
166 | hb = 'IPythonQtConsoleApp.hb_port', | |
167 | shell = 'IPythonQtConsoleApp.shell_port', |
|
167 | shell = 'IPythonQtConsoleApp.shell_port', | |
168 | iopub = 'IPythonQtConsoleApp.iopub_port', |
|
168 | iopub = 'IPythonQtConsoleApp.iopub_port', | |
169 | stdin = 'IPythonQtConsoleApp.stdin_port', |
|
169 | stdin = 'IPythonQtConsoleApp.stdin_port', | |
170 | ip = 'IPythonQtConsoleApp.ip', |
|
170 | ip = 'IPythonQtConsoleApp.ip', | |
171 |
|
171 | |||
172 | plain = 'IPythonQtConsoleApp.plain', |
|
172 | plain = 'IPythonQtConsoleApp.plain', | |
173 | pure = 'IPythonQtConsoleApp.pure', |
|
173 | pure = 'IPythonQtConsoleApp.pure', | |
174 | gui_completion = 'FrontendWidget.gui_completion', |
|
174 | gui_completion = 'FrontendWidget.gui_completion', | |
175 | style = 'IPythonWidget.syntax_style', |
|
175 | style = 'IPythonWidget.syntax_style', | |
176 | stylesheet = 'IPythonQtConsoleApp.stylesheet', |
|
176 | stylesheet = 'IPythonQtConsoleApp.stylesheet', | |
177 | colors = 'ZMQInteractiveShell.colors', |
|
177 | colors = 'ZMQInteractiveShell.colors', | |
178 |
|
178 | |||
179 | editor = 'IPythonWidget.editor', |
|
179 | editor = 'IPythonWidget.editor', | |
180 | pi = 'IPythonWidget.in_prompt', |
|
180 | pi = 'IPythonWidget.in_prompt', | |
181 | po = 'IPythonWidget.out_prompt', |
|
181 | po = 'IPythonWidget.out_prompt', | |
182 | si = 'IPythonWidget.input_sep', |
|
182 | si = 'IPythonWidget.input_sep', | |
183 | so = 'IPythonWidget.output_sep', |
|
183 | so = 'IPythonWidget.output_sep', | |
184 | so2 = 'IPythonWidget.output_sep2', |
|
184 | so2 = 'IPythonWidget.output_sep2', | |
185 | )) |
|
185 | )) | |
186 |
|
186 | |||
187 | #----------------------------------------------------------------------------- |
|
187 | #----------------------------------------------------------------------------- | |
188 | # IPythonQtConsole |
|
188 | # IPythonQtConsole | |
189 | #----------------------------------------------------------------------------- |
|
189 | #----------------------------------------------------------------------------- | |
190 |
|
190 | |||
191 | class IPythonQtConsoleApp(BaseIPythonApplication): |
|
191 | class IPythonQtConsoleApp(BaseIPythonApplication): | |
192 | name = 'ipython-qtconsole' |
|
192 | name = 'ipython-qtconsole' | |
193 | default_config_file_name='ipython_config.py' |
|
193 | default_config_file_name='ipython_config.py' | |
194 | classes = [IPKernelApp, IPythonWidget, ZMQInteractiveShell, ProfileDir] |
|
194 | classes = [IPKernelApp, IPythonWidget, ZMQInteractiveShell, ProfileDir] | |
195 | flags = Dict(flags) |
|
195 | flags = Dict(flags) | |
196 | aliases = Dict(aliases) |
|
196 | aliases = Dict(aliases) | |
197 |
|
197 | |||
198 | kernel_argv = List(Unicode) |
|
198 | kernel_argv = List(Unicode) | |
199 |
|
199 | |||
200 | # connection info: |
|
200 | # connection info: | |
201 | ip = Unicode(LOCALHOST, config=True, |
|
201 | ip = Unicode(LOCALHOST, config=True, | |
202 | help="""Set the kernel\'s IP address [default localhost]. |
|
202 | help="""Set the kernel\'s IP address [default localhost]. | |
203 | If the IP address is something other than localhost, then |
|
203 | If the IP address is something other than localhost, then | |
204 | Consoles on other machines will be able to connect |
|
204 | Consoles on other machines will be able to connect | |
205 | to the Kernel, so be careful!""" |
|
205 | to the Kernel, so be careful!""" | |
206 | ) |
|
206 | ) | |
207 | hb_port = Int(0, config=True, |
|
207 | hb_port = Int(0, config=True, | |
208 | help="set the heartbeat port [default: random]") |
|
208 | help="set the heartbeat port [default: random]") | |
209 | shell_port = Int(0, config=True, |
|
209 | shell_port = Int(0, config=True, | |
210 | help="set the shell (XREP) port [default: random]") |
|
210 | help="set the shell (XREP) port [default: random]") | |
211 | iopub_port = Int(0, config=True, |
|
211 | iopub_port = Int(0, config=True, | |
212 | help="set the iopub (PUB) port [default: random]") |
|
212 | help="set the iopub (PUB) port [default: random]") | |
213 | stdin_port = Int(0, config=True, |
|
213 | stdin_port = Int(0, config=True, | |
214 | help="set the stdin (XREQ) port [default: random]") |
|
214 | help="set the stdin (XREQ) port [default: random]") | |
215 |
|
215 | |||
216 | existing = Bool(False, config=True, |
|
216 | existing = Bool(False, config=True, | |
217 | help="Whether to connect to an already running Kernel.") |
|
217 | help="Whether to connect to an already running Kernel.") | |
218 |
|
218 | |||
219 | stylesheet = Unicode('', config=True, |
|
219 | stylesheet = Unicode('', config=True, | |
220 | help="path to a custom CSS stylesheet") |
|
220 | help="path to a custom CSS stylesheet") | |
221 |
|
221 | |||
222 | pure = Bool(False, config=True, |
|
222 | pure = Bool(False, config=True, | |
223 | help="Use a pure Python kernel instead of an IPython kernel.") |
|
223 | help="Use a pure Python kernel instead of an IPython kernel.") | |
224 | plain = Bool(False, config=True, |
|
224 | plain = Bool(False, config=True, | |
225 | help="Use a pure Python kernel instead of an IPython kernel.") |
|
225 | help="Use a plaintext widget instead of rich text (plain can't print/save).") | |
226 |
|
226 | |||
227 | def _pure_changed(self, name, old, new): |
|
227 | def _pure_changed(self, name, old, new): | |
228 | kind = 'plain' if self.plain else 'rich' |
|
228 | kind = 'plain' if self.plain else 'rich' | |
229 | self.config.ConsoleWidget.kind = kind |
|
229 | self.config.ConsoleWidget.kind = kind | |
230 | if self.pure: |
|
230 | if self.pure: | |
231 | self.widget_factory = FrontendWidget |
|
231 | self.widget_factory = FrontendWidget | |
232 | elif self.plain: |
|
232 | elif self.plain: | |
233 | self.widget_factory = IPythonWidget |
|
233 | self.widget_factory = IPythonWidget | |
234 | else: |
|
234 | else: | |
235 | self.widget_factory = RichIPythonWidget |
|
235 | self.widget_factory = RichIPythonWidget | |
236 |
|
236 | |||
237 | _plain_changed = _pure_changed |
|
237 | _plain_changed = _pure_changed | |
238 |
|
238 | |||
239 | # the factory for creating a widget |
|
239 | # the factory for creating a widget | |
240 | widget_factory = Any(RichIPythonWidget) |
|
240 | widget_factory = Any(RichIPythonWidget) | |
241 |
|
241 | |||
242 | def parse_command_line(self, argv=None): |
|
242 | def parse_command_line(self, argv=None): | |
243 | super(IPythonQtConsoleApp, self).parse_command_line(argv) |
|
243 | super(IPythonQtConsoleApp, self).parse_command_line(argv) | |
244 | if argv is None: |
|
244 | if argv is None: | |
245 | argv = sys.argv[1:] |
|
245 | argv = sys.argv[1:] | |
246 |
|
246 | |||
247 | self.kernel_argv = list(argv) # copy |
|
247 | self.kernel_argv = list(argv) # copy | |
248 |
|
248 | |||
249 | # scrub frontend-specific flags |
|
249 | # scrub frontend-specific flags | |
250 | for a in argv: |
|
250 | for a in argv: | |
251 | if a.startswith('--') and a[2:] in qt_flags: |
|
251 | if a.startswith('--') and a[2:] in qt_flags: | |
252 | self.kernel_argv.remove(a) |
|
252 | self.kernel_argv.remove(a) | |
253 |
|
253 | |||
254 | def init_kernel_manager(self): |
|
254 | def init_kernel_manager(self): | |
255 | # Don't let Qt or ZMQ swallow KeyboardInterupts. |
|
255 | # Don't let Qt or ZMQ swallow KeyboardInterupts. | |
256 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
|
256 | signal.signal(signal.SIGINT, signal.SIG_DFL) | |
257 |
|
257 | |||
258 | # Create a KernelManager and start a kernel. |
|
258 | # Create a KernelManager and start a kernel. | |
259 | self.kernel_manager = QtKernelManager( |
|
259 | self.kernel_manager = QtKernelManager( | |
260 | shell_address=(self.ip, self.shell_port), |
|
260 | shell_address=(self.ip, self.shell_port), | |
261 | sub_address=(self.ip, self.iopub_port), |
|
261 | sub_address=(self.ip, self.iopub_port), | |
262 | stdin_address=(self.ip, self.stdin_port), |
|
262 | stdin_address=(self.ip, self.stdin_port), | |
263 | hb_address=(self.ip, self.hb_port) |
|
263 | hb_address=(self.ip, self.hb_port) | |
264 | ) |
|
264 | ) | |
265 | # start the kernel |
|
265 | # start the kernel | |
266 | if not self.existing: |
|
266 | if not self.existing: | |
267 | kwargs = dict(ip=self.ip, ipython=not self.pure) |
|
267 | kwargs = dict(ip=self.ip, ipython=not self.pure) | |
268 | kwargs['extra_arguments'] = self.kernel_argv |
|
268 | kwargs['extra_arguments'] = self.kernel_argv | |
269 | self.kernel_manager.start_kernel(**kwargs) |
|
269 | self.kernel_manager.start_kernel(**kwargs) | |
270 | self.kernel_manager.start_channels() |
|
270 | self.kernel_manager.start_channels() | |
271 |
|
271 | |||
272 |
|
272 | |||
273 | def init_qt_elements(self): |
|
273 | def init_qt_elements(self): | |
274 | # Create the widget. |
|
274 | # Create the widget. | |
275 | self.app = QtGui.QApplication([]) |
|
275 | self.app = QtGui.QApplication([]) | |
276 | local_kernel = (not self.existing) or self.ip in LOCAL_IPS |
|
276 | local_kernel = (not self.existing) or self.ip in LOCAL_IPS | |
277 | self.widget = self.widget_factory(config=self.config, |
|
277 | self.widget = self.widget_factory(config=self.config, | |
278 | local_kernel=local_kernel) |
|
278 | local_kernel=local_kernel) | |
279 | self.widget.kernel_manager = self.kernel_manager |
|
279 | self.widget.kernel_manager = self.kernel_manager | |
280 | self.window = MainWindow(self.app, self.widget, self.existing, |
|
280 | self.window = MainWindow(self.app, self.widget, self.existing, | |
281 | may_close=local_kernel) |
|
281 | may_close=local_kernel) | |
282 | self.window.setWindowTitle('Python' if self.pure else 'IPython') |
|
282 | self.window.setWindowTitle('Python' if self.pure else 'IPython') | |
283 |
|
283 | |||
284 | def init_colors(self): |
|
284 | def init_colors(self): | |
285 | """Configure the coloring of the widget""" |
|
285 | """Configure the coloring of the widget""" | |
286 | # Note: This will be dramatically simplified when colors |
|
286 | # Note: This will be dramatically simplified when colors | |
287 | # are removed from the backend. |
|
287 | # are removed from the backend. | |
288 |
|
288 | |||
289 | if self.pure: |
|
289 | if self.pure: | |
290 | # only IPythonWidget supports styling |
|
290 | # only IPythonWidget supports styling | |
291 | return |
|
291 | return | |
292 |
|
292 | |||
293 | # parse the colors arg down to current known labels |
|
293 | # parse the colors arg down to current known labels | |
294 | try: |
|
294 | try: | |
295 | colors = self.config.ZMQInteractiveShell.colors |
|
295 | colors = self.config.ZMQInteractiveShell.colors | |
296 | except AttributeError: |
|
296 | except AttributeError: | |
297 | colors = None |
|
297 | colors = None | |
298 | try: |
|
298 | try: | |
299 | style = self.config.IPythonWidget.colors |
|
299 | style = self.config.IPythonWidget.colors | |
300 | except AttributeError: |
|
300 | except AttributeError: | |
301 | style = None |
|
301 | style = None | |
302 |
|
302 | |||
303 | # find the value for colors: |
|
303 | # find the value for colors: | |
304 | if colors: |
|
304 | if colors: | |
305 | colors=colors.lower() |
|
305 | colors=colors.lower() | |
306 | if colors in ('lightbg', 'light'): |
|
306 | if colors in ('lightbg', 'light'): | |
307 | colors='lightbg' |
|
307 | colors='lightbg' | |
308 | elif colors in ('dark', 'linux'): |
|
308 | elif colors in ('dark', 'linux'): | |
309 | colors='linux' |
|
309 | colors='linux' | |
310 | else: |
|
310 | else: | |
311 | colors='nocolor' |
|
311 | colors='nocolor' | |
312 | elif style: |
|
312 | elif style: | |
313 | if style=='bw': |
|
313 | if style=='bw': | |
314 | colors='nocolor' |
|
314 | colors='nocolor' | |
315 | elif styles.dark_style(style): |
|
315 | elif styles.dark_style(style): | |
316 | colors='linux' |
|
316 | colors='linux' | |
317 | else: |
|
317 | else: | |
318 | colors='lightbg' |
|
318 | colors='lightbg' | |
319 | else: |
|
319 | else: | |
320 | colors=None |
|
320 | colors=None | |
321 |
|
321 | |||
322 | # Configure the style. |
|
322 | # Configure the style. | |
323 | widget = self.widget |
|
323 | widget = self.widget | |
324 | if style: |
|
324 | if style: | |
325 | widget.style_sheet = styles.sheet_from_template(style, colors) |
|
325 | widget.style_sheet = styles.sheet_from_template(style, colors) | |
326 | widget.syntax_style = style |
|
326 | widget.syntax_style = style | |
327 | widget._syntax_style_changed() |
|
327 | widget._syntax_style_changed() | |
328 | widget._style_sheet_changed() |
|
328 | widget._style_sheet_changed() | |
329 | elif colors: |
|
329 | elif colors: | |
330 | # use a default style |
|
330 | # use a default style | |
331 | widget.set_default_style(colors=colors) |
|
331 | widget.set_default_style(colors=colors) | |
332 | else: |
|
332 | else: | |
333 | # this is redundant for now, but allows the widget's |
|
333 | # this is redundant for now, but allows the widget's | |
334 | # defaults to change |
|
334 | # defaults to change | |
335 | widget.set_default_style() |
|
335 | widget.set_default_style() | |
336 |
|
336 | |||
337 | if self.stylesheet: |
|
337 | if self.stylesheet: | |
338 | # we got an expicit stylesheet |
|
338 | # we got an expicit stylesheet | |
339 | if os.path.isfile(self.stylesheet): |
|
339 | if os.path.isfile(self.stylesheet): | |
340 | with open(self.stylesheet) as f: |
|
340 | with open(self.stylesheet) as f: | |
341 | sheet = f.read() |
|
341 | sheet = f.read() | |
342 | widget.style_sheet = sheet |
|
342 | widget.style_sheet = sheet | |
343 | widget._style_sheet_changed() |
|
343 | widget._style_sheet_changed() | |
344 | else: |
|
344 | else: | |
345 | raise IOError("Stylesheet %r not found."%self.stylesheet) |
|
345 | raise IOError("Stylesheet %r not found."%self.stylesheet) | |
346 |
|
346 | |||
347 | def initialize(self, argv=None): |
|
347 | def initialize(self, argv=None): | |
348 | super(IPythonQtConsoleApp, self).initialize(argv) |
|
348 | super(IPythonQtConsoleApp, self).initialize(argv) | |
349 | self.init_kernel_manager() |
|
349 | self.init_kernel_manager() | |
350 | self.init_qt_elements() |
|
350 | self.init_qt_elements() | |
351 | self.init_colors() |
|
351 | self.init_colors() | |
352 |
|
352 | |||
353 | def start(self): |
|
353 | def start(self): | |
354 |
|
354 | |||
355 | # draw the window |
|
355 | # draw the window | |
356 | self.window.show() |
|
356 | self.window.show() | |
357 |
|
357 | |||
358 | # Start the application main loop. |
|
358 | # Start the application main loop. | |
359 | self.app.exec_() |
|
359 | self.app.exec_() | |
360 |
|
360 | |||
361 | #----------------------------------------------------------------------------- |
|
361 | #----------------------------------------------------------------------------- | |
362 | # Main entry point |
|
362 | # Main entry point | |
363 | #----------------------------------------------------------------------------- |
|
363 | #----------------------------------------------------------------------------- | |
364 |
|
364 | |||
365 | def main(): |
|
365 | def main(): | |
366 | app = IPythonQtConsoleApp() |
|
366 | app = IPythonQtConsoleApp() | |
367 | app.initialize() |
|
367 | app.initialize() | |
368 | app.start() |
|
368 | app.start() | |
369 |
|
369 | |||
370 |
|
370 | |||
371 | if __name__ == '__main__': |
|
371 | if __name__ == '__main__': | |
372 | main() |
|
372 | main() |
@@ -1,219 +1,222 b'' | |||||
1 | .. _qtconsole: |
|
1 | .. _qtconsole: | |
2 |
|
2 | |||
3 | ========================= |
|
3 | ========================= | |
4 | IPython as a QtGUI widget |
|
4 | IPython as a QtGUI widget | |
5 | ========================= |
|
5 | ========================= | |
6 |
|
6 | |||
7 | We now have a version of IPython, using the new two-process :ref:`ZeroMQ Kernel <ipythonzmq>`, |
|
7 | We now have a version of IPython, using the new two-process :ref:`ZeroMQ Kernel <ipythonzmq>`, | |
8 | running in a PyQt_ GUI. |
|
8 | running in a PyQt_ GUI. | |
9 |
|
9 | |||
10 | Overview |
|
10 | Overview | |
11 | ======== |
|
11 | ======== | |
12 |
|
12 | |||
13 | The Qt frontend has hand-coded emacs-style bindings for text navigation. This is not yet |
|
13 | The Qt frontend has hand-coded emacs-style bindings for text navigation. This is not yet | |
14 | configurable. |
|
14 | configurable. | |
15 |
|
15 | |||
16 | .. seealso:: |
|
16 | .. seealso:: | |
17 |
|
17 | |||
18 | :ref:`The original IPython-Qt project description. <ipython_qt>` |
|
18 | :ref:`The original IPython-Qt project description. <ipython_qt>` | |
19 |
|
19 | |||
20 | ``%loadpy`` |
|
20 | ``%loadpy`` | |
21 | =========== |
|
21 | =========== | |
22 |
|
22 | |||
23 | The ``%loadpy`` magic has been added, just for the GUI frontend. It takes any python |
|
23 | The ``%loadpy`` magic has been added, just for the GUI frontend. It takes any python | |
24 | script (must end in '.py'), and pastes its contents as your next input, so you can edit it |
|
24 | script (must end in '.py'), and pastes its contents as your next input, so you can edit it | |
25 | before executing. The script may be on your machine, but you can also specify a url, and |
|
25 | before executing. The script may be on your machine, but you can also specify a url, and | |
26 | it will download the script from the web. This is particularly useful for playing with |
|
26 | it will download the script from the web. This is particularly useful for playing with | |
27 | examples from documentation, such as matplotlib. |
|
27 | examples from documentation, such as matplotlib. | |
28 |
|
28 | |||
29 | .. sourcecode:: ipython |
|
29 | .. sourcecode:: ipython | |
30 |
|
30 | |||
31 | In [6]: %loadpy |
|
31 | In [6]: %loadpy | |
32 | http://matplotlib.sourceforge.net/plot_directive/mpl_examples/mplot3d/contour3d_demo.py |
|
32 | http://matplotlib.sourceforge.net/plot_directive/mpl_examples/mplot3d/contour3d_demo.py | |
33 |
|
33 | |||
34 | In [7]: from mpl_toolkits.mplot3d import axes3d |
|
34 | In [7]: from mpl_toolkits.mplot3d import axes3d | |
35 | ...: import matplotlib.pyplot as plt |
|
35 | ...: import matplotlib.pyplot as plt | |
36 | ...: |
|
36 | ...: | |
37 | ...: fig = plt.figure() |
|
37 | ...: fig = plt.figure() | |
38 | ...: ax = fig.add_subplot(111, projection='3d') |
|
38 | ...: ax = fig.add_subplot(111, projection='3d') | |
39 | ...: X, Y, Z = axes3d.get_test_data(0.05) |
|
39 | ...: X, Y, Z = axes3d.get_test_data(0.05) | |
40 | ...: cset = ax.contour(X, Y, Z) |
|
40 | ...: cset = ax.contour(X, Y, Z) | |
41 | ...: ax.clabel(cset, fontsize=9, inline=1) |
|
41 | ...: ax.clabel(cset, fontsize=9, inline=1) | |
42 | ...: |
|
42 | ...: | |
43 | ...: plt.show() |
|
43 | ...: plt.show() | |
44 |
|
44 | |||
45 | Pylab |
|
45 | Pylab | |
46 | ===== |
|
46 | ===== | |
47 |
|
47 | |||
48 | One of the most exciting features of the new console is embedded matplotlib figures. You |
|
48 | One of the most exciting features of the new console is embedded matplotlib figures. You | |
49 | can use any standard matplotlib GUI backend (Except native MacOSX) to draw the figures, |
|
49 | can use any standard matplotlib GUI backend (Except native MacOSX) to draw the figures, | |
50 | and since there is now a two-process model, there is no longer a conflict between user |
|
50 | and since there is now a two-process model, there is no longer a conflict between user | |
51 | input and the drawing eventloop. |
|
51 | input and the drawing eventloop. | |
52 |
|
52 | |||
53 | .. image:: figs/besselj.png |
|
53 | .. image:: figs/besselj.png | |
54 | :width: 519px |
|
54 | :width: 519px | |
55 |
|
55 | |||
56 | .. pastefig: |
|
56 | .. pastefig: | |
57 |
|
57 | |||
58 | :func:`pastefig` |
|
58 | :func:`pastefig` | |
59 | **************** |
|
59 | **************** | |
60 |
|
60 | |||
61 | An additional function, :func:`pastefig`, will be added to the global namespace if you |
|
61 | An additional function, :func:`pastefig`, will be added to the global namespace if you | |
62 |
specify the `` |
|
62 | specify the ``pylab`` argument. This takes the active figures in matplotlib, and embeds | |
63 | them in your document. This is especially useful for saving_ your work. |
|
63 | them in your document. This is especially useful for saving_ your work. | |
64 |
|
64 | |||
65 | .. _inline: |
|
65 | .. _inline: | |
66 |
|
66 | |||
67 |
`` |
|
67 | ``pylab=inline`` | |
68 | ****************** |
|
68 | ****************** | |
69 |
|
69 | |||
70 | If you want to have all of your figures embedded in your session, instead of calling |
|
70 | If you want to have all of your figures embedded in your session, instead of calling | |
71 |
:func:`pastefig`, you can specify `` |
|
71 | :func:`pastefig`, you can specify ``pylab=inline``, and each time you make a plot, it | |
72 | will show up in your document, as if you had called :func:`pastefig`. |
|
72 | will show up in your document, as if you had called :func:`pastefig`. | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | .. _saving: |
|
75 | .. _saving: | |
76 |
|
76 | |||
77 | Saving and Printing |
|
77 | Saving and Printing | |
78 | =================== |
|
78 | =================== | |
79 |
|
79 | |||
80 | IPythonQt has the ability to save your current session, as either HTML or XHTML. If you |
|
80 | IPythonQt has the ability to save your current session, as either HTML or XHTML. If you | |
81 | have been using :func:`pastefig` or inline_ pylab, your figures will be PNG |
|
81 | have been using :func:`pastefig` or inline_ pylab, your figures will be PNG | |
82 | in HTML, or inlined as SVG in XHTML. PNG images have the option to be either in an |
|
82 | in HTML, or inlined as SVG in XHTML. PNG images have the option to be either in an | |
83 | external folder, as in many browsers' "Webpage, Complete" option, or inlined as well, for |
|
83 | external folder, as in many browsers' "Webpage, Complete" option, or inlined as well, for | |
84 | a larger, but more portable file. |
|
84 | a larger, but more portable file. | |
85 |
|
85 | |||
86 | The widget also exposes the ability to print directly, via the default print shortcut or |
|
86 | The widget also exposes the ability to print directly, via the default print shortcut or | |
87 | context menu. |
|
87 | context menu. | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | .. Note:: |
|
90 | .. Note:: | |
91 |
|
91 | |||
92 |
Saving is only available to richtext Qt widgets, |
|
92 | Saving is only available to richtext Qt widgets, which are used by default, but | |
93 | ``--rich`` flag, or with ``--pylab``, which always uses a richtext widget. |
|
93 | if you pass the ``--plain`` flag, saving will not be available to you. | |
94 |
|
94 | |||
95 |
|
95 | |||
96 | See these examples of :download:`png/html<figs/jn.html>` and :download:`svg/xhtml |
|
96 | See these examples of :download:`png/html<figs/jn.html>` and :download:`svg/xhtml | |
97 | <figs/jn.xhtml>` output. Note that syntax highlighting does not survive export. This is a known |
|
97 | <figs/jn.xhtml>` output. Note that syntax highlighting does not survive export. This is a known | |
98 | issue, and is being investigated. |
|
98 | issue, and is being investigated. | |
99 |
|
99 | |||
100 | Colors and Highlighting |
|
100 | Colors and Highlighting | |
101 | ======================= |
|
101 | ======================= | |
102 |
|
102 | |||
103 | Terminal IPython has always had some coloring, but never syntax highlighting. There are a |
|
103 | Terminal IPython has always had some coloring, but never syntax highlighting. There are a | |
104 |
few simple color choices, specified by the `` |
|
104 | few simple color choices, specified by the ``colors`` flag or ``%colors`` magic: | |
105 |
|
105 | |||
106 | * LightBG for light backgrounds |
|
106 | * LightBG for light backgrounds | |
107 | * Linux for dark backgrounds |
|
107 | * Linux for dark backgrounds | |
108 | * NoColor for a simple colorless terminal |
|
108 | * NoColor for a simple colorless terminal | |
109 |
|
109 | |||
110 |
The Qt widget has full support for the `` |
|
110 | The Qt widget has full support for the ``colors`` flag used in the terminal shell. | |
111 | aliases for the colors (the old names still work): dark=Linux, light=LightBG, bw=NoColor. |
|
|||
112 |
|
111 | |||
113 | The Qt widget, however, has full syntax highlighting as you type, handled by the |
|
112 | The Qt widget, however, has full syntax highlighting as you type, handled by the | |
114 |
`pygments`_ library. The `` |
|
113 | `pygments`_ library. The ``style`` argument exposes access to any style by name that can | |
115 |
be found by pygments, and there are several already installed. The `` |
|
114 | be found by pygments, and there are several already installed. The ``colors`` argument, | |
116 | if unspecified, will be guessed based on the chosen style. Similarly, there are default |
|
115 | if unspecified, will be guessed based on the chosen style. Similarly, there are default | |
117 |
styles associated with each `` |
|
116 | styles associated with each ``colors`` option. | |
118 |
|
117 | |||
119 |
|
118 | |||
120 |
Screenshot of ``ipython-qtconsole |
|
119 | Screenshot of ``ipython-qtconsole colors=linux``, which uses the 'monokai' theme by | |
121 | default: |
|
120 | default: | |
122 |
|
121 | |||
123 | .. image:: figs/colors_dark.png |
|
122 | .. image:: figs/colors_dark.png | |
124 | :width: 627px |
|
123 | :width: 627px | |
125 |
|
124 | |||
126 | .. Note:: |
|
125 | .. Note:: | |
127 |
|
126 | |||
128 | Calling ``ipython-qtconsole -h`` will show all the style names that pygments can find |
|
127 | Calling ``ipython-qtconsole -h`` will show all the style names that pygments can find | |
129 | on your system. |
|
128 | on your system. | |
130 |
|
129 | |||
131 | You can also pass the filename of a custom CSS stylesheet, if you want to do your own |
|
130 | You can also pass the filename of a custom CSS stylesheet, if you want to do your own | |
132 |
coloring, via the `` |
|
131 | coloring, via the ``stylesheet`` argument. The default LightBG stylesheet: | |
133 |
|
132 | |||
134 | .. sourcecode:: css |
|
133 | .. sourcecode:: css | |
135 |
|
134 | |||
136 | QPlainTextEdit, QTextEdit { background-color: white; |
|
135 | QPlainTextEdit, QTextEdit { background-color: white; | |
137 | color: black ; |
|
136 | color: black ; | |
138 | selection-background-color: #ccc} |
|
137 | selection-background-color: #ccc} | |
139 | .error { color: red; } |
|
138 | .error { color: red; } | |
140 | .in-prompt { color: navy; } |
|
139 | .in-prompt { color: navy; } | |
141 | .in-prompt-number { font-weight: bold; } |
|
140 | .in-prompt-number { font-weight: bold; } | |
142 | .out-prompt { color: darkred; } |
|
141 | .out-prompt { color: darkred; } | |
143 | .out-prompt-number { font-weight: bold; } |
|
142 | .out-prompt-number { font-weight: bold; } | |
144 |
|
143 | |||
|
144 | Fonts | |||
|
145 | ===== | |||
|
146 | ||||
|
147 | The QtConsole has configurable via the ConsoleWidget. To change these, set the ``font_family`` | |||
|
148 | or ``font_size`` traits of the ConsoleWidget. For instance, to use 9pt Anonymous Pro:: | |||
|
149 | ||||
|
150 | $> ipython-qtconsole ConsoleWidget.font_family="Anonymous Pro" ConsoleWidget.font_size=9 | |||
|
151 | ||||
145 | Process Management |
|
152 | Process Management | |
146 | ================== |
|
153 | ================== | |
147 |
|
154 | |||
148 | With the two-process ZMQ model, the frontend does not block input during execution. This |
|
155 | With the two-process ZMQ model, the frontend does not block input during execution. This | |
149 | means that actions can be taken by the frontend while the Kernel is executing, or even |
|
156 | means that actions can be taken by the frontend while the Kernel is executing, or even | |
150 | after it crashes. The most basic such command is via 'Ctrl-.', which restarts the kernel. |
|
157 | after it crashes. The most basic such command is via 'Ctrl-.', which restarts the kernel. | |
151 | This can be done in the middle of a blocking execution. The frontend can also know, via a |
|
158 | This can be done in the middle of a blocking execution. The frontend can also know, via a | |
152 | heartbeat mechanism, that the kernel has died. This means that the frontend can safely |
|
159 | heartbeat mechanism, that the kernel has died. This means that the frontend can safely | |
153 | restart the kernel. |
|
160 | restart the kernel. | |
154 |
|
161 | |||
155 | Multiple Consoles |
|
162 | Multiple Consoles | |
156 | ***************** |
|
163 | ***************** | |
157 |
|
164 | |||
158 | Since the Kernel listens on the network, multiple frontends can connect to it. These |
|
165 | Since the Kernel listens on the network, multiple frontends can connect to it. These | |
159 | do not have to all be qt frontends - any IPython frontend can connect and run code. |
|
166 | do not have to all be qt frontends - any IPython frontend can connect and run code. | |
160 | When you start ipython-qtconsole, there will be an output line, like:: |
|
167 | When you start ipython-qtconsole, there will be an output line, like:: | |
161 |
|
168 | |||
162 | To connect another client to this kernel, use: |
|
169 | To connect another client to this kernel, use: | |
163 |
- |
|
170 | --external shell=62109 iopub=62110 stdin=62111 hb=62112 | |
164 |
|
171 | |||
165 | Other frontends can connect to your kernel, and share in the execution. This is great for |
|
172 | Other frontends can connect to your kernel, and share in the execution. This is great for | |
166 | collaboration. The `-e` flag is for 'external'. Starting other consoles with that flag |
|
173 | collaboration. The `-e` flag is for 'external'. Starting other consoles with that flag | |
167 | will not try to start their own, but rather connect to yours. Ultimately, you will not |
|
174 | will not try to start their own, but rather connect to yours. Ultimately, you will not | |
168 | have to specify each port individually, but for now this copy-paste method is best. |
|
175 | have to specify each port individually, but for now this copy-paste method is best. | |
169 |
|
176 | |||
170 | By default (for security reasons), the kernel only listens on localhost, so you can only |
|
177 | By default (for security reasons), the kernel only listens on localhost, so you can only | |
171 | connect multiple frontends to the kernel from your local machine. You can specify to |
|
178 | connect multiple frontends to the kernel from your local machine. You can specify to | |
172 |
listen on an external interface by specifying the `` |
|
179 | listen on an external interface by specifying the ``ip`` argument:: | |
173 |
|
180 | |||
174 |
$> ipython-qtconsole |
|
181 | $> ipython-qtconsole ip=192.168.1.123 | |
175 |
|
182 | |||
176 | If you specify the ip as 0.0.0.0, that refers to all interfaces, so any computer that can |
|
183 | If you specify the ip as 0.0.0.0, that refers to all interfaces, so any computer that can | |
177 | see yours can connect to the kernel. |
|
184 | see yours can connect to the kernel. | |
178 |
|
185 | |||
179 | .. warning:: |
|
186 | .. warning:: | |
180 |
|
187 | |||
181 | Since the ZMQ code currently has no security, listening on an external-facing IP |
|
188 | Since the ZMQ code currently has no security, listening on an external-facing IP | |
182 | is dangerous. You are giving any computer that can see you on the network the ability |
|
189 | is dangerous. You are giving any computer that can see you on the network the ability | |
183 | to issue arbitrary shell commands as you on your machine. Be very careful with this. |
|
190 | to issue arbitrary shell commands as you on your machine. Be very careful with this. | |
184 |
|
191 | |||
185 |
|
192 | |||
186 | Stopping Kernels and Consoles |
|
193 | Stopping Kernels and Consoles | |
187 | ***************************** |
|
194 | ***************************** | |
188 |
|
195 | |||
189 | Since there can be many consoles per kernel, the shutdown mechanism and dialog are |
|
196 | Since there can be many consoles per kernel, the shutdown mechanism and dialog are | |
190 | probably more complicated than you are used to. Since you don't always want to shutdown a |
|
197 | probably more complicated than you are used to. Since you don't always want to shutdown a | |
191 | kernel when you close a window, you are given the option to just close the console window |
|
198 | kernel when you close a window, you are given the option to just close the console window | |
192 | or also close the Kernel and *all other windows*. Note that this only refers to all other |
|
199 | or also close the Kernel and *all other windows*. Note that this only refers to all other | |
193 | *local* windows, as remote Consoles are not allowed to shutdown the kernel, and shutdowns |
|
200 | *local* windows, as remote Consoles are not allowed to shutdown the kernel, and shutdowns | |
194 | do not close Remote consoles (to allow for saving, etc.). |
|
201 | do not close Remote consoles (to allow for saving, etc.). | |
195 |
|
202 | |||
196 | Rules: |
|
203 | Rules: | |
197 |
|
204 | |||
198 | * Restarting the kernel automatically clears all *local* Consoles, and prompts remote |
|
205 | * Restarting the kernel automatically clears all *local* Consoles, and prompts remote | |
199 | Consoles about the reset. |
|
206 | Consoles about the reset. | |
200 | * Shutdown closes all *local* Consoles, and notifies remotes that |
|
207 | * Shutdown closes all *local* Consoles, and notifies remotes that | |
201 | the Kernel has been shutdown. |
|
208 | the Kernel has been shutdown. | |
202 | * Remote Consoles may not restart or shutdown the kernel. |
|
209 | * Remote Consoles may not restart or shutdown the kernel. | |
203 |
|
210 | |||
204 |
|
211 | |||
205 | Regressions |
|
212 | Regressions | |
206 | =========== |
|
213 | =========== | |
207 |
|
214 | |||
208 | There are some features, where the qt console lags behind the Terminal frontend. We hope |
|
215 | There are some features, where the qt console lags behind the Terminal frontend. We hope | |
209 | to have these fixed by 0.11 release. |
|
216 | to have these fixed by 0.11 release. | |
210 |
|
217 | |||
211 | * Configuration: The Qt frontend and ZMQ kernel are not yet hooked up to the IPython |
|
|||
212 | configuration system |
|
|||
213 | * History Persistence: Currently the history of a GUI session does |
|
|||
214 | not persist between sessions. |
|
|||
215 | * !cmd input: Due to our use of pexpect, we cannot pass input to subprocesses launched |
|
218 | * !cmd input: Due to our use of pexpect, we cannot pass input to subprocesses launched | |
216 | using the '!' escape. (this will not be fixed). |
|
219 | using the '!' escape. (this will not be fixed). | |
217 |
|
220 | |||
218 | .. [PyQt] PyQt4 http://www.riverbankcomputing.co.uk/software/pyqt/download |
|
221 | .. [PyQt] PyQt4 http://www.riverbankcomputing.co.uk/software/pyqt/download | |
219 | .. [pygments] Pygments http://pygments.org/ |
|
222 | .. [pygments] Pygments http://pygments.org/ |
General Comments 0
You need to be logged in to leave comments.
Login now