2007-06-17 20:55:16 +02:00
|
|
|
# Copyright (C) 2007, One Laptop Per Child
|
|
|
|
#
|
|
|
|
# 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
|
2007-02-21 21:12:27 +01:00
|
|
|
from gettext import gettext as _
|
|
|
|
|
2006-11-15 13:56:19 +01:00
|
|
|
import hippo
|
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
from sugar.graphics.menu import Menu, MenuItem
|
2006-11-15 13:56:19 +01:00
|
|
|
from sugar.graphics.canvasicon import CanvasIcon
|
2007-02-21 21:12:27 +01:00
|
|
|
from sugar.graphics import color
|
|
|
|
from sugar.graphics import font
|
2006-11-15 13:56:19 +01:00
|
|
|
|
2007-04-27 11:43:40 +02:00
|
|
|
from view.ClipboardBubble import ClipboardBubble
|
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
class ClipboardProgressBar(ClipboardBubble):
|
2006-11-15 13:56:19 +01:00
|
|
|
|
2007-02-20 14:57:50 +01:00
|
|
|
def __init__(self, percent = 0):
|
2007-01-11 23:57:06 +01:00
|
|
|
self._text_item = None
|
|
|
|
ClipboardBubble.__init__(self, percent=percent)
|
2007-02-24 14:35:31 +01:00
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
self._text_item = hippo.CanvasText(text=str(percent) + ' %')
|
2007-02-21 21:12:27 +01:00
|
|
|
self._text_item.props.color = color.LABEL_TEXT.get_int()
|
|
|
|
self._text_item.props.font_desc = font.DEFAULT.get_pango_desc()
|
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
self.append(self._text_item)
|
|
|
|
|
|
|
|
def do_set_property(self, pspec, value):
|
|
|
|
if pspec.name == 'percent':
|
|
|
|
if self._text_item:
|
|
|
|
self._text_item.set_property('text', str(value) + ' %')
|
2006-11-15 13:56:19 +01:00
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
ClipboardBubble.do_set_property(self, pspec, value)
|
|
|
|
|
2006-11-15 13:56:19 +01:00
|
|
|
class ClipboardMenu(Menu):
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
ACTION_DELETE = 0
|
2007-01-11 23:57:06 +01:00
|
|
|
ACTION_OPEN = 1
|
2006-12-04 20:12:24 +01:00
|
|
|
ACTION_STOP_DOWNLOAD = 2
|
2007-06-17 20:55:16 +02:00
|
|
|
ACTION_SAVE_TO_JOURNAL = 3
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-04-20 20:12:49 +02:00
|
|
|
def __init__(self, name, percent, preview, activity, installable):
|
2006-12-04 20:12:24 +01:00
|
|
|
Menu.__init__(self, name)
|
2007-02-24 14:35:31 +01:00
|
|
|
self.props.border = 0
|
2006-12-14 13:50:42 +01:00
|
|
|
|
|
|
|
if percent < 100:
|
2007-02-21 21:12:27 +01:00
|
|
|
self._progress_bar = ClipboardProgressBar(percent)
|
|
|
|
self.append(self._progress_bar)
|
2006-12-14 13:50:42 +01:00
|
|
|
else:
|
|
|
|
self._progress_bar = None
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
self._remove_item = None
|
|
|
|
self._open_item = None
|
|
|
|
self._stop_item = None
|
2007-06-17 20:55:16 +02:00
|
|
|
self._journal_item = None
|
2007-02-21 21:12:27 +01:00
|
|
|
|
|
|
|
if preview:
|
|
|
|
self._preview_text = hippo.CanvasText(text=preview,
|
|
|
|
size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
|
|
|
|
self._preview_text.props.color = color.LABEL_TEXT.get_int()
|
|
|
|
self._preview_text.props.font_desc = font.DEFAULT.get_pango_desc()
|
|
|
|
self.append(self._preview_text)
|
2007-06-17 20:55:16 +02:00
|
|
|
|
2007-04-20 20:12:49 +02:00
|
|
|
self._update_icons(percent, activity, installable)
|
2007-06-17 20:55:16 +02:00
|
|
|
|
2007-04-20 20:12:49 +02:00
|
|
|
def _update_icons(self, percent, activity, installable):
|
|
|
|
if percent == 100 and (activity or installable):
|
2007-06-17 20:55:16 +02:00
|
|
|
self._add_remove_item()
|
|
|
|
self._add_open_item()
|
|
|
|
self._remove_stop_item()
|
|
|
|
self._add_journal_item()
|
2007-04-20 20:12:49 +02:00
|
|
|
elif percent == 100 and (not activity and not installable):
|
2007-06-17 20:55:16 +02:00
|
|
|
self._add_remove_item()
|
|
|
|
self._remove_open_item()
|
|
|
|
self._remove_stop_item()
|
|
|
|
self._add_journal_item()
|
2006-12-04 20:12:24 +01:00
|
|
|
else:
|
2007-06-17 20:55:16 +02:00
|
|
|
self._remove_remove_item()
|
|
|
|
self._remove_open_item()
|
|
|
|
self._add_stop_item()
|
|
|
|
self._remove_journal_item()
|
2007-01-11 23:57:06 +01:00
|
|
|
|
2007-04-20 20:12:49 +02:00
|
|
|
def set_state(self, name, percent, preview, activity, installable):
|
2007-04-11 18:22:52 +02:00
|
|
|
self.set_title(name)
|
2006-12-14 13:50:42 +01:00
|
|
|
if self._progress_bar:
|
2007-04-11 18:22:52 +02:00
|
|
|
self._progress_bar.set_property('percent', percent)
|
2007-04-20 20:12:49 +02:00
|
|
|
self._update_icons(percent, activity, installable)
|
2007-06-17 20:55:16 +02:00
|
|
|
|
|
|
|
def _add_remove_item(self):
|
|
|
|
if not self._remove_item:
|
|
|
|
self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE,
|
|
|
|
_('Remove'),
|
|
|
|
'theme:stock-remove')
|
|
|
|
self.add_item(self._remove_item)
|
|
|
|
|
|
|
|
def _add_open_item(self):
|
|
|
|
if not self._open_item:
|
|
|
|
self._open_item = MenuItem(ClipboardMenu.ACTION_OPEN,
|
|
|
|
_('Open'),
|
|
|
|
'theme:stock-keep')
|
|
|
|
self.add_item(self._open_item)
|
|
|
|
|
|
|
|
def _add_stop_item(self):
|
|
|
|
if not self._stop_item:
|
|
|
|
self._stop_item = MenuItem(ClipboardMenu.ACTION_STOP_DOWNLOAD,
|
|
|
|
_('Stop download'),
|
|
|
|
'theme:stock-close')
|
|
|
|
self.add_item(self._stop_item)
|
|
|
|
|
|
|
|
def _add_journal_item(self):
|
|
|
|
if not self._journal_item:
|
|
|
|
self._journal_item = MenuItem(ClipboardMenu.ACTION_SAVE_TO_JOURNAL,
|
|
|
|
_('Add to journal'),
|
|
|
|
'theme:stock-save')
|
|
|
|
self.add_item(self._journal_item)
|
|
|
|
|
|
|
|
def _remove_open_item(self):
|
|
|
|
if self._open_item:
|
|
|
|
self.remove_item(self._open_item)
|
|
|
|
self._open_item = None
|
|
|
|
|
|
|
|
def _remove_stop_item(self):
|
|
|
|
if self._stop_item:
|
|
|
|
self.remove_item(self._stop_item)
|
|
|
|
self._stop_item = None
|
|
|
|
|
|
|
|
def _remove_remove_item(self):
|
|
|
|
if self._remove_item:
|
|
|
|
self.remove_item(self._remove_item)
|
|
|
|
self._remove_item = None
|
|
|
|
|
|
|
|
def _remove_journal_item(self):
|
|
|
|
if self._journal_item:
|
|
|
|
self.remove_item(self._journal_item)
|
|
|
|
self._journal_item = None
|
|
|
|
|