OllamaInterface/OllamaWidget.py

changeset 68
ca2e671f894e
parent 67
3c2bcbf7eeaf
diff -r 3c2bcbf7eeaf -r ca2e671f894e OllamaInterface/OllamaWidget.py
--- a/OllamaInterface/OllamaWidget.py	Tue Dec 10 15:48:48 2024 +0100
+++ b/OllamaInterface/OllamaWidget.py	Mon Apr 07 18:22:14 2025 +0200
@@ -12,7 +12,15 @@
 import os
 import shutil
 
-from PyQt6.QtCore import QProcess, QProcessEnvironment, Qt, QTimer, QUrl, pyqtSlot
+from PyQt6.QtCore import (
+    QEvent,
+    QProcess,
+    QProcessEnvironment,
+    Qt,
+    QTimer,
+    QUrl,
+    pyqtSlot,
+)
 from PyQt6.QtGui import QDesktopServices
 from PyQt6.QtWidgets import (
     QDialog,
@@ -62,6 +70,8 @@
         super().__init__(parent)
         self.setupUi(self)
 
+        self.messageEdit.installEventFilter(self)
+
         self.__plugin = plugin
         self.__client = OllamaClient(plugin, self)
 
@@ -1154,3 +1164,27 @@
             self.__pullProgressDialog.setFinished(True)
             self.__pulling = False
             self.__client.list()
+
+    def eventFilter(self, obj, evt):
+        """
+        Public method to process some events for the message edit.
+
+        @param obj reference to the object the event was meant for
+        @type QObject
+        @param evt reference to the event object
+        @type QEvent
+        @return flag to indicate that the event was handled
+        @rtype bool
+        """
+        if (
+            obj is self.messageEdit
+            and evt.type() == QEvent.Type.KeyPress
+            and evt.key() in (Qt.Key.Key_Return, Qt.Key.Key_Enter)
+            and evt.modifiers() == Qt.KeyboardModifier.ControlModifier
+        ):
+            # Ctrl-Enter or Ctrl-Return => commit
+            self.sendButton.animateClick()
+            return True
+        else:
+            # standard event processing
+            return super().eventFilter(obj, evt)

eric ide

mercurial