diff --git a/plover/gui_qt/lookup_dialog.py b/plover/gui_qt/lookup_dialog.py
index fd868fba5..d70c5c74b 100644
--- a/plover/gui_qt/lookup_dialog.py
+++ b/plover/gui_qt/lookup_dialog.py
@@ -1,10 +1,20 @@
from PyQt5.QtCore import QEvent, Qt
+from PyQt5.QtGui import (
+ QCursor,
+ QFont,
+)
+from PyQt5.QtWidgets import (
+ QAction,
+ QFontDialog,
+ QMenu,
+)
from plover import _
from plover.translation import unescape_translation
from plover.gui_qt.lookup_dialog_ui import Ui_LookupDialog
+from plover.gui_qt.utils import ToolBar
from plover.gui_qt.tool import Tool
@@ -26,6 +36,45 @@ def __init__(self, engine):
self.pattern.setFocus()
self.restore_state()
self.finished.connect(self.save_state)
+ self.layout().addWidget(ToolBar(
+ self.action_SelectFont,
+ ))
+
+ # Font popup menu.
+ self._font_menu = QMenu()
+ # i18n: Widget: “SuggestionsDialog”, “font” menu.
+ self._font_menu_text = QAction(_('&Text'), self._font_menu)
+ # i18n: Widget: “SuggestionsDialog”, “font” menu.
+ self._font_menu_strokes = QAction(_('&Strokes'), self._font_menu)
+ self._font_menu.addActions([self._font_menu_text, self._font_menu_strokes])
+
+ def _get_font(self, name):
+ return getattr(self.suggestions, name)
+
+ def _set_font(self, name, font):
+ setattr(self.suggestions, name, font)
+
+ def _restore_state(self, settings):
+ for name in (
+ 'text_font',
+ 'strokes_font',
+ ):
+ font_string = settings.value(name)
+ if font_string is None:
+ continue
+ font = QFont()
+ if not font.fromString(font_string):
+ continue
+ self._set_font(name, font)
+
+ def _save_state(self, settings):
+ for name in (
+ 'text_font',
+ 'strokes_font',
+ ):
+ font = self._get_font(name)
+ font_string = font.toString()
+ settings.setValue(name, font_string)
def eventFilter(self, watched, event):
if event.type() == QEvent.KeyPress and \
@@ -47,3 +96,18 @@ def changeEvent(self, event):
if event.type() == QEvent.ActivationChange and self.isActiveWindow():
self.pattern.setFocus()
self.pattern.selectAll()
+
+ def on_select_font(self):
+ action = self._font_menu.exec_(QCursor.pos())
+ if action is None:
+ return
+ if action == self._font_menu_text:
+ name = 'text_font'
+ font_options = ()
+ elif action == self._font_menu_strokes:
+ name = 'strokes_font'
+ font_options = (QFontDialog.MonospacedFonts,)
+ font = self._get_font(name)
+ font, ok = QFontDialog.getFont(font, self, '', *font_options)
+ if ok:
+ self._set_font(name, font)
diff --git a/plover/gui_qt/lookup_dialog.ui b/plover/gui_qt/lookup_dialog.ui
index 61b7713f7..4c70a0b30 100644
--- a/plover/gui_qt/lookup_dialog.ui
+++ b/plover/gui_qt/lookup_dialog.ui
@@ -23,16 +23,6 @@
true
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::NoButton
-
-
-
-
@@ -63,6 +53,18 @@
+
+
+
+ :/font_selector.svg:/font_selector.svg
+
+
+ Select &font
+
+
+ Open font selection dialog.
+
+
@@ -75,55 +77,40 @@
- buttonBox
- accepted()
- LookupDialog
- accept()
-
-
- 248
- 254
-
-
- 157
- 274
-
-
-
-
- buttonBox
- rejected()
+ pattern
+ textEdited(QString)
LookupDialog
- reject()
+ on_lookup(QString)
- 316
- 260
+ 190
+ 19
- 286
- 274
+ 190
+ 130
- pattern
- textEdited(QString)
+ action_SelectFont
+ triggered()
LookupDialog
- on_lookup(QString)
+ on_select_font()
- 190
- 19
+ -1
+ -1
- 190
- 130
+ 123
+ 214
on_lookup(QString)
+ on_select_font()