Source

filesnake / filesnake / gui / menu.py

from ..pygtkhelpers.delegates import ToplevelView
import gtk

class UserMenu(ToplevelView):
    '''
    Contextual menu for `UserList`

    Ideas:
    It should be moved in `UserList` module?
    '''
    def __init__(self, parent):
        self.parent = parent        
        super(UserMenu, self).__init__()

    def create_ui(self,):
        self.menu = gtk.Menu()
        
        # sendfile and sendfolder are gtk.Actions
        self.menu.append(self.parent.sendfile.create_menu_item())
        self.menu.append(self.parent.sendfolder.create_menu_item())
        
        #self.sendfile.show()
        #self.sendfolder.show()
        
        self.userlist = self.parent.userlist.treeview
        
    def on_userlist__button_press_event(self, treeview, event):
        '''
        On right click on the userlist it spawns the MENU
        '''
        if event.button == 3:
            x = int(event.x)
            y = int(event.y)
            time = event.time
            pthinfo = treeview.get_path_at_pos(x, y)
            if pthinfo is not None:
                path, col, cellx, celly = pthinfo
                treeview.grab_focus()
                treeview.set_cursor( path, col, 0)
                self.menu.popup( None, None, None, event.button, time)
            return True