Skip to content

Commit

Permalink
feat: added quick edit dialog
Browse files Browse the repository at this point in the history
dialog for fast lyrics preparation before syncing
  • Loading branch information
Dzheremi2 committed Dec 4, 2024
1 parent 8f60182 commit 9d6896d
Show file tree
Hide file tree
Showing 30 changed files with 1,305 additions and 805 deletions.
11 changes: 10 additions & 1 deletion data/gtk/components/preferences.blp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ using Gtk 4.0;
using Adw 1;

template $LrcmakePreferences: Adw.PreferencesDialog {
height-request: 300;
height-request: 330;

Adw.PreferencesPage {
title: _("General");
icon-name: "general-page-symbolic";

Adw.PreferencesGroup {
title: _("General App Behavior");

Adw.SwitchRow reset_quick_edit_on_close_switch {
title: _("Reset quick edit dialog on close?");
subtitle: _("Choose, if quick edit dialog text should be cleaned after exit or not");
}
}

Adw.PreferencesGroup {
title: _("Sync Page Behavior");

Expand Down
58 changes: 56 additions & 2 deletions data/gtk/window.blp
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
using Gtk 4.0;
using Adw 1;

Adw.Dialog quick_edit_dialog {
width-request: 500;
height-request: 600;
can-close: true;

Adw.ToolbarView {
margin-bottom: 12;
margin-end: 12;
margin-start: 12;
margin-top: 12;

[top]
Adw.HeaderBar {
Label {
label: _("Quick edit");

styles [
'title-3'
]
}
}

ScrolledWindow {
TextView quick_edit_dialog_input {
right-margin: 4;
bottom-margin: 4;
top-margin: 4;
left-margin: 4;
}
}

[bottom]
Box {
orientation: horizontal;
margin-top: 4;
halign: end;

Button quick_edit_dialog_copy_button {
label: _("Copy to clipboard");

styles [
"suggested-action",
]
}
}
}
}

template $LrcmakeWindow: Adw.ApplicationWindow {
default-height: 735;
default-width: 910;
Expand Down Expand Up @@ -32,7 +80,7 @@ template $LrcmakeWindow: Adw.ApplicationWindow {

[end]
MenuButton {
tooltip-text: _("App settings and info");
tooltip-text: _("App settings, info and utils");
icon-name: "app-menu-symbolic";
menu-model: about_app;
}
Expand Down Expand Up @@ -82,7 +130,7 @@ template $LrcmakeWindow: Adw.ApplicationWindow {
max-children-per-line: 100;
homogeneous: true;
halign: center;
valign: center;
valign: start;
column-spacing: 12;
row-spacing: 12;
margin-top: 12;
Expand Down Expand Up @@ -402,6 +450,12 @@ menu line_actions {
}

menu about_app {
section {
item {
label: _("Quick edit");
action: "app.open_quick_edit";
}
}
section {
item {
label: _("Preferences");
Expand Down
3 changes: 3 additions & 0 deletions data/io.github.dzheremi2.lrcmake-gtk.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</choices>
<default>".lrc"</default>
</key>
<key name="reset-quick-edit-on-close" type="b">
<default>true</default>
</key>
</schema>

<schema id="@APP_ID@.State" path="@PREFIX@/State/">
Expand Down
4 changes: 3 additions & 1 deletion lrcmake/components/preferences.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gi.repository import Gtk, Adw, Gio
from gi.repository import Gtk, Adw, Gio # type: ignore
from lrcmake import shared

@Gtk.Template(resource_path="/io/github/dzheremi2/lrcmake-gtk/gtk/components/preferences.ui")
Expand All @@ -7,6 +7,7 @@ class LrcmakePreferences(Adw.PreferencesDialog):

auto_file_manipulation_switch = Gtk.Template.Child()
auto_file_manipulation_format = Gtk.Template.Child()
reset_quick_edit_on_close_switch = Gtk.Template.Child()

opened = False

Expand All @@ -18,6 +19,7 @@ def __init__(self, **kwargs):
self.auto_file_manipulation_format.connect("notify::selected", self.update_auto_file_format_schema)

shared.schema.bind("auto-file-manipulation", self.auto_file_manipulation_switch, "enable-expansion", Gio.SettingsBindFlags.DEFAULT)
shared.schema.bind("reset-quick-edit-on-close", self.reset_quick_edit_on_close_switch, "active", Gio.SettingsBindFlags.DEFAULT)
if shared.schema.get_string("auto-file-format") == ".lrc":
self.auto_file_manipulation_format.set_selected(0)
elif shared.schema.get_string("auto-file-format") == ".txt":
Expand Down
4 changes: 1 addition & 3 deletions lrcmake/components/songCard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import Gdk
from gi.repository import Gtk, GLib, Gdk # type: ignore
from .fileDetails import fileDetails
from lrcmake import shared
import os
Expand Down
3 changes: 2 additions & 1 deletion lrcmake/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def do_activate(self):
sorting_action.connect("activate", shared.win.on_sorting_action)
self.add_action(sorting_action)
shared.win.music_lib.set_filter_func(filtering)
self.create_action('open_quick_edit', shared.win.show_quick_edit_dialog)

# Emmits when app is closed
def do_shutdown(self):
Expand Down Expand Up @@ -95,7 +96,7 @@ def show_about_dialog(self, *args):
)
)
dialog.set_designers(("Dzheremi",))
dialog.set_translator_credits(_("Thanks for all translators on Hosted Weblate! https://hosted.weblate.org/projects/lrcmake/lrcmake/"))
dialog.set_translator_credits(_("Thanks for all translators on Hosted Weblate! https://hosted.weblate.org/projects/lrcmake/lrcmake/")) # type: ignore
dialog.set_copyright("© 2024 Dzheremi")
dialog.add_legal_section(
"LRClib",
Expand Down
8 changes: 6 additions & 2 deletions lrcmake/methods/exportData.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gi.repository import Gdk, Adw, Gtk
from gi.repository import Gdk, Adw, Gtk # type: ignore

import re
from lrcmake.methods.parsers import arg_line_parser
Expand All @@ -13,6 +13,10 @@ def export_clipboard(*args):
lyrics = lyrics[:-1]
clipboard.set(lyrics)

def arg_export_clipboard(text):
clipboard = Gdk.Display.get_default().get_clipboard()
clipboard.set(text)

# Return string with synced lyrics for publishing
def prepare_synced_lyrics():
lyrics = ''
Expand All @@ -21,7 +25,7 @@ def prepare_synced_lyrics():
lyrics = lyrics + (child.get_text() + "\n")
else:
shared.win.export_lyrics.set_icon_name("export-to-symbolic")
toast = Adw.Toast(title=_("Seems like not every line is synced!"))
toast = Adw.Toast(title=_("Seems like not every line is synced!")) # type: ignore
shared.win.toast_overlay.add_toast(toast)
raise IndexError("Not all lines have timestamps")
lyrics = lyrics[:-1]
Expand Down
3 changes: 1 addition & 2 deletions lrcmake/methods/parsers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gi.repository import Gdk, GLib, Gtk
from gi.repository import Gdk, GLib, Gtk # type: ignore

import os
import eyed3
Expand All @@ -12,7 +12,6 @@
def dir_parser(path, *args):
shared.win.source_selection_button.set_child(Gtk.Spinner(spinning=True))
shared.win.music_lib.remove_all()
shared.win.music_lib.set_property('halign', 'start')
shared.win.music_lib.set_property('valign', 'start')
shared.win.music_lib.set_property('homogeneous', True)
for file in os.listdir(path + "/"):
Expand Down
3 changes: 1 addition & 2 deletions lrcmake/shared.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ state_schema = Gio.Settings.new(APP_ID + ".State")
app = None
win = None
selected_row = None
lyrics_list = None
scanning_progress = None
lyrics_list = None
47 changes: 37 additions & 10 deletions lrcmake/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@
from lrcmake.components.syncLine import syncLine
from lrcmake.components.fileDetails import fileDetails
from lrcmake.methods.parsers import timing_parser, arg_timing_parser, sorting
from lrcmake.methods.exportData import arg_export_clipboard
from lrcmake import shared

@Gtk.Template(resource_path='/io/github/dzheremi2/lrcmake-gtk/gtk/window.ui')
class LrcmakeWindow(Adw.ApplicationWindow):
__gtype_name__ = 'LrcmakeWindow'

# Main Window
source_selection_button = Gtk.Template.Child()
music_lib = Gtk.Template.Child()
nav_view = Gtk.Template.Child()
sort_revealer = Gtk.Template.Child()
sorting_menu = Gtk.Template.Child()
library = Gtk.Template.Child()
search_button = Gtk.Template.Child()
search_bar = Gtk.Template.Child()
search_entry = Gtk.Template.Child()
search_button_revealer = Gtk.Template.Child()

# Sync mode
replay_line_button = Gtk. Template.Child()
syncing = Gtk.Template.Child()
sync_page_cover = Gtk.Template.Child()
sync_page_title = Gtk.Template.Child()
Expand All @@ -27,15 +39,13 @@ class LrcmakeWindow(Adw.ApplicationWindow):
forw100_button = Gtk.Template.Child()
toast_overlay = Gtk.Template.Child()
export_lyrics = Gtk.Template.Child()
sort_revealer = Gtk.Template.Child()
sorting_menu = Gtk.Template.Child()
library = Gtk.Template.Child()
search_button = Gtk.Template.Child()
search_bar = Gtk.Template.Child()
search_entry = Gtk.Template.Child()
search_button_revealer = Gtk.Template.Child()
replay_line_button = Gtk. Template.Child()

# Quick edit dialog
quick_edit_dialog = Gtk.Template.Child()
quick_edit_dialog_input = Gtk.Template.Child()
quick_edit_dialog_copy_button = Gtk.Template.Child()

# Class vars
title = None
artist = None
filename = None
Expand All @@ -54,14 +64,15 @@ def __init__(self, **kwargs):
self.rew100_button.connect('clicked', self.do_100ms_rew)
self.forw100_button.connect('clicked', self.do_100ms_forw)
self.replay_line_button.connect('clicked', self.do_replay_line)
self.quick_edit_dialog.connect('closed', self.reset_quick_edit_dialog)
self.quick_edit_dialog_copy_button.connect('clicked', self.clipboard_quick_edit_dialog_input)
self.music_lib.set_sort_func(sorting)
self.search_bar.connect_entry(self.search_entry)
self.search_button_revealer.set_reveal_child(self.search_button)
self.search_entry.connect("search-changed", self.on_search_changed)

# Showing greeting hint if no directory selected yet
if self.music_lib.get_child_at_index(0) == None:
self.music_lib.set_property('halign', 'center')
self.music_lib.set_property('valign', 'center')
self.music_lib.set_property('homogeneous', False)
self.music_lib.append(noDirSelectedGreeting())
Expand Down Expand Up @@ -221,4 +232,20 @@ def on_sorting_action(self, action, state):

# Action emmited when search filed text changed
def on_search_changed(self, *args):
self.music_lib.invalidate_filter()
self.music_lib.invalidate_filter()

def show_quick_edit_dialog(self, *args):
self.quick_edit_dialog.present(self)

def reset_quick_edit_dialog(self, *args):
if shared.schema.get_boolean("reset-quick-edit-on-close") == True:
self.quick_edit_dialog_input.set_buffer(Gtk.TextBuffer().new())

def clipboard_quick_edit_dialog_input(self, *args):
arg_export_clipboard(
self.quick_edit_dialog_input.get_buffer().get_text(
start = self.quick_edit_dialog_input.get_buffer().get_start_iter(),
end = self.quick_edit_dialog_input.get_buffer().get_end_iter(),
include_hidden_chars = False
)
)
Loading

0 comments on commit 9d6896d

Please sign in to comment.