##// END OF EJS Templates
add 'ipython kernel' entry point...
MinRK -
Show More
@@ -1,383 +1,387 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 """
3 """
4 The :class:`~IPython.core.application.Application` object for the command
4 The :class:`~IPython.core.application.Application` object for the command
5 line :command:`ipython` program.
5 line :command:`ipython` program.
6
6
7 Authors
7 Authors
8 -------
8 -------
9
9
10 * Brian Granger
10 * Brian Granger
11 * Fernando Perez
11 * Fernando Perez
12 * Min Ragan-Kelley
12 * Min Ragan-Kelley
13 """
13 """
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Copyright (C) 2008-2010 The IPython Development Team
16 # Copyright (C) 2008-2010 The IPython Development Team
17 #
17 #
18 # Distributed under the terms of the BSD License. The full license is in
18 # Distributed under the terms of the BSD License. The full license is in
19 # the file COPYING, distributed as part of this software.
19 # the file COPYING, distributed as part of this software.
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Imports
23 # Imports
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25
25
26 from __future__ import absolute_import
26 from __future__ import absolute_import
27
27
28 import logging
28 import logging
29 import os
29 import os
30 import sys
30 import sys
31
31
32 from IPython.config.loader import (
32 from IPython.config.loader import (
33 Config, PyFileConfigLoader
33 Config, PyFileConfigLoader
34 )
34 )
35 from IPython.config.application import boolean_flag
35 from IPython.config.application import boolean_flag
36 from IPython.core import release
36 from IPython.core import release
37 from IPython.core import usage
37 from IPython.core import usage
38 from IPython.core.crashhandler import CrashHandler
38 from IPython.core.crashhandler import CrashHandler
39 from IPython.core.formatters import PlainTextFormatter
39 from IPython.core.formatters import PlainTextFormatter
40 from IPython.core.application import (
40 from IPython.core.application import (
41 ProfileDir, BaseIPythonApplication, base_flags, base_aliases
41 ProfileDir, BaseIPythonApplication, base_flags, base_aliases
42 )
42 )
43 from IPython.core.shellapp import (
43 from IPython.core.shellapp import (
44 InteractiveShellApp, shell_flags, shell_aliases
44 InteractiveShellApp, shell_flags, shell_aliases
45 )
45 )
46 from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
46 from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
47 from IPython.lib import inputhook
47 from IPython.lib import inputhook
48 from IPython.utils import warn
48 from IPython.utils import warn
49 from IPython.utils.path import get_ipython_dir, check_for_old_config
49 from IPython.utils.path import get_ipython_dir, check_for_old_config
50 from IPython.utils.traitlets import (
50 from IPython.utils.traitlets import (
51 Bool, List, Dict, CaselessStrEnum
51 Bool, List, Dict, CaselessStrEnum
52 )
52 )
53
53
54 #-----------------------------------------------------------------------------
54 #-----------------------------------------------------------------------------
55 # Globals, utilities and helpers
55 # Globals, utilities and helpers
56 #-----------------------------------------------------------------------------
56 #-----------------------------------------------------------------------------
57
57
58 #: The default config file name for this application.
58 #: The default config file name for this application.
59 default_config_file_name = u'ipython_config.py'
59 default_config_file_name = u'ipython_config.py'
60
60
61 _examples = """
61 _examples = """
62 ipython --pylab # start in pylab mode
62 ipython --pylab # start in pylab mode
63 ipython --pylab=qt # start in pylab mode with the qt4 backend
63 ipython --pylab=qt # start in pylab mode with the qt4 backend
64 ipython --log-level=DEBUG # set logging to DEBUG
64 ipython --log-level=DEBUG # set logging to DEBUG
65 ipython --profile=foo # start with profile foo
65 ipython --profile=foo # start with profile foo
66
66
67 ipython qtconsole # start the qtconsole GUI application
67 ipython qtconsole # start the qtconsole GUI application
68 ipython qtconsole -h # show the help string for the qtconsole subcmd
68 ipython qtconsole -h # show the help string for the qtconsole subcmd
69
69
70 ipython profile create foo # create profile foo w/ default config files
70 ipython profile create foo # create profile foo w/ default config files
71 ipython profile -h # show the help string for the profile subcmd
71 ipython profile -h # show the help string for the profile subcmd
72 """
72 """
73
73
74 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
75 # Crash handler for this application
75 # Crash handler for this application
76 #-----------------------------------------------------------------------------
76 #-----------------------------------------------------------------------------
77
77
78 class IPAppCrashHandler(CrashHandler):
78 class IPAppCrashHandler(CrashHandler):
79 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
79 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
80
80
81 def __init__(self, app):
81 def __init__(self, app):
82 contact_name = release.authors['Fernando'][0]
82 contact_name = release.authors['Fernando'][0]
83 contact_email = release.authors['Fernando'][1]
83 contact_email = release.authors['Fernando'][1]
84 bug_tracker = 'http://github.com/ipython/ipython/issues'
84 bug_tracker = 'http://github.com/ipython/ipython/issues'
85 super(IPAppCrashHandler,self).__init__(
85 super(IPAppCrashHandler,self).__init__(
86 app, contact_name, contact_email, bug_tracker
86 app, contact_name, contact_email, bug_tracker
87 )
87 )
88
88
89 def make_report(self,traceback):
89 def make_report(self,traceback):
90 """Return a string containing a crash report."""
90 """Return a string containing a crash report."""
91
91
92 sec_sep = self.section_sep
92 sec_sep = self.section_sep
93 # Start with parent report
93 # Start with parent report
94 report = [super(IPAppCrashHandler, self).make_report(traceback)]
94 report = [super(IPAppCrashHandler, self).make_report(traceback)]
95 # Add interactive-specific info we may have
95 # Add interactive-specific info we may have
96 rpt_add = report.append
96 rpt_add = report.append
97 try:
97 try:
98 rpt_add(sec_sep+"History of session input:")
98 rpt_add(sec_sep+"History of session input:")
99 for line in self.app.shell.user_ns['_ih']:
99 for line in self.app.shell.user_ns['_ih']:
100 rpt_add(line)
100 rpt_add(line)
101 rpt_add('\n*** Last line of input (may not be in above history):\n')
101 rpt_add('\n*** Last line of input (may not be in above history):\n')
102 rpt_add(self.app.shell._last_input_line+'\n')
102 rpt_add(self.app.shell._last_input_line+'\n')
103 except:
103 except:
104 pass
104 pass
105
105
106 return ''.join(report)
106 return ''.join(report)
107
107
108 #-----------------------------------------------------------------------------
108 #-----------------------------------------------------------------------------
109 # Aliases and Flags
109 # Aliases and Flags
110 #-----------------------------------------------------------------------------
110 #-----------------------------------------------------------------------------
111 flags = dict(base_flags)
111 flags = dict(base_flags)
112 flags.update(shell_flags)
112 flags.update(shell_flags)
113 addflag = lambda *args: flags.update(boolean_flag(*args))
113 addflag = lambda *args: flags.update(boolean_flag(*args))
114 addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax',
114 addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax',
115 'Turn on auto editing of files with syntax errors.',
115 'Turn on auto editing of files with syntax errors.',
116 'Turn off auto editing of files with syntax errors.'
116 'Turn off auto editing of files with syntax errors.'
117 )
117 )
118 addflag('banner', 'TerminalIPythonApp.display_banner',
118 addflag('banner', 'TerminalIPythonApp.display_banner',
119 "Display a banner upon starting IPython.",
119 "Display a banner upon starting IPython.",
120 "Don't display a banner upon starting IPython."
120 "Don't display a banner upon starting IPython."
121 )
121 )
122 addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit',
122 addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit',
123 """Set to confirm when you try to exit IPython with an EOF (Control-D
123 """Set to confirm when you try to exit IPython with an EOF (Control-D
124 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
124 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
125 you can force a direct exit without any confirmation.""",
125 you can force a direct exit without any confirmation.""",
126 "Don't prompt the user when exiting."
126 "Don't prompt the user when exiting."
127 )
127 )
128 addflag('term-title', 'TerminalInteractiveShell.term_title',
128 addflag('term-title', 'TerminalInteractiveShell.term_title',
129 "Enable auto setting the terminal title.",
129 "Enable auto setting the terminal title.",
130 "Disable auto setting the terminal title."
130 "Disable auto setting the terminal title."
131 )
131 )
132 classic_config = Config()
132 classic_config = Config()
133 classic_config.InteractiveShell.cache_size = 0
133 classic_config.InteractiveShell.cache_size = 0
134 classic_config.PlainTextFormatter.pprint = False
134 classic_config.PlainTextFormatter.pprint = False
135 classic_config.InteractiveShell.prompt_in1 = '>>> '
135 classic_config.InteractiveShell.prompt_in1 = '>>> '
136 classic_config.InteractiveShell.prompt_in2 = '... '
136 classic_config.InteractiveShell.prompt_in2 = '... '
137 classic_config.InteractiveShell.prompt_out = ''
137 classic_config.InteractiveShell.prompt_out = ''
138 classic_config.InteractiveShell.separate_in = ''
138 classic_config.InteractiveShell.separate_in = ''
139 classic_config.InteractiveShell.separate_out = ''
139 classic_config.InteractiveShell.separate_out = ''
140 classic_config.InteractiveShell.separate_out2 = ''
140 classic_config.InteractiveShell.separate_out2 = ''
141 classic_config.InteractiveShell.colors = 'NoColor'
141 classic_config.InteractiveShell.colors = 'NoColor'
142 classic_config.InteractiveShell.xmode = 'Plain'
142 classic_config.InteractiveShell.xmode = 'Plain'
143
143
144 flags['classic']=(
144 flags['classic']=(
145 classic_config,
145 classic_config,
146 "Gives IPython a similar feel to the classic Python prompt."
146 "Gives IPython a similar feel to the classic Python prompt."
147 )
147 )
148 # # log doesn't make so much sense this way anymore
148 # # log doesn't make so much sense this way anymore
149 # paa('--log','-l',
149 # paa('--log','-l',
150 # action='store_true', dest='InteractiveShell.logstart',
150 # action='store_true', dest='InteractiveShell.logstart',
151 # help="Start logging to the default log file (./ipython_log.py).")
151 # help="Start logging to the default log file (./ipython_log.py).")
152 #
152 #
153 # # quick is harder to implement
153 # # quick is harder to implement
154 flags['quick']=(
154 flags['quick']=(
155 {'TerminalIPythonApp' : {'quick' : True}},
155 {'TerminalIPythonApp' : {'quick' : True}},
156 "Enable quick startup with no config files."
156 "Enable quick startup with no config files."
157 )
157 )
158
158
159 flags['i'] = (
159 flags['i'] = (
160 {'TerminalIPythonApp' : {'force_interact' : True}},
160 {'TerminalIPythonApp' : {'force_interact' : True}},
161 """If running code from the command line, become interactive afterwards.
161 """If running code from the command line, become interactive afterwards.
162 Note: can also be given simply as '-i.'"""
162 Note: can also be given simply as '-i.'"""
163 )
163 )
164 flags['pylab'] = (
164 flags['pylab'] = (
165 {'TerminalIPythonApp' : {'pylab' : 'auto'}},
165 {'TerminalIPythonApp' : {'pylab' : 'auto'}},
166 """Pre-load matplotlib and numpy for interactive use with
166 """Pre-load matplotlib and numpy for interactive use with
167 the default matplotlib backend."""
167 the default matplotlib backend."""
168 )
168 )
169
169
170 aliases = dict(base_aliases)
170 aliases = dict(base_aliases)
171 aliases.update(shell_aliases)
171 aliases.update(shell_aliases)
172
172
173 # it's possible we don't want short aliases for *all* of these:
173 # it's possible we don't want short aliases for *all* of these:
174 aliases.update(dict(
174 aliases.update(dict(
175 gui='TerminalIPythonApp.gui',
175 gui='TerminalIPythonApp.gui',
176 pylab='TerminalIPythonApp.pylab',
176 pylab='TerminalIPythonApp.pylab',
177 ))
177 ))
178
178
179 #-----------------------------------------------------------------------------
179 #-----------------------------------------------------------------------------
180 # Main classes and functions
180 # Main classes and functions
181 #-----------------------------------------------------------------------------
181 #-----------------------------------------------------------------------------
182
182
183 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
183 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
184 name = u'ipython'
184 name = u'ipython'
185 description = usage.cl_usage
185 description = usage.cl_usage
186 default_config_file_name = default_config_file_name
186 default_config_file_name = default_config_file_name
187 crash_handler_class = IPAppCrashHandler
187 crash_handler_class = IPAppCrashHandler
188 examples = _examples
188 examples = _examples
189
189
190 flags = Dict(flags)
190 flags = Dict(flags)
191 aliases = Dict(aliases)
191 aliases = Dict(aliases)
192 classes = List()
192 classes = List()
193 def _classes_default(self):
193 def _classes_default(self):
194 """This has to be in a method, for TerminalIPythonApp to be available."""
194 """This has to be in a method, for TerminalIPythonApp to be available."""
195 return [
195 return [
196 InteractiveShellApp, # ShellApp comes before TerminalApp, because
196 InteractiveShellApp, # ShellApp comes before TerminalApp, because
197 self.__class__, # it will also affect subclasses (e.g. QtConsole)
197 self.__class__, # it will also affect subclasses (e.g. QtConsole)
198 TerminalInteractiveShell,
198 TerminalInteractiveShell,
199 ProfileDir,
199 ProfileDir,
200 PlainTextFormatter,
200 PlainTextFormatter,
201 ]
201 ]
202
202
203 subcommands = Dict(dict(
203 subcommands = Dict(dict(
204 qtconsole=('IPython.frontend.qt.console.qtconsoleapp.IPythonQtConsoleApp',
204 qtconsole=('IPython.frontend.qt.console.qtconsoleapp.IPythonQtConsoleApp',
205 """Launch the IPython Qt Console."""
205 """Launch the IPython Qt Console."""
206 ),
206 ),
207 profile = ("IPython.core.profileapp.ProfileApp",
207 profile = ("IPython.core.profileapp.ProfileApp",
208 "Create and manage IPython profiles.")
208 "Create and manage IPython profiles."
209 ),
210 kernel = ("IPython.zmq.ipkernel.IPKernelApp",
211 "Start a kernel without an attached frontend."
212 ),
209 ))
213 ))
210
214
211 # *do* autocreate requested profile, but don't create the config file.
215 # *do* autocreate requested profile, but don't create the config file.
212 auto_create=Bool(True)
216 auto_create=Bool(True)
213 # configurables
217 # configurables
214 ignore_old_config=Bool(False, config=True,
218 ignore_old_config=Bool(False, config=True,
215 help="Suppress warning messages about legacy config files"
219 help="Suppress warning messages about legacy config files"
216 )
220 )
217 quick = Bool(False, config=True,
221 quick = Bool(False, config=True,
218 help="""Start IPython quickly by skipping the loading of config files."""
222 help="""Start IPython quickly by skipping the loading of config files."""
219 )
223 )
220 def _quick_changed(self, name, old, new):
224 def _quick_changed(self, name, old, new):
221 if new:
225 if new:
222 self.load_config_file = lambda *a, **kw: None
226 self.load_config_file = lambda *a, **kw: None
223 self.ignore_old_config=True
227 self.ignore_old_config=True
224
228
225 gui = CaselessStrEnum(('qt','wx','gtk'), config=True,
229 gui = CaselessStrEnum(('qt','wx','gtk'), config=True,
226 help="Enable GUI event loop integration ('qt', 'wx', 'gtk')."
230 help="Enable GUI event loop integration ('qt', 'wx', 'gtk')."
227 )
231 )
228 pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'auto'],
232 pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'auto'],
229 config=True,
233 config=True,
230 help="""Pre-load matplotlib and numpy for interactive use,
234 help="""Pre-load matplotlib and numpy for interactive use,
231 selecting a particular matplotlib backend and loop integration.
235 selecting a particular matplotlib backend and loop integration.
232 """
236 """
233 )
237 )
234 display_banner = Bool(True, config=True,
238 display_banner = Bool(True, config=True,
235 help="Whether to display a banner upon starting IPython."
239 help="Whether to display a banner upon starting IPython."
236 )
240 )
237
241
238 # if there is code of files to run from the cmd line, don't interact
242 # if there is code of files to run from the cmd line, don't interact
239 # unless the --i flag (App.force_interact) is true.
243 # unless the --i flag (App.force_interact) is true.
240 force_interact = Bool(False, config=True,
244 force_interact = Bool(False, config=True,
241 help="""If a command or file is given via the command-line,
245 help="""If a command or file is given via the command-line,
242 e.g. 'ipython foo.py"""
246 e.g. 'ipython foo.py"""
243 )
247 )
244 def _force_interact_changed(self, name, old, new):
248 def _force_interact_changed(self, name, old, new):
245 if new:
249 if new:
246 self.interact = True
250 self.interact = True
247
251
248 def _file_to_run_changed(self, name, old, new):
252 def _file_to_run_changed(self, name, old, new):
249 if new and not self.force_interact:
253 if new and not self.force_interact:
250 self.interact = False
254 self.interact = False
251 _code_to_run_changed = _file_to_run_changed
255 _code_to_run_changed = _file_to_run_changed
252
256
253 # internal, not-configurable
257 # internal, not-configurable
254 interact=Bool(True)
258 interact=Bool(True)
255
259
256
260
257 def parse_command_line(self, argv=None):
261 def parse_command_line(self, argv=None):
258 """override to allow old '-pylab' flag with deprecation warning"""
262 """override to allow old '-pylab' flag with deprecation warning"""
259
263
260 argv = sys.argv[1:] if argv is None else argv
264 argv = sys.argv[1:] if argv is None else argv
261
265
262 if '-pylab' in argv:
266 if '-pylab' in argv:
263 # deprecated `-pylab` given,
267 # deprecated `-pylab` given,
264 # warn and transform into current syntax
268 # warn and transform into current syntax
265 argv = argv[:] # copy, don't clobber
269 argv = argv[:] # copy, don't clobber
266 idx = argv.index('-pylab')
270 idx = argv.index('-pylab')
267 warn.warn("`-pylab` flag has been deprecated.\n"
271 warn.warn("`-pylab` flag has been deprecated.\n"
268 " Use `--pylab` instead, or `--pylab=foo` to specify a backend.")
272 " Use `--pylab` instead, or `--pylab=foo` to specify a backend.")
269 sub = '--pylab'
273 sub = '--pylab'
270 if len(argv) > idx+1:
274 if len(argv) > idx+1:
271 # check for gui arg, as in '-pylab qt'
275 # check for gui arg, as in '-pylab qt'
272 gui = argv[idx+1]
276 gui = argv[idx+1]
273 if gui in ('wx', 'qt', 'qt4', 'gtk', 'auto'):
277 if gui in ('wx', 'qt', 'qt4', 'gtk', 'auto'):
274 sub = '--pylab='+gui
278 sub = '--pylab='+gui
275 argv.pop(idx+1)
279 argv.pop(idx+1)
276 argv[idx] = sub
280 argv[idx] = sub
277
281
278 return super(TerminalIPythonApp, self).parse_command_line(argv)
282 return super(TerminalIPythonApp, self).parse_command_line(argv)
279
283
280 def initialize(self, argv=None):
284 def initialize(self, argv=None):
281 """Do actions after construct, but before starting the app."""
285 """Do actions after construct, but before starting the app."""
282 super(TerminalIPythonApp, self).initialize(argv)
286 super(TerminalIPythonApp, self).initialize(argv)
283 if self.subapp is not None:
287 if self.subapp is not None:
284 # don't bother initializing further, starting subapp
288 # don't bother initializing further, starting subapp
285 return
289 return
286 if not self.ignore_old_config:
290 if not self.ignore_old_config:
287 check_for_old_config(self.ipython_dir)
291 check_for_old_config(self.ipython_dir)
288 # print self.extra_args
292 # print self.extra_args
289 if self.extra_args:
293 if self.extra_args:
290 self.file_to_run = self.extra_args[0]
294 self.file_to_run = self.extra_args[0]
291 # create the shell
295 # create the shell
292 self.init_shell()
296 self.init_shell()
293 # and draw the banner
297 # and draw the banner
294 self.init_banner()
298 self.init_banner()
295 # Now a variety of things that happen after the banner is printed.
299 # Now a variety of things that happen after the banner is printed.
296 self.init_gui_pylab()
300 self.init_gui_pylab()
297 self.init_extensions()
301 self.init_extensions()
298 self.init_code()
302 self.init_code()
299
303
300 def init_shell(self):
304 def init_shell(self):
301 """initialize the InteractiveShell instance"""
305 """initialize the InteractiveShell instance"""
302 # I am a little hesitant to put these into InteractiveShell itself.
306 # I am a little hesitant to put these into InteractiveShell itself.
303 # But that might be the place for them
307 # But that might be the place for them
304 sys.path.insert(0, '')
308 sys.path.insert(0, '')
305
309
306 # Create an InteractiveShell instance.
310 # Create an InteractiveShell instance.
307 # shell.display_banner should always be False for the terminal
311 # shell.display_banner should always be False for the terminal
308 # based app, because we call shell.show_banner() by hand below
312 # based app, because we call shell.show_banner() by hand below
309 # so the banner shows *before* all extension loading stuff.
313 # so the banner shows *before* all extension loading stuff.
310 self.shell = TerminalInteractiveShell.instance(config=self.config,
314 self.shell = TerminalInteractiveShell.instance(config=self.config,
311 display_banner=False, profile_dir=self.profile_dir,
315 display_banner=False, profile_dir=self.profile_dir,
312 ipython_dir=self.ipython_dir)
316 ipython_dir=self.ipython_dir)
313
317
314 def init_banner(self):
318 def init_banner(self):
315 """optionally display the banner"""
319 """optionally display the banner"""
316 if self.display_banner and self.interact:
320 if self.display_banner and self.interact:
317 self.shell.show_banner()
321 self.shell.show_banner()
318 # Make sure there is a space below the banner.
322 # Make sure there is a space below the banner.
319 if self.log_level <= logging.INFO: print
323 if self.log_level <= logging.INFO: print
320
324
321
325
322 def init_gui_pylab(self):
326 def init_gui_pylab(self):
323 """Enable GUI event loop integration, taking pylab into account."""
327 """Enable GUI event loop integration, taking pylab into account."""
324 gui = self.gui
328 gui = self.gui
325
329
326 # Using `pylab` will also require gui activation, though which toolkit
330 # Using `pylab` will also require gui activation, though which toolkit
327 # to use may be chosen automatically based on mpl configuration.
331 # to use may be chosen automatically based on mpl configuration.
328 if self.pylab:
332 if self.pylab:
329 activate = self.shell.enable_pylab
333 activate = self.shell.enable_pylab
330 if self.pylab == 'auto':
334 if self.pylab == 'auto':
331 gui = None
335 gui = None
332 else:
336 else:
333 gui = self.pylab
337 gui = self.pylab
334 else:
338 else:
335 # Enable only GUI integration, no pylab
339 # Enable only GUI integration, no pylab
336 activate = inputhook.enable_gui
340 activate = inputhook.enable_gui
337
341
338 if gui or self.pylab:
342 if gui or self.pylab:
339 try:
343 try:
340 self.log.info("Enabling GUI event loop integration, "
344 self.log.info("Enabling GUI event loop integration, "
341 "toolkit=%s, pylab=%s" % (gui, self.pylab) )
345 "toolkit=%s, pylab=%s" % (gui, self.pylab) )
342 activate(gui)
346 activate(gui)
343 except:
347 except:
344 self.log.warn("Error in enabling GUI event loop integration:")
348 self.log.warn("Error in enabling GUI event loop integration:")
345 self.shell.showtraceback()
349 self.shell.showtraceback()
346
350
347 def start(self):
351 def start(self):
348 if self.subapp is not None:
352 if self.subapp is not None:
349 return self.subapp.start()
353 return self.subapp.start()
350 # perform any prexec steps:
354 # perform any prexec steps:
351 if self.interact:
355 if self.interact:
352 self.log.debug("Starting IPython's mainloop...")
356 self.log.debug("Starting IPython's mainloop...")
353 self.shell.mainloop()
357 self.shell.mainloop()
354 else:
358 else:
355 self.log.debug("IPython not interactive...")
359 self.log.debug("IPython not interactive...")
356
360
357
361
358 def load_default_config(ipython_dir=None):
362 def load_default_config(ipython_dir=None):
359 """Load the default config file from the default ipython_dir.
363 """Load the default config file from the default ipython_dir.
360
364
361 This is useful for embedded shells.
365 This is useful for embedded shells.
362 """
366 """
363 if ipython_dir is None:
367 if ipython_dir is None:
364 ipython_dir = get_ipython_dir()
368 ipython_dir = get_ipython_dir()
365 profile_dir = os.path.join(ipython_dir, 'profile_default')
369 profile_dir = os.path.join(ipython_dir, 'profile_default')
366 cl = PyFileConfigLoader(default_config_file_name, profile_dir)
370 cl = PyFileConfigLoader(default_config_file_name, profile_dir)
367 try:
371 try:
368 config = cl.load_config()
372 config = cl.load_config()
369 except IOError:
373 except IOError:
370 # no config found
374 # no config found
371 config = Config()
375 config = Config()
372 return config
376 return config
373
377
374
378
375 def launch_new_instance():
379 def launch_new_instance():
376 """Create and run a full blown IPython instance"""
380 """Create and run a full blown IPython instance"""
377 app = TerminalIPythonApp.instance()
381 app = TerminalIPythonApp.instance()
378 app.initialize()
382 app.initialize()
379 app.start()
383 app.start()
380
384
381
385
382 if __name__ == '__main__':
386 if __name__ == '__main__':
383 launch_new_instance()
387 launch_new_instance()
General Comments 0
You need to be logged in to leave comments. Login now