diff --git a/gnucash/python/init.py b/gnucash/python/init.py index 5cf1f99c96..a619eec5e3 100644 --- a/gnucash/python/init.py +++ b/gnucash/python/init.py @@ -43,8 +43,9 @@ class Console (cons.Console): """ GTK python console """ def __init__(self, argv=[], shelltype='python', banner=[], - filename=None, size=100): - cons.Console.__init__(self, argv, shelltype, banner, filename, size) + filename=None, size=100, user_local_ns=None, user_global_ns=None): + cons.Console.__init__(self, argv, shelltype, banner, filename, size, + user_local_ns=user_local_ns, user_global_ns=user_global_ns) self.buffer.create_tag('center', justification=Gtk.Justification.CENTER, font='Mono 4') @@ -101,12 +102,15 @@ if False: title = "gnucash "+shelltype+" shell" banner_style = 'title' banner = "Welcome to "+title+"!\n" - console = Console(argv = [], shelltype = shelltype, banner = [[banner, banner_style]], size = 100) window = Gtk.Window(type = Gtk.WindowType.TOPLEVEL) window.set_position(Gtk.WindowPosition.CENTER) window.set_default_size(800,600) window.set_border_width(0) + + console = Console(argv = [], shelltype = shelltype, banner = [[banner, banner_style]], + size = 100, user_local_ns=locals(), user_global_ns=globals()) + window.connect('destroy-event', console.quit_event) window.connect('delete-event', console.quit_event) window.add (console) diff --git a/gnucash/python/pycons/console.py b/gnucash/python/pycons/console.py index d12f753927..b3a27035fe 100644 --- a/gnucash/python/pycons/console.py +++ b/gnucash/python/pycons/console.py @@ -126,7 +126,7 @@ class Console (Gtk.ScrolledWindow): """ GTK python console """ def __init__(self, argv=[], shelltype='python', banner=[], - filename=None, size=100): + filename=None, size=100, user_local_ns=None, user_global_ns=None): """ Console interface building + initialization""" @@ -184,12 +184,18 @@ class Console (Gtk.ScrolledWindow): self.history_init(filename, size) self.cout = io.StringIO() self.cout.truncate(0) + + if not user_local_ns: + user_local_ns = locals() + if not user_global_ns: + user_global_ns = globals() + if shelltype=='ipython': - self.shell = ishell.Shell(argv,locals(),globals(), + self.shell = ishell.Shell(argv,user_local_ns, user_global_ns, cout=self.cout, cerr=self.cout, input_func=self.raw_input) else: - self.shell = shell.Shell(locals(),globals()) + self.shell = shell.Shell(user_local_ns,user_global_ns) self.interrupt = False self.input_mode = False self.input = None