Re: List view, editable renderers and popupmenus



* Remco Poelstra <r j poelstra student tue nl>:

Hi,

How can I make sure that the right mouse button only selects the row 
and not turns it in edit mode? And how can I make sure that the row is 
selected before the menu is displayed.

I've been working on a TreeView widget using Python + GTK, and I have
implemented a context menu like you want to (with the aggravating
problem that I set the rows as reorderable, so every button event
invariably activated the reordering callback); mind that this is Python
code, but should be understandable enough to convert it under any
language you're using.

First, I've connected the 'button_press_event'[1] of the treeview
widget, and in the callback I make sure that the pressed button was
the third one (right click):

        if event and event.type == gtk.gdk.BUTTON_PRESS:
            if not event.button == 3:
                # not a right-click: propagate
                return gtk.FALSE
            
            # event info
            button = event.button
            time = event.time
            x, y = event.x, event.y
            
Then, in order to select the row before creating the context menu, I
retrieve the path where the user clicked the mouse button:

            try:
                path, column, cell_x, cell_y = schedule.get_path_at_pos(x, y)
                iter = model.get_iter(path)
                selection = schedule.get_selection()
                selection.set_selected(iter)
            except TypeError, e:
                # user clicked below the rows, so select nothing
                pass

At this point, I handle the `popup_menu' event (user pressed Shift+F10):
        
        else:
            button = 0
            time = gtk.get_current_event_time()

Then, I create the context menu, and show it:

        context_menu = gtk.Menu()
        # [...]
        
        context_menu.popup(None, None, None, button, time)

        # stop propagating the event
        return gtk.TRUE

Hope This Helps,
 Emmanuele.

-- 
Emmanuele Bassi (Zefram)              [ http://digilander.iol.it/ebassi/ ]
GnuPG Key fingerprint = 4DD0 C90D 4070 F071 5738  08BD 8ECC DB8F A432 0FF4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]