Remove hippo from naming alert

Reimplement the favorite icon as a ToggleButton, and use standard
boxes, entrys and textviews for the other aspects.
This commit is contained in:
Daniel Drake 2011-09-17 18:29:46 +01:00
parent d39a813969
commit 720b33ab30

View File

@ -21,17 +21,13 @@ import os
import gio import gio
import gtk import gtk
import gobject import gobject
import hippo
import gconf import gconf
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics.icon import Icon from sugar.graphics.icon import Icon
from sugar.graphics.xocolor import XoColor from sugar.graphics.xocolor import XoColor
from sugar.graphics.icon import CanvasIcon
from sugar.graphics.icon import get_icon_file_name from sugar.graphics.icon import get_icon_file_name
from sugar.graphics.entry import CanvasEntry
from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.canvastextview import CanvasTextView
from sugar.bundle.activitybundle import ActivityBundle from sugar.bundle.activitybundle import ActivityBundle
@ -114,45 +110,37 @@ class NamingToolbar(gtk.Toolbar):
self.emit('keep-clicked') self.emit('keep-clicked')
class FavoriteIcon(CanvasIcon): class FavoriteIcon(gtk.ToggleButton):
def __init__(self, favorite): def __init__(self):
CanvasIcon.__init__(self, icon_name='emblem-favorite', gtk.ToggleButton.__init__(self)
box_width=style.GRID_CELL_SIZE * 3 / 5, self.set_relief(gtk.RELIEF_NONE)
size=style.SMALL_ICON_SIZE) self.set_focus_on_click(False)
self._favorite = None
self.set_favorite(favorite)
self.connect('button-release-event', self.__release_event_cb)
self.connect('motion-notify-event', self.__motion_notify_event_cb)
def set_favorite(self, favorite): self._icon = Icon(icon_name='emblem-favorite',
if favorite == self._favorite: pixel_size=style.SMALL_ICON_SIZE)
return self.set_image(self._icon)
self._favorite = favorite self.connect('toggled', self.__toggled_cb)
if favorite: self.connect('leave-notify-event', self.__leave_notify_event_cb)
self.connect('enter-notify-event', self.__enter_notify_event_cb)
def __toggled_cb(self, widget):
if self.get_active():
client = gconf.client_get_default() client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color')) color = XoColor(client.get_string('/desktop/sugar/user/color'))
self.props.xo_color = color self._icon.props.xo_color = color
else: else:
self.props.stroke_color = style.COLOR_BUTTON_GREY.get_svg() self._icon.props.stroke_color = style.COLOR_BUTTON_GREY.get_svg()
self.props.fill_color = style.COLOR_WHITE.get_svg() self._icon.props.fill_color = style.COLOR_WHITE.get_svg()
def get_favorite(self): def __enter_notify_event_cb(self, icon, event):
return self._favorite if not self.get_active():
self._icon.props.fill_color = style.COLOR_BUTTON_GREY.get_svg()
favorite = gobject.property( def __leave_notify_event_cb(self, icon, event):
type=bool, default=False, getter=get_favorite, setter=set_favorite) if not self.get_active():
self._icon.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
def __release_event_cb(self, icon, event):
self.props.favorite = not self.props.favorite
def __motion_notify_event_cb(self, icon, event):
if not self._favorite:
if event.detail == hippo.MOTION_DETAIL_ENTER:
icon.props.fill_color = style.COLOR_BUTTON_GREY.get_svg()
elif event.detail == hippo.MOTION_DETAIL_LEAVE:
icon.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
class NamingAlert(gtk.Window): class NamingAlert(gtk.Window):
@ -194,71 +182,66 @@ class NamingAlert(gtk.Window):
vbox.pack_start(toolbar, False) vbox.pack_start(toolbar, False)
toolbar.show() toolbar.show()
canvas = hippo.Canvas()
self._root = hippo.CanvasBox()
self._root.props.background_color = style.COLOR_WHITE.get_int()
canvas.set_root(self._root)
vbox.pack_start(canvas)
canvas.show()
body = self._create_body() body = self._create_body()
self._root.append(body, hippo.PACK_EXPAND) vbox.pack_start(body, expand=True, fill=True)
body.show()
widget = self._title.get_property('widget') self._title.grab_focus()
widget.grab_focus()
def _create_body(self): def _create_body(self):
body = hippo.CanvasBox() body = gtk.VBox(spacing=style.DEFAULT_SPACING)
body.props.orientation = hippo.ORIENTATION_VERTICAL body.set_border_width(style.DEFAULT_SPACING * 3)
body.props.background_color = style.COLOR_WHITE.get_int() header = self._create_header()
body.props.padding_top = style.DEFAULT_SPACING * 3 body.pack_start(header, expand=False, padding=style.DEFAULT_PADDING)
header = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, body.pack_start(self._create_separator(style.DEFAULT_SPACING),
padding=style.DEFAULT_PADDING, expand=False)
padding_right=style.GRID_CELL_SIZE,
spacing=style.DEFAULT_SPACING)
body.append(header)
descriptions = hippo.CanvasBox( body.pack_start(self._create_label(_('Description:')), expand=False)
orientation=hippo.ORIENTATION_HORIZONTAL,
spacing=style.DEFAULT_SPACING * 3,
padding_left=style.GRID_CELL_SIZE,
padding_right=style.GRID_CELL_SIZE,
padding_top=style.DEFAULT_SPACING * 3)
body.append(descriptions, hippo.PACK_EXPAND) description = self._activity.metadata.get('description', '')
description_box, self._description = self._create_text_view(description)
body.pack_start(description_box, expand=True, fill=True)
first_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, body.pack_start(self._create_separator(style.DEFAULT_PADDING),
spacing=style.DEFAULT_SPACING) expand=False)
descriptions.append(first_column)
second_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL,
spacing=style.DEFAULT_SPACING)
descriptions.append(second_column, hippo.PACK_EXPAND)
self._favorite_icon = self._create_favorite_icon() body.pack_start(self._create_label(_('Tags:')), expand=False)
header.append(self._favorite_icon)
entry_icon = self._create_entry_icon() tags = self._activity.metadata.get('tags', '')
header.append(entry_icon) tags_box, self._tags = self._create_text_view(tags)
body.pack_start(tags_box, expand=True, fill=True)
self._title = self._create_title()
header.append(self._title, hippo.PACK_EXPAND)
if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
header.reverse()
description_box, self._description = self._create_description()
second_column.append(description_box)
tags_box, self._tags = self._create_tags()
second_column.append(tags_box)
body.show_all()
return body return body
def _create_favorite_icon(self): def _create_label(self, text):
favorite_icon = FavoriteIcon(False) text = gtk.Label(text)
return favorite_icon text.set_alignment(0, 0.5)
text.modify_fg(gtk.STATE_NORMAL,
style.COLOR_BUTTON_GREY.get_gdk_color())
return text
def _create_separator(self, height):
separator = gtk.HSeparator()
separator.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color())
separator.set_size_request(-1, height)
return separator
def _create_header(self):
header = gtk.HBox(spacing=style.DEFAULT_SPACING)
self._favorite_icon = FavoriteIcon()
header.pack_start(self._favorite_icon, expand=False)
entry_icon = self._create_entry_icon()
header.pack_start(entry_icon, expand=False)
self._title = self._create_title()
header.pack_start(self._title, expand=True)
return header
def _create_entry_icon(self): def _create_entry_icon(self):
bundle_id = self._activity.metadata.get('activity', '') bundle_id = self._activity.metadata.get('activity', '')
@ -270,83 +253,52 @@ class NamingAlert(gtk.Window):
else: else:
activity_bundle = ActivityBundle(self._bundle_path) activity_bundle = ActivityBundle(self._bundle_path)
file_name = activity_bundle.get_icon() file_name = activity_bundle.get_icon()
entry_icon = CanvasIcon(file_name=file_name) entry_icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
if self._activity.metadata.get('icon-color'): if self._activity.metadata.get('icon-color'):
entry_icon.props.xo_color = XoColor( \ entry_icon.props.xo_color = XoColor( \
self._activity.metadata['icon-color']) self._activity.metadata['icon-color'])
return entry_icon return entry_icon
def _create_title(self): def _create_title(self):
title = CanvasEntry() title = gtk.Entry()
title.set_background(style.COLOR_WHITE.get_html()) title.set_text(self._activity.metadata.get('title', _('Untitled')))
title.props.text = self._activity.metadata.get('title', _('Untitled'))
return title return title
def _create_description(self): def _create_text_view(self, text):
vbox = hippo.CanvasBox() scrolled_window = gtk.ScrolledWindow()
vbox.props.spacing = style.DEFAULT_SPACING scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
scrolled_window.set_border_width(style.LINE_WIDTH)
scrolled_window.set_shadow_type(gtk.SHADOW_IN)
text = hippo.CanvasText(text=_('Description:'), text_view = gtk.TextView()
font_desc=style.FONT_NORMAL.get_pango_desc()) text_view.set_left_margin(style.DEFAULT_PADDING)
text.props.color = style.COLOR_BUTTON_GREY.get_int() text_view.set_wrap_mode(gtk.WRAP_WORD_CHAR)
text_view.set_accepts_tab(False)
text_view.get_buffer().set_text(text)
scrolled_window.add(text_view)
if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: return scrolled_window, text_view
text.props.xalign = hippo.ALIGNMENT_END
else:
text.props.xalign = hippo.ALIGNMENT_START
vbox.append(text)
description = self._activity.metadata.get('description', '')
text_view = CanvasTextView(description,
box_height=style.GRID_CELL_SIZE * 2)
vbox.append(text_view, hippo.PACK_EXPAND)
text_view.text_view_widget.props.accepts_tab = False
return vbox, text_view
def _create_tags(self):
vbox = hippo.CanvasBox()
vbox.props.spacing = style.DEFAULT_SPACING
text = hippo.CanvasText(text=_('Tags:'),
font_desc=style.FONT_NORMAL.get_pango_desc())
text.props.color = style.COLOR_BUTTON_GREY.get_int()
if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
text.props.xalign = hippo.ALIGNMENT_END
else:
text.props.xalign = hippo.ALIGNMENT_START
vbox.append(text)
tags = self._activity.metadata.get('tags', '')
text_view = CanvasTextView(tags, box_height=style.GRID_CELL_SIZE * 2)
vbox.append(text_view, hippo.PACK_EXPAND)
text_view.text_view_widget.props.accepts_tab = False
return vbox, text_view
def __realize_cb(self, widget): def __realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self.window.set_accept_focus(True) self.window.set_accept_focus(True)
def __keep_cb(self, widget): def __keep_cb(self, widget):
is_favorite = self._favorite_icon.get_favorite() if self._favorite_icon.get_active():
if is_favorite:
self._activity.metadata['keep'] = 1 self._activity.metadata['keep'] = 1
else: else:
self._activity.metadata['keep'] = 0 self._activity.metadata['keep'] = 0
self._activity.metadata['title'] = self._title.props.text self._activity.metadata['title'] = self._title.get_text()
new_tags = self._tags.text_view_widget.props.buffer.props.text text_buffer = self._tags.get_buffer()
start, end = text_buffer.get_bounds()
new_tags = text_buffer.get_text(start, end)
self._activity.metadata['tags'] = new_tags self._activity.metadata['tags'] = new_tags
new_description = \ text_buffer = self._description.get_buffer()
self._description.text_view_widget.props.buffer.props.text start, end = text_buffer.get_bounds()
new_description = text_buffer.get_text(start, end)
self._activity.metadata['description'] = new_description self._activity.metadata['description'] = new_description
self._activity.metadata['title_set_by_user'] = '1' self._activity.metadata['title_set_by_user'] = '1'