Make ClipboardIcon use the new Menu.

This commit is contained in:
Tomeu Vizoso 2007-02-21 21:12:27 +01:00
parent 9ba487fa1f
commit b452b7d718
10 changed files with 121 additions and 94 deletions

View File

@ -1,16 +1,17 @@
import logging
from sugar.graphics.menuicon import MenuIcon
from sugar.graphics.canvasicon import CanvasIcon
from view.clipboardmenu import ClipboardMenu
from sugar.graphics.iconcolor import IconColor
from sugar.activity import activityfactory
from sugar.clipboard import clipboardservice
from sugar import util
class ClipboardIcon(MenuIcon):
class ClipboardIcon(CanvasIcon):
def __init__(self, menu_shell, object_id, name):
MenuIcon.__init__(self, menu_shell)
def __init__(self, popup_context, object_id, name):
CanvasIcon.__init__(self)
self._popup_context = popup_context
self._object_id = object_id
self._name = name
self._percent = 0
@ -19,12 +20,15 @@ class ClipboardIcon(MenuIcon):
self.connect('activated', self._icon_activated_cb)
self._menu = None
def create_menu(self):
def get_popup(self):
self._menu = ClipboardMenu(self._name, self._percent, self._preview,
self._activity)
self._menu.connect('action', self._popup_action_cb)
return self._menu
def get_popup_context(self):
return self._popup_context
def set_state(self, name, percent, icon_name, preview, activity):
self._name = name
self._percent = percent
@ -60,8 +64,8 @@ class ClipboardIcon(MenuIcon):
def _icon_activated_cb(self, icon):
self._open_file()
def _popup_action_cb(self, popup, action):
self.popdown()
def _popup_action_cb(self, popup, menu_item):
action = menu_item.props.action_id
if action == ClipboardMenu.ACTION_STOP_DOWNLOAD:
raise "Stopping downloads still not implemented."

View File

@ -1,16 +1,23 @@
from gettext import gettext as _
import hippo
from sugar.graphics.menu import Menu
from sugar.graphics.menu import Menu, MenuItem
from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics.ClipboardBubble import ClipboardBubble
from sugar.graphics import color
from sugar.graphics import font
class ClipboardMenuItem(ClipboardBubble):
class ClipboardProgressBar(ClipboardBubble):
def __init__(self, percent = 0):
self._text_item = None
ClipboardBubble.__init__(self, percent=percent)
self._text_item = hippo.CanvasText(text=str(percent) + ' %')
self._text_item.props.color = color.LABEL_TEXT.get_int()
self._text_item.props.font_desc = font.DEFAULT.get_pango_desc()
self.append(self._text_item)
def do_set_property(self, pspec, value):
@ -30,57 +37,69 @@ class ClipboardMenu(Menu):
Menu.__init__(self, name)
if percent < 100:
self._progress_bar = ClipboardMenuItem(percent)
self._root.append(self._progress_bar)
self._progress_bar = ClipboardProgressBar(percent)
self.append(self._progress_bar)
else:
self._progress_bar = None
self._remove_icon = None
self._open_icon = None
self._stop_icon = None
self._remove_item = None
self._open_item = None
self._stop_item = None
self.add_item(preview, wrap=True)
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)
self._update_icons(percent, activity)
def _update_icons(self, percent, activity):
if percent == 100 and activity:
if not self._remove_icon:
self._remove_icon = CanvasIcon(icon_name='theme:stock-remove')
self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE)
if not self._remove_item:
self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE,
_('Remove'),
'theme:stock-remove')
self.add_item(self._remove_item)
if not self._open_icon:
self._open_icon = CanvasIcon(icon_name='theme:stock-keep')
self.add_action(self._open_icon, ClipboardMenu.ACTION_OPEN)
if not self._open_item:
self._open_item = MenuItem(ClipboardMenu.ACTION_OPEN,
_('Open'),
'theme:stock-keep')
self.add_item(self._open_item)
if self._stop_icon:
self.remove_action(self._stop_icon)
self._stop_icon = None
if self._stop_item:
self.remove_item(self._stop_item)
self._stop_item = None
elif percent == 100 and not activity:
if not self._remove_icon:
self._remove_icon = CanvasIcon(icon_name='theme:stock-remove')
self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE)
if not self._remove_item:
self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE,
_('Remove'),
'theme:stock-remove')
self.add_item(self._remove_item)
if self._open_icon:
self.remove_action(self._open_icon)
self._open_icon = None
if self._open_item:
self.remove_item(self._open_item)
self._open_item = None
if self._stop_icon:
self.remove_action(self._stop_icon)
self._stop_icon = None
if self._stop_item:
self.remove_item(self._stop_item)
self._stop_item = None
else:
if not self._stop_icon:
self._stop_icon = CanvasIcon(icon_name='theme:stock-close')
self.add_action(self._stop_icon, ClipboardMenu.ACTION_STOP_DOWNLOAD)
if not self._stop_item:
self._stop_item = MenuItem(ClipboardMenu.ACTION_STOP_DOWNLOAD,
_('Stop download'),
'theme:stock-close')
self.add_item(self._stop_item)
if self._remove_icon:
self.remove_action(self._remove_icon)
self._remove_icon = None
if self._remove_item:
self.remove_item(self._remove_item)
self._remove_item = None
if self._open_icon:
self.remove_action(self._open_icon)
self._open_icon = None
if self._open_item:
self.remove_item(self._open_item)
self._open_item = None
def set_state(self, name, percent, preview, activity):
self.set_title(name)

