##// END OF EJS Templates
Added --gui to match %gui use, better docs and behavior for %pylab code....
Fernando Perez -
Show More
@@ -244,22 +244,39 b' cl_args = ('
244 244 action='store_true', dest='Global.force_interact', default=NoConfigDefault,
245 245 help="If running code from the command line, become interactive afterwards.")
246 246 ),
247
248 # Options to start with GUI control enabled from the beginning
249 (('--gui',), dict(
250 type=str, dest='Global.gui', default=NoConfigDefault,
251 help="Enable GUI event loop integration ('qt', 'wx', 'gtk').",
252 metavar='gui-mode')
253 ),
254
255 (('--pylab',), dict(
256 type=str, dest='Global.pylab', default=NoConfigDefault,
257 nargs='?', const='auto', metavar='gui-mode',
258 help="Pre-load matplotlib and numpy for interactive use. "+
259 "If no value is given, the gui backend is matplotlib's, else use "+
260 "one of: ['tk', 'qt', 'wx', 'gtk'].")
261 ),
262
263 # Legacy GUI options. Leave them in for backwards compatibility, but the
264 # 'thread' names are really a misnomer now.
247 265 (('--wthread','-wthread'), dict(
248 266 action='store_true', dest='Global.wthread', default=NoConfigDefault,
249 help="Enable wxPython event loop integration.")
267 help="Enable wxPython event loop integration "+
268 "(DEPRECATED, use --gui wx)")
250 269 ),
251 270 (('--q4thread','--qthread','-q4thread','-qthread'), dict(
252 271 action='store_true', dest='Global.q4thread', default=NoConfigDefault,
253 help="Enable Qt4 event loop integration. Qt3 is no longer supported.")
272 help="Enable Qt4 event loop integration. Qt3 is no longer supported. "+
273 "(DEPRECATED, use --gui qt)")
254 274 ),
255 275 (('--gthread','-gthread'), dict(
256 276 action='store_true', dest='Global.gthread', default=NoConfigDefault,
257 help="Enable GTK event loop integration.")
277 help="Enable GTK event loop integration. "+
278 "(DEPRECATED, use --gui gtk)")
258 279 ),
259 (('--pylab',), dict(
260 action='store_true', dest='Global.pylab', default=NoConfigDefault,
261 help="Pre-load matplotlib and numpy for interactive use.")
262 )
263 280 )
264 281
265 282
@@ -298,6 +315,7 b' class IPythonApp(Application):'
298 315 super(IPythonApp, self).create_default_config()
299 316 # Eliminate multiple lookups
300 317 Global = self.default_config.Global
318
301 319 # Set all default values
302 320 Global.display_banner = True
303 321
@@ -312,13 +330,18 b' class IPythonApp(Application):'
312 330 Global.interact = True
313 331
314 332 # No GUI integration by default
315 Global.wthread = False
316 Global.q4thread = False
317 Global.gthread = False
318
333 Global.gui = False
319 334 # Pylab off by default
320 335 Global.pylab = False
321 336
337 # Deprecated versions of gui support that used threading, we support
338 # them just for bacwards compatibility as an alternate spelling for
339 # '--gui X'
340 Global.qthread = False
341 Global.q4thread = False
342 Global.wthread = False
343 Global.gthread = False
344
322 345 def create_command_line_config(self):
323 346 """Create and return a command line config loader."""
324 347 return IPythonAppCLConfigLoader(
@@ -415,32 +438,41 b' class IPythonApp(Application):'
415 438 Global = self.master_config.Global
416 439
417 440 # Select which gui to use
418 if Global.wthread:
441 if Global.gui:
442 gui = Global.gui
443 # The following are deprecated, but there's likely to be a lot of use
444 # of this form out there, so we might as well support it for now. But
445 # the --gui option above takes precedence.
446 elif Global.wthread:
419 447 gui = inputhook.GUI_WX
420 elif Global.q4thread:
448 elif Global.qthread:
421 449 gui = inputhook.GUI_QT
422 450 elif Global.gthread:
423 451 gui = inputhook.GUI_GTK
424 452 else:
425 453 gui = None
426 454
455 # Using --pylab will also require gui activation, though which toolkit
456 # to use may be chosen automatically based on mpl configuration.
427 457 if Global.pylab:
428 458 activate = self.shell.enable_pylab
459 if Global.pylab == 'auto':
460 gui = None
461 else:
462 gui = Global.pylab
429 463 else:
430 464 # Enable only GUI integration, no pylab
431 465 activate = inputhook.enable_gui
432 466
433 467 if gui or Global.pylab:
434 468 try:
435 m = "Enabling GUI event loop integration, toolkit=%s, pylab=%s"\
436 % (gui, Global.pylab)
437 self.log.info(m)
469 self.log.info("Enabling GUI event loop integration, "
470 "toolkit=%s, pylab=%s" % (gui, Global.pylab) )
438 471 activate(gui)
439 472 except:
440 473 self.log.warn("Error in enabling GUI event loop integration:")
441 474 self.shell.showtraceback()
442 475
443
444 476 def _load_extensions(self):
445 477 """Load all IPython extensions in Global.extensions.
446 478
@@ -827,7 +827,7 b' class InteractiveShell(Component, Magic):'
827 827 # An auxiliary namespace that checks what parts of the user_ns were
828 828 # loaded at startup, so we can list later only variables defined in
829 829 # actual interactive use. Since it is always a subset of user_ns, it
830 # doesn't need to be seaparately tracked in the ns_table
830 # doesn't need to be separately tracked in the ns_table.
831 831 self.user_config_ns = {}
832 832
833 833 # A namespace to keep track of internal data structures to prevent
@@ -2451,13 +2451,36 b' class InteractiveShell(Component, Magic):'
2451 2451 #-------------------------------------------------------------------------
2452 2452
2453 2453 def enable_pylab(self, gui=None):
2454 """Activate pylab support at runtime.
2455
2456 This turns on support for matplotlib, preloads into the interactive
2457 namespace all of numpy and pylab, and configures IPython to correcdtly
2458 interact with the GUI event loop. The GUI backend to be used can be
2459 optionally selected with the optional :param:`gui` argument.
2460
2461 Parameters
2462 ----------
2463 gui : optional, string
2464
2465 If given, dictates the choice of matplotlib GUI backend to use
2466 (should be one of IPython's supported backends, 'tk', 'qt', 'wx' or
2467 'gtk'), otherwise we use the default chosen by matplotlib (as
2468 dictated by the matplotlib build-time options plus the user's
2469 matplotlibrc configuration file).
2454 2470 """
2455 """
2456 gui = pylab_activate(self.user_ns, gui)
2471 # We want to prevent the loading of pylab to pollute the user's
2472 # namespace as shown by the %who* magics, so we execute the activation
2473 # code in an empty namespace, and we update *both* user_ns and
2474 # user_config_ns with this information.
2475 ns = {}
2476 gui = pylab_activate(ns, gui)
2477 self.user_ns.update(ns)
2478 self.user_config_ns.update(ns)
2479 # Now we must activate the gui pylab wants to use, and fix %run to take
2480 # plot updates into account
2457 2481 enable_gui(gui)
2458 2482 self.magic_run = self._pylab_magic_run
2459 2483
2460
2461 2484 #-------------------------------------------------------------------------
2462 2485 # Things related to IPython exiting
2463 2486 #-------------------------------------------------------------------------
@@ -845,16 +845,11 b' class AutoHandler(PrefilterHandler):'
845 845 pre = line_info.pre
846 846 continue_prompt = line_info.continue_prompt
847 847 obj = line_info.ofind(self)['obj']
848
849 848 #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun,the_rest) # dbg
850 849
851 850 # This should only be active for single-line input!
852 851 if continue_prompt:
853 # XXX - Ugly hack! We are breaking on multiline input and I'm out
854 # of time tonight to disentangle the component hirerarchy issue
855 # here... Fix this more cleanly later.
856 852 self.shell.log(line,line,continue_prompt)
857
858 853 return line
859 854
860 855 force_auto = isinstance(obj, IPyAutocall)
General Comments 0
You need to be logged in to leave comments. Login now