Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gladevcp: use logger for all console outputs instead of print() #3184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/hal/user_comps/gladevcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -228,29 +229,30 @@ 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)

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)
Expand Down Expand Up @@ -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:
Expand All @@ -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, "")

Expand All @@ -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:
Expand All @@ -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__':
Expand Down
Loading