Now About Social Code
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2025-01-21 17:30:52 +0000
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2025-01-21 17:30:52 +0000
commit8bd5b17906ac145fd35383bad413bca4aa342688 (patch)
tree64539142e5c48b0e0c1cb8cb4135070a89520a76
parentf3201c850ed6fa967074e0a07d9d017540ae69f4 (diff)
chat: Attempt to add spell checking with a GtkSourceView widget
Does not currently work
-rw-r--r--src/chat.py27
-rw-r--r--src/gtk/chat.ui20
-rw-r--r--src/style.css5
3 files changed, 45 insertions, 7 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)
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 @@
<object class="GtkButton">
<property name="icon-name">mail-attachment</property>
<style>
+ <class name="raised"/>
<class name="image-button"/>
</style>
<signal name="clicked" handler="attach_file"/>
</object>
</child>
<child>
- <object class="GtkEntry" id="text_entry">
+ <object class="GtkScrolledWindow">
+ <property name="max-content-height">10</property>
+ <property name="margin-start">5</property>
+ <property name="margin-end">5</property>
<property name="halign">fill</property>
<property name="hexpand">True</property>
<property name="hexpand-set">True</property>
- <property name="width-request">50</property>
- <property name="margin-start">5</property>
- <property name="margin-end">5</property>
- <signal name="activate" handler="entry_activate"/>
+ <property name="vscrollbar-policy">GTK_POLICY_EXTERNAL</property>
+ <style>
+ <class name="entry-frame"/>
+ </style>
+ <property name="child">
+ <object class="GtkSourceView" id="text_entry">
+ <property name="valign">center</property>
+ </object>
+ </property>
</object>
</child>
<child>
<object class="GtkButton">
<property name="icon-name">mail-forward</property>
<style>
+ <class name="raised"/>
<class name="image-button"/>
</style>
<signal name="clicked" handler="entry_activate"/>
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;
+}