diff --git a/dialect/dialect.gresource.xml b/dialect/dialect.gresource.xml
index 803f73a5..98dd4aee 100644
--- a/dialect/dialect.gresource.xml
+++ b/dialect/dialect.gresource.xml
@@ -1,23 +1,50 @@
-
+
style.css
- style-dark.css
preferences.ui
- shortcuts.ui
+ shortcuts-dialog.ui
window.ui
- widgets/lang_row.ui
- widgets/lang_selector.ui
- widgets/provider_preferences.ui
- widgets/speech_button.ui
- widgets/theme_switcher.ui
+ widgets/lang_row.ui
+ widgets/lang_selector.ui
+ widgets/provider_preferences.ui
+ widgets/speech_button.ui
+ widgets/theme_switcher.ui
- @appstream-path@
+ @appstream-path@
- icons/settings-symbolic.svg
- icons/speakers-broken-symbolic.svg
+ icons/settings-symbolic.svg
+ icons/speakers-broken-symbolic.svg
diff --git a/dialect/main.py b/dialect/main.py
index 68e7cd92..ee7a8984 100755
--- a/dialect/main.py
+++ b/dialect/main.py
@@ -21,7 +21,7 @@
gi.require_version("Spelling", "1")
gi.require_version("GtkSource", "5")
- from gi.repository import Adw, Gio, GLib, Gst
+ from gi.repository import Adw, Gio, GLib, Gst, Gtk
except ImportError or ValueError:
logging.error("Error: GObject dependencies not met.")
exit()
@@ -144,12 +144,17 @@ def setup_actions(self):
about.connect("activate", self._on_about)
self.add_action(about)
+ shortcuts = Gio.SimpleAction(name="shortcuts")
+ shortcuts.connect("activate", self._on_shortcuts)
+ self.add_action(shortcuts)
+
quit_action = Gio.SimpleAction(name="quit")
quit_action.connect("activate", self._on_quit)
self.add_action(quit_action)
self.set_accels_for_action("app.pronunciation", ["P"])
self.set_accels_for_action("app.preferences", ["comma"])
+ self.set_accels_for_action("app.shortcuts", ["question"])
self.set_accels_for_action("app.quit", ["Q"])
self.set_accels_for_action("win.back", ["Left"])
@@ -164,7 +169,6 @@ def setup_actions(self):
self.set_accels_for_action("win.copy", ["C"])
self.set_accels_for_action("win.listen-dest", ["L"])
self.set_accels_for_action("win.listen-src", ["L"])
- self.set_accels_for_action("win.show-help-overlay", ["question"])
def _on_pronunciation(self, action: Gio.SimpleAction, value: GLib.Variant):
"""Update show pronunciation setting"""
@@ -193,6 +197,27 @@ def _on_about(self, _action, _param):
about.present(self.window)
+ def _on_shortcuts(self, _action, _param):
+ """Show shortcuts dialog"""
+ if not self.window:
+ return
+
+ # Load the shortcuts dialog from resources
+ builder = Gtk.Builder.new_from_resource(f"{RES_PATH}/shortcuts-dialog.ui")
+ dialog = builder.get_object("shortcuts_dialog")
+ translation_section = builder.get_object("translation_section")
+
+ if not Settings.get().live_translation:
+ # Set the accelerator from settings
+ translate_shortcut = Adw.ShortcutsItem(
+ title=_("Translate"),
+ accelerator=Settings.get().translate_accel,
+ )
+ translation_section.add(translate_shortcut)
+
+ if dialog:
+ dialog.present(self.window)
+
def _on_quit(self, _action, _param):
self.quit()
diff --git a/dialect/meson.build b/dialect/meson.build
index 79c4b6ea..78358a56 100644
--- a/dialect/meson.build
+++ b/dialect/meson.build
@@ -5,7 +5,7 @@ pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.proje
# Resources
blueprints = custom_target('blueprints',
input: files(
- 'shortcuts.blp',
+ 'shortcuts-dialog.blp',
'window.blp',
'widgets/lang_selector.blp',
'widgets/lang_row.blp',
@@ -65,7 +65,6 @@ sources = [
'preferences.py',
'session.py',
'settings.py',
- 'shortcuts.py',
'utils.py',
'window.py',
]
@@ -76,4 +75,4 @@ install_data(sources, install_dir: moduledir)
install_subdir('widgets', install_dir: moduledir)
# Install providers
-install_subdir('providers', install_dir: moduledir)
\ No newline at end of file
+install_subdir('providers', install_dir: moduledir)
diff --git a/dialect/shortcuts-dialog.blp b/dialect/shortcuts-dialog.blp
new file mode 100644
index 00000000..e09a98a0
--- /dev/null
+++ b/dialect/shortcuts-dialog.blp
@@ -0,0 +1,95 @@
+using Gtk 4.0;
+using Adw 1;
+
+Adw.ShortcutsDialog shortcuts_dialog {
+ Adw.ShortcutsSection translation_section {
+ title: C_("shortcuts window", "Translator");
+
+ Adw.ShortcutsItem switch_shortcut {
+ title: C_("shortcuts window", "Switch Languages");
+ action-name: "win.switch";
+ }
+
+ Adw.ShortcutsItem from_shortcut {
+ title: C_("shortcuts window", "Select source language");
+ action-name: "win.from";
+ }
+
+ Adw.ShortcutsItem to_shortcut {
+ title: C_("shortcuts window", "Select destination language");
+ action-name: "win.to";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Clear source text");
+ action-name: "win.clear";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Copy translation");
+ action-name: "win.copy";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Show Pronunciation");
+ action-name: "app.pronunciation";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Increase font size");
+ action-name: "win.font-size-inc";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Decrease font size");
+ action-name: "win.font-size-dec";
+ }
+ }
+
+ Adw.ShortcutsSection {
+ title: C_("shortcuts window", "Text-to-Speech");
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Listen to source text");
+ action-name: "win.listen-src";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Listen to translation");
+ action-name: "win.listen-dest";
+ }
+ }
+
+ Adw.ShortcutsSection {
+ title: C_("shortcuts window", "Navigation");
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Go back in history");
+ action-name: "win.back";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Go forward in history");
+ action-name: "win.forward";
+ }
+ }
+
+ Adw.ShortcutsSection {
+ title: C_("shortcuts window", "General");
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Preferences");
+ action-name: "app.preferences";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcut window", "Shortcuts");
+ action-name: "app.shortcuts";
+ }
+
+ Adw.ShortcutsItem {
+ title: C_("shortcuts window", "Quit");
+ action-name: "app.quit";
+ }
+ }
+}
diff --git a/dialect/shortcuts.blp b/dialect/shortcuts.blp
deleted file mode 100644
index 99187018..00000000
--- a/dialect/shortcuts.blp
+++ /dev/null
@@ -1,108 +0,0 @@
-using Gtk 4.0;
-
-template $DialectShortcutsWindow : ShortcutsWindow {
- modal: true;
-
- show => $_on_show();
-
- ShortcutsSection {
- section-name: "shortcuts";
- max-height: 10;
-
- ShortcutsGroup {
- title: C_("shortcuts window", "Translator");
-
- ShortcutsShortcut translate_shortcut {
- title: C_("shortcuts window", "Translate");
- accelerator: "Return";
- }
-
- ShortcutsShortcut switch_shortcut {
- title: C_("shortcuts window", "Switch Languages");
- action-name: "win.switch";
- }
-
- ShortcutsShortcut from_shortcut {
- title: C_("shortcuts window", "Select source language");
- action-name: "win.from";
- }
-
- ShortcutsShortcut to_shortcut {
- title: C_("shortcuts window", "Select destination language");
- action-name: "win.to";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Clear source text");
- action-name: "win.clear";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Copy translation");
- action-name: "win.copy";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Show Pronunciation");
- action-name: "app.pronunciation";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Increase font size");
- action-name: "win.font-size-inc";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Decrease font size");
- action-name: "win.font-size-dec";
- }
- }
-
- ShortcutsGroup {
- title: C_("shortcuts window", "Text-to-Speech");
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Listen to source text");
- action-name: "win.listen-src";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Listen to translation");
- action-name: "win.listen-dest";
- }
- }
-
- ShortcutsGroup {
- title: C_("shortcuts window", "Navigation");
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Go back in history");
- action-name: "win.back";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Go forward in history");
- action-name: "win.forward";
- }
- }
-
- ShortcutsGroup {
- title: C_("shortcuts window", "General");
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Preferences");
- action-name: "app.preferences";
- }
-
- ShortcutsShortcut {
- title: C_("shortcut window", "Shortcuts");
- action-name: "win.show-help-overlay";
- }
-
- ShortcutsShortcut {
- title: C_("shortcuts window", "Quit");
- action-name: "app.quit";
- }
- }
- }
-}
diff --git a/dialect/shortcuts.py b/dialect/shortcuts.py
deleted file mode 100644
index 966c7e30..00000000
--- a/dialect/shortcuts.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright 2021 Mufeed Ali
-# Copyright 2021 Rafael Mardojai CM
-# SPDX-License-Identifier: GPL-3.0-or-later
-
-from gi.repository import Gtk
-
-from dialect.define import RES_PATH
-from dialect.settings import Settings
-
-
-@Gtk.Template(resource_path=f"{RES_PATH}/shortcuts.ui")
-class DialectShortcutsWindow(Gtk.ShortcutsWindow):
- __gtype_name__ = "DialectShortcutsWindow"
-
- translate_shortcut: Gtk.ShortcutsShortcut = Gtk.Template.Child() # type: ignore
-
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
-
- @Gtk.Template.Callback()
- def _on_show(self, _data):
- """Called on self::show signal"""
- self.translate_shortcut.props.visible = not Settings.get().live_translation
- self.translate_shortcut.props.accelerator = Settings.get().translate_accel
diff --git a/dialect/style-dark.css b/dialect/style-dark.css
deleted file mode 100644
index e69de29b..00000000
diff --git a/dialect/window.blp b/dialect/window.blp
index e21dadc5..ba911cc5 100644
--- a/dialect/window.blp
+++ b/dialect/window.blp
@@ -27,7 +27,7 @@ menu app-menu {
item {
label: _("Keyboard Shortcuts");
- action: "win.show-help-overlay";
+ action: "app.shortcuts";
}
item {
@@ -37,17 +37,17 @@ menu app-menu {
}
}
-template $DialectWindow : Adw.ApplicationWindow {
+template $DialectWindow: Adw.ApplicationWindow {
default-width: 800;
default-height: 300;
width-request: 360;
height-request: 320;
focus-widget: src_text;
-
notify::is-active => $_on_is_active_changed();
Adw.Breakpoint {
condition ("max-width: 680px")
+
setters {
multi_layout.layout-name: "mobile";
error_buttons.orientation: vertical;
@@ -62,6 +62,7 @@ template $DialectWindow : Adw.ApplicationWindow {
StackPage {
name: "loading";
+
child: WindowHandle {
Adw.StatusPage loading_page {
paintable: Adw.SpinnerPaintable {
@@ -77,8 +78,8 @@ template $DialectWindow : Adw.ApplicationWindow {
StackPage {
name: "error";
- child: Adw.ToolbarView {
+ child: Adw.ToolbarView {
[top]
Adw.HeaderBar {}
@@ -116,8 +117,8 @@ template $DialectWindow : Adw.ApplicationWindow {
StackPage {
name: "api-key";
- child: Adw.ToolbarView {
+ child: Adw.ToolbarView {
[top]
Adw.HeaderBar {}
@@ -158,22 +159,22 @@ template $DialectWindow : Adw.ApplicationWindow {
/* Translation View */
StackPage {
name: "translate";
+
child: Adw.ToastOverlay toast_overlay {
vexpand: true;
child: Adw.MultiLayoutView multi_layout {
-
/* Desktop Layout */
Adw.Layout {
name: "desktop";
- content: Adw.ToolbarView {
+ content: Adw.ToolbarView {
[top]
Adw.HeaderBar {
centering-policy: strict;
title-widget: Adw.LayoutSlot {
- id: "langs-selector";
+ id: "langs-selector";
};
Adw.LayoutSlot {
@@ -199,10 +200,10 @@ template $DialectWindow : Adw.ApplicationWindow {
/* Mobile Layout */
Adw.Layout {
name: "mobile";
+
content: Adw.ToolbarView {
[top]
Adw.HeaderBar {
-
Adw.LayoutSlot {
id: "back-btn";
}
@@ -224,7 +225,6 @@ template $DialectWindow : Adw.ApplicationWindow {
[bottom]
Adw.LayoutSlot {
id: "langs-selector";
-
halign: center;
styles [
@@ -235,6 +235,7 @@ template $DialectWindow : Adw.ApplicationWindow {
}
/* Menu */
+
[menu]
MenuButton menu_btn {
menu-model: app-menu;
@@ -244,6 +245,7 @@ template $DialectWindow : Adw.ApplicationWindow {
}
/* Nav back */
+
[back-btn]
Button return_btn {
action-name: "win.back";
@@ -252,6 +254,7 @@ template $DialectWindow : Adw.ApplicationWindow {
}
/* Nav forward */
+
[forward-btn]
Button forward_btn {
action-name: "win.forward";
@@ -260,6 +263,7 @@ template $DialectWindow : Adw.ApplicationWindow {
}
/* Languages Selector */
+
[langs-selector]
Box langs_button_box {
spacing: 6;
@@ -284,6 +288,7 @@ template $DialectWindow : Adw.ApplicationWindow {
}
/* Translation Booxes */
+
[translation]
Box translator_box {
vexpand: true;
@@ -311,12 +316,11 @@ template $DialectWindow : Adw.ApplicationWindow {
right-margin: 9;
top-margin: 9;
bottom-margin: 9;
-
activate => $_on_src_activated();
}
styles [
- "translation-scrolled"
+ "translation-scrolled",
]
}
@@ -340,7 +344,7 @@ template $DialectWindow : Adw.ApplicationWindow {
styles [
"translation-scrolled",
- "top-undershoot"
+ "top-undershoot",
]
}
}
@@ -363,13 +367,12 @@ template $DialectWindow : Adw.ApplicationWindow {
can-focus: false;
wrap: true;
wrap-mode: word_char;
-
activate-link => $_on_mistakes_clicked();
}
styles [
"card",
- "mistakes"
+ "mistakes",
]
}
}
@@ -405,7 +408,7 @@ template $DialectWindow : Adw.ApplicationWindow {
styles [
"dim-label",
"caption-heading",
- "numeric"
+ "numeric",
]
}
@@ -445,7 +448,7 @@ template $DialectWindow : Adw.ApplicationWindow {
}
styles [
- "translation-scrolled"
+ "translation-scrolled",
]
}
@@ -469,7 +472,7 @@ template $DialectWindow : Adw.ApplicationWindow {
styles [
"translation-scrolled",
- "top-undershoot"
+ "top-undershoot",
]
}
}
@@ -479,6 +482,7 @@ template $DialectWindow : Adw.ApplicationWindow {
StackPage {
name: "default";
+
child: Box {
Adw.Spinner trans_spinner {
tooltip-text: _("Translating…");
@@ -522,6 +526,7 @@ template $DialectWindow : Adw.ApplicationWindow {
StackPage {
name: "edit";
+
child: Box {
Button cancel_btn {
action-name: "win.suggest-cancel";
@@ -559,10 +564,20 @@ template $DialectWindow : Adw.ApplicationWindow {
Gtk.SizeGroup {
mode: both;
- widgets [src_lang_selector, dest_lang_selector]
+
+ widgets [
+ src_lang_selector,
+ dest_lang_selector,
+ ]
}
Gtk.SizeGroup mobile_buttons_size {
mode: none;
- widgets [error_retry_btn, error_open_prefs_btn, rmv_key_btn, key_open_prefs_btn]
+
+ widgets [
+ error_retry_btn,
+ error_open_prefs_btn,
+ rmv_key_btn,
+ key_open_prefs_btn,
+ ]
}
diff --git a/dialect/window.py b/dialect/window.py
index 4f00f1f6..9ae83f30 100644
--- a/dialect/window.py
+++ b/dialect/window.py
@@ -25,7 +25,6 @@
TranslationRequest,
)
from dialect.settings import Settings
-from dialect.shortcuts import DialectShortcutsWindow
from dialect.utils import find_item_match, first_exclude
from dialect.widgets import LangSelector, SpeechButton, TextView, ThemeSwitcher
@@ -222,7 +221,6 @@ def setup(self):
self.setup_selectors()
self.setup_translation()
self.setup_spell_checking()
- self.set_help_overlay(DialectShortcutsWindow())
# Load translator
self.load_translator()