diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-08-30 23:55:34 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-08-30 23:55:34 (GMT) |
commit | 02c3fed9dc41f2304270a34c0748c278f9fe6931 (patch) | |
tree | 7621c09f70028c38dfaf95982a704ba91416cc16 /sugar/sweetener | |
parent | 87458b0aea14739324c822aaa4cea11722b347df (diff) |
Update Sweetener
Diffstat (limited to 'sugar/sweetener')
-rw-r--r-- | sugar/sweetener/basic_options.py | 2 | ||||
-rw-r--r-- | sugar/sweetener/coloritem.py | 64 | ||||
-rw-r--r-- | sugar/sweetener/colors.py | 32 | ||||
-rw-r--r-- | sugar/sweetener/help.py | 91 | ||||
-rw-r--r-- | sugar/sweetener/icon.py | 18 | ||||
-rw-r--r-- | sugar/sweetener/item.py | 2 | ||||
-rw-r--r-- | sugar/sweetener/itembox.py | 1 | ||||
-rw-r--r-- | sugar/sweetener/profile.py | 27 | ||||
-rw-r--r-- | sugar/sweetener/radioitem.py | 45 | ||||
-rw-r--r-- | sugar/sweetener/settingsitem.py | 53 | ||||
-rw-r--r-- | sugar/sweetener/settingsradioitem.py | 44 | ||||
-rw-r--r-- | sugar/sweetener/shortcontentitem.py | 41 | ||||
-rw-r--r-- | sugar/sweetener/stock.py | 2 | ||||
-rw-r--r-- | sugar/sweetener/toggleitem.py | 56 | ||||
-rw-r--r-- | sugar/sweetener/xocolor.py | 18 |
15 files changed, 494 insertions, 2 deletions
diff --git a/sugar/sweetener/basic_options.py b/sugar/sweetener/basic_options.py index a2221f6..52f4ebd 100644 --- a/sugar/sweetener/basic_options.py +++ b/sugar/sweetener/basic_options.py @@ -36,7 +36,7 @@ class BasicOptions(ActivityToolbarButton): if export_formats != None: if len(export_formats) == 1: stock.register('sweetener-%s' % export_formats[0][1], - _('Save as %s') % export_formats[0][0], + _('Export as %s') % export_formats[0][0], None, export_formats[0][1].replace('/', '-')) export = Item('sweetener-%s' % export_formats[0][1]) diff --git a/sugar/sweetener/coloritem.py b/sugar/sweetener/coloritem.py new file mode 100644 index 0000000..30a3ad3 --- /dev/null +++ b/sugar/sweetener/coloritem.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import logging +logger = logging.getLogger('option') + +import gobject +import gtk + +from sugar.graphics.colorbutton import ColorToolButton + +from colors import color2string +from item import Item + + +class ColorItem(Item): + __gsignals__ = {'updated': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING,))} + + def __init__(self, parent=None, important=False): + Item.__init__(self, gtk.STOCK_SELECT_COLOR) + self.color = '#FFFFFF' + + def set_color(self, color): + self.color = color + if self.toolitem and self.color: + self.toolitem.set_color(gtk.gdk.Color(self.color)) + + def get_tool_item(self): + self.toolitem = ColorToolButton() + self.toolitem.connect('notify::color', self._color_changed_cb) + self.setup_tooltip() + self.set_color(self.color) + return self.toolitem + + def setup_tooltip(self): + if self.tooltip: + self.toolitem.set_title(self.tooltip) + else: + text = gtk.stock_lookup(self.stock_id)[1] + self.toolitem.set_title(text.replace('_', '')) + self.setup_accelerator() + + def _color_changed_cb(self, widget, pspec): + color_gdk = widget.get_color() + self.color = color2string(color_gdk) + self.emit('updated', self.color) diff --git a/sugar/sweetener/colors.py b/sugar/sweetener/colors.py new file mode 100644 index 0000000..3b5d938 --- /dev/null +++ b/sugar/sweetener/colors.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import logging +logger = logging.getLogger('colors') + + +def color2string(color): + color_string = ["#"] + color_string.append("%02x" % (color.red / 256)) + color_string.append("%02x" % (color.green / 256)) + color_string.append("%02x" % (color.blue / 256)) + string = "".join(color_string) + #logger.debug(str(color) + ' ' + string) + return string diff --git a/sugar/sweetener/help.py b/sugar/sweetener/help.py new file mode 100644 index 0000000..c2250ff --- /dev/null +++ b/sugar/sweetener/help.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# Based on helpbutton by Gonzalo Odiard <gonzalo@laptop.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +from gettext import gettext as _ +import gtk + +from sugar.graphics import style +from sugar.graphics.icon import Icon + +import stock +from settingsitem import SettingsItem +from itemgroup import ItemGroup +import info +import helpcontent + + +class Help(SettingsItem): + def __init__(self, box): + title = gtk.stock_lookup(gtk.STOCK_HELP)[1] + stock.register('sweetener-help-contents', title, + '<Ctrl>H', 'toolbar-help') + SettingsItem.__init__(self, None, 'sweetener-help-contents') + + sw = gtk.ScrolledWindow() + sw.set_size_request(int(gtk.gdk.screen_width() / 2.8), + gtk.gdk.screen_height() - style.GRID_CELL_SIZE * 3) + sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + self._max_text_width = int(gtk.gdk.screen_width() / 3) - 20 + self._vbox = gtk.VBox() + self._vbox.set_homogeneous(False) + hbox = gtk.HBox() + hbox.pack_start(self._vbox, False, True, 0) + sw.add_with_viewport(hbox) + sw.show() + self.content = sw + item = self.get_tool_item() + item.show_all() + separator = gtk.SeparatorToolItem() + separator.show() + box.toolbar.insert(separator, + len(box.toolbar.get_children()[:-2])) + box.toolbar.insert(item, + len(box.toolbar.get_children()[:-2])) + for i in helpcontent.help: + self.add_section(i[0]) + for text, icon in i[1:]: + self.add_paragraph(text, icon) + + def add_section(self, section_text): + hbox = gtk.HBox() + label = gtk.Label() + label.set_use_markup(True) + label.set_markup('<b>%s</b>' % section_text) + label.set_line_wrap(True) + label.set_size_request(self._max_text_width, -1) + hbox.add(label) + hbox.show_all() + self._vbox.pack_start(hbox, False, False, padding=5) + + def add_paragraph(self, text, icon=None): + hbox = gtk.HBox() + label = gtk.Label(text) + label.set_justify(gtk.JUSTIFY_LEFT) + label.set_line_wrap(True) + hbox.add(label) + if icon is not None: + _icon = Icon(icon_name=icon) + hbox.add(_icon) + label.set_size_request(self._max_text_width - 20, -1) + else: + label.set_size_request(self._max_text_width, -1) + + hbox.show_all() + self._vbox.pack_start(hbox, False, False, padding=5) diff --git a/sugar/sweetener/icon.py b/sugar/sweetener/icon.py new file mode 100644 index 0000000..59be87a --- /dev/null +++ b/sugar/sweetener/icon.py @@ -0,0 +1,18 @@ +# Copyright (C) 2006-2007 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +from sugar.graphics.icon import * diff --git a/sugar/sweetener/item.py b/sugar/sweetener/item.py index f9c39d0..291204a 100644 --- a/sugar/sweetener/item.py +++ b/sugar/sweetener/item.py @@ -66,7 +66,7 @@ class Item(gobject.GObject): accelerator[1], accelerator[0]) except: logger.error( - 'Could not set up accelerator; if toogletoolbutton, update your sugar version') +'Could not set up accelerator; if toogletoolbutton, update your sugar version') def get_tool_item(self): if self._stock_id in stock.icons: diff --git a/sugar/sweetener/itembox.py b/sugar/sweetener/itembox.py index 8c6467f..d861c52 100644 --- a/sugar/sweetener/itembox.py +++ b/sugar/sweetener/itembox.py @@ -21,6 +21,7 @@ import gtk from sugar.graphics.toolbarbox import ToolbarBox from sugar.activity.widgets import StopButton + class ItemBox(ToolbarBox): def __init__(self, activity): ToolbarBox.__init__(self) diff --git a/sugar/sweetener/profile.py b/sugar/sweetener/profile.py new file mode 100644 index 0000000..39d1c97 --- /dev/null +++ b/sugar/sweetener/profile.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import gtk +from sugar import profile +profile_color = profile.get_color() +fill_color = gtk.gdk.color_parse(profile_color.get_fill_color()) +stroke_color = gtk.gdk.color_parse(profile_color.get_stroke_color()) + +get_fill_color = lambda widget: fill_color +get_stroke_color = lambda widget: stroke_color diff --git a/sugar/sweetener/radioitem.py b/sugar/sweetener/radioitem.py new file mode 100644 index 0000000..93c640b --- /dev/null +++ b/sugar/sweetener/radioitem.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import logging +logger = logging.getLogger('toggleoption') +import gtk +from sugar.graphics.radiotoolbutton import RadioToolButton +import stock +from toggleitem import ToggleItem + + +class RadioItem(ToggleItem): + def __init__(self, group, default_value=True, + stock_id=None, important=False): + ToggleItem.__init__(self, default_value, stock_id, important) + self.group = group + + def get_tool_item(self): + self.toolitem = RadioToolButton() + if self.group: + self.toolitem.set_group(self.group.toolitem) + self.toolitem.set_named_icon(stock.icons[self._stock_id] + if self._stock_id in stock.icons + else self._stock_id) + self.toolitem.set_active(self.default_value) + self.toolitem.connect('toggled', self.toggled_cb) + self.setup_tooltip() + return self.toolitem diff --git a/sugar/sweetener/settingsitem.py b/sugar/sweetener/settingsitem.py new file mode 100644 index 0000000..4dcfdf5 --- /dev/null +++ b/sugar/sweetener/settingsitem.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import logging +logger = logging.getLogger('option') + +import gobject +import gtk + +from item import Item + + +class SettingsItem(Item): + __gsignals__ = {'closed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + tuple())} + + def __init__(self, parent=None, stock_id=None, important=False): + Item.__init__(self, stock_id, important) + self.content = gtk.EventBox() + self.parent = parent + self.created = False + # For toggleoptions + self.active = True + + def get_tool_item(self): + self.tool_item = Item.get_tool_item(self) + self.palette = self.toolitem.get_palette() + self.palette.set_content(self.content) + self.content.show_all() + return self.tool_item + + def do_activate(self): + if self.active: + self.toolitem.props.palette.popup(immediate=True, state=1) + #TODO: Send close event when de palette is closed. + #self.emit('close') diff --git a/sugar/sweetener/settingsradioitem.py b/sugar/sweetener/settingsradioitem.py new file mode 100644 index 0000000..cf1492d --- /dev/null +++ b/sugar/sweetener/settingsradioitem.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import logging +logger = logging.getLogger('option') + +import gobject +from radioitem import RadioItem +from settingsitem import SettingsItem + + +class SettingsRadioItem(SettingsItem, RadioItem): + __gsignals__ = {'toggled': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_BOOLEAN,))} + + def __init__(self, group, default_value=True, parent=None, + stock_id=None, important=False): + SettingsItem.__init__(self, parent, stock_id, important) + RadioItem.__init__(self, group, default_value, stock_id, important) + + def get_tool_item(self): + RadioItem.get_tool_item(self) + self.toolitem.connect('clicked', self.activate_cb) + self.palette = self.toolitem.get_palette() + self.palette.set_content(self.content) + self.content.show_all() + return self.toolitem diff --git a/sugar/sweetener/shortcontentitem.py b/sugar/sweetener/shortcontentitem.py new file mode 100644 index 0000000..82fceba --- /dev/null +++ b/sugar/sweetener/shortcontentitem.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import logging +logger = logging.getLogger('option') + +import gobject +import gtk + +from item import Item + + +class ShortContentItem(Item): + + def __init__(self, parent=None, stock_id=None, important=False): + Item.__init__(self, stock_id, important) + self.content = gtk.EventBox() + self.parent = parent + self.separator = None + + def get_tool_item(self): + self.toolitem = gtk.ToolItem() + self.toolitem.add(self.content) + return self.toolitem diff --git a/sugar/sweetener/stock.py b/sugar/sweetener/stock.py index 3ba898a..8fbca2e 100644 --- a/sugar/sweetener/stock.py +++ b/sugar/sweetener/stock.py @@ -26,6 +26,7 @@ icon_factory = gtk.IconFactory() # Set the icon name for the stock items, this is used only in Sugar. icons = {gtk.STOCK_ADD: 'list-add'} + def register(name, label, accelerator, icon_name): if accelerator == None: keyval = 0 @@ -42,6 +43,7 @@ def register(name, label, accelerator, icon_name): icon_factory.add_default() icons[name] = icon_name + def overwrite_stock(stock_id, new_accelerator): info = list(gtk.stock_lookup(stock_id)) keyval, mask = gtk.accelerator_parse(new_accelerator) diff --git a/sugar/sweetener/toggleitem.py b/sugar/sweetener/toggleitem.py new file mode 100644 index 0000000..d7b8c86 --- /dev/null +++ b/sugar/sweetener/toggleitem.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import logging +logger = logging.getLogger('toggleoption') +import gobject +import gtk +from sugar.graphics.toggletoolbutton import ToggleToolButton +import stock +from item import Item + + +class ToggleItem(Item): + __gsignals__ = {'toggled': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_BOOLEAN,))} + + def __init__(self, default_value=True, stock_id=None, important=False): + Item.__init__(self, stock_id, important) + self.default_value = default_value + self.active = default_value + + def get_menu_item(self): + return None + + def toggled_cb(self, widget): + active = widget.get_active() + self.toolitem.set_active(active) + self.active = active + self.emit('toggled', active) + + def get_tool_item(self): + self.toolitem = ToggleToolButton() + self.toolitem.set_named_icon(stock.icons[self._stock_id] + if self._stock_id in stock.icons + else self._stock_id) + self.toolitem.set_active(self.default_value) + self.toolitem.connect('toggled', self.toggled_cb) + self.setup_tooltip() + return self.toolitem diff --git a/sugar/sweetener/xocolor.py b/sugar/sweetener/xocolor.py new file mode 100644 index 0000000..a5344cc --- /dev/null +++ b/sugar/sweetener/xocolor.py @@ -0,0 +1,18 @@ +# Copyright (C) 2012 Daniel Francis <francis@sugarlabs.org> +# +# 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 3 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 Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +from sugar.graphics.xocolor import * |