This commit is contained in:
Kovid Goyal 2019-08-20 21:07:40 +05:30
parent 37bde2c949
commit 31118409ae
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,8 +8,8 @@ import os
import sys import sys
from PyQt5.Qt import ( from PyQt5.Qt import (
QApplication, QComboBox, QHBoxLayout, QLabel, Qt, QTimer, QUrl, QVBoxLayout, QApplication, QComboBox, QDialog, QHBoxLayout, QIcon, QLabel, QPushButton, Qt,
QWidget QTimer, QUrl, QVBoxLayout, QWidget
) )
from PyQt5.QtWebEngineWidgets import ( from PyQt5.QtWebEngineWidgets import (
QWebEnginePage, QWebEngineProfile, QWebEngineView QWebEnginePage, QWebEngineProfile, QWebEngineView
@ -19,6 +19,7 @@ from calibre import prints, random_user_agent
from calibre.constants import cache_dir from calibre.constants import cache_dir
from calibre.gui2.viewer.web_view import vprefs from calibre.gui2.viewer.web_view import vprefs
from calibre.gui2.webengine import create_script, insert_scripts, secure_webengine from calibre.gui2.webengine import create_script, insert_scripts, secure_webengine
from calibre.gui2.widgets2 import Dialog
vprefs.defaults['lookup_locations'] = [ vprefs.defaults['lookup_locations'] = [
{ {
@ -42,6 +43,15 @@ vprefs.defaults['lookup_locations'] = [
vprefs.defaults['lookup_location'] = 'Google dictionary' vprefs.defaults['lookup_location'] = 'Google dictionary'
class SourcesEditor(Dialog):
def __init__(self, parent):
Dialog.__init__(self, _('Edit lookup sources'), 'viewer-edit-lookup-sources', parent=parent)
def setup_ui(self):
pass
def create_profile(): def create_profile():
ans = getattr(create_profile, 'ans', None) ans = getattr(create_profile, 'ans', None)
if ans is None: if ans is None:
@ -91,6 +101,14 @@ class Lookup(QWidget):
self.source_box.currentIndexChanged.connect(self.source_changed) self.source_box.currentIndexChanged.connect(self.source_changed)
self.view.setHtml('<p>' + _('Double click on a word in the viewer window' self.view.setHtml('<p>' + _('Double click on a word in the viewer window'
' to look it up.')) ' to look it up.'))
self.add_button = b = QPushButton(QIcon(I('plus.png')), _('Add more sources'))
b.clicked.connect(self.add_sources)
l.addWidget(b)
def add_sources(self):
if SourcesEditor(self).exec_() == QDialog.Accepted:
self.populate_sources()
self.update_query()
def source_changed(self): def source_changed(self):
vprefs['lookup_location'] = self.source['name'] vprefs['lookup_location'] = self.source['name']
@ -99,11 +117,13 @@ class Lookup(QWidget):
def populate_sources(self): def populate_sources(self):
sb = self.source_box sb = self.source_box
sb.clear() sb.clear()
sb.blockSignals(True)
for item in vprefs['lookup_locations']: for item in vprefs['lookup_locations']:
sb.addItem(item['name'], item) sb.addItem(item['name'], item)
idx = sb.findText(vprefs['lookup_location'], Qt.MatchExactly) idx = sb.findText(vprefs['lookup_location'], Qt.MatchExactly)
if idx > -1: if idx > -1:
sb.setCurrentIndex(idx) sb.setCurrentIndex(idx)
sb.blockSignals(False)
def visibility_changed(self, is_visible): def visibility_changed(self, is_visible):
self.is_visible = is_visible self.is_visible = is_visible