On 11/18/06, Brian <[EMAIL PROTECTED]> wrote:
> I have three cell renderers in one column, so the path I get in
'button-clicked'
> callback is always the same no matter what cell I click in the column.
> Is there a way to know exactly what whas clicked in the column?
>
> I have to check if I'll be able to get cell renderer position boundaries and
> match it with button-press event x/y position. However it'll be a bit dirty,
> even if it works.
>
We use to have the toggle packed into a column like that as well. If I
remember correctly clicking anywhere on the row would always toggle the
toggle. The other problem we had was that it would not always render
correctly. The line spacing was wrong with rows overlapping I think.
Then we added more columns with additional information as well as right
mouse button popup menus. I would recommend you separate out the toggle
into its own column. It will simplify things. Otherwise I think you
will have to get mouse pointer coordinates and compute its position on
your window... until you figure out if it was your toggle it was over.
I did it. This is how it works now:
def on_sets_button_press( self, tree, event ):
if event.type == gtk.gdk.BUTTON_PRESS and event.button in (1, 3):
pathinfo = tree.get_path_at_pos( int(event.x), int(event.y) )
if pathinfo is not None and event.button == 1:
path, col = pathinfo[:2]
cell = col.get_cell_renderers()[SETS_COL_TOGGLE] # Toggle cell.
ctmin = 16 * len(path) # <- this is the left
toggle boundary.
ctmax = ctmin + cell.get_size(tree, None)[2] # <- and
this is right one.
if ctmin <= event.x < ctmax: # Toggle cell.
# <- Toggle current node (and all subnodes).
return True # <- do not propagate event (no cursor-changed).
elif pathinfo is not None and event.button == 3:
# <- context menu
return True # <- same as above.
return False
TODO:
1. I have to find out what is the width of those treeview expand "thingies".
That's why I use fixed 16px width.
http://pu.kielce.pl/~pipen/varez/pygtk-toggle.png
2. I should add column spacing between cells to the result of ctmax.
Here is another way of calculating ctmax (however result slightly differ (2px)):
ctmax = ctmin + col.cell_get_position(cell)[1]
Thanks for your help.
--
Artur M. Piwko
AMP29-RIPE
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/