Use Tray also for the frame friends view.

Drop the deprecated IconButton.
This commit is contained in:
Marco Pesenti Gritti 2007-09-03 01:48:03 +02:00
parent 8a2cb49ffb
commit a09a786ff7
9 changed files with 56 additions and 88 deletions

View File

@ -24,7 +24,6 @@ from sugar.graphics import style
from sugar import profile from sugar import profile
from sugar import activity from sugar import activity
from frameinvoker import FrameCanvasInvoker
from activitybutton import ActivityButton from activitybutton import ActivityButton
class InviteButton(TrayButton): class InviteButton(TrayButton):

View File

@ -6,9 +6,9 @@ sugar_PYTHON = \
clipboardbox.py \ clipboardbox.py \
clipboardpanelwindow.py \ clipboardpanelwindow.py \
frameinvoker.py \ frameinvoker.py \
FriendsBox.py \ friendstray.py \
eventarea.py \ eventarea.py \
frame.py \ frame.py \
overlaybox.py \ overlaybox.py \
framewindow.py \ framewindow.py \
zoombox.py zoomtoolbar.py

View File

@ -29,7 +29,7 @@ from view.frame.eventarea import EventArea
from view.frame.ActivitiesBox import ActivitiesBox from view.frame.ActivitiesBox import ActivitiesBox
from view.frame.zoomtoolbar import ZoomToolbar from view.frame.zoomtoolbar import ZoomToolbar
from view.frame.overlaybox import OverlayBox from view.frame.overlaybox import OverlayBox
from view.frame.FriendsBox import FriendsBox from view.frame.friendstray import FriendsTray
from view.frame.framewindow import FrameWindow from view.frame.framewindow import FrameWindow
from view.frame.clipboardpanelwindow import ClipboardPanelWindow from view.frame.clipboardpanelwindow import ClipboardPanelWindow
from model.shellmodel import ShellModel from model.shellmodel import ShellModel
@ -227,8 +227,9 @@ class Frame(object):
def _create_right_panel(self): def _create_right_panel(self):
panel = self._create_panel(gtk.POS_RIGHT) panel = self._create_panel(gtk.POS_RIGHT)
box = FriendsBox(self._shell) tray = FriendsTray(self._shell)
panel.append(box) panel.append(hippo.CanvasWidget(widget=tray), hippo.PACK_EXPAND)
tray.show()
return panel return panel

View File

@ -37,10 +37,3 @@ class FrameWidgetInvoker(WidgetInvoker):
self._position_hint = self.ANCHORED self._position_hint = self.ANCHORED
self._screen_area = _get_screen_area() self._screen_area = _get_screen_area()
class FrameCanvasInvoker(CanvasInvoker):
def __init__(self, item):
CanvasInvoker.__init__(self, item)
self._position_hint = self.ANCHORED
self._screen_area = _get_screen_area()

View File

@ -16,32 +16,27 @@
import hippo import hippo
from sugar.graphics.palette import Palette
from sugar.graphics.icon import CanvasIcon
from sugar.graphics import style
from sugar.presence import presenceservice from sugar.presence import presenceservice
from sugar.graphics.tray import VTray, TrayIcon
from view.BuddyIcon import BuddyIcon from view.BuddyMenu import BuddyMenu
from view.frame.frameinvoker import FrameWidgetInvoker
from model.BuddyModel import BuddyModel from model.BuddyModel import BuddyModel
from view.frame.frameinvoker import FrameCanvasInvoker
class FriendIcon(BuddyIcon): class FriendIcon(TrayIcon):
def __init__(self, shell, buddy): def __init__(self, shell, buddy):
BuddyIcon.__init__(self, shell, buddy) TrayIcon.__init__(self, icon_name='computer-xo',
xo_color=buddy.get_color())
palette = self.get_palette() palette = BuddyMenu(shell, buddy)
self.set_palette(palette)
palette.set_group_id('frame') palette.set_group_id('frame')
palette.props.invoker = FrameCanvasInvoker(self) palette.props.invoker = FrameWidgetInvoker(self)
def prelight(self, enter): class FriendsTray(VTray):
if enter:
self.props.background_color = style.COLOR_BLACK.get_int()
else:
self.props.background_color = style.COLOR_TOOLBAR_GREY.get_int()
class FriendsBox(hippo.CanvasBox):
def __init__(self, shell): def __init__(self, shell):
hippo.CanvasBox.__init__(self) VTray.__init__(self)
self._shell = shell self._shell = shell
self._activity_ps = None self._activity_ps = None
self._joined_hid = -1 self._joined_hid = -1
@ -68,8 +63,10 @@ class FriendsBox(hippo.CanvasBox):
return return
model = BuddyModel(buddy=buddy) model = BuddyModel(buddy=buddy)
icon = FriendIcon(self._shell, model) icon = FriendIcon(self._shell, model)
self.append(icon) self.add_item(icon)
icon.show()
self._buddies[buddy.props.key] = icon self._buddies[buddy.props.key] = icon
@ -77,11 +74,11 @@ class FriendsBox(hippo.CanvasBox):
if not self._buddies.has_key(buddy.props.key): if not self._buddies.has_key(buddy.props.key):
return return
self.remove(self._buddies[buddy.props.key]) self.remove_item(self._buddies[buddy.props.key])
def clear(self): def clear(self):
for item in self.get_children(): for item in self.get_children():
self.remove(item) self.remove_item(item)
self._buddies = {} self._buddies = {}
def __activity_appeared_cb(self, pservice, activity_ps): def __activity_appeared_cb(self, pservice, activity_ps):

