From 2f8b441be9ebd1540c37ee1b329b6eeff3e2647c Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 09 Jul 2011 15:46:28 +0000 Subject: removed hippo from detail view; some remaining issues with event handling --- diff --git a/src/jarabe/journal/detailview.py b/src/jarabe/journal/detailview.py index aa8c039..b5a7a2b 100644 --- a/src/jarabe/journal/detailview.py +++ b/src/jarabe/journal/detailview.py @@ -19,7 +19,6 @@ from gettext import gettext as _ import gobject import gtk -import hippo from sugar.graphics import style from sugar.graphics.icon import CanvasIcon @@ -39,21 +38,23 @@ class DetailView(gtk.VBox): self._metadata = None self._expanded_entry = None - canvas = hippo.Canvas() - - self._root = hippo.CanvasBox() - self._root.props.background_color = style.COLOR_PANEL_GREY.get_int() - canvas.set_root(self._root) + root_box = gtk.EventBox() + root_box.modify_bg(gtk.STATE_NORMAL, + style.COLOR_WHITE.get_gdk_color()) + self._root = gtk.VBox() + root_box.add(self._root) back_bar = BackBar() back_bar.connect('button-release-event', self.__back_bar_release_event_cb) - self._root.append(back_bar) + self._root.pack_start(back_bar, False, False, style.DEFAULT_SPACING) gobject.GObject.__init__(self, **kwargs) + gtk.VBox.__init__(self) - self.pack_start(canvas) - canvas.show() + self.pack_start(root_box, True, True, 0) + self._root.show() + self.show_all() def _fav_icon_activated_cb(self, fav_icon): keep = not self._expanded_entry.get_keep() @@ -67,8 +68,9 @@ class DetailView(gtk.VBox): def _update_view(self): if self._expanded_entry is None: self._expanded_entry = ExpandedEntry() - self._root.append(self._expanded_entry, hippo.PACK_EXPAND) + self._root.pack_start(self._expanded_entry) self._expanded_entry.set_metadata(self._metadata) + self._root.show_all() def refresh(self): logging.debug('DetailView.refresh') @@ -86,34 +88,35 @@ class DetailView(gtk.VBox): type=object, getter=get_metadata, setter=set_metadata) -class BackBar(hippo.CanvasBox): +class BackBar(gtk.EventBox): def __init__(self): - hippo.CanvasBox.__init__(self, - orientation=hippo.ORIENTATION_HORIZONTAL, - border=style.LINE_WIDTH, - background_color=style.COLOR_PANEL_GREY.get_int(), - border_color=style.COLOR_SELECTION_GREY.get_int(), - padding=style.DEFAULT_PADDING, - padding_left=style.DEFAULT_SPACING, - spacing=style.DEFAULT_SPACING) - + gtk.EventBox.__init__(self) + self.set_border_width(style.DEFAULT_SPACING) + self.modify_bg(gtk.STATE_NORMAL, + style.COLOR_PANEL_GREY.get_gdk_color()) + hbox = gtk.HBox() icon = CanvasIcon(icon_name='go-previous', size=style.SMALL_ICON_SIZE, fill_color=style.COLOR_TOOLBAR_GREY.get_svg()) - self.append(icon) + hbox.pack_start(icon, False, False, style.DEFAULT_SPACING) - label = hippo.CanvasText(text=_('Back'), - font_desc=style.FONT_NORMAL.get_pango_desc()) - self.append(label) + label = gtk.Label() + label.set_text(_('Back')) + halign = gtk.Alignment(0, 0, 0, 0) + halign.add(label) + hbox.pack_start(halign, True, True, style.DEFAULT_SPACING) + hbox.show() + self.add(hbox) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: - self.reverse() + hbox.reverse() self.connect('motion-notify-event', self.__motion_notify_event_cb) def __motion_notify_event_cb(self, box, event): - if event.detail == hippo.MOTION_DETAIL_ENTER: - box.props.background_color = style.COLOR_SELECTION_GREY.get_int() - elif event.detail == hippo.MOTION_DETAIL_LEAVE: - box.props.background_color = style.COLOR_PANEL_GREY.get_int() + if event.detail == 1: # TODO: enter + box.props.background_color = style.COLOR_SELECTION_GREY.get_gdk_color() + elif event.detail == 0: # TODO: leave + box.props.background_color = style.COLOR_PANEL_GREY.get_gdk_color() return False + diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py index 476156a..c4de473 100644 --- a/src/jarabe/journal/expandedentry.py +++ b/src/jarabe/journal/expandedentry.py @@ -20,7 +20,6 @@ import StringIO import time import os -import hippo import cairo import gobject import gtk @@ -38,105 +37,98 @@ from jarabe.journal import misc from jarabe.journal import model -class Separator(hippo.CanvasBox, hippo.CanvasItem): +class Separator(gtk.VBox): def __init__(self, orientation): - hippo.CanvasBox.__init__(self, - background_color=style.COLOR_PANEL_GREY.get_int()) - - if orientation == hippo.ORIENTATION_VERTICAL: - self.props.box_width = style.LINE_WIDTH - else: - self.props.box_height = style.LINE_WIDTH + gtk.VBox.__init__(self, + background_color=style.COLOR_PANEL_GREY.get_gdk_color()) -class BuddyList(hippo.CanvasBox): +class BuddyList(gtk.Alignment): def __init__(self, buddies): - hippo.CanvasBox.__init__(self, xalign=hippo.ALIGNMENT_START, - orientation=hippo.ORIENTATION_HORIZONTAL) + gtk.Alignment.__init__(self, 0, 0, 0, 0) + hbox = gtk.HBox() for buddy in buddies: nick_, color = buddy - hbox = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL) icon = CanvasIcon(icon_name='computer-xo', xo_color=XoColor(color), size=style.STANDARD_ICON_SIZE) icon.set_palette(BuddyPalette(buddy)) - hbox.append(icon) - self.append(hbox) + hbox.pack_start(icon) + self.add(hbox) -class ExpandedEntry(hippo.CanvasBox): +class ExpandedEntry(gtk.EventBox): def __init__(self): - hippo.CanvasBox.__init__(self) - self.props.orientation = hippo.ORIENTATION_VERTICAL - self.props.background_color = style.COLOR_WHITE.get_int() - self.props.padding_top = style.DEFAULT_SPACING * 3 + gtk.EventBox.__init__(self) + + # We need an EventBox in order to set the border and background color. + self.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) + self.set_border_width(style.DEFAULT_SPACING) self._metadata = None self._update_title_sid = None - # Create header - header = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, - padding=style.DEFAULT_PADDING, - padding_right=style.GRID_CELL_SIZE, - spacing=style.DEFAULT_SPACING) - self.append(header) + # Everything will go into vbox + vbox = gtk.VBox() + self.add(vbox) - # Create two column body + # Create a header + header = gtk.HBox() + vbox.pack_start(header, False, False, style.DEFAULT_SPACING * 2) - body = hippo.CanvasBox(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) + # Create a two-column body + body_box = gtk.EventBox() + body_box.set_border_width(style.DEFAULT_SPACING) + body_box.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) + vbox.pack_start(body_box) + body = gtk.HBox() + body_box.add(body) - self.append(body, hippo.PACK_EXPAND) + first_column = gtk.VBox() + body.pack_start(first_column, False, False, style.DEFAULT_SPACING) - first_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, - spacing=style.DEFAULT_SPACING) - body.append(first_column) - - second_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, - spacing=style.DEFAULT_SPACING) - body.append(second_column, hippo.PACK_EXPAND) + second_column = gtk.VBox() + body.pack_start(second_column) # Header - self._keep_icon = self._create_keep_icon() - header.append(self._keep_icon) + header.pack_start(self._keep_icon, False, False, style.DEFAULT_SPACING) self._icon = None - self._icon_box = hippo.CanvasBox() - header.append(self._icon_box) + self._icon_box = gtk.HBox() + header.pack_start(self._icon_box, False, False, style.DEFAULT_SPACING) self._title = self._create_title() - header.append(self._title, hippo.PACK_EXPAND) + header.pack_start(self._title) # TODO: create a version list popup instead of a date label self._date = self._create_date() - header.append(self._date) + header.pack_start(self._date, False, False, style.DEFAULT_SPACING) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: header.reverse() - # First column + # First body column + self._preview_box = gtk.VBox() + first_column.pack_start(self._preview_box) - self._preview_box = hippo.CanvasBox() - first_column.append(self._preview_box) - - self._technical_box = hippo.CanvasBox() - first_column.append(self._technical_box) - - # Second column + self._technical_box = gtk.VBox() + first_column.pack_start(self._technical_box) + # Second body column description_box, self._description = self._create_description() - second_column.append(description_box) + second_column.pack_start(description_box, True, True, + style.DEFAULT_SPACING) tags_box, self._tags = self._create_tags() - second_column.append(tags_box) + second_column.pack_start(tags_box, True, True, + style.DEFAULT_SPACING) - self._buddy_list = hippo.CanvasBox() - second_column.append(self._buddy_list) + self._buddy_list = gtk.VBox() + second_column.pack_start(self._buddy_list) + + self.show_all() def set_metadata(self, metadata): if self._metadata == metadata: @@ -146,39 +138,38 @@ class ExpandedEntry(hippo.CanvasBox): self._keep_icon.keep = (int(metadata.get('keep', 0)) == 1) self._icon = self._create_icon() - self._icon_box.clear() - self._icon_box.append(self._icon) - - self._date.props.text = misc.get_date(metadata) + self._icon_box.foreach(self._icon_box.remove) + self._icon_box.pack_start(self._icon, False, False, + style.DEFAULT_SPACING) - title = self._title.props.widget - title.props.text = metadata.get('title', _('Untitled')) - title.props.editable = model.is_editable(metadata) + self._date.set_text(misc.get_date(metadata)) - self._preview_box.clear() - self._preview_box.append(self._create_preview()) + self._title.set_text(metadata.get('title', _('Untitled'))) - self._technical_box.clear() - self._technical_box.append(self._create_technical()) + self._preview_box.foreach(self._preview_box.remove) + self._preview_box.pack_start(self._create_preview(), False, False, + style.DEFAULT_SPACING) - self._buddy_list.clear() - self._buddy_list.append(self._create_buddy_list()) + self._technical_box.foreach(self._technical_box.remove) + self._technical_box.pack_start(self._create_technical(), + False, False, style.DEFAULT_SPACING) - description = self._description.text_view_widget - description.props.buffer.props.text = metadata.get('description', '') - description.props.editable = model.is_editable(metadata) + self._buddy_list.foreach(self._buddy_list.remove) + self._buddy_list.pack_start(self._create_buddy_list(), False, False, + style.DEFAULT_SPACING) - tags = self._tags.text_view_widget - tags.props.buffer.props.text = metadata.get('tags', '') - tags.props.editable = model.is_editable(metadata) + self._description.get_buffer().set_text(metadata.get('description', '')) + self._tags.get_buffer().set_text(metadata.get('tags', '')) def _create_keep_icon(self): keep_icon = KeepIcon(False) - keep_icon.connect('activated', self._keep_icon_activated_cb) + # TODO: figure out proper signals + # keep_icon.connect('activate', self._keep_icon_activated_cb) return keep_icon def _create_icon(self): - icon = CanvasIcon(file_name=misc.get_icon_name(self._metadata)) + icon = CanvasIcon(file_name=misc.get_icon_name(self._metadata), + size=style.MEDIUM_ICON_SIZE) icon.connect_after('button-release-event', self._icon_button_release_event_cb) @@ -201,17 +192,16 @@ class ExpandedEntry(hippo.CanvasBox): entry.modify_bg(gtk.STATE_INSENSITIVE, bg_color) entry.modify_base(gtk.STATE_INSENSITIVE, bg_color) - return hippo.CanvasWidget(widget=entry) + return entry def _create_date(self): - date = hippo.CanvasText(xalign=hippo.ALIGNMENT_START, - font_desc=style.FONT_NORMAL.get_pango_desc()) + date = gtk.Label() return date def _create_preview(self): width = style.zoom(320) height = style.zoom(240) - box = hippo.CanvasBox() + box = gtk.HBox() if len(self._metadata.get('preview', '')) > 4: if self._metadata['preview'][1:4] == 'PNG': @@ -225,6 +215,13 @@ class ExpandedEntry(hippo.CanvasBox): png_file = StringIO.StringIO(preview_data) try: surface = cairo.ImageSurface.create_from_png(png_file) + pixmap = gtk.gdk.Pixmap(None, width, height, 24) + cr = pixmap.cairo_create() + cr.set_source_surface(surface, 0, 0) + cr.paint() + + im = gtk.Image() + im.set_from_pixmap(pixmap, None) has_preview = True except Exception: logging.exception('Error while loading the preview') @@ -233,50 +230,34 @@ class ExpandedEntry(hippo.CanvasBox): has_preview = False if has_preview: - preview_box = hippo.CanvasImage(image=surface, - border=style.LINE_WIDTH, - border_color=style.COLOR_BUTTON_GREY.get_int(), - xalign=hippo.ALIGNMENT_CENTER, - yalign=hippo.ALIGNMENT_CENTER, - scale_width=width, - scale_height=height) + box.pack_start(im) else: - preview_box = hippo.CanvasText(text=_('No preview'), - font_desc=style.FONT_NORMAL.get_pango_desc(), - xalign=hippo.ALIGNMENT_CENTER, - yalign=hippo.ALIGNMENT_CENTER, - border=style.LINE_WIDTH, - border_color=style.COLOR_BUTTON_GREY.get_int(), - color=style.COLOR_BUTTON_GREY.get_int(), - box_width=width, - box_height=height) - preview_box.connect_after('button-release-event', - self._preview_box_button_release_event_cb) - box.append(preview_box) + label = gtk.Label() + label.set_text(_('No preview')) + box.pack_start(label) + + box.connect_after('button-release-event', + self._preview_box_button_release_event_cb) return box def _create_technical(self): - vbox = hippo.CanvasBox() + vbox = gtk.VBox() vbox.props.spacing = style.DEFAULT_SPACING - lines = [ - _('Kind: %s') % (self._metadata.get('mime_type') or _('Unknown'),), - _('Date: %s') % (self._format_date(),), - _('Size: %s') % (format_size(int(self._metadata.get('filesize', - model.get_file_size(self._metadata['uid']))))), - ] - - for line in lines: - text = hippo.CanvasText(text=line, - 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) + label = \ + _('Kind: %s') % (self._metadata.get('mime_type') or \ + _('Unknown'),) + '\n' + \ + _('Date: %s') % (self._format_date(),) + '\n' + \ + _('Size: %s') % (format_size(int(self._metadata.get( + 'filesize', + model.get_file_size(self._metadata['uid']))))) + + text = gtk.Label() + text.set_markup('%s' % ( + style.COLOR_BUTTON_GREY.get_html(), label)) + halign = gtk.Alignment(0, 0, 0, 0) + halign.add(text) + vbox.pack_start(halign, False, False, 0) return vbox @@ -294,76 +275,54 @@ class ExpandedEntry(hippo.CanvasBox): def _create_buddy_list(self): - vbox = hippo.CanvasBox() + vbox = gtk.VBox() vbox.props.spacing = style.DEFAULT_SPACING - text = hippo.CanvasText(text=_('Participants:'), - 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) + text = gtk.Label() + text.set_markup('%s' % ( + style.COLOR_BUTTON_GREY.get_html(), _('Participants:'))) + halign = gtk.Alignment(0, 0, 0, 0) + halign.add(text) + vbox.pack_start(halign, False, False, 0) if self._metadata.get('buddies'): buddies = simplejson.loads(self._metadata['buddies']).values() - vbox.append(BuddyList(buddies)) + vbox.pack_start(BuddyList(buddies), False, False, 0) return vbox else: return vbox - def _create_description(self): - vbox = hippo.CanvasBox() + def _create_scrollable(self, label): + vbox = gtk.VBox() vbox.props.spacing = style.DEFAULT_SPACING - text = hippo.CanvasText(text=_('Description:'), - 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 + text = gtk.Label() + text.set_markup('%s' % ( + style.COLOR_BUTTON_GREY.get_html(), label)) - vbox.append(text) + halign = gtk.Alignment(0, 0, 0, 0) + halign.add(text) + vbox.pack_start(halign, False, False, 0) - text_view = CanvasTextView('', - box_height=style.GRID_CELL_SIZE * 2) - vbox.append(text_view, hippo.PACK_EXPAND) + scrolled_window = gtk.ScrolledWindow() + scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + scrolled_window.set_border_width(style.LINE_WIDTH) + text_buffer = gtk.TextBuffer() + text_view = gtk.TextView(text_buffer) + scrolled_window.add_with_viewport(text_view) + vbox.pack_start(scrolled_window) - text_view.text_view_widget.props.accepts_tab = False - text_view.text_view_widget.connect('focus-out-event', - self._description_focus_out_event_cb) + # FIXME: + # text_view.text_view_widget.connect('focus-out-event', + # self._description_focus_out_event_cb) 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) - - text_view = CanvasTextView('', - box_height=style.GRID_CELL_SIZE * 2) - vbox.append(text_view, hippo.PACK_EXPAND) - - text_view.text_view_widget.props.accepts_tab = False - text_view.text_view_widget.connect('focus-out-event', - self._tags_focus_out_event_cb) + def _create_description(self): + return self._create_scrollable(_('Description:')) - return vbox, text_view + def _create_tags(self): + return self._create_scrollable(_('Tags:')) def _title_notify_text_cb(self, entry, pspec): if not self._update_title_sid: @@ -384,7 +343,7 @@ class ExpandedEntry(hippo.CanvasBox): return old_title = self._metadata.get('title', None) - new_title = self._title.props.widget.props.text + new_title = self._title.get_text() if old_title != new_title: self._icon.palette.props.primary_text = new_title self._metadata['title'] = new_title @@ -392,14 +351,14 @@ class ExpandedEntry(hippo.CanvasBox): needs_update = True old_tags = self._metadata.get('tags', None) - new_tags = self._tags.text_view_widget.props.buffer.props.text + new_tags = self._tags.get_text() if old_tags != new_tags: self._metadata['tags'] = new_tags needs_update = True old_description = self._metadata.get('description', None) new_description = \ - self._description.text_view_widget.props.buffer.props.text + self._description.get_text() if old_description != new_description: self._metadata['description'] = new_description needs_update = True -- cgit v0.9.1