diff options
author | Simon Schampijer <simon@schampijer.de> | 2008-06-04 19:06:12 (GMT) |
---|---|---|
committer | Simon Schampijer <simon@schampijer.de> | 2008-06-04 19:06:12 (GMT) |
commit | 754b4c5d460db45555a36bbc0cddcb385ea071e0 (patch) | |
tree | 01efe2f65776b3d7c137a812266d478079fac279 /src/controlpanel | |
parent | 2b6e3b653dd3de53991e180ef390b6a2abaeaf1d (diff) |
Control Panel push missed these changes
Diffstat (limited to 'src/controlpanel')
-rw-r--r-- | src/controlpanel/Makefile.am | 9 | ||||
-rw-r--r-- | src/controlpanel/cmd.py | 131 | ||||
-rw-r--r-- | src/controlpanel/control.py | 479 |
3 files changed, 99 insertions, 520 deletions
diff --git a/src/controlpanel/Makefile.am b/src/controlpanel/Makefile.am index f89132c..5acd9a1 100644 --- a/src/controlpanel/Makefile.am +++ b/src/controlpanel/Makefile.am @@ -1,5 +1,12 @@ +SUBDIRS = model view + sugardir = $(pkgdatadir)/shell/controlpanel sugar_PYTHON = \ __init__.py \ cmd.py \ - control.py + gui.py \ + inlinealert.py \ + sectionview.py \ + toolbar.py + + diff --git a/src/controlpanel/cmd.py b/src/controlpanel/cmd.py index 24653b2..a46a0aa 100644 --- a/src/controlpanel/cmd.py +++ b/src/controlpanel/cmd.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007, One Laptop Per Child +# Copyright (C) 2007, 2008 One Laptop Per Child # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,11 +16,20 @@ import sys import getopt +import os from gettext import gettext as _ -from controlpanel import control - +import config + +_RESTART = 1 + +_same_option_warning = _("sugar-control-panel: WARNING, found more than" + " one option with the same name: %s module: %r") +_no_option_error = _("sugar-control-panel: key=%s not an available option") +_general_error = _("sugar-control-panel: %s") + def cmd_help(): + '''Print the help to the screen''' print _('Usage: sugar-control-panel [ option ] key [ args ... ] \n\ Control for the sugar environment. \n\ Options: \n\ @@ -31,47 +40,89 @@ def cmd_help(): -s key set the current value for the key \n\ ') +def note_restart(): + '''Instructions how to restart sugar''' + print _('To apply your changes you have to restart sugar.\n' + + 'Hit ctrl+alt+erase on the keyboard to trigger a restart.') + +def load_modules(): + '''Build a list of pointers to available modules in the model directory + and load them. + ''' + subpath = ['controlpanel', 'model'] + file_names = os.listdir(os.path.join(config.shell_path, '/'.join(subpath))) + + modules = [] + for file_name in file_names: + if file_name.endswith('.py') and file_name != '__init__.py': + module_name = file_name.strip('.py') + module = __import__('.'.join(subpath) + '.' + + module_name, globals(), locals(), + [module_name]) + modules.append(module) + return modules + def main(): try: - opts, args = getopt.getopt(sys.argv[1:], "h:s:g:l", []) + options, args = getopt.getopt(sys.argv[1:], "h:s:g:l", []) except getopt.GetoptError: cmd_help() sys.exit(2) - if not opts: + if not options: cmd_help() - sys.exit() - - for opt, key in opts: - if opt in ("-h"): - method = getattr(control, 'set_' + key, None) - if method is None: - print _("sugar-control-panel: key=%s not an available option" - % key) - sys.exit() - else: - 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: - 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: - print _("sugar-control-panel: key=%s not an available option" - % key) - sys.exit() - else: - try: - method(*args) - except Exception, e: - print _("sugar-control-panel: %s"% e) + sys.exit(2) + + modules = load_modules() + + for option, key in options: + found = 0 + if option in ("-h"): + for module in modules: + method = getattr(module, 'set_' + key, None) + if method: + found += 1 + if found == 1: + print method.__doc__ + else: + print _(_same_option_warning % (key, module)) + if found == 0: + print _(_no_option_error % key) + if option in ("-l"): + for module in modules: + methods = dir(module) + print '%s:' % module.__name__.split('.')[-1] + for method in methods: + if method.startswith('get_'): + print ' %s' % method[4:] + if option in ("-g"): + for module in modules: + method = getattr(module, 'print_' + key, None) + if method: + found += 1 + if found == 1: + try: + method() + except Exception, detail: + print _(_general_error % detail) + else: + print _(_same_option_warning % (key, module)) + if found == 0: + print _(_no_option_error % key) + if option in ("-s"): + for module in modules: + method = getattr(module, 'set_' + key, None) + if method: + note = 0 + found += 1 + if found == 1: + try: + note = method(*args) + except Exception, detail: + print _(_general_error % detail) + if note == _RESTART: + note_restart() + else: + print _(_same_option_warning % (key, module)) + if found == 0: + print _(_no_option_error % key) diff --git a/src/controlpanel/control.py b/src/controlpanel/control.py deleted file mode 100644 index bf3e681..0000000 --- a/src/controlpanel/control.py +++ /dev/null @@ -1,479 +0,0 @@ -# Copyright (C) 2007, One Laptop Per Child -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# -# -# The language config is based on the system-config-language -# (http://fedoraproject.org/wiki/SystemConfig/language) tool -# and the timezone config on the system-config-date -# (http://fedoraproject.org/wiki/SystemConfig/date) tool. -# Parts of the code were reused. -# - -import os -import shutil -from gettext import gettext as _ -import dbus - -from sugar import profile -from sugar.graphics.xocolor import XoColor - -NM_SERVICE_NAME = 'org.freedesktop.NetworkManager' -NM_SERVICE_PATH = '/org/freedesktop/NetworkManager' -NM_SERVICE_IFACE = 'org.freedesktop.NetworkManager' -NM_ASLEEP = 1 - -_COLORS = {'red': {'dark':'#b20008', 'medium':'#e6000a', 'light':'#ffadce'}, - 'orange': {'dark':'#9a5200', 'medium':'#c97e00', 'light':'#ffc169'}, - 'yellow': {'dark':'#807500', 'medium':'#be9e00', 'light':'#fffa00'}, - 'green': {'dark':'#008009', 'medium':'#00b20d', 'light':'#8bff7a'}, - 'blue': {'dark':'#00588c', 'medium':'#005fe4', 'light':'#bccdff'}, - 'purple': {'dark':'#5e008c', 'medium':'#7f00bf', 'light':'#d1a3ff'} - } - -_MODIFIERS = ('dark', 'medium', 'light') - -_TIMEZONE_CONFIG = '/etc/sysconfig/clock' - -_LANGUAGES = { - 'Afrikaans/South_Africa': 'af_ZA', - 'Albanian': 'sq_AL.UTF-8', - 'Amharic/Ethiopian': 'am_ET.UTF-8', - 'Arabic/Algeria': 'ar_DZ.UTF-8', - 'Arabic/Bahrain': 'ar_BH.UTF-8', - 'Arabic/Egypt': 'ar_EG.UTF-8', - 'Arabic/India': 'ar_IN.UTF-8', - 'Arabic/Iraq': 'ar_IQ.UTF-8', - 'Arabic/Jordan': 'ar_JO.UTF-8', - 'Arabic/Kuwait': 'ar_KW.UTF-8', - 'Arabic/Lebanon': 'ar_LB.UTF-8', - 'Arabic/Libyan_Arab_Jamahiriya': 'ar_LY.UTF-8', - 'Arabic/Morocco': 'ar_MA.UTF-8', - 'Arabic/Oman': 'ar_OM.UTF-8', - 'Arabic/Qatar': 'ar_QA.UTF-8', - 'Arabic/Saudi_Arabia': 'ar_SA.UTF-8', - 'Arabic/Sudan': 'ar_SD.UTF-8', - 'Arabic/Syrian_Arab_Republic': 'ar_SY.UTF-8', - 'Arabic/Tunisia': 'ar_TN.UTF-8', - 'Arabic/United_Arab_Emirates': 'ar_AE.UTF-8', - 'Arabic/Yemen': 'ar_YE.UTF-8', - 'Basque/Spain': 'eu_ES.UTF-8', - 'Belarusian': 'be_BY.UTF-8', - 'Bengali/BD': 'bn_BD.UTF-8', - 'Bengali/India': 'bn_IN.UTF-8', - 'Bosnian/Bosnia_and_Herzegowina': 'bs_BA', - 'Breton/France': 'br_FR', - 'Bulgarian': 'bg_BG.UTF-8', - 'Catalan/Spain': 'ca_ES.UTF-8', - 'Chinese/Hong_Kong': 'zh_HK.UTF-8', - 'Chinese/P.R._of_China': 'zh_CN.UTF-8', - 'Chinese/Taiwan': 'zh_TW.UTF-8', - 'Cornish/Britain': 'kw_GB.UTF-8', - 'Croatian': 'hr_HR.UTF-8', - 'Czech': 'cs_CZ.UTF-8', - 'Danish': 'da_DK.UTF-8', - 'Dutch/Belgium': 'nl_BE.UTF-8', - 'Dutch/Netherlands': 'nl_NL.UTF-8', - 'English/Australia': 'en_AU.UTF-8', - 'English/Botswana': 'en_BW.UTF-8', - 'English/Canada': 'en_CA.UTF-8', - 'English/Denmark': 'en_DK.UTF-8', - 'English/Great_Britain': 'en_GB.UTF-8', - 'English/Hong_Kong': 'en_HK.UTF-8', - 'English/India': 'en_IN.UTF-8', - 'English/Ireland': 'en_IE.UTF-8', - 'English/New_Zealand': 'en_NZ.UTF-8', - 'English/Philippines': 'en_PH.UTF-8', - 'English/Singapore': 'en_SG.UTF-8', - 'English/South_Africa': 'en_ZA.UTF-8', - 'English/USA': 'en_US.UTF-8', - 'English/Zimbabwe': 'en_ZW.UTF-8', - 'Estonian': 'et_EE.UTF-8', - 'Faroese/Faroe_Islands': 'fo_FO.UTF-8', - 'Finnish': 'fi_FI.UTF-8', - 'French/Belgium': 'fr_BE.UTF-8', - 'French/Canada': 'fr_CA.UTF-8', - 'French/France': 'fr_FR.UTF-8', - 'French/Luxemburg': 'fr_LU.UTF-8', - 'French/Switzerland': 'fr_CH.UTF-8', - 'Galician/Spain': 'gl_ES.UTF-8', - 'German/Austria': 'de_AT.UTF-8', - 'German/Belgium': 'de_BE.UTF-8', - 'German/Germany': 'de_DE.UTF-8', - 'German/Luxemburg': 'de_LU.UTF-8', - 'German/Switzerland': 'de_CH.UTF-8', - 'Greek': 'el_GR.UTF-8', - 'Greenlandic/Greenland': 'kl_GL.UTF-8', - 'Gujarati/India': 'gu_IN.UTF-8', - 'Hausa/Nigeria': 'ha_NG.UTF-8', - 'Hebrew/Israel': 'he_IL.UTF-8', - 'Hindi/India': 'hi_IN.UTF-8', - 'Hungarian': 'hu_HU.UTF-8', - 'Icelandic': 'is_IS.UTF-8', - 'Igbo/Nigeria': 'ig_NG.UTF-8', - 'Indonesian': 'id_ID.UTF-8', - 'Irish': 'ga_IE.UTF-8', - 'Italian/Italy': 'it_IT.UTF-8', - 'Italian/Switzerland': 'it_CH.UTF-8', - 'Japanese': 'ja_JP.UTF-8', - 'Korean/Republic_of_Korea': 'ko_KR.UTF-8', - 'Lao/Laos': 'lo_LA.UTF-8', - 'Latvian/Latvia': 'lv_LV.UTF-8', - 'Lithuanian': 'lt_LT.UTF-8', - 'Macedonian': 'mk_MK.UTF-8', - 'Malay/Malaysia': 'ms_MY.UTF-8', - 'Maltese/malta': 'mt_MT.UTF-8', - 'Manx/Britain': 'gv_GB.UTF-8', - 'Marathi/India': 'mr_IN.UTF-8', - 'Mongolian': 'mn_MN.UTF-8', - 'Nepali': 'ne_NP.UTF-8', - 'Northern/Norway': 'se_NO', - 'Norwegian': 'nb_NO.UTF-8', - 'Norwegian,/Norway': 'nn_NO.UTF-8', - 'Occitan/France': 'oc_FR', - 'Oriya/India': 'or_IN.UTF-8', - 'Persian/Iran': 'fa_IR.UTF-8', - 'Polish': 'pl_PL.UTF-8', - 'Portuguese/Brasil': 'pt_BR.UTF-8', - 'Portuguese/Portugal': 'pt_PT.UTF-8', - 'Punjabi/India': 'pa_IN.UTF-8', - 'Romanian': 'ro_RO.UTF-8', - 'Russian': 'ru_RU.UTF-8', - 'Russian/Ukraine': 'ru_UA.UTF-8', - 'Serbian': 'sr_CS.UTF-8', - 'Serbian/Latin': 'sr_CS.UTF-8@Latn', - 'Slovak': 'sk_SK.UTF-8', - 'Slovenian/Slovenia': 'sl_SI.UTF-8', - 'Spanish/Argentina': 'es_AR.UTF-8', - 'Spanish/Bolivia': 'es_BO.UTF-8', - 'Spanish/Chile': 'es_CL.UTF-8', - 'Spanish/Colombia': 'es_CO.UTF-8', - 'Spanish/Costa_Rica': 'es_CR.UTF-8', - 'Spanish/Dominican_Republic': 'es_DO.UTF-8', - 'Spanish/El_Salvador': 'es_SV.UTF-8', - 'Spanish/Equador': 'es_EC.UTF-8', - 'Spanish/Guatemala': 'es_GT.UTF-8', - 'Spanish/Honduras': 'es_HN.UTF-8', - 'Spanish/Mexico': 'es_MX.UTF-8', - 'Spanish/Nicaragua': 'es_NI.UTF-8', - 'Spanish/Panama': 'es_PA.UTF-8', - 'Spanish/Paraguay': 'es_PY.UTF-8', - 'Spanish/Peru': 'es_PE.UTF-8', - 'Spanish/Puerto_Rico': 'es_PR.UTF-8', - 'Spanish/Spain': 'es_ES.UTF-8', - 'Spanish/USA': 'es_US.UTF-8', - 'Spanish/Uruguay': 'es_UY.UTF-8', - 'Spanish/Venezuela': 'es_VE.UTF-8', - 'Swedish/Finland': 'sv_FI.UTF-8', - 'Swedish/Sweden': 'sv_SE.UTF-8', - 'Tagalog/Philippines': 'tl_PH', - 'Tamil/India': 'ta_IN.UTF-8', - 'Telugu/India': 'te_IN.UTF-8', - 'Thai': 'th_TH.UTF-8', - 'Turkish': 'tr_TR.UTF-8', - 'Ukrainian': 'uk_UA.UTF-8', - 'Urdu/Pakistan': 'ur_PK', - 'Uzbek/Uzbekistan': 'uz_UZ', - 'Walloon/Belgium': 'wa_BE@euro', - 'Welsh/Great_Britain': 'cy_GB.UTF-8', - 'Xhosa/South_Africa': 'xh_ZA.UTF-8', - 'Yoruba/Nigeria': 'yo_NG.UTF-8', - 'Zulu/South_Africa': 'zu_ZA.UTF-8' - } - - -def _initialize(): - timezones = _read_zonetab() - - j = 0 - for timezone in timezones: - set_timezone.__doc__ += timezone+', ' - j += 1 - if j % 3 == 0: - set_timezone.__doc__ += '\n' - - keys = _LANGUAGES.keys() - keys.sort() - i = 0 - for key in keys: - set_language.__doc__ += key + ', ' - i += 1 - if i % 3 == 0: - set_language.__doc__ += '\n' - -def _note_restart(): - print _('To apply your changes you have to restart sugar.\n' + - 'Hit at the same time ctrl+alt+erase on the keyboard to do this.') - -def get_jabber(): - pro = profile.get_profile() - return pro.jabber_server - -def print_jabber(): - print get_jabber() - -def set_jabber(server): - """Set the jabber server - server : e.g. 'olpc.collabora.co.uk' - """ - pro = profile.get_profile() - pro.jabber_server = server - pro.jabber_registered = False - pro.save() - _note_restart() - -def get_color(): - return profile.get_color() - -def print_color(): - color = get_color().to_string() - tmp = color.split(',') - - stroke = None - fill = None - for color in _COLORS: - for hue in _COLORS[color]: - if _COLORS[color][hue] == tmp[0]: - stroke = (color, hue) - if _COLORS[color][hue] == tmp[1]: - fill = (color, hue) - - if stroke is not None: - print 'stroke: color=%s hue=%s' % (stroke[0], stroke[1]) - else: - print 'stroke: %s' % (tmp[0]) - if fill is not None: - print 'fill: color=%s hue=%s' % (fill[0], fill[1]) - else: - print 'fill: %s' % (tmp[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] - stroke : [red, orange, yellow, blue, purple] - hue stroke : [dark, medium, light] (optional) - hue fill : [dark, medium, light] (optional) - """ - - if modstroke not in _MODIFIERS or modfill not in _MODIFIERS: - print (_("Error in specified color modifiers.")) - return - if stroke not in _COLORS or fill not in _COLORS: - print (_("Error in specified colors.")) - return - - if modstroke == modfill: - if modfill == 'medium': - modfill = 'light' - else: - modfill = 'medium' - - color = _COLORS[stroke][modstroke] + ',' + _COLORS[fill][modfill] - pro = profile.get_profile() - pro.color = XoColor(color) - pro.save() - _note_restart() - -def get_nick(): - return profile.get_nick_name() - -def print_nick(): - print get_nick() - -def set_nick(nick): - """Set the nickname. - nick : e.g. 'walter' - """ - pro = profile.get_profile() - pro.nick_name = nick - pro.save() - _note_restart() - -def get_radio(): - bus = dbus.SystemBus() - proxy = bus.get_object(NM_SERVICE_NAME, NM_SERVICE_PATH) - nm = dbus.Interface(proxy, NM_SERVICE_IFACE) - state = nm.getWirelessEnabled() - if state == 0: - return _('off') - elif state == 1: - return _('on') - else: - return _('State is unknown.') - -def print_radio(): - print get_radio() - -def set_radio(state): - """Turn Radio 'on' or 'off' - state : 'on/off' - """ - if state == 'on': - bus = dbus.SystemBus() - proxy = bus.get_object(NM_SERVICE_NAME, NM_SERVICE_PATH) - nm = dbus.Interface(proxy, NM_SERVICE_IFACE) - nm.setWirelessEnabled(True) - elif state == 'off': - bus = dbus.SystemBus() - proxy = bus.get_object(NM_SERVICE_NAME, NM_SERVICE_PATH) - nm = dbus.Interface(proxy, NM_SERVICE_IFACE) - nm.setWirelessEnabled(False) - else: - print (_("Error in specified radio argument use on/off.")) - -def _check_for_superuser(): - if os.getuid(): - print _("Permission denied. You need to be root to run this method.") - return False - return True - -def get_timezone(): - if not os.access(_TIMEZONE_CONFIG, os.R_OK): - # this is what the default is for the /etc/localtime - return "America/New_York" - fd = open(_TIMEZONE_CONFIG, "r") - lines = fd.readlines() - fd.close() - try: - for line in lines: - line = line.strip() - if len (line) and line[0] == '#': - continue - try: - tokens = line.split("=") - if tokens[0] == "ZONE": - timezone = tokens[1].replace('"', '') - return timezone - except Exception, e: - print "get_timezone: %s" % e - except Exception, e: - print "get_timezone: %s" % e - return None - -def print_timezone(): - timezone = get_timezone() - if timezone is None: - print (_("Error in reading timezone")) - else: - print timezone - -def _read_zonetab(fn='/usr/share/zoneinfo/zone.tab'): - fd = open (fn, 'r') - lines = fd.readlines() - fd.close() - timezones = [] - for line in lines: - if line.startswith('#'): - continue - line = line.split() - if len(line) > 1: - timezones.append(line[2]) - timezones.sort() - return timezones - -def set_timezone(timezone): - """Set the system timezone - timezone : - """ - if not _check_for_superuser(): - return - - timezones = _read_zonetab() - if timezone in timezones: - fromfile = os.path.join("/usr/share/zoneinfo/", timezone) - try: - shutil.copyfile(fromfile, "/etc/localtime") - except OSError, detail: - print (_("Error copying timezone (from %s): %s") % - (fromfile, detail)) - return - try: - os.chmod("/etc/localtime", 0644) - except OSError, detail: - print (_("Changing permission of timezone: %s") % detail) - return - - # Write info to the /etc/sysconfig/clock file - fd = open(_TIMEZONE_CONFIG, "w") - fd.write('# use sugar-control-panel to change this\n') - fd.write('ZONE="%s"\n' % timezone) - fd.write('UTC=true\n') - fd.close() - else: - print (_("Error timezone does not exist.")) - -def _write_i18n(lang): - path = os.path.join(os.environ.get("HOME"), '.i18n') - if os.access(path, os.W_OK) == 0: - print(_("Could not access %s. Create standard settings.") % path) - fd = open(path, 'w') - fd.write('LANG="en_US.UTF-8"\n') - fd.close() - else: - fd = open(path, 'r') - lines = fd.readlines() - fd.close() - for i in range(len(lines)): - if lines[i][:5] == "LANG=": - lines[i] = 'LANG="' + lang + '"\n' - fd = open(path, 'w') - fd.writelines(lines) - fd.close() - -def get_language(): - path = os.path.join(os.environ.get("HOME"), '.i18n') - if os.access(path, os.R_OK) == 0: - print(_("Could not access %s. Create standard settings.") % path) - fd = open(path, 'w') - default = 'en_US.UTF-8' - fd.write('LANG="%s"\n' % default) - fd.close() - return default - - fd = open(path, "r") - lines = fd.readlines() - fd.close() - - lang = None - - for line in lines: - if line[:5] == "LANG=": - lang = line[5:].replace('"', '') - lang = lang.strip() - - return lang - -def print_language(): - code = get_language() - - for lang in _LANGUAGES: - if _LANGUAGES[lang] == code: - print lang - return - print (_("Language for code=%s could not be determined.") % code) - -def set_language(language): - """Set the system language. - languages : - """ - if language in _LANGUAGES: - _write_i18n(_LANGUAGES[language]) - _note_restart() - else: - print (_("Sorry I do not speak \'%s\'.") % language) - -# inilialize the docstrings for the timezone and language -_initialize() - |