From a03b08420c6e66f3a8d3827ed7cf8b05d1950327 Mon Sep 17 00:00:00 2001 From: Hans Unzner Date: Sun, 17 Nov 2024 23:10:21 +0100 Subject: [PATCH] gladevcp: use logger for all console outputs instead of print() --- src/hal/user_comps/gladevcp.py | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/hal/user_comps/gladevcp.py b/src/hal/user_comps/gladevcp.py index 7b0bbd8e9ad..5d1a8ecdb55 100644 --- a/src/hal/user_comps/gladevcp.py +++ b/src/hal/user_comps/gladevcp.py @@ -43,6 +43,7 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gdk +from gi.repository import GLib import signal # Set up the base logger @@ -90,7 +91,7 @@ def dbg(string): global gladevcp_debug if not gladevcp_debug: return - print(string) + LOG.debug(string) def on_window_destroy(widget, data=None): Gtk.main_quit() @@ -125,7 +126,7 @@ def add_handler(method, f): try: mod = __import__(basename) except ImportError as msg: - print("module '%s' skipped - import error: %s" %(basename,msg)) + LOG.error("module '%s' skipped - import error: %s" %(basename,msg)) continue LOG.debug("module '%s' imported OK" % mod.__name__) try: @@ -154,7 +155,7 @@ def add_handler(method, f): LOG.debug("Register callback '%s' in %s" % (method, object)) add_handler(method, f) except Exception as e: - print("gladevcp: trouble looking for handlers in '%s': %s" %(basename, e)) + LOG.warning("gladevcp: trouble looking for handlers in '%s': %s" %(basename, e)) traceback.print_exc() # Wrap lists in Trampoline, unwrap single functions @@ -194,15 +195,15 @@ def main(): if opts.debug: # Log level defaults to INFO, so set lower if in debug mode logger.setGlobalLevel(logger.DEBUG) - LOG.debug('DEBUGGING logging on') + LOG.info('DEBUGGING logging on') elif opts.info: logger.setGlobalLevel(logger.INFO) - print('INFO logging on') + LOG.info('INFO logging on') elif opts.quiet: logger.setGlobalLevel(logger.ERROR) elif opts.verbose: logger.setGlobalLevel(logger.VERBOSE) - print('VERBOSE logging on') + LOG.info('VERBOSE logging on') else: logger.setGlobalLevel(logger.WARNING) @@ -228,21 +229,22 @@ def main(): try: builder = Gtk.Builder() builder.add_from_file(xmlname) - except Exception as e: + + except GLib.Error as e: + LOG.error(e.message) try: # try loading as a Gtk.builder project - LOG.debug("**** GLADE VCP INFO: Not a builder project, trying to load as a lib glade project") - print(e) + LOG.info("GLADE VCP INFO: Not a builder project, trying to load as a lib glade project") builder = Gtk.glade.XML(xmlname) builder = GladeBuilder(builder) except Exception as e: - print("**** GLADE VCP ERROR: With xml file: %s : %s" % (xmlname,e), file=sys.stderr) + LOG.error(f"GLADE VCP ERROR: With xml file: '{xmlname}': {e}") sys.exit(0) window = builder.get_object("window1") if window is None: - print('*** GLADE VCP ERROR: No window named "window1" found. The toplevel windows has to be named "window1"!') + LOG.error('GLADE VCP ERROR: No window named "window1" found. The toplevel windows has to be named "window1"!') sys.exit(0) window.set_title(opts.component) @@ -250,7 +252,7 @@ def main(): try: halcomp = hal.component(opts.component) except: - print("*** GLADE VCP ERROR: Asking for a HAL component using a name that already exists.", file=sys.stderr) + LOG.error("GLADE VCP ERROR: Asking for a HAL component using a name that already exists.") sys.exit(0) panel = gladevcp.makepins.GladePanel( halcomp, xmlname, builder, None) @@ -304,7 +306,7 @@ def main(): pos = j[2].partition("+") window.move( int(pos[0]), int(pos[2]) ) except: - print("**** GLADE VCP ERROR: With window position data", file=sys.stderr) + LOG.error("GLADE VCP ERROR: With window position data") parser.print_usage() sys.exit(1) if "x" in opts.geometry: @@ -316,17 +318,17 @@ def main(): t = window_geometry.partition("x") window.resize( int(t[0]), int(t[2]) ) except: - print("**** GLADE VCP ERROR: With window resize data", file=sys.stderr) + LOG.error("GLADE VCP ERROR: With window resize data") parser.print_usage() sys.exit(1) if opts.gtk_rc: - LOG.debug( "**** GLADE VCP INFO: %s reading gtkrc file '%s'" %(opts.component,opts.gtk_rc)) + LOG.debug( "GLADE VCP INFO: %s reading gtkrc file '%s'" %(opts.component,opts.gtk_rc)) Gtk.rc_add_default_file(opts.gtk_rc) Gtk.rc_parse(opts.gtk_rc) if opts.theme: - LOG.debug("**** GLADE VCP INFO: Switching %s to '%s' theme" %(opts.component,opts.theme)) + LOG.debug("GLADE VCP INFO: Switching %s to '%s' theme" %(opts.component,opts.theme)) settings = Gtk.Settings.get_default() settings.set_string_property("gtk-theme-name", opts.theme, "") @@ -353,7 +355,7 @@ def main(): # push the XWindow id number to standard out if opts.push_XID or opts.parent: w_id = window.get_property('window').get_xid() - print(w_id, file=sys.stdout) + LOG.debug(f"XID: {w_id}") sys.stdout.flush() if signal_func in handlers: @@ -372,7 +374,7 @@ def main(): Gdk.flush() error = Gdk.error_trap_pop() if error and opts.debug: - print("**** GLADE VCP ERROR: X Protocol Error: %s" % str(error), file=sys.stderr) + LOG.error("GLADE VCP ERROR: X Protocol Error: %s" % str(error)) if __name__ == '__main__':