Abel Daniel <[EMAIL PROTECTED]> writes:

> The FAQ entry 13.17 on popup menus in TreeViews
> (http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq13.017.htp)
> has the unfortunate feature that it forces the selection to be the row
> that is clicked. (The line "treeview.set_cursor( path, col, 0)" )
> 
> This means that if multiple selection is allowed in the Treeview, and
> one selects multiple lines then right-clicks, the previous selection
> is lost.
> 
> Obviously this is not the right thing to do as other programs in this
> situation change the selection as if a normal mouseclick with the same
> modifier keys would have been pressed. (So if the ctrl is pressed,
> they add that row, if shift is pressed, they select the rows between
> the two clicks, etc.)
> 
> How should I implement that?
> 
> The current version works if no modifier-keys are pressed.
> Handling ctrl correctly is pretty easy.
> The bigger problem is shift. It seems to me that the accepted meaning
> of shift-click in a list is "select all rows between this and the
> place of last click". How could I get the place of the last event?
> 
> Would it be easier if I would simply generate a fake left-click event
> with the right modifier keys? How could I do this?

That's a good observation.  The recipe in FAQ 13.17 doesn't work with
multiple selections.

Unfortunately I don't know how to do what you ask.  Instead, I suggest
cheating by making the problem much easier (trivial) and solving that.

Instead of overloading right click to be select + pop up, how about
selecting only with a left click and popping up only with right?  On a
right click, ignore the modifier keys (shift or ctrl) and test to see
if there's a selection.  If there's no selection then the popup needs
something to work with, so use set_cursor() to select the row that was
right clicked on like the FAQ entry does.  If there is a selection
then right click can just pop up the menu and work with the current
selection without changing it.  In addition to being much easier to
implement, this might also be easier for the user to understand.
Single selection + popup requires only a single right click.  Multiple
selection + popup can require on extra left click, but this doesn't
seem burdensome.
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to