From 70079de872305eaaacf70364801895ad036d1c4f Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Thu, 1 Nov 2007 12:37:43 +0100 Subject: [PATCH] refinements in output of sugar-control --- bin/sugar-control-panel | 29 ++++++++++++++++++++--------- shell/controlpanel/control.py | 19 +++++++++++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/bin/sugar-control-panel b/bin/sugar-control-panel index 367372d8..5399a552 100755 --- a/bin/sugar-control-panel +++ b/bin/sugar-control-panel @@ -19,6 +19,7 @@ import sys import getopt +from gettext import gettext as _ from sugar import env @@ -27,18 +28,19 @@ sys.path.insert(0, env.get_shell_path()) from controlpanel import control def cmd_help(): - print 'Usage: sugar-control [ option ] key [ args ... ] \n\ + print _('Usage: sugar-control-panel [ option ] key [ args ... ] \n\ Control for the sugar environment. \n\ Options: \n\ - -h, --help show this help message and exit \n\ + -h show this help message and exit \n\ + -l list all the available options \n\ -h key show information about this key \n\ -g key get the current value of the key \n\ -s key set the current value for the key \n\ - ' + ') def main(): try: - opts, args = getopt.getopt(sys.argv[1:], "h:s:g:", ["help"]) + opts, args = getopt.getopt(sys.argv[1:], "h:s:g:l", []) except getopt.GetoptError: cmd_help() sys.exit(2) @@ -46,31 +48,40 @@ def main(): output = None verbose = False + if not opts: + cmd_help() + sys.exit() + for opt, key in opts: if opt in ("-h"): method = getattr(control, 'set_' + key, None) if method is None: - cmd_help() + print _("sugar-control-panel: key=%s not an available option"% key) sys.exit() else: - print method.__doc__ + print method.__doc__ + if opt in ("-l"): + elems = dir(control) + for elem in elems: + if elem.startswith('set_'): + print elem[4:] if opt in ("-g"): method = getattr(control, 'print_' + key, None) if method is None: - cmd_help() + print _("sugar-control-panel: key=%s not an available option"% key) sys.exit() else: method() if opt in ("-s"): method = getattr(control, 'set_' + key, None) if method is None: - cmd_help() + print _("sugar-control-panel: key=%s not an available option"% key) sys.exit() else: try: method(*args) except Exception, e: - print "sugar-control: %s"% e + print _("sugar-control-panel: %s"% e) if __name__ == '__main__': main() diff --git a/shell/controlpanel/control.py b/shell/controlpanel/control.py index 63d97906..8e748255 100644 --- a/shell/controlpanel/control.py +++ b/shell/controlpanel/control.py @@ -236,13 +236,24 @@ def print_color(): color = get_color().to_string() str = color.split(',') + stroke = None + fill = None for color in _COLORS: for hue in _COLORS[color]: if _COLORS[color][hue] == str[0]: - print 'stroke: color=%s hue=%s'%(color, hue) + stroke = (color, hue) if _COLORS[color][hue] == str[1]: - print 'fill: color=%s hue=%s'%(color, hue) + fill = (color, hue) + if stroke is not None: + print 'stroke: color=%s hue=%s'%(stroke[0], stroke[1]) + else: + print 'stroke: %s'%(str[0]) + if fill is not None: + print 'fill: color=%s hue=%s'%(fill[0], fill[1]) + else: + print 'fill: %s'%(str[1]) + def set_color(stroke, fill, modstroke='medium', modfill='medium'): """Set the system color by setting a fill and stroke color. fill : [red, orange, yellow, blue, purple] @@ -343,9 +354,9 @@ def get_timezone(): timezone = string.replace(tokens[1], '"', '') return timezone except Exception, e: - print (_("get_timezone: %s") % e) + print "get_timezone: %s"% e except Exception, e: - print (_("get_timezone: %s") % e) + print "get_timezone: %s"% e return None def print_timezone():