View File

@ -10,4 +10,5 @@ sugar_PYTHON = \
ZoomBox.py \
notificationtray.py \
overlaybox.py \
PanelWindow.py
PanelWindow.py \
framepopupcontext.py

View File

@ -17,7 +17,6 @@
import gtk
import hippo
from sugar.graphics.menushell import MenuShell
from sugar.graphics import units
class PanelWindow(gtk.Window):
@ -51,13 +50,8 @@ class PanelWindow(gtk.Window):
self.add(self._canvas)
self._canvas.show()
self._menu_shell = MenuShell(self._canvas)
self.resize(width, height)
def get_menu_shell(self):
return self._menu_shell
def get_root(self):
return self._bg

View File

@ -42,9 +42,10 @@ class ActivityMenu(Menu):
'theme:stock-close'))
class ActivityButton(IconButton):
def __init__(self, shell, activity_model):
def __init__(self, shell, activity_model, popup_context):
self._shell = shell
self._activity_model = activity_model
self._popup_context = popup_context
icon_name = self._activity_model.get_icon_name()
icon_color = self._activity_model.get_icon_color()
@ -57,7 +58,7 @@ class ActivityButton(IconButton):
return menu
def get_popup_context(self):
return self._shell.get_popup_context()
return self._popup_context
def _action_cb(self, menu, menu_item):
# TODO: Wouldn't be better to share/close the activity associated with
@ -73,11 +74,11 @@ class ActivityButton(IconButton):
activity.close()
class ZoomBox(hippo.CanvasBox):
def __init__(self, shell, menu_shell):
def __init__(self, shell, popup_context):
hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_HORIZONTAL)
self._shell = shell
self._menu_shell = menu_shell
self._popup_context = popup_context
self._activity_icon = None
icon = IconButton(icon_name='theme:stock-zoom-mesh')
@ -106,7 +107,7 @@ class ZoomBox(hippo.CanvasBox):
self.remove(self._activity_icon)
if home_activity:
icon = ActivityButton(self._shell, home_activity)
icon = ActivityButton(self._shell, home_activity, self._popup_context)
self.append(icon)
self._activity_icon = icon
else:

View File

@ -37,9 +37,9 @@ class _ContextMap:
class ClipboardBox(hippo.CanvasBox):
def __init__(self, menu_shell):
def __init__(self, popup_context):
hippo.CanvasBox.__init__(self)
self._menu_shell = menu_shell
self._popup_context = popup_context
self._icons = {}
self._context_map = _ContextMap()
@ -74,7 +74,7 @@ class ClipboardBox(hippo.CanvasBox):
on_disk = False)
def _object_added_cb(self, cb_service, object_id, name):
icon = ClipboardIcon(self._menu_shell, object_id, name)
icon = ClipboardIcon(self._popup_context, object_id, name)
self.append(icon)
self._icons[object_id] = icon

View File

@ -17,10 +17,9 @@ class ClipboardPanelWindow(PanelWindow):
clipboard = gtk.Clipboard()
clipboard.connect("owner-change", self._owner_change_cb)
menu_shell = self.get_menu_shell()
root = self.get_root()
box = ClipboardBox(menu_shell)
box = ClipboardBox(frame.get_popup_context())
root.append(box)
# Receiving dnd drops

View File

