[pygtk] Coordinates of a TreeView cell

Jiri Bajer sarimak at seznam.cz
Sat Aug 22 03:55:29 WST 2009


Hi,

I'm trying to create my own TreeView's CellRenderer for a calendar and
have troubles with proper positioning of popup for editing the date.

My class CellRendererDate is derived from gtk.CellRendererText - during
its do_start_editing() method I create a gtk.Dialog without decorations
and with transient set to None containing a gtk.Calendar. I try to
position it below the edited cell and there I got stuck.

I add coordinates of cell_background argument of do_start_editing to
TreeView's get_bin_window().get_origin() to count the position of popup
and it works fine unless I shrink the main window and scroll the
TreeView. Since cell_background ignores scroll the popup is shifted.

I've tried to juggle with widget_to_tree_coords() and vice versa but got
lost. Both unconverted and converted coordinates are do not fit. B-(

Could anyone please give me an advice how to take the scrolling of
TreeView into account properly? Big thanks in advance!

Jiri Bajer

PS: The reason I'm creating my own popup instead of using gtk.Editable
and returning it from do_start_editing() is that:

1) gtk.Calendar does not implement gtk.Editable interface

2) gtk.Calendar is bigger than the cell and thus I'm not able to render
it over the cells

3) I would like to reuse the same code for multiline text renderer -
CellRendererText would inflate the cell if the text has more than one
line

Code snippet (uninteresting parts omitted):

class CellRendererDate(gtk.CellRendererText):

  def do_start_editing(self, event, treeview, path, background_area,
cell_area, flags):
    self.calendar_window = gtk.Dialog(parent=treeview.get_toplevel())
    ...
    self.calendar.show()
    self.calendar_window.realize()
    ...
    (tree_x, tree_y) = treeview.get_bin_window().get_origin()
    (bg_x, bg_y) = treeview.widget_to_tree_coords(background_area.x,
background_area.y)
    self.calendar_window.move(tree_x + bg_x, tree_y + bg_y)
    ...
    return None




More information about the pygtk mailing list