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.

Quentin Engles
  • 2,744
  • 1
  • 20
  • 33

1 Answers1

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.

Quentin Engles
  • 2,744
  • 1
  • 20
  • 33
  • 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. – Quentin Engles Feb 12 '13 at 04:46
  • The problem is wait_for_text deselects the text it retrieves. Any one have an idea to fix this? – Quentin Engles Feb 12 '13 at 05:24