Skip to content
Permalink
Browse files
Port to WebKit2
Tested-by: James Cameron <quozl@laptop.org>
  • Loading branch information
sanatankc authored and quozl committed Dec 29, 2017
1 parent f02ccfe commit ae8ccca
Showing 1 changed file with 8 additions and 11 deletions.
@@ -20,15 +20,15 @@
import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit', '3.0')
gi.require_version('WebKit2', '4.0')
gi.require_version('Gst', '1.0')

from gi.repository import GObject
GObject.threads_init()
from gi.repository import Gdk
from gi.repository import Gtk
from gi.repository import Pango
from gi.repository import WebKit
from gi.repository import WebKit2 as WebKit


import logging
@@ -57,7 +57,6 @@
EMPTY_HTML = '<body bgcolor="#E5E5E5"></body>'
_AUTOSEARCH_TIMEOUT = 1000


class FilterToolItem(Gtk.ToolButton):

_LABEL_MAX_WIDTH = 18
@@ -456,13 +455,11 @@ def __init__(self, handle):
speak2.set_halign(Gtk.Align.END)
speak2.connect("clicked", self.__speak_dictionary_cb)
result_container.attach(speak2, 1, 2, 1, 1)

self.dictionary = WebKit.WebView()
self.dictionary.load_html_string(EMPTY_HTML, 'file:///')
self.dictionary.load_html(EMPTY_HTML, 'file:///')
self.dictionary.set_zoom_level(0.75)
settings = self.dictionary.get_settings()
settings.set_property('enable-default-context-menu', False)
self.dictionary.set_settings(settings)
# Removes right-click context menu
self.dictionary.connect("button-press-event", lambda w, e: e.button == 3)

scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,
@@ -605,7 +602,7 @@ def _translate(self, inmediate_suggestions=False):
self._suggestions_model.clear()
self.translated.get_buffer().set_text('')
self._html_definition = ''
self.dictionary.load_html_string(EMPTY_HTML, 'file:///')
self.dictionary.load_html(EMPTY_HTML, 'file:///')
return

# verify if the languagemodel is right
@@ -650,7 +647,7 @@ def _get_suggestions(self, text):

def _get_definition(self, text):
self._html_definition = ''
self.dictionary.load_html_string(EMPTY_HTML, 'file:///')
self.dictionary.load_html(EMPTY_HTML, 'file:///')
if self.origin_lang == 'eng' and self._english_dictionary is not None:
definition = self._english_dictionary.get_definition(text)
if definition:
@@ -662,4 +659,4 @@ def _get_definition(self, text):
# set background color to #E5E5E5
html = '<body bgcolor="#E5E5E5">' + html + '</body>'
self._html_definition = html
self.dictionary.load_html_string(html, 'file:///')
self.dictionary.load_html(html, 'file:///')

0 comments on commit ae8ccca

Please sign in to comment.