From 973b0bd9def313cf6cf9ffea967c4626ebb9ffc6 Mon Sep 17 00:00:00 2001 From: Harsh Verma Date: Mon, 22 Mar 2010 20:31:07 +0000 Subject: fontpanel --- diff --git a/configure.ac b/configure.ac index 5174dea..de17c2c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ -AC_INIT([Sugar],[0.87.8],[],[sugar]) +AC_INIT([Sugar],[0.87.4],[],[sugar]) AC_PREREQ([2.59]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([configure.ac]) -SUCROSE_VERSION="0.87.7" +SUCROSE_VERSION="0.87.4" AC_SUBST(SUCROSE_VERSION) AM_INIT_AUTOMAKE([1.9 foreign dist-bzip2 no-dist-gzip]) @@ -53,6 +53,7 @@ extensions/cpsection/aboutcomputer/Makefile extensions/cpsection/aboutme/Makefile extensions/cpsection/datetime/Makefile extensions/cpsection/frame/Makefile +extensions/cpsection/font/Makefile extensions/cpsection/keyboard/Makefile extensions/cpsection/language/Makefile extensions/cpsection/modemconfiguration/Makefile diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am index a35643a..da1edcd 100644 --- a/data/icons/Makefile.am +++ b/data/icons/Makefile.am @@ -10,6 +10,7 @@ sugar_DATA = \ module-modemconfiguration.svg \ module-network.svg \ module-power.svg \ + module-text-size.svg \ module-updater.svg EXTRA_DIST = $(sugar_DATA) diff --git a/data/icons/module-text-size.svg b/data/icons/module-text-size.svg new file mode 100644 index 0000000..527efd9 --- /dev/null +++ b/data/icons/module-text-size.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/extensions/cpsection/Makefile.am b/extensions/cpsection/Makefile.am index a92b5dd..5bfa8ef 100644 --- a/extensions/cpsection/Makefile.am +++ b/extensions/cpsection/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = aboutme aboutcomputer datetime frame keyboard language \ +SUBDIRS = aboutme aboutcomputer datetime font frame keyboard language \ modemconfiguration network power updater sugardir = $(pkgdatadir)/extensions/cpsection diff --git a/extensions/cpsection/font/Makefile.am b/extensions/cpsection/font/Makefile.am new file mode 100644 index 0000000..fa75e3a --- /dev/null +++ b/extensions/cpsection/font/Makefile.am @@ -0,0 +1,6 @@ +sugardir = $(pkgdatadir)/extensions/cpsection/font + +sugar_PYTHON = \ + __init__.py \ + model.py \ + view.py diff --git a/extensions/cpsection/font/__init__.py b/extensions/cpsection/font/__init__.py new file mode 100644 index 0000000..27f6753 --- /dev/null +++ b/extensions/cpsection/font/__init__.py @@ -0,0 +1,21 @@ +# 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 _ + +CLASS = 'Font' +ICON = 'module-text-size' +TITLE = _('Appearance') diff --git a/extensions/cpsection/font/model.py b/extensions/cpsection/font/model.py new file mode 100644 index 0000000..747ec35 --- /dev/null +++ b/extensions/cpsection/font/model.py @@ -0,0 +1,56 @@ +# 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 + +def get_font_size(): + client = gconf.client_get_default() + font_size= client.get_int('/desktop/sugar/font/font_size') + return font_size + +def print_font_size(): + print get_font_size() + +def set_font_size(size): + try: + int(size) + except ValueError: + raise ValueError(_("value must be an integer")) + client =gconf.client_get_default() + client.set_int('/desktop/sugar/font/font_size',int(size)) + return 0 +def get_scale_steps(): + client = gconf.client_get_default() + scale_steps = client.get_int('/desktop/sugar/font/scale_steps') + return scale_steps + +def print_scale_steps(): + print get_scale_steps() + +def set_scale_steps(size): + try: + int(size) + except ValueError: + raise ValueError(_("must be an integer")) + client = gconf.client_get_default() + client.set_int('/desktop/sugar/font/scale_steps',int(size)) + return 0 + + + + diff --git a/extensions/cpsection/font/view.py b/extensions/cpsection/font/view.py new file mode 100644 index 0000000..02ef45d --- /dev/null +++ b/extensions/cpsection/font/view.py @@ -0,0 +1,241 @@ +#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 + +import gtk +import gobject +import pango +import pygtk +from gettext import gettext as _ + +from sugar.graphics import style + +from jarabe.controlpanel.sectionview import SectionView +from jarabe.controlpanel.inlinealert import InlineAlert + +_Small = _('8') +_Default =_('10') +_Large = _('24') +_seconds_label = _('%s ') +_MAX_DELAY = 1 + +class Font(SectionView): + def __init__(self, model, alerts): + SectionView.__init__(self) + + self._model = model + self._font_size_sid = 0 + self._font_size_change_is_valid = True + self._font_size_change_handler = None + self._makechange = True + self.restart_alerts = alerts + + self.set_border_width(style.DEFAULT_SPACING * 2) + self.set_spacing(style.DEFAULT_SPACING) + self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) + + separator = gtk.HSeparator() + self.pack_start(separator, expand=False) + separator.show() + + label_activation = gtk.Label(_('Font')) + label_activation.set_alignment(0, 0) + self.pack_start(label_activation, expand=False) + label_activation.show() + + + self._box_sliders = gtk.VBox() + self._box_sliders.set_border_width(style.DEFAULT_SPACING) + self._box_sliders.set_spacing(style.DEFAULT_SPACING * 2) + + self._font_size_slider = None + self._font_size_alert = None + self._setup_font() + + + self.pack_start(self._box_sliders, expand=False) + self._box_sliders.show() + + + + self.box_prevw = gtk.HBox() + self.box_prevw.set_border_width(style.DEFAULT_SPACING) + self.box_prevw.set_spacing(style.DEFAULT_SPACING * 2) + + self._setup_preview() + + + self.pack_start(self.box_prevw, expand =False) + self.box_prevw.show() + self.setup() + + def _setup_font(self): + + """Here we create a HBox and in that we pack both the font size label and the scale with the marks as small, default and large """ + + box_size = gtk.HBox(spacing=style.DEFAULT_SPACING) + label_size = gtk.Label(_('Font size')) + self._group.add_widget(label_size) + label_size.set_alignment(1, 0.35) + label_size.modify_fg(gtk.STATE_NORMAL, + style.COLOR_SELECTION_GREY.get_gdk_color()) + box_size.pack_start(label_size, expand=False) + self._group.add_widget(label_size) + label_size.show() + + + + adj = gtk.Adjustment(value=1, lower=8, upper=24, step_incr=1, page_incr=100, page_size=0) + self._font_size_slider = gtk.HScale(adj) + self._font_size_slider.set_digits(0) + self._font_size_slider.connect('value_changed', self._font_size_delay_format_cb,gtk.UPDATE_CONTINUOUS ) + + self._font_size_slider.connect('value_changed', self.cb_font_size,gtk.UPDATE_CONTINUOUS ) + + self._font_size_slider.add_mark(0.0,gtk.POS_BOTTOM,_('Small')) + self._font_size_slider.add_mark(10.0,gtk.POS_BOTTOM,_('Default')) + self._font_size_slider.add_mark(24.0,gtk.POS_BOTTOM,_('Large')) + + box_size.pack_start(self._font_size_slider) + self._font_size_slider.show() + self._box_sliders.pack_start(box_size, expand =False) + box_size.show() + + + + self._font_size_alert = InlineAlert() + label_size_error = gtk.Label() + self._group.add_widget(label_size_error) + + delay_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) + delay_alert_box.pack_start(label_size_error, expand=False) + label_size_error.show() + delay_alert_box.pack_start(self._font_size_alert, expand=False) + self._box_sliders.pack_start(delay_alert_box,expand=False) + delay_alert_box.show() + + + + if 'font_size' in self.restart_alerts: + self._font_size_alert.props.msg = self.restart_msg + self._font_size_alert.show() + + def _setup_preview(self): + + """ Here we create another HBox within which we have font preview label and the text """ + box_preview=gtk.HBox(spacing=style.DEFAULT_SPACING) + label_activation = gtk.Label(_('Font preview:')) + label_activation.set_alignment(1, 0.35) + label_activation.modify_fg(gtk.STATE_NORMAL,style.COLOR_SELECTION_GREY.get_gdk_color()) + box_preview.pack_start(label_activation, expand=False) + self._group.add_widget(label_activation) + label_activation.show() + + + self.label_font_activation = gtk.Label(_('The quick brown fox jumps over the lazy dog')) + + self.label_font_activation.set_alignment(1.5, 0.35) + box_preview.pack_start(self.label_font_activation) + + + + + self.label_font_activation.show() + + self.box_prevw.pack_start(box_preview, expand=False) + box_preview.show() + + + + def setup(self): + + """ now we get the value of the slider with a restriction that it has to be integer and connect the handler to the _font_size_changed_cb(which will show the values on the scale at a point on the scale""" + self._font_size_slider.set_value(self._model.get_font_size()) + self._font_size_change_is_valid=True + self.needs_restart=False + self._font_size_change_handler = self._font_size_slider.connect('value-changed', self._font_size_changed_cb) + + + def undo(self): + self._font_size_slider.disconnect(self._font_size_change_handler) + self._model.undo() + self._font_size_alert.hide() + + def _validate(self): + if self._font_size_change_is_valid: + self.props.is_valid =True + else: + self.props.is_valid = False + + + def cb_font_size(self,label_font_activation,pos): + self.label_font_activation.set_value_pos(pos) + + def _font_size_changed_cb(self, scale ,data=None): + + """ It will remove the event of restart if the value remains same and if different value then _font_size_sid will be reset""" + if self._font_size_sid: + gobject.source_remove(self._font_size_sid) + self._font_size_sid = gobject.timeout_add(self._APPLY_TIMEOUT,self._font_size_timeout_cb, scale) + + + + + def _font_size_timeout_cb(self,scale): + + """text will remain unchanged if the scale value and the model integer value remains same else it will show the restart message""" + self._font_size_sid = 0 + if scale.get_value() == self._model.get_font_size(): + return + try: + self._model.set_font_size(scale.get_value()) + except ValueError, detail: + self._font_size_alert.props.msg = detail + self._font_size_change_is_valid = False + + else: + self._font_size_alert.props.msg = self.restart_msg + self._font_size_change_is_valid = True + self.needs_restart=True + self.restart_alerts.append('font_size') + self._validate() + self._font_size_alert.show() + return False + + def _font_size_delay_format_cb(self, scale, value): + """ It's value will be returned to setup(self) to place the slider position on the value returned by this""" + if value == _MAX_DELAY: + return _large + elif value == 0: + return _small + elif value == 500: + return _default + else: + return _seconds_label % (value / _MAX_DELAY) + + + + + + + + + + + + + + + -- cgit v0.9.1