connect up the key-press-event and have the context menus pop up when the menu key is pressed

This commit is contained in:
Damien Churchill 2009-08-24 22:13:54 +00:00
parent bcbe3108c9
commit 32ed499b2a
2 changed files with 28 additions and 1 deletions

View File

@ -34,7 +34,7 @@
#
import gtk, gtk.glade
import gtk, gtk.glade, gtk.gdk
import gobject
import gettext
import os.path
@ -187,6 +187,7 @@ class FilesTab(Tab):
]
self.listview.connect("row-activated", self._on_row_activated)
self.listview.connect("key-press-event", self._on_key_press_event)
self.listview.connect("button-press-event", self._on_button_press_event)
self.listview.enable_model_drag_source(
@ -471,6 +472,17 @@ class FilesTab(Tab):
self.file_menu.popup(None, None, None, event.button, event.time)
return True
def _on_key_press_event(self, widget, event):
# Menu key
if gtk.gdk.keyval_name(event.keyval) != "Menu":
return
if not self.get_selected_files():
return
self.file_menu.popup(None, None, None, 3, event.time)
return True
def _on_menuitem_open_file_activate(self, menuitem):
self._on_row_activated(None, None, None)

View File

@ -214,6 +214,9 @@ class TorrentView(listview.ListView, component.Component):
# torrent menu popup.
self.treeview.connect("button-press-event",
self.on_button_press_event)
# Connect to the 'key-press-event' to know when the bring up the
# torrent menu popup via keypress.
self.treeview.connect("key-press-event", self.on_key_press_event)
# Connect to the 'changed' event of TreeViewSelection to get selection
# changes.
self.treeview.get_selection().connect("changed",
@ -459,6 +462,18 @@ class TorrentView(listview.ListView, component.Component):
torrentmenu = component.get("MenuBar").torrentmenu
torrentmenu.popup(None, None, None, event.button, event.time)
return True
def on_key_press_event(self, widget, event):
# Menu key
if gtk.gdk.keyval_name(event.keyval) != "Menu":
return
if not self.get_selected_torrent():
return
torrentmenu = component.get("MenuBar").torrentmenu
torrentmenu.popup(None, None, None, 3, event.time)
return True
def on_selection_changed(self, treeselection):
"""This callback is know when the selection has changed."""