From 2b200cda7787769b6cc718a8ffd6addb4e675033 Mon Sep 17 00:00:00 2001 From: Daniel Francis Date: Tue, 23 Oct 2012 12:53:02 +0000 Subject: -Initial- commit This is moved from git.sl.org/sweetener/sweetener for be used trought git-submodule Signed-off-by: Daniel Francis --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eef29c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.pyc + diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..22ff499 --- /dev/null +++ b/__init__.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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. diff --git a/alerts.py b/alerts.py new file mode 100644 index 0000000..9609a82 --- /dev/null +++ b/alerts.py @@ -0,0 +1,61 @@ +# Copyright (C) 2012 S. Daniel Francis +# +# 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.alert import Alert as SugarAlert +from sugar.graphics.alert import NotifyAlert as SugarNotify + +from icon import Icon + + +class Alert(SugarAlert): + def __init__(self, parent, title, content, mtype): + SugarAlert.__init__(self) + self._parent = parent + if mtype == gtk.MESSAGE_INFO: + icon = Icon(icon_name='emblem-notification') + icon.show() + self.props.icon = icon + icon.props.pixel_size = style.SMALL_ICON_SIZE * 2 + self.props.title = title + self.props.msg = content + ok_icon = Icon(icon_name='dialog-ok') + self.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon) + ok_icon.show() + self.connect('response', self.remove_myself) + + def remove_myself(self, widget=None, response=None): + self._parent.remove_alert(self) + + +class NotifyAlert(SugarNotify): + def __init__(self, parent, title, content, icon, timeout): + SugarNotify.__init__(self, timeout) + self._parent = parent + self.props.title = title + self.props.msg = content + if icon is not None: + icon = Icon(icon_name=icon) + icon.show() + self.props.icon = icon + icon.props.pixel_size = style.SMALL_ICON_SIZE * 2 + self.connect('response', self.remove_myself) + + def remove_myself(self, widget=None, response=None): + self._parent.remove_alert(self) diff --git a/basic_options.py b/basic_options.py new file mode 100644 index 0000000..52f4ebd --- /dev/null +++ b/basic_options.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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 _ + +from sugar.activity.widgets import ActivityToolbarButton + +import stock +from item import Item + +DOCUMENT = 0 +CONFIG = 1 + + +class BasicOptions(ActivityToolbarButton): + def __init__(self, activity, box, export_formats=None): + ActivityToolbarButton.__init__(self, activity) + box.toolbar.insert(self, 0) + self.show() + if export_formats != None: + if len(export_formats) == 1: + stock.register('sweetener-%s' % export_formats[0][1], + _('Export as %s') % export_formats[0][0], + None, export_formats[0][1].replace('/', + '-')) + export = Item('sweetener-%s' % export_formats[0][1]) + export.connect('activate', activity.export, + export_formats[0]) + self.page.insert(export.get_tool_item(), -1) diff --git a/coloritem.py b/coloritem.py new file mode 100644 index 0000000..30a3ad3 --- /dev/null +++ b/coloritem.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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/colors.py b/colors.py new file mode 100644 index 0000000..96d48ba --- /dev/null +++ b/colors.py @@ -0,0 +1,30 @@ +# Copyright (C) 2012 Daniel Francis +# +# 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') + +from sugar.graphics.xocolor import XoColor + +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/help.py b/help.py new file mode 100644 index 0000000..c2250ff --- /dev/null +++ b/help.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# Based on helpbutton by Gonzalo Odiard +# +# 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, + '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('%s' % 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/icon.py b/icon.py new file mode 100644 index 0000000..07c8c47 --- /dev/null +++ b/icon.py @@ -0,0 +1,18 @@ +# Copyright (C) 2012 Daniel Francis +# +# 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/item.py b/item.py new file mode 100644 index 0000000..291204a --- /dev/null +++ b/item.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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.toolbutton import ToolButton + +import stock + + +class Item(gobject.GObject): + __gsignals__ = {'activate': (gobject.SIGNAL_RUN_LAST, + gobject.TYPE_NONE, + tuple())} + toolitem = None + + def __init__(self, stock_id=gtk.STOCK_CLEAR, important=False): + gobject.GObject.__init__(self) + self._stock_id = stock_id + self.accel_group = None + self.important = important + self.connection = None + self.connection_data = None + self.tooltip = None + + def set_stock_id(self, stock_id): + self._stock_id = stock_id + + def get_stock_id(self): + return self._stock_id + + stock_id = property(get_stock_id, set_stock_id) + + def get_menu_item(self): + return None + + def activate_cb(self, widget): + self.emit('activate') + + def setup_accelerator(self): + accelerator = stock.get_accelerator(self._stock_id) + logger.debug(str(accelerator)) + try: + if accelerator[1] > 0: + self.toolitem.props.accelerator = gtk.accelerator_name( + accelerator[1], accelerator[0]) + except: + logger.error( +'Could not set up accelerator; if toogletoolbutton, update your sugar version') + + def get_tool_item(self): + if self._stock_id in stock.icons: + icon_name = stock.icons[self._stock_id] + else: + icon_name = self._stock_id + self.toolitem = ToolButton(icon_name) + self.toolitem.connect('clicked', self.activate_cb) + self.setup_tooltip() + return self.toolitem + + def setup_tooltip(self): + if self.tooltip: + self.toolitem.set_tooltip(self.tooltip) + else: + text = gtk.stock_lookup(self._stock_id)[1] + self.toolitem.set_tooltip(text.replace('_', '')) + self.setup_accelerator() diff --git a/itembox.py b/itembox.py new file mode 100644 index 0000000..d861c52 --- /dev/null +++ b/itembox.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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.graphics.toolbarbox import ToolbarBox +from sugar.activity.widgets import StopButton + + +class ItemBox(ToolbarBox): + def __init__(self, activity): + ToolbarBox.__init__(self) + self._parent = activity + separator = gtk.SeparatorToolItem() + separator.set_draw(False) + separator.set_expand(True) + separator.show() + self.toolbar.insert(separator, -1) + self.stopbutton = StopButton(activity) + self.toolbar.insert(self.stopbutton, -1) + self.stopbutton.show() diff --git a/itemgroup.py b/itemgroup.py new file mode 100644 index 0000000..637eb4f --- /dev/null +++ b/itemgroup.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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 gobject +import gtk +from sugar.activity.widgets import ToolbarButton + + +class ItemGroup(gobject.GObject): + def __init__(self, box, name=None, icon=None): + gobject.GObject.__init__(self) + self.items = [] + self.item = ToolbarButton(icon_name=icon) + box.toolbar.insert(self.item, len(box.toolbar) - 2) + self.toolbar = gtk.Toolbar() + self.item.props.page = self.toolbar + self.toolbar.show() + self.item.show() + self.activity = box._parent + self.last_position = 0 + + def append_item(self, item): + tool_item = item.get_tool_item() + self.toolbar.insert(tool_item, len(self.items) - self.last_position) + tool_item.show_all() + self.items.append(item) + + def append_separator(self, important=False): + toolitem = gtk.SeparatorToolItem() + toolitem.show() + self.toolbar.insert(toolitem, len(self.items) - self.last_position) + self.items.append(self.toolbar) + return toolitem + + +class GhostGroup(ItemGroup): + def __init__(self, box, name): + gobject.GObject.__init__(self) + self.items = [i for i in box.toolbar.get_children()[:-2]] + self.toolbar = box.toolbar + self.activity = box._parent + self.last_position = 0 + + +class SubGroup(ItemGroup): + def __init__(self, group, name=None): + gobject.GObject.__init__(self) + self.items = group.items + self.last_position = group.last_position + if len(self.items) > 0: + group.append_separator() + group.append_separator() + self.toolbar = group.toolbar + self.last_position = 1 diff --git a/profile.py b/profile.py new file mode 100644 index 0000000..39d1c97 --- /dev/null +++ b/profile.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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/radioitem.py b/radioitem.py new file mode 100644 index 0000000..93c640b --- /dev/null +++ b/radioitem.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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/settingsitem.py b/settingsitem.py new file mode 100644 index 0000000..4dcfdf5 --- /dev/null +++ b/settingsitem.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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/settingsradioitem.py b/settingsradioitem.py new file mode 100644 index 0000000..cf1492d --- /dev/null +++ b/settingsradioitem.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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/shortcontentitem.py b/shortcontentitem.py new file mode 100644 index 0000000..82fceba --- /dev/null +++ b/shortcontentitem.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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/stock.py b/stock.py new file mode 100644 index 0000000..9ceb998 --- /dev/null +++ b/stock.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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('stock') +import gtk + +icon_factory = gtk.IconFactory() + +# Set the icon name for the stock items, this is used only in Sugar. +# Associate here every default stock id with an icon name if you need it. +icons = {gtk.STOCK_ADD: 'list-add'} + + +def register(name, label, accelerator, icon_name): + if accelerator == None: + keyval = 0 + mask = 0 + else: + keyval, mask = gtk.accelerator_parse(accelerator) + gtk.stock_add([(name, label, mask, keyval, '')]) + if icon_name: + icon_source = gtk.IconSource() + icon_source.set_icon_name(icon_name) + icon = gtk.IconSet() + icon.add_source(icon_source) + icon_factory.add(name, icon) + 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) + info[2] = mask + info[3] = keyval + logger.debug(str(info)) + gtk.stock_add([(info[0], info[1], info[2], info[3], info[4])]) + +# Here we overwrite the key accelerators for some stock ids. +# Feel free to add here any other stock id if you need it at your activity, +# and send us a patch. + +overwrite_stock(gtk.STOCK_ZOOM_IN, 'plus') +overwrite_stock(gtk.STOCK_ZOOM_OUT, 'minus') +overwrite_stock(gtk.STOCK_ZOOM_100, '0') +# Key accelerator will be F11 on desktops and return on Sugar. +overwrite_stock(gtk.STOCK_FULLSCREEN, 'Return') +overwrite_stock(gtk.STOCK_ADD, 'A') +overwrite_stock(gtk.STOCK_REMOVE, 'R') +overwrite_stock(gtk.STOCK_SELECT_COLOR, 'L') + + +def get_label(stock, underline): + text = gtk.stock_lookup(stock)[1] + if underline: + text = text.replace('_', '') + return text + + +def get_accelerator(stock): + return gtk.stock_lookup(stock)[2:-1] diff --git a/toggleitem.py b/toggleitem.py new file mode 100644 index 0000000..d7b8c86 --- /dev/null +++ b/toggleitem.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012 S. Daniel Francis +# +# 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 -- cgit v0.9.1