@ -27,9 +27,9 @@ from view.frame.FriendsBox import FriendsBox
from view.frame.PanelWindow import PanelWindow
from view.frame.clipboardpanelwindow import ClipboardPanelWindow
from view.frame.notificationtray import NotificationTray
from view.frame.framepopupcontext import FramePopupContext
from model.ShellModel import ShellModel
from sugar.graphics.timeline import Timeline
from sugar.graphics.menushell import MenuShell
from sugar.graphics import units
_ANIMATION = False
@ -62,6 +62,12 @@ class Frame:
self._event_frame.connect('leave', self._event_frame_leave_cb)
self._event_frame.show()
self._popup_context = FramePopupContext()
self._popup_context.connect('activated',
self._popup_context_activated_cb)
self._popup_context.connect('deactivated',
self._popup_context_deactivated_cb)
self._top_panel = self._create_top_panel()
self._bottom_panel = self._create_bottom_panel()
self._left_panel = self._create_left_panel()
@ -70,20 +76,11 @@ class Frame:
shell.get_model().connect('notify::state',
self._shell_state_changed_cb)
popup_context = shell.get_popup_context()
popup_context.connect('activated',
self._popup_context_activated_cb)
popup_context.connect('deactivated',
self._popup_context_deactivated_cb)
def _create_top_panel(self):
panel = self._create_panel(hippo.ORIENTATION_HORIZONTAL)
menu_shell = panel.get_menu_shell()
root = panel.get_root()
menu_shell.set_position(MenuShell.BOTTOM)
box = ZoomBox(self._shell, menu_shell)
box = ZoomBox(self._shell, self._popup_context)
root.append(box)
tray = NotificationTray()
@ -103,11 +100,8 @@ class Frame:
def _create_bottom_panel(self):
panel = self._create_panel(hippo.ORIENTATION_HORIZONTAL)
menu_shell = panel.get_menu_shell()
root = panel.get_root()
menu_shell.set_position(MenuShell.TOP)
box = ActivitiesBox(self._shell)
root.append(box)
@ -115,12 +109,9 @@ class Frame:
def _create_right_panel(self):
panel = self._create_panel(hippo.ORIENTATION_VERTICAL)
menu_shell = panel.get_menu_shell()
root = panel.get_root()
menu_shell.set_position(MenuShell.LEFT)
box = FriendsBox(self._shell, menu_shell)
box = FriendsBox(self._shell, self._popup_context)
root.append(box)
return panel
@ -158,19 +149,6 @@ class Frame:
panel.connect('enter-notify-event', self._enter_notify_cb)
panel.connect('leave-notify-event', self._leave_notify_cb)
menu_shell = panel.get_menu_shell()
menu_shell.connect('activated',
self._menu_shell_activated_cb)
menu_shell.connect('deactivated',
self._menu_shell_deactivated_cb)
def _menu_shell_activated_cb(self, menu_shell):
self._timeline.goto('slide_in', True)
def _menu_shell_deactivated_cb(self, menu_shell):
if self._mode != Frame.STICKY and not self._hover_frame:
self._timeline.play('before_slide_out', 'slide_out')
def _popup_context_activated_cb(self, popup_context):
self._timeline.goto('slide_in', True)
@ -205,8 +183,7 @@ class Frame:
def _leave_notify(self, panel):
self._hover_frame = False
if not panel.get_menu_shell().is_active() and \
not self._shell.get_popup_context().is_active() and \
if not self._popup_context.is_active() and \
(self._mode == Frame.HIDE_ON_LEAVE or \
self._mode == Frame.AUTOMATIC):
self._timeline.play('before_slide_out', 'slide_out')
@ -281,3 +258,6 @@ class Frame:
def is_visible(self):
return self._top_panel.props.visible
def get_popup_context(self):
return self._popup_context

View File

@ -0,0 +1,26 @@
# Copyright (C) 2007, One Laptop Per Child
#
# 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.
import gobject
import hippo
from sugar.graphics.popupcontext import PopupContext
class FramePopupContext(PopupContext):
__gtype_name__ = 'SugarFramePopupContext'
def __init__(self):
PopupContext.__init__(self)

View File

@ -98,6 +98,9 @@ class Menu(Popup):
item.connect('button-press-event', self._item_button_press_event_cb)
self.append(item)
def remove_item(self, item):
self.remove(item)
def add_separator(self):
box = hippo.CanvasBox()
box.props.background_color = color.MENU_SEPARATOR.get_int()