I had this exact same problem earlier. For the first part, make sure that
your button_press handler returns True anytime you actually handle the
event. This will stop the selection from being changed by right clicking.
Inside your button_press handler you have access to the widget (in this
case a treeview) that the mouse was pressed over. You can get the
selection by doing treeview.get_selection() (assuming the first parameter
in your callback is name treeview).
This returns a TreeSelection object. You can then call
selection.count_selected_rows() to determine if 1 or multiple rows are
selected.
There is one other caveat to think about. Lets assume you have a list
with 4 elements in it. If they select 2 and 4, and then right click on 3
the selection wont be changed because we are now returning true from the
button_press handler, so you have to do that manually. This is also
included. The following is just an example typed mostly from memory, so
it MAY not be syntactically correct. You should be able to figure out
what I mean though.
Example code:
def button_press_handler(treeview,event):
if event.button == 3:
# Figure out which item they right clicked on
path = treeview.get_path_at_pos(int(event.x),int(event.y))
# Get the selection
selection = treeview.get_selection()
# Get the selected path(s)
rows = selection.get_rows()
# If they didnt right click on a currently selected row, change
the selection
if path[0] not in rows[1]:
selection.unselect_all()
selection.select_path(path[0])
if selection.count_selected_rows() > 1:
#popup multiple selection menu
else:
#popup single selection box
return True
Useful references:
gtk.TreeView: http://pygtk.org/pygtk2reference/class-gtktreeview.html
gtk.TreeSelection:
http://pygtk.org/pygtk2reference/class-gtktreeselection.html
Jody Steele
On Thu, 09 Jun 2005 05:27:30 -0400, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
Hi list,
I'm selecting multiple row in a treeview using CTRL button.
Then if i right click , i lost all the previous selection.
Connecting the button_press event overwrites not this behaviour.
I would be able to keep the selection (and the blue color on the
selected rows) and when i right click, a specific popup menu for
multiple rows is displayed.
Does anyone know how to do this?
I can test if multiple rows are selected:
-> if yes: keeping previous selection and displaying a sepcific popup
menu for multiple rows..
-> if not: normal behaviour. Right click = changing selection and
displaying a popup menu for simple row.
Thanks a lot for your help,
Philippe
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/