Permalink
Browse files

Fix problem with rc_override.

EmbeddedSphinxShell is instantiated at import time, this patch works around
the issue.
  • Loading branch information...
1 parent 54fed50 commit 3e84e9f446b752aef4c798b3a086084b5cdcb679 Václav Šmilauer committed with fperez Jan 10, 2010
Showing with 35 additions and 12 deletions.
  1. +26 −11 IPython/Shell.py
  2. +9 −1 docs/sphinxext/ipython_directive.py
View
@@ -773,17 +773,17 @@ def __init__(self,argv=None,user_ns=None,user_global_ns=None,
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 @@ def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1):
#-----------------------------------------------------------------------------
# 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]
@@ -25,6 +25,7 @@
prompt_in2=" .\D..",
prompt_out=" -> [\#]:"
)
+ id.reconfig_shell()
import ipython_console_highlighting as ich
ich.IPythonConsoleLexer.input_prompt=
@@ -213,7 +214,7 @@ def __init__(self):
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 @@ def ensure_pyplot(self):
# 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,

0 comments on commit 3e84e9f

Please sign in to comment.