diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2025-01-21 17:30:52 +0000 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2025-01-21 17:30:52 +0000 |
commit | 8bd5b17906ac145fd35383bad413bca4aa342688 (patch) | |
tree | 64539142e5c48b0e0c1cb8cb4135070a89520a76 /src/chat.py | |
parent | f3201c850ed6fa967074e0a07d9d017540ae69f4 (diff) |
chat: Attempt to add spell checking with a GtkSourceView widget
Does not currently work
Diffstat (limited to 'src/chat.py')
-rw-r--r-- | src/chat.py | 27 |
1 files changed, 25 insertions, 2 deletions
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 <https://www.gnu.org/licenses/>. # # 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) |