From 9e620ce6e9c71edd2b8b02eea4e85698cec0b836 Mon Sep 17 00:00:00 2001 From: Michal Siedlaczek Date: Thu, 21 Sep 2017 12:09:55 -0400 Subject: [PATCH] Fix spell with new config --- MANIFEST.in | 2 +- .../browser/webengine/webenginesettings.py | 10 ++++------ qutebrowser/config/configdata.yml | 15 +++++++++++++++ tests/unit/browser/webengine/test_spell.py | 7 ++++--- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index d6f9e713a..b8ae5c718 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -18,7 +18,7 @@ include tox.ini include qutebrowser.py include misc/cheatsheet.svg include qutebrowser/config/configdata.yml -include misc/lang_list +include qutebrowser/browser/webengine/langs.tsv prune www prune scripts/dev diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py index 9124fec06..ed87dd88f 100644 --- a/qutebrowser/browser/webengine/webenginesettings.py +++ b/qutebrowser/browser/webengine/webenginesettings.py @@ -27,9 +27,9 @@ Module attributes: constants. """ -import os import ctypes import ctypes.util +import os from PyQt5.QtGui import QFont from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile, @@ -38,8 +38,7 @@ from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile, from qutebrowser.browser import shared from qutebrowser.browser.webengine.spell import get_installed_languages from qutebrowser.config import config, websettings -from qutebrowser.utils import utils, standarddir, javascript, qtutils - +from qutebrowser.utils import utils, standarddir, javascript, qtutils, message # The default QWebEngineProfile default_profile = None @@ -133,8 +132,7 @@ class DictionaryLanguageSetter(DefaultProfileSetter): """Sets paths to dictionary files based on language codes.""" def __init__(self): - super().__init__('setSpellCheckLanguages', default=[], - min_version='5.8') + super().__init__('setSpellCheckLanguages', default=[]) def _set(self, value, settings=None): if settings is not None: @@ -326,7 +324,7 @@ MAPPINGS = { Attribute(QWebEngineSettings.ScrollAnimatorEnabled), 'spell': DefaultProfileSetter('setSpellCheckEnabled'), - 'spell-languages': DictionaryLanguageSetter() + 'spell_languages': DictionaryLanguageSetter() } try: diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index f0e5ae74d..3eae6890e 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -975,6 +975,21 @@ scrolling.smooth: Note smooth scrolling does not work with the `:scroll-px` command. +## spell + +spell: + type: Bool + default: true + desc: Enable spell checking. + +spell_languages: + type: + name: List + valtype: String + none_ok: true + default: + desc: Spell checking languages. + ## statusbar statusbar.hide: diff --git a/tests/unit/browser/webengine/test_spell.py b/tests/unit/browser/webengine/test_spell.py index e7d353cbf..8c802881c 100644 --- a/tests/unit/browser/webengine/test_spell.py +++ b/tests/unit/browser/webengine/test_spell.py @@ -47,8 +47,9 @@ def test_get_installed_languages_non_empty(tmpdir, mocker): mocker.patch('qutebrowser.browser.webengine.spell.get_dictionary_dir', lambda: str(tmpdir)) for lang in LANGUAGE_LIST: - open(join(tmpdir, lang.file), 'w').close() - for actual, expected in zip(spell.get_installed_languages(), LANGUAGE_LIST): + open(join(tmpdir, lang.file), 'w', encoding='UTF-8').close() + for actual, expected in zip(spell.get_installed_languages(), + LANGUAGE_LIST): assert (actual.code, actual.name, actual.file) ==\ (expected.code, expected.name, expected.file) @@ -79,7 +80,7 @@ def test_install(tmpdir, mocker): mocker.patch('qutebrowser.browser.webengine.spell.get_dictionary_dir', lambda: str(tmpdir)) mocker.patch('qutebrowser.browser.webengine.spell.download_dictionary', - lambda url, dest: open(dest, 'w').close()) + lambda url, dest: open(dest, 'w', encoding='UTF-8').close()) spell.install(LANGUAGE_LIST) installed_files = [basename(str(file)) for file in tmpdir.listdir()] expected_files = [lang.file for lang in LANGUAGE_LIST]