Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions dialect/dialect.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<gresources>
<gresource prefix="/app/drey/Dialect">
<file compressed="true">style.css</file>
<file compressed="true">style-dark.css</file>

<file compressed="true" preprocess="xml-stripblanks">preferences.ui</file>
<file compressed="true" preprocess="xml-stripblanks">shortcuts.ui</file>
<file
compressed="true"
preprocess="xml-stripblanks"
>shortcuts-dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks">window.ui</file>
<file compressed="true" preprocess="xml-stripblanks">widgets/lang_row.ui</file>
<file compressed="true" preprocess="xml-stripblanks">widgets/lang_selector.ui</file>
<file compressed="true" preprocess="xml-stripblanks">widgets/provider_preferences.ui</file>
<file compressed="true" preprocess="xml-stripblanks">widgets/speech_button.ui</file>
<file compressed="true" preprocess="xml-stripblanks">widgets/theme_switcher.ui</file>
<file
compressed="true"
preprocess="xml-stripblanks"
>widgets/lang_row.ui</file>
<file
compressed="true"
preprocess="xml-stripblanks"
>widgets/lang_selector.ui</file>
<file
compressed="true"
preprocess="xml-stripblanks"
>widgets/provider_preferences.ui</file>
<file
compressed="true"
preprocess="xml-stripblanks"
>widgets/speech_button.ui</file>
<file
compressed="true"
preprocess="xml-stripblanks"
>widgets/theme_switcher.ui</file>

<file compressed="true" preprocess="xml-stripblanks" alias="appdata.xml">@appstream-path@</file>
<file
compressed="true"
preprocess="xml-stripblanks"
alias="appdata.xml"
>@appstream-path@</file>
</gresource>

<gresource prefix="/app/drey/Dialect/icons/scalable/emblems/">
<file preprocess="xml-stripblanks" alias="dialect-settings-symbolic.svg">icons/settings-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="dialect-speakers-broken-symbolic.svg">icons/speakers-broken-symbolic.svg</file>
<file
preprocess="xml-stripblanks"
alias="dialect-settings-symbolic.svg"
>icons/settings-symbolic.svg</file>
<file
preprocess="xml-stripblanks"
alias="dialect-speakers-broken-symbolic.svg"
>icons/speakers-broken-symbolic.svg</file>
</gresource>
</gresources>
29 changes: 27 additions & 2 deletions dialect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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", ["<Primary>P"])
self.set_accels_for_action("app.preferences", ["<Primary>comma"])
self.set_accels_for_action("app.shortcuts", ["<Primary>question"])
self.set_accels_for_action("app.quit", ["<Primary>Q"])

self.set_accels_for_action("win.back", ["<Alt>Left"])
Expand All @@ -164,7 +169,6 @@ def setup_actions(self):
self.set_accels_for_action("win.copy", ["<Primary><Shift>C"])
self.set_accels_for_action("win.listen-dest", ["<Primary>L"])
self.set_accels_for_action("win.listen-src", ["<Primary><Shift>L"])
self.set_accels_for_action("win.show-help-overlay", ["<Primary>question"])

def _on_pronunciation(self, action: Gio.SimpleAction, value: GLib.Variant):
"""Update show pronunciation setting"""
Expand Down Expand Up @@ -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()

Expand Down
5 changes: 2 additions & 3 deletions dialect/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -65,7 +65,6 @@ sources = [
'preferences.py',
'session.py',
'settings.py',
'shortcuts.py',
'utils.py',
'window.py',
]
Expand All @@ -76,4 +75,4 @@ install_data(sources, install_dir: moduledir)
install_subdir('widgets', install_dir: moduledir)

# Install providers
install_subdir('providers', install_dir: moduledir)
install_subdir('providers', install_dir: moduledir)
95 changes: 95 additions & 0 deletions dialect/shortcuts-dialog.blp
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
108 changes: 0 additions & 108 deletions dialect/shortcuts.blp

This file was deleted.

24 changes: 0 additions & 24 deletions dialect/shortcuts.py

This file was deleted.

Empty file removed dialect/style-dark.css
Empty file.
Loading