Ticket #3989: 0002-CellRendererIcon-add-active-state-SL-3989.patch

File 0002-CellRendererIcon-add-active-state-SL-3989.patch, 4.1 KB (added by manuq, 10 years ago)

Toolkit patch to add active state to cellrenderer icons

  • src/sugar3/graphics/icon.py

    From 08d7b63a5bd0874536251ba91d45d9df30a16b24 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Thu, 18 Oct 2012 10:42:32 -0300
    Subject: [PATCH shell 2/3] CellRendererIcon: add active state - SL #3989
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    For press feedback.  Do this connecting to the treeview press and
    release signals, as the palette invoker does.  After this, the active
    state can be styled in the artwork.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/sugar3/graphics/icon.py | 40 +++++++++++++++++++++++++++++++++-------
     1 file changed, 33 insertions(+), 7 deletions(-)
    
    diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
    index 60c1804..507db41 100644
    a b class CellRendererIcon(Gtk.CellRenderer): 
    758758        self._stroke_color = None
    759759        self._prelit_fill_color = None
    760760        self._prelit_stroke_color = None
     761        self._active_state = False
    761762        self._palette_invoker = CellRendererInvoker()
    762763
    763764        Gtk.CellRenderer.__init__(self)
    764765
     766        tree_view.connect('button-press-event',
     767                          self.__button_press_event_cb)
     768        tree_view.connect('button-release-event',
     769                          self.__button_release_event_cb)
     770
    765771        self._palette_invoker.attach_cell_renderer(tree_view, self)
    766772
    767773    def __del__(self):
    768774        self._palette_invoker.detach()
    769775
     776    def __button_press_event_cb(self, widget, event):
     777        if self._point_in_cell_renderer(widget, event.x, event.y):
     778            self._active_state = True
     779
     780    def __button_release_event_cb(self, widget, event):
     781        self._active_state = False
     782
    770783    def create_palette(self):
    771784        return None
    772785
    class CellRendererIcon(Gtk.CellRenderer): 
    863876                         flags):
    864877        pass
    865878
    866     def _is_prelit(self, tree_view):
    867         x, y = tree_view.get_pointer()
    868         x, y = tree_view.convert_widget_to_bin_window_coords(x, y)
    869         pos = tree_view.get_path_at_pos(x, y)
     879    def _point_in_cell_renderer(self, tree_view, x=None, y=None):
     880        """Check if the point with coordinates x, y is inside this icon.
     881
     882        If the x, y coordinates are not given, they are taken from the
     883        pointer current position.
     884
     885        """
     886        if x is None and y is None:
     887            x, y = tree_view.get_pointer()
     888            x, y = tree_view.convert_widget_to_bin_window_coords(x, y)
     889        pos = tree_view.get_path_at_pos(int(x), int(y))
    870890        if pos is None:
    871891            return False
    872892
    873         path_, column, x, y = pos
     893        path_, column, x, y_ = pos
    874894
    875895        for cell_renderer in column.get_cells():
    876896            if cell_renderer == self:
    class CellRendererIcon(Gtk.CellRenderer): 
    886906        context.save()
    887907        context.add_class("sugar-icon-cell")
    888908
     909        pointer_inside = self._point_in_cell_renderer(widget)
     910
    889911        # The context will have prelight state if the mouse pointer is
    890912        # in the entire row, but we want that state if the pointer is
    891913        # in this cell only:
    892914        if flags & Gtk.CellRendererState.PRELIT:
    893             if not self._is_prelit(widget):
     915            if pointer_inside:
     916                if self._active_state:
     917                    context.set_state(Gtk.StateFlags.ACTIVE)
     918            else:
    894919                context.set_state(Gtk.StateFlags.NORMAL)
    895920
     921
    896922        Gtk.render_background(context, cr, background_area.x, background_area.y,
    897923                              background_area.width, background_area.height)
    898924
    class CellRendererIcon(Gtk.CellRenderer): 
    914940                                         prelit_stroke_color]
    915941
    916942        if flags & Gtk.CellRendererState.PRELIT and has_prelit_colors and \
    917                 self._is_prelit(widget):
     943                pointer_inside:
    918944
    919945            self._buffer.fill_color = prelit_fill_color
    920946            self._buffer.stroke_color = prelit_stroke_color