View File

@ -6,7 +6,6 @@ sugar_PYTHON = \
combobox.py \ combobox.py \
entry.py \ entry.py \
icon.py \ icon.py \
iconbutton.py \
iconentry.py \ iconentry.py \
menuitem.py \ menuitem.py \
notebook.py \ notebook.py \

View File

@ -1,48 +0,0 @@
# 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.
#
# DEPRECATED. Do not use in new code. We will reimplement it in gtk
#
import sys
import gobject
import hippo
from sugar.graphics.icon import CanvasIcon
from sugar.graphics import style
class IconButton(CanvasIcon, hippo.CanvasItem):
__gtype_name__ = 'SugarIconButton'
def __init__(self, **kwargs):
CanvasIcon.__init__(self, **kwargs)
if not self.props.fill_color and not self.props.stroke_color:
self.props.fill_color = style.Color("#404040").get_svg()
self.props.stroke_color = style.Color("#FFFFFF").get_svg()
self.connect('activated', self._icon_clicked_cb)
self.props.box_width = style.GRID_CELL_SIZE
self.props.box_height = style.GRID_CELL_SIZE
self.props.size = style.STANDARD_ICON_SIZE
def _icon_clicked_cb(self, button):
if self._palette:
self._palette.popdown(True)

View File

@ -19,6 +19,7 @@ import gobject
import gtk import gtk
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics.palette import Palette, ToolInvoker
from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.icon import Icon from sugar.graphics.icon import Icon
@ -145,6 +146,9 @@ class HTray(gtk.HBox):
scroll_left.viewport = self._viewport scroll_left.viewport = self._viewport
scroll_right.viewport = self._viewport scroll_right.viewport = self._viewport
def get_children(self):
return self._viewport.traybar.get_children()
def add_item(self, item, index=-1): def add_item(self, item, index=-1):
self._viewport.traybar.insert(item, index) self._viewport.traybar.insert(item, index)
@ -173,6 +177,9 @@ class VTray(gtk.VBox):
scroll_left.viewport = self._viewport scroll_left.viewport = self._viewport
scroll_right.viewport = self._viewport scroll_right.viewport = self._viewport
def get_children(self):
return self._viewport.traybar.get_children()
def add_item(self, item, index=-1): def add_item(self, item, index=-1):
self._viewport.traybar.insert(item, index) self._viewport.traybar.insert(item, index)
@ -185,3 +192,24 @@ class VTray(gtk.VBox):
class TrayButton(ToolButton): class TrayButton(ToolButton):
def __init__(self, **kwargs): def __init__(self, **kwargs):
ToolButton.__init__(self, **kwargs) ToolButton.__init__(self, **kwargs)
class TrayIcon(gtk.ToolItem):
def __init__(self, icon_name=None, xo_color=None):
gtk.ToolItem.__init__(self)
event_box = gtk.EventBox()
icon = Icon(icon_name=icon_name, xo_color=xo_color,
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
event_box.add(icon)
icon.show()
self.add(event_box)
event_box.show()
def set_palette(self, palette):
self._palette = palette
self._palette.props.invoker = ToolInvoker(self.child)
def set_tooltip(self, text):
self.set_palette(Palette(text))

View File

@ -21,9 +21,8 @@ Test the sugar.graphics.icon.Icon widget.
import gtk import gtk
from sugar.graphics.tray import HTray from sugar.graphics.tray import HTray, VTray
from sugar.graphics.tray import VTray from sugar.graphics.tray import TrayButton, TrayIcon
from sugar.graphics.tray import TrayButton
import common import common
@ -47,9 +46,9 @@ vbox.pack_start(tray, False)
tray.show() tray.show()
for i in range(0, 10): for i in range(0, 10):
button = TrayButton(icon_name=theme_icons[i]) icon = TrayIcon(icon_name=theme_icons[i])
tray.add_item(button) tray.add_item(icon)
button.show() icon.show()
hbox = gtk.HBox() hbox = gtk.HBox()