Ticket #3989: 0003-CellRendererInvoker-remove-duplicate-code-in-CellRen.patch

File 0003-CellRendererInvoker-remove-duplicate-code-in-CellRen.patch, 4.5 KB (added by manuq, 10 years ago)

Patch that removes duplicated code from the CellRendererInvoker.

  • src/sugar3/graphics/icon.py

    From 4f88636ae44ea41559b842c32d979edc305661d6 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Mon, 29 Oct 2012 17:46:33 -0300
    Subject: [PATCH shell 3/3] CellRendererInvoker: remove duplicate code in
     CellRendererIcon
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    Make public the method to check if the pointer is inside the
    CellRendererIcon and remove it from CellRendererInvoker.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/sugar3/graphics/icon.py          |  6 +++---
     src/sugar3/graphics/palettewindow.py | 28 +++++++---------------------
     2 files changed, 10 insertions(+), 24 deletions(-)
    
    diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
    index 507db41..4946b6f 100644
    a b class CellRendererIcon(Gtk.CellRenderer): 
    774774        self._palette_invoker.detach()
    775775
    776776    def __button_press_event_cb(self, widget, event):
    777         if self._point_in_cell_renderer(widget, event.x, event.y):
     777        if self.point_in_cell_renderer(widget, event.x, event.y):
    778778            self._active_state = True
    779779
    780780    def __button_release_event_cb(self, widget, event):
    class CellRendererIcon(Gtk.CellRenderer): 
    876876                         flags):
    877877        pass
    878878
    879     def _point_in_cell_renderer(self, tree_view, x=None, y=None):
     879    def point_in_cell_renderer(self, tree_view, x=None, y=None):
    880880        """Check if the point with coordinates x, y is inside this icon.
    881881
    882882        If the x, y coordinates are not given, they are taken from the
    class CellRendererIcon(Gtk.CellRenderer): 
    906906        context.save()
    907907        context.add_class("sugar-icon-cell")
    908908
    909         pointer_inside = self._point_in_cell_renderer(widget)
     909        pointer_inside = self.point_in_cell_renderer(widget)
    910910
    911911        # The context will have prelight state if the mouse pointer is
    912912        # in the entire row, but we want that state if the pointer is
  • src/sugar3/graphics/palettewindow.py

    diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py
    index 0407bfc..b4529c2 100644
    a b class CellRendererInvoker(Invoker): 
    12561256    def __motion_notify_event_cb(self, widget, event):
    12571257        if event.window != widget.get_bin_window():
    12581258            return
    1259         if self._point_in_cell_renderer(event.x, event.y):
     1259        if self._cell_renderer.point_in_cell_renderer(widget, event.x, event.y):
    12601260
    12611261            tree_view = self._tree_view
    12621262            path, column_, x_, y_ = tree_view.get_path_at_pos(int(event.x),
    class CellRendererInvoker(Invoker): 
    12951295        return False
    12961296
    12971297    def __button_release_event_cb(self, widget, event):
    1298         if event.button == 1 and self._point_in_cell_renderer(event.x,
    1299             event.y):
     1298        if event.button == 1 and \
     1299                self._cell_renderer.point_in_cell_renderer(widget,
     1300                                                           event.x, event.y):
    13001301            tree_view = self._tree_view
    13011302            path, column_, x_, y_ = tree_view.get_path_at_pos(int(event.x),
    13021303                                                              int(event.y))
    13031304            self._cell_renderer.emit('clicked', path)
    13041305            # So the treeview receives it and knows a drag isn't going on
    13051306            return False
    1306         if event.button == 3 and self._point_in_cell_renderer(event.x,
    1307             event.y):
     1307        if event.button == 3 and \
     1308                self._cell_renderer.point_in_cell_renderer(widget,
     1309                                                           event.x, event.y):
    13081310            self.notify_right_click()
    13091311            return True
    13101312        else:
    13111313            return False
    13121314
    1313     def _point_in_cell_renderer(self, event_x, event_y):
    1314         pos = self._tree_view.get_path_at_pos(int(event_x), int(event_y))
    1315         if pos is None:
    1316             return False
    1317 
    1318         path_, column, x, y_ = pos
    1319 
    1320         for cell_renderer in column.get_cells():
    1321             if cell_renderer == self._cell_renderer:
    1322                 cell_x, cell_width = column.cell_get_position(cell_renderer)
    1323                 if x > cell_x and x < (cell_x + cell_width):
    1324                     return True
    1325                 return False
    1326 
    1327         return False
    1328 
    13291315    def get_toplevel(self):
    13301316        return self._tree_view.get_toplevel()
    13311317