From e1a599bb8508e1a0607e052a2f086289844dee60 Mon Sep 17 00:00:00 2001 From: Daniel Francis Date: Tue, 02 Oct 2012 01:20:34 +0000 Subject: Initial commit --- (limited to 'desktop/sweetener/basic_options.py') diff --git a/desktop/sweetener/basic_options.py b/desktop/sweetener/basic_options.py new file mode 100644 index 0000000..83636e1 --- /dev/null +++ b/desktop/sweetener/basic_options.py @@ -0,0 +1,71 @@ +""" +This module provides a "File" menu at desktops and an ActivityToolbar at Sugar. +See class BasicOptions. +""" +# 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 + +import stock +from item import Item +from itemgroup import ItemGroup + +DOCUMENT = 0 +CONFIG = 1 + + +class BasicOptions(ItemGroup): + """This class has the basic options for your program.""" + def __init__(self, activity, box, export_formats=None): + """Create and append the basic items to a ItemBox. + activity -- The activity used as argument at Canvas and Options. + box -- sweetener.itembox.ItemBox of the activity. + export_formats -- list of tuples or none. Each tuple should have: + ['generic_type', 'mime_type', 'mime_filter', 'filter_name'] + """ + ItemGroup.__init__(self, box, _('_File'), None) + + if activity.save_type != CONFIG: + new = Item(gtk.STOCK_NEW, True) + new.connect('activate', lambda w: activity.new()) + self.append_item(new) + _open = Item(gtk.STOCK_OPEN, True) + _open.connect('activate', lambda w: activity.open()) + self.append_item(_open) + self.append_separator() + save_option = Item(gtk.STOCK_SAVE, True) + save_option.connect('activate', lambda w: activity.save()) + self.append_item(save_option) + save_as_option = Item(gtk.STOCK_SAVE_AS) + save_as_option.connect('activate', lambda w: activity.save_as()) + self.append_item(save_as_option) + 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.append_item(export) + self.append_separator() + _quit = Item(gtk.STOCK_QUIT) + _quit.connect('activate', lambda w: activity.stop()) + self.append_item(_quit) -- cgit v0.9.1