From 8bd5b17906ac145fd35383bad413bca4aa342688 Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Tue, 21 Jan 2025 17:30:52 +0000 Subject: chat: Attempt to add spell checking with a GtkSourceView widget Does not currently work --- src/chat.py | 27 +++++++++++++++++++++++++-- src/gtk/chat.ui | 20 +++++++++++++++----- src/style.css | 5 +++++ 3 files changed, 45 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/chat.py b/src/chat.py index e99a524..ab33ebe 100644 --- a/src/chat.py +++ b/src/chat.py @@ -16,7 +16,9 @@ # along with this program. If not, see . # # SPDX-License-Identifier: GPL-3.0-or-later -from gi.repository import Adw, Gtk, Gio, GObject, GLib +import gi +gi.require_version("Spelling", "1") +from gi.repository import Adw, Gtk, Gdk, Gio, GObject, GLib, Spelling, GtkSource from .message import WeegtkMessage from .color import Color @@ -25,6 +27,7 @@ from weegtk import netfile import json +GObject.type_register(GtkSource.View) @Gtk.Template(resource_path='/com/fryzekconcepts/weegtk/gtk/chat.ui') class WeegtkChat(Adw.Bin): __gtype_name__ = 'WeegtkChat' @@ -65,6 +68,16 @@ class WeegtkChat(Adw.Bin): adj.connect("value-changed", self.scroll_changes) adj.connect("notify::upper", self.upper_notify) + self.text_entry.get_buffer().connect("insert-text", self.text_inserted) + + # Enable spell checking + self.checker = Spelling.Checker.get_default() + self.adapter = Spelling.TextBufferAdapter.new(self.text_entry.get_buffer(), self.checker) + self.extra_menu = self.adapter.get_menu_model() + self.text_entry.set_extra_menu(self.extra_menu) + self.text_entry.insert_action_group("spelling", self.adapter) + self.adapter.set_enabled(True) + # TODO figure out why style is not being taken from ui file self.add_css_class("view") @@ -181,13 +194,23 @@ class WeegtkChat(Adw.Bin): # TODO clear chat buffer pass + @Gtk.Template.Callback() def entry_activate(self, *args): entry_buffer = self.text_entry.get_buffer() - text = entry_buffer.get_text() + text = entry_buffer.get_text(entry_buffer.get_start_iter(), entry_buffer.get_end_iter(), False) entry_buffer.set_text("", 0) self.emit("buffer_input", self.data['full_name'], text) + def text_inserted(self, buffer, location, text, length): + if text == "\n": + print("Got newline!") + entry_buffer = self.text_entry.get_buffer() + text = entry_buffer.get_text(entry_buffer.get_start_iter(), entry_buffer.get_end_iter(), False) + print("Buffer is {}".format(text)) + print("Last char is {}".format(text[-1])) + self.entry_activate() + def open_file_dialog(self, dialog, result, caller): try: file = dialog.open_finish(result) diff --git a/src/gtk/chat.ui b/src/gtk/chat.ui index 05d23f2..33cb41f 100644 --- a/src/gtk/chat.ui +++ b/src/gtk/chat.ui @@ -90,26 +90,36 @@ mail-attachment - + + 10 + 5 + 5 fill True True - 50 - 5 - 5 - + GTK_POLICY_EXTERNAL + + + + center + + mail-forward diff --git a/src/style.css b/src/style.css index a95fb4d..c4342cc 100644 --- a/src/style.css +++ b/src/style.css @@ -15,3 +15,8 @@ box.message { .system-message { opacity: 0.6; } + +.entry-frame { + border: 3px solid #ebebeb; + border-radius: 10px; +} -- cgit