Walter Leibbrandt wrote:
> Hi,
>
> I took another swing at creating a custom cell renderer that can render 
> any arbitrary widget in a TreeView. It currently works, albeit with a 
> few annoyances. The source is available at 
> https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/cellrendererwidget.py
>
> The widget (retrieved from the TreeView's model) is rendered by wrapping 
> it in a gtk.CellEditable, which was the only way I could find to render 
> arbitrary widgets. This means that the cell renderer must use the 
> editable mode and that the activatable mode is of no use. So the cell is 
> currently rendered in one of three states:
> * Unselected: A CellRendererText is emulatedwith the strfunc callable 
> supplying the string to render.
> * Selected (not editing): When selecting a row (with the mouse or 
> keyboard) the cell is empty. Neither the string or the widget is rendered.
> * Editing: When clicking on the cell (or pressing Enter on it) after it 
> has been selected it enters editing mode and displays the appropriate 
> widget.
>
> The problem is the second state mentioned above and that brings me to my 
> actual question: How can I get CellRenderer to enter editing mode as 
> soon as it is selected?
>
> I have tried testing the flags parameter (in on_render) for 
> gtk.CELL_RENDERER_SELECTED and then calling self.start_editing() myself. 
> I have confirmed that my on_start_editing() is indeed called, but that 
> does not seem to be enough to put the cell in editing mode and show the 
> widget.
>
> This is has been solved in Virtaal (the application I'm working on), but 
> it involved creating a custom TreeModel implementation. This model would 
> return True for get_value() calls on the (hard-coded) column number of 
> the editable property, only if the internal iterator matched the 
> get_value() call's parameter. This is a big hack I'd like to avoid in my 
> implementation. For this implementation the CellRenderer is in 
> https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/storeviewwidgets.py
>  
> and the CellEditable is in 
> https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/unitview.py
>
> Any insight would be greatly appreciated.
>
> Thanks in advance,
>
>   
I've got it working with a hack, but one important problem remains: The 
CellRenderer's size is calculated based on the string rendered for 
unselected cells. This means that, if the widget rendered in a selected 
cell needs more space than the rendered string, it is simply cut off. 
The problem (as far as I can tell) seems to arise from the fact that the 
widget to render in the cell has not yet been realize()d and thus has no 
allocation.

So this is a call to anyone who has implemented a custom cell renderer's 
do_get_size() to please take a look at the code and make any 
recommendations and/or observations that might help me calculate the 
correct size for the cell. The code is at 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/cellrendererwidget.py

Thanks in advance,

-- 
Walter Leibbrandt                  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget


_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to