Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/sweetener
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-10-02 01:20:34 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-10-02 01:20:34 (GMT)
commite1a599bb8508e1a0607e052a2f086289844dee60 (patch)
tree20473626eef9a8891cd4a77769d0e0dd81c3fd04 /sugar/sweetener
Initial commit
Diffstat (limited to 'sugar/sweetener')
-rw-r--r--sugar/sweetener/__init__.py19
-rw-r--r--sugar/sweetener/basic_options.py45
-rw-r--r--sugar/sweetener/item.py87
-rw-r--r--sugar/sweetener/itembox.py36
-rw-r--r--sugar/sweetener/stock.py77
5 files changed, 264 insertions, 0 deletions
diff --git a/sugar/sweetener/__init__.py b/sugar/sweetener/__init__.py
new file mode 100644
index 0000000..22ff499
--- /dev/null
+++ b/sugar/sweetener/__init__.py
@@ -0,0 +1,19 @@
+#!/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.
diff --git a/sugar/sweetener/basic_options.py b/sugar/sweetener/basic_options.py
new file mode 100644
index 0000000..52f4ebd
--- /dev/null
+++ b/sugar/sweetener/basic_options.py
@@ -0,0 +1,45 @@
+# -*- 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.
+
+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/sugar/sweetener/item.py b/sugar/sweetener/item.py
new file mode 100644
index 0000000..291204a
--- /dev/null
+++ b/sugar/sweetener/item.py
@@ -0,0 +1,87 @@
+#!/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.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/sugar/sweetener/itembox.py b/sugar/sweetener/itembox.py
new file mode 100644
index 0000000..d861c52
--- /dev/null
+++ b/sugar/sweetener/itembox.py
@@ -0,0 +1,36 @@
+# -*- 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.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/sugar/sweetener/stock.py b/sugar/sweetener/stock.py
new file mode 100644
index 0000000..a6451a7
--- /dev/null
+++ b/sugar/sweetener/stock.py
@@ -0,0 +1,77 @@
+# -*- 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('stock')
+import gtk
+
+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
+ 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, '<Ctrl>plus')
+overwrite_stock(gtk.STOCK_ZOOM_OUT, '<Ctrl>minus')
+overwrite_stock(gtk.STOCK_ZOOM_100, '<Ctrl>0')
+# Key accelerator will be F11 on desktops and <Alt>return on Sugar.
+overwrite_stock(gtk.STOCK_FULLSCREEN, '<Alt>Return')
+overwrite_stock(gtk.STOCK_ADD, '<Ctrl>A')
+overwrite_stock(gtk.STOCK_REMOVE, '<Ctrl>R')
+overwrite_stock(gtk.STOCK_SELECT_COLOR, '<Ctrl>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]