1

Using webkit version 1.6 I have been trying to figure out the class method/function to get the currently selected text. There's has_selection, but that only returns a bool.

I'm on linux mint using python gtk3 with webkit 1.6.

If I have to I'll use javascript, but I'd prefer a webkit method.

I don't really need a listener or signal. An event already creates a popup. I want to print the selected text in the popup.

I've tried:

webkit.webview.get_selected_text()

webkit.webview.get_selection()

webkit.webview.selected_text()

webkit.webview.get_property("selected-text")

Just shooting in the dark.

1 Answer 1

0

Looks like there is no special method for webkit to get selected text.

For now the gtk clipboard works to get text from a selection in the webkit.webview.

Use:

c = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
print c.wait_for_text()

It's a little funky, but it works.

2
  • Looks like this method interferes with execCommand in javascript used with webview.execute_javascript. I don't know if this is a bug, or it's to be expected. Feb 12, 2013 at 4:46
  • The problem is wait_for_text deselects the text it retrieves. Any one have an idea to fix this? Feb 12, 2013 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.