webkit - Customizing context menus in python wwebkit gtk programs -
I work on using the Python WebKit and gtk modules to turn on the HTML / Javascript page in a desktop / application I am here. To do this, I have created a webkit window along with any other feature other than the WebKit window.
import webkit, gtk, subprocess w = gtk.Window (gtk.WINDOW_TOPLEVEL) w.set_resizable (false) w.set_size_request (900600) w.connect ("delete_event", gtk.main_quit) Scroll_window = gtk.ScrolledWindow (none, none) web = webkit.WebView () web.open ('/ home / user / html / mypage .html') settings = web.get_settings () settings.set_property ('enable- Default-context-menu ', True) scroll_window.add (web) w.add (scroll_window) w.show_all () gtk.main () This works differently from context menu When I right click on most areas of the page, the context menu gives me the following options: back, forward, etc. TOP, reload.
But when I right-click on a link, I get: Open Link, Open Link in New Window, Download Linked File, Download Copy Link Location
I would like to customize it so that when I right-click on a link, only I will get: Open link
I am disturbed and have seen other posts on stack overflow , But although I can detect the disable of the context menu, I do not know how to optimize them.
PS Unless you can tell, I am new to Python and am very new to the gtk and webkit module. "post-text" itemprop = "text">
To customize the context menu, you must first add the related 'context-menu' callback. This function can modify display context menu by using append or remove methods. You can add gtk.ImageMenuItem. This should work as an example:
def callback (webview, context_manu, hit_pustelt_events, event): option = gtk.imageMenuItem ('do this') option. Connect ('active', option_activate_cb) Context_menu.append (option) option.show () def Option_activate_ab (image_menu_item): print ('This works.') Web.connect ('context-menu', callback) An additional note: You do not have to enable the context menu. It is enabled by default.
Comments
Post a Comment