gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Mon Apr 6 14:29:29 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/5adf54a5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/71eae1f2 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0c42c94c (commit)
	from  https://github.com/Gnucash/gnucash/commit/2bdc9366 (commit)



commit 5adf54a5ec6617b915e31e38c007234ec3c4d10f
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Apr 6 11:28:49 2020 -0700

    Make python console less noisy without --debug.

diff --git a/gnucash/python/init.py b/gnucash/python/init.py
index a619eec5e..bd8e383dd 100644
--- a/gnucash/python/init.py
+++ b/gnucash/python/init.py
@@ -1,14 +1,13 @@
 import sys
 import gnucash._sw_app_utils as _sw_app_utils
 from gnucash import *
-from gnucash._sw_core_utils import gnc_prefs_is_extra_enabled
+from gnucash._sw_core_utils import gnc_prefs_is_extra_enabled, gnc_prefs_is_debugging_enabled
 from gi import require_version
 require_version('Gtk', '3.0')
 from gi.repository import Gtk
 import os
 sys.path.append(os.path.dirname(__file__))
-noisy = gnc_prefs_is_extra_enabled()
-if noisy:
+if gnc_prefs_is_extra_enabled():
     print("woop", os.path.dirname(__file__))
 # Importing the console class causes SIGTTOU to be thrown if GnuCash is
 # started in the background.  This causes a hang if it is not handled, 
@@ -21,7 +20,7 @@ import pycons.console as cons
 # Restore the SIGTTOU handler
 signal.signal(signal.SIGTTOU, old_sigttou)
 
-if noisy:
+if gnc_prefs_is_extra_enabled() and gnc_prefs_is_debugging_enabled():
     print("Hello from python!")
     print("test", sys.modules.keys())
     print("test2", dir(_sw_app_utils))

commit 71eae1f2233d99aeb30b186fff4b0e8ffe367720
Merge: 2bdc93669 0c42c94cd
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Apr 6 11:15:04 2020 -0700

    Merge Christoph Holtermann's 'python-shell-access-outer-variables' into maint.


commit 0c42c94cd315ec5ad52b37b41918cd5399834db0
Author: c-holtermann <mail at c-holtermann.net>
Date:   Sat Apr 4 14:13:42 2020 +0200

    provide locals and globals of calling context to shell on shell init

diff --git a/gnucash/python/init.py b/gnucash/python/init.py
index 5cf1f99c9..a619eec5e 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 d12f75392..b3a27035f 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



Summary of changes:
 gnucash/python/init.py           | 17 ++++++++++-------
 gnucash/python/pycons/console.py | 12 +++++++++---
 2 files changed, 19 insertions(+), 10 deletions(-)



More information about the gnucash-changes mailing list