Sorry for the noise, I've finally managed to do the trick and posted the result in PyGTK FAQ as #13.56 in hope my solution could be reused in the future. See http://faq.pygtk.org/index.py?req=all#13.56 for details.
The main trick was to use cell_area instead of background_area and forget about all tree <-> widget conversions. I've also added code for keeping the popup window within toplevel window's allocation that leverages x and y coords from TreeView.get_visible_rect() - they show how much is the TreeView scrolled, (0,0) means no scroll. Is there any good tutorial discussing the different coordinate systems and conversions among them - with special focus on TreeView? I wasn't able to find anything useful and discovering the right combination (even with the official docs, tutorials and several code examples from this list) took me several days. B-( Jirka On Fri, 2009-08-21 at 21:55 +0200, Jiri Bajer wrote: > 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 > > > _______________________________________________ > pygtk mailing list [email protected] > http://www.daa.com.au/mailman/listinfo/pygtk > Read the PyGTK FAQ: http://faq.pygtk.org/ _______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
