From b6db5b8af0af7ebfdd44cb53b09d63b819989338 Mon Sep 17 00:00:00 2001 From: Julio Reyes Date: Fri, 05 Jul 2013 14:13:11 +0000 Subject: Initial Commit --- (limited to 'extensions/cpsection/aboutme') diff --git a/extensions/cpsection/aboutme/Makefile.am b/extensions/cpsection/aboutme/Makefile.am new file mode 100644 index 0000000..9ca91d2 --- /dev/null +++ b/extensions/cpsection/aboutme/Makefile.am @@ -0,0 +1,6 @@ +sugardir = $(pkgdatadir)/extensions/cpsection/aboutme + +sugar_PYTHON = \ + __init__.py \ + model.py \ + view.py diff --git a/extensions/cpsection/aboutme/Makefile.in b/extensions/cpsection/aboutme/Makefile.in new file mode 100644 index 0000000..f8ea8cd --- /dev/null +++ b/extensions/cpsection/aboutme/Makefile.in @@ -0,0 +1,442 @@ +# Makefile.in generated by automake 1.11.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = extensions/cpsection/aboutme +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(sugar_PYTHON) +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile) +am__installdirs = "$(DESTDIR)$(sugardir)" +py_compile = $(top_srcdir)/py-compile +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CATALOGS = @CATALOGS@ +CATOBJEXT = @CATOBJEXT@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIRNAME = @DATADIRNAME@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GCONFTOOL = @GCONFTOOL@ +GCONF_SCHEMA_CONFIG_SOURCE = @GCONF_SCHEMA_CONFIG_SOURCE@ +GCONF_SCHEMA_FILE_DIR = @GCONF_SCHEMA_FILE_DIR@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GMOFILES = @GMOFILES@ +GMSGFMT = @GMSGFMT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INSTOBJEXT = @INSTOBJEXT@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@ +INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@ +INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@ +INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +MKINSTALLDIRS = @MKINSTALLDIRS@ +MSGFMT = @MSGFMT@ +MSGFMT_OPTS = @MSGFMT_OPTS@ +MSGMERGE = @MSGMERGE@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POFILES = @POFILES@ +POSUB = @POSUB@ +PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ +PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SHELL_CFLAGS = @SHELL_CFLAGS@ +SHELL_LIBS = @SHELL_LIBS@ +STRIP = @STRIP@ +SUCROSE_VERSION = @SUCROSE_VERSION@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +intltool__v_merge_options_ = @intltool__v_merge_options_@ +intltool__v_merge_options_0 = @intltool__v_merge_options_0@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +sugardir = $(pkgdatadir)/extensions/cpsection/aboutme +sugar_PYTHON = \ + __init__.py \ + model.py \ + view.py + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign extensions/cpsection/aboutme/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign extensions/cpsection/aboutme/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-sugarPYTHON: $(sugar_PYTHON) + @$(NORMAL_INSTALL) + test -z "$(sugardir)" || $(MKDIR_P) "$(DESTDIR)$(sugardir)" + @list='$(sugar_PYTHON)'; dlist=; list2=; test -n "$(sugardir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then b=; else b="$(srcdir)/"; fi; \ + if test -f $$b$$p; then \ + $(am__strip_dir) \ + dlist="$$dlist $$f"; \ + list2="$$list2 $$b$$p"; \ + else :; fi; \ + done; \ + for file in $$list2; do echo $$file; done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(sugardir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(sugardir)" || exit $$?; \ + done || exit $$?; \ + if test -n "$$dlist"; then \ + $(am__py_compile) --destdir "$(DESTDIR)" \ + --basedir "$(sugardir)" $$dlist; \ + else :; fi + +uninstall-sugarPYTHON: + @$(NORMAL_UNINSTALL) + @list='$(sugar_PYTHON)'; test -n "$(sugardir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + dir='$(DESTDIR)$(sugardir)'; \ + filesc=`echo "$$files" | sed 's|$$|c|'`; \ + fileso=`echo "$$files" | sed 's|$$|o|'`; \ + st=0; \ + for files in "$$files" "$$filesc" "$$fileso"; do \ + $(am__uninstall_files_from_dir) || st=$$?; \ + done; \ + exit $$st +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: + for dir in "$(DESTDIR)$(sugardir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-sugarPYTHON + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-sugarPYTHON + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic distclean \ + distclean-generic distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip install-sugarPYTHON installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \ + uninstall-am uninstall-sugarPYTHON + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/extensions/cpsection/aboutme/__init__.py b/extensions/cpsection/aboutme/__init__.py new file mode 100644 index 0000000..7ded428 --- /dev/null +++ b/extensions/cpsection/aboutme/__init__.py @@ -0,0 +1,26 @@ +# Copyright (C) 2008, OLPC +# +# 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 + +from gettext import gettext as _ +import gconf + +from sugar.graphics.xocolor import XoColor + +CLASS = 'AboutMe' +ICON = 'module-about_me' +TITLE = _('About Me') +client = gconf.client_get_default() +COLOR = XoColor(client.get_string('/desktop/sugar/user/color')) diff --git a/extensions/cpsection/aboutme/model.py b/extensions/cpsection/aboutme/model.py new file mode 100644 index 0000000..fb4c2f1 --- /dev/null +++ b/extensions/cpsection/aboutme/model.py @@ -0,0 +1,125 @@ +# Copyright (C) 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 +# 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 +# + +from gettext import gettext as _ +import gconf + + +_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') + + +def get_nick(): + client = gconf.client_get_default() + return client.get_string('/desktop/sugar/user/nick') + + +def print_nick(): + print get_nick() + + +def set_nick(nick): + """Set the nickname. + nick : e.g. 'walter' + """ + if not nick: + raise ValueError(_('You must enter a name.')) + if not isinstance(nick, unicode): + nick = unicode(nick, 'utf-8') + client = gconf.client_get_default() + client.set_string('/desktop/sugar/user/nick', nick) + return 1 + + +def get_color(): + client = gconf.client_get_default() + return client.get_string('/desktop/sugar/user/color') + + +def print_color(): + color_string = get_color() + tmp = color_string.split(',') + + stroke_tuple = None + fill_tuple = None + for color in _COLORS: + for hue in _COLORS[color]: + if _COLORS[color][hue] == tmp[0]: + stroke_tuple = (color, hue) + if _COLORS[color][hue] == tmp[1]: + fill_tuple = (color, hue) + + if stroke_tuple is not None: + print _('stroke: color=%s hue=%s') % (stroke_tuple[0], + stroke_tuple[1]) + else: + print _('stroke: %s') % (tmp[0]) + if fill_tuple is not None: + print _('fill: color=%s hue=%s') % (fill_tuple[0], fill_tuple[1]) + else: + print _('fill: %s') % (tmp[1]) + + +def set_color(stroke, fill, stroke_modifier='medium', fill_modifier='medium'): + """Set the system color by setting a fill and stroke color. + fill : [red, orange, yellow, blue, green, purple] + stroke : [red, orange, yellow, blue, green, purple] + hue stroke : [dark, medium, light] (optional) + hue fill : [dark, medium, light] (optional) + """ + + if stroke_modifier not in _MODIFIERS or fill_modifier 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 stroke_modifier == fill_modifier: + if fill_modifier == 'medium': + fill_modifier = 'light' + else: + fill_modifier = 'medium' + + color = _COLORS[stroke][stroke_modifier] + ',' \ + + _COLORS[fill][fill_modifier] + + client = gconf.client_get_default() + client.set_string('/desktop/sugar/user/color', color) + return 1 + + +def get_color_xo(): + client = gconf.client_get_default() + return client.get_string('/desktop/sugar/user/color') + + +def set_color_xo(color): + """Set a color with an XoColor + This method is used by the graphical user interface + """ + client = gconf.client_get_default() + client.set_string('/desktop/sugar/user/color', color) + return 1 diff --git a/extensions/cpsection/aboutme/view.py b/extensions/cpsection/aboutme/view.py new file mode 100644 index 0000000..84daec7 --- /dev/null +++ b/extensions/cpsection/aboutme/view.py @@ -0,0 +1,340 @@ +# Copyright (C) 2008, OLPC +# Copyright (C) 2010, Sugar Labs +# +# 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 + +import gtk +import gobject +from gettext import gettext as _ + +from sugar.graphics.icon import Icon +from sugar.graphics import style +from sugar.graphics.xocolor import XoColor, colors + +from jarabe.controlpanel.sectionview import SectionView +from jarabe.controlpanel.inlinealert import InlineAlert + +_STROKE_COLOR = 0 +_FILL_COLOR = 1 + + +def _get_next_stroke_color(color): + """ Return the next color pair in the list that shares the same fill + as color. """ + current_index = _get_current_index(color) + if current_index == -1: + return '%s,%s' % (color.stroke, color.fill) + next_index = _next_index(current_index) + while(colors[next_index][_FILL_COLOR] != \ + colors[current_index][_FILL_COLOR]): + next_index = _next_index(next_index) + return '%s,%s' % (colors[next_index][_STROKE_COLOR], + colors[next_index][_FILL_COLOR]) + + +def _get_previous_stroke_color(color): + """ Return the previous color pair in the list that shares the same fill + as color. """ + current_index = _get_current_index(color) + if current_index == -1: + return '%s,%s' % (color.stroke, color.fill) + previous_index = _previous_index(current_index) + while (colors[previous_index][_FILL_COLOR] != \ + colors[current_index][_FILL_COLOR]): + previous_index = _previous_index(previous_index) + return '%s,%s' % (colors[previous_index][_STROKE_COLOR], + colors[previous_index][_FILL_COLOR]) + + +def _get_next_fill_color(color): + """ Return the next color pair in the list that shares the same stroke + as color. """ + current_index = _get_current_index(color) + if current_index == -1: + return '%s,%s' % (color.stroke, color.fill) + next_index = _next_index(current_index) + while (colors[next_index][_STROKE_COLOR] != \ + colors[current_index][_STROKE_COLOR]): + next_index = _next_index(next_index) + return '%s,%s' % (colors[next_index][_STROKE_COLOR], + colors[next_index][_FILL_COLOR]) + + +def _get_previous_fill_color(color): + """ Return the previous color pair in the list that shares the same stroke + as color. """ + current_index = _get_current_index(color) + if current_index == -1: + return '%s,%s' % (color.stroke, color.fill) + previous_index = _previous_index(current_index) + while (colors[previous_index][_STROKE_COLOR] != \ + colors[current_index][_STROKE_COLOR]): + previous_index = _previous_index(previous_index) + return '%s,%s' % (colors[previous_index][_STROKE_COLOR], + colors[previous_index][_FILL_COLOR]) + + +def _next_index(current_index): + next_index = current_index + 1 + if next_index == len(colors): + next_index = 0 + return next_index + + +def _previous_index(current_index): + previous_index = current_index - 1 + if previous_index < 0: + previous_index = len(colors) - 1 + return previous_index + + +def _get_current_index(color): + return colors.index([color.stroke, color.fill]) + + +_PREVIOUS_FILL_COLOR = 0 +_NEXT_FILL_COLOR = 1 +_CURRENT_COLOR = 2 +_NEXT_STROKE_COLOR = 3 +_PREVIOUS_STROKE_COLOR = 4 + + +class EventIcon(gtk.EventBox): + __gtype_name__ = 'SugarEventIcon' + + def __init__(self, **kwargs): + gtk.EventBox.__init__(self) + + self.icon = Icon(pixel_size=style.XLARGE_ICON_SIZE, **kwargs) + + self.set_visible_window(False) + self.set_app_paintable(True) + self.set_events(gtk.gdk.BUTTON_PRESS_MASK) + + self.add(self.icon) + self.icon.show() + + +class ColorPicker(EventIcon): + __gsignals__ = { + 'color-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([object])), + } + + def __init__(self, picker): + EventIcon.__init__(self) + + self.icon.props.icon_name = 'computer-xo' + self._picker = picker + self._color = None + + self.icon.props.pixel_size = style.XLARGE_ICON_SIZE + + self.connect('button_press_event', self.__pressed_cb, picker) + + def update(self, color): + if self._picker == _PREVIOUS_FILL_COLOR: + self._color = XoColor(_get_previous_fill_color(color)) + elif self._picker == _PREVIOUS_STROKE_COLOR: + self._color = XoColor(_get_previous_stroke_color(color)) + elif self._picker == _NEXT_FILL_COLOR: + self._color = XoColor(_get_next_fill_color(color)) + elif self._picker == _NEXT_STROKE_COLOR: + self._color = XoColor(_get_next_stroke_color(color)) + else: + self._color = color + self.icon.props.xo_color = self._color + + def __pressed_cb(self, button, event, picker): + if picker != _CURRENT_COLOR: + self.emit('color-changed', self._color) + + +class AboutMe(SectionView): + + def __init__(self, model, alerts): + SectionView.__init__(self) + + self._model = model + self.restart_alerts = alerts + self._nick_sid = 0 + self._color_valid = True + self._nick_valid = True + + self.set_border_width(style.DEFAULT_SPACING * 2) + self.set_spacing(style.DEFAULT_SPACING) + self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) + + self._color_label = gtk.HBox(spacing=style.DEFAULT_SPACING) + self._color_box = gtk.HBox(spacing=style.DEFAULT_SPACING) + self._color_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) + self._color_alert = None + + self._pickers = { + _PREVIOUS_FILL_COLOR: ColorPicker(_PREVIOUS_FILL_COLOR), + _NEXT_FILL_COLOR: ColorPicker(_NEXT_FILL_COLOR), + _CURRENT_COLOR: ColorPicker(_CURRENT_COLOR), + _NEXT_STROKE_COLOR: ColorPicker(_NEXT_STROKE_COLOR), + _PREVIOUS_STROKE_COLOR: ColorPicker(_PREVIOUS_STROKE_COLOR), + } + + self._setup_color() + initial_color = XoColor(self._model.get_color_xo()) + self._update_pickers(initial_color) + + self._nick_box = gtk.HBox(spacing=style.DEFAULT_SPACING) + self._nick_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) + self._nick_entry = None + self._nick_alert = None + self._setup_nick() + self.setup() + + def _setup_nick(self): + self._nick_entry = gtk.Entry() + self._nick_entry.modify_bg(gtk.STATE_INSENSITIVE, + style.COLOR_WHITE.get_gdk_color()) + self._nick_entry.modify_base(gtk.STATE_INSENSITIVE, + style.COLOR_WHITE.get_gdk_color()) + self._nick_entry.set_width_chars(25) + self._nick_box.pack_start(self._nick_entry, expand=False) + self._nick_entry.show() + + label_entry_error = gtk.Label() + self._group.add_widget(label_entry_error) + self._nick_alert_box.pack_start(label_entry_error, expand=False) + label_entry_error.show() + + self._nick_alert = InlineAlert() + self._nick_alert_box.pack_start(self._nick_alert) + if 'nick' in self.restart_alerts: + self._nick_alert.props.msg = self.restart_msg + self._nick_alert.show() + + self._center_in_panel = gtk.Alignment(0.5) + self._center_in_panel.add(self._nick_box) + self.pack_start(self._center_in_panel, False) + self.pack_start(self._nick_alert_box, False) + self._nick_box.show() + self._nick_alert_box.show() + self._center_in_panel.show() + + def _setup_color(self): + label_color = gtk.Label(_('Click to change your color:')) + label_color.modify_fg(gtk.STATE_NORMAL, + style.COLOR_SELECTION_GREY.get_gdk_color()) + self._group.add_widget(label_color) + self._color_label.pack_start(label_color, expand=False) + label_color.show() + + for picker_index in sorted(self._pickers.keys()): + if picker_index == _CURRENT_COLOR: + left_separator = gtk.SeparatorToolItem() + left_separator.show() + self._color_box.pack_start(left_separator, expand=False) + + picker = self._pickers[picker_index] + picker.show() + self._color_box.pack_start(picker, expand=False) + + if picker_index == _CURRENT_COLOR: + right_separator = gtk.SeparatorToolItem() + right_separator.show() + self._color_box.pack_start(right_separator, expand=False) + + label_color_error = gtk.Label() + self._group.add_widget(label_color_error) + self._color_alert_box.pack_start(label_color_error, expand=False) + label_color_error.show() + + self._color_alert = InlineAlert() + self._color_alert_box.pack_start(self._color_alert) + if 'color' in self.restart_alerts: + self._color_alert.props.msg = self.restart_msg + self._color_alert.show() + + self._center_in_panel = gtk.Alignment(0.5) + self._center_in_panel.add(self._color_box) + self.pack_start(self._color_label, False) + self.pack_start(self._center_in_panel, False) + self.pack_start(self._color_alert_box, False) + self._color_label.show() + self._color_box.show() + self._color_alert_box.show() + self._center_in_panel.show() + + def setup(self): + self._nick_entry.set_text(self._model.get_nick()) + self._color_valid = True + self._nick_valid = True + self.needs_restart = False + + self._nick_entry.connect('changed', self.__nick_changed_cb) + for picker in self._pickers.values(): + picker.connect('color-changed', self.__color_changed_cb) + + def undo(self): + self._model.undo() + self._nick_alert.hide() + self._color_alert.hide() + + def _update_pickers(self, color): + for picker in self._pickers.values(): + picker.update(color) + + def _validate(self): + if self._nick_valid and self._color_valid: + self.props.is_valid = True + else: + self.props.is_valid = False + + def __nick_changed_cb(self, widget, data=None): + if self._nick_sid: + gobject.source_remove(self._nick_sid) + self._nick_sid = gobject.timeout_add(self._APPLY_TIMEOUT, + self.__nick_timeout_cb, widget) + + def __nick_timeout_cb(self, widget): + self._nick_sid = 0 + + if widget.get_text() == self._model.get_nick(): + return False + try: + self._model.set_nick(widget.get_text()) + except ValueError, detail: + self._nick_alert.props.msg = detail + self._nick_valid = False + else: + self._nick_alert.props.msg = self.restart_msg + self._nick_valid = True + self.needs_restart = True + self.restart_alerts.append('nick') + self._validate() + self._nick_alert.show() + return False + + def __color_changed_cb(self, colorpicker, color): + self._model.set_color_xo(color.to_string()) + self.needs_restart = True + self._color_alert.props.msg = self.restart_msg + self._color_valid = True + self.restart_alerts.append('color') + + self._validate() + self._color_alert.show() + + self._update_pickers(color) + + return False -- cgit v0.9.1