From 3e84e9f446b752aef4c798b3a086084b5cdcb679 2010-01-10 17:51:35 From: Václav Šmilauer Date: 2010-01-10 17:51:35 Subject: [PATCH] Fix problem with rc_override. EmbeddedSphinxShell is instantiated at import time, this patch works around the issue. --- diff --git a/IPython/Shell.py b/IPython/Shell.py index 2dd9dac..1f084ba 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -773,17 +773,17 @@ class IPShellGTK(IPThread): debug=1,shell_class=MTInteractiveShell): import gtk - # Check for set_interactive, coming up in new pygtk. - # Disable it so that this code works, but notify - # the user that he has a better option as well. - # XXX TODO better support when set_interactive is released - try: - gtk.set_interactive(False) - print "Your PyGtk has set_interactive(), so you can use the" - print "more stable single-threaded Gtk mode." - print "See https://bugs.launchpad.net/ipython/+bug/270856" - except AttributeError: - pass + ## # Check for set_interactive, coming up in new pygtk. + ## # Disable it so that this code works, but notify + ## # the user that he has a better option as well. + ## # XXX TODO better support when set_interactive is released + ## try: + ## gtk.set_interactive(False) + ## print "Your PyGtk has set_interactive(), so you can use the" + ## print "more stable single-threaded Gtk mode." + ## print "See https://bugs.launchpad.net/ipython/+bug/270856" + ## except AttributeError: + ## pass self.gtk = gtk self.gtk_mainloop = hijack_gtk() @@ -1149,6 +1149,15 @@ class IPShellMatplotlibQt4(IPShellQt4): #----------------------------------------------------------------------------- # Factory functions to actually start the proper thread-aware shell +def check_gtk(mode): + import gtk + if hasattr(gtk,'set_interactive'): + gtk.set_interactive(False) + return 'tkthread' + else: + return mode + + def _select_shell(argv): """Select a shell from the given argv vector. @@ -1218,6 +1227,9 @@ def _select_shell(argv): else: # Any other backend, use plain Tk th_mode = 'tkthread' + + # New versions of pygtk don't need the brittle threaded support. + th_mode = check_gtk(th_mode) return mpl_shell[th_mode] else: @@ -1226,6 +1238,9 @@ def _select_shell(argv): th_mode = special_opts.pop() except KeyError: th_mode = 'tkthread' + + # New versions of pygtk don't need the brittle threaded support. + th_mode = check_gtk(th_mode) return th_shell[th_mode] diff --git a/docs/sphinxext/ipython_directive.py b/docs/sphinxext/ipython_directive.py index 81e7f92..374834f 100644 --- a/docs/sphinxext/ipython_directive.py +++ b/docs/sphinxext/ipython_directive.py @@ -25,6 +25,7 @@ prompts ``Yade [1]:`` and ``-> [1]:``:: prompt_in2=" .\D..", prompt_out=" -> [\#]:" ) + id.reconfig_shell() import ipython_console_highlighting as ich ich.IPythonConsoleLexer.input_prompt= @@ -213,7 +214,7 @@ class EmbeddedSphinxShell(object): argv, self.user_ns, self.user_glocal_ns, embedded=True, #shell_class=IPython.Shell.InteractiveShell, shell_class=MatplotlibShell, - rc_override = dict(colors = 'NoColor'), **rc_override) + rc_override = dict(colors = 'NoColor', **rc_override)) self.input = '' self.output = '' @@ -402,6 +403,13 @@ class EmbeddedSphinxShell(object): # ipython_directive itself. shell = EmbeddedSphinxShell() +def reconfig_shell(): + """Called after setting module-level variables to re-instantiate + with the set values (since shell is instantiated first at import-time + when module variables have default values)""" + global shell + shell = EmbeddedSphinxShell() + def ipython_directive(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine,