Filled in some of the skeleton methods.

Sat, 03 Aug 2024 19:54:43 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 03 Aug 2024 19:54:43 +0200
changeset 2
fee250704d3d
parent 1
124e1b8f276b
child 3
ca28466a186d

Filled in some of the skeleton methods.

PluginAiOllama.epj file | annotate | diff | comparison | revisions
PluginAiOllama.py file | annotate | diff | comparison | revisions
__init__.py file | annotate | diff | comparison | revisions
pyproject.toml file | annotate | diff | comparison | revisions
--- a/PluginAiOllama.epj	Sat Aug 03 18:30:37 2024 +0200
+++ b/PluginAiOllama.epj	Sat Aug 03 19:54:43 2024 +0200
@@ -93,7 +93,46 @@
       "changelog.md",
       "pyproject.toml"
     ],
-    "OTHERTOOLSPARMS": {},
+    "OTHERTOOLSPARMS": {
+      "Black": {
+        "exclude": "/(\\.direnv|\\.eggs|\\.git|\\.hg|\\.ipynb_checkpoints|\\.mypy_cache|\\.nox|\\.pytest_cache|\\.ruff_cache|\\.tox|\\.svn|\\.venv|\\.vscode|__pypackages__|_build|buck-out|build|dist|venv)/",
+        "extend-exclude": "/(\n    Ui_.*\\.py\n)",
+        "force-exclude": "",
+        "line-length": 88,
+        "skip-magic-trailing-comma": false,
+        "skip-string-normalization": false,
+        "source": "project",
+        "target-version": [
+          "py313",
+          "py312",
+          "py311",
+          "py310",
+          "py39",
+          "py38"
+        ]
+      },
+      "isort": {
+        "combine_as_imports": true,
+        "config_source": "project",
+        "extend_skip_glob": [
+          "*/Ui_*.py"
+        ],
+        "known_first_party": [
+          "OllamaInterface",
+          "eric7"
+        ],
+        "lines_between_types": 1,
+        "profile": "black",
+        "sort_order": "natural",
+        "supported_extensions": [
+          "py",
+          "pyi",
+          "pyx",
+          "pxd",
+          "pyw"
+        ]
+      }
+    },
     "PACKAGERSPARMS": {},
     "PROGLANGUAGE": "Python3",
     "PROJECTTYPE": "PyQt6",
--- a/PluginAiOllama.py	Sat Aug 03 18:30:37 2024 +0200
+++ b/PluginAiOllama.py	Sat Aug 03 19:54:43 2024 +0200
@@ -7,9 +7,12 @@
 Module implementing the ollama Interface plug-in.
 """
 
-from PyQt6.QtCore import QObject
+import os
+
+from PyQt6.QtCore import QObject, Qt, QTranslator
 
 from eric7 import Preferences
+from eric7.EricWidgets.EricApplication import ericApp
 
 # Start-Of-Header
 __header__ = {
@@ -31,6 +34,8 @@
 
 error = ""  # noqa: U200
 
+ollamaInterfacePluginObject = None
+
 
 def pageCreationFunction(configDlg):
     """
@@ -96,7 +101,22 @@
         """
         super().__init__(ui)
         self.__ui = ui
-        # TODO: not implemented yet
+        self.__initialize()
+
+        self.__defaults = {
+            "OllamaScheme": "http",
+            "OllamaHost": "localhost",
+            "OllamaPort": 11434,
+        }
+
+        self.__translator = None
+        self.__loadTranslator()
+
+    def __initialize(self):
+        """
+        Private slot to (re)initialize the plugin.
+        """
+        self.__widget = None
 
     def activate(self):
         """
@@ -118,6 +138,47 @@
         # TODO: not implemented yet
         pass
 
+    def __loadTranslator(self):
+        """
+        Private method to load the translation file.
+        """
+        if self.__ui is not None:
+            loc = self.__ui.getLocale()
+            if loc and loc != "C":
+                locale_dir = os.path.join(
+                    os.path.dirname(__file__), "OllamaInterface", "i18n"
+                )
+                translation = "ollama_{0}".format(loc)
+                translator = QTranslator(None)
+                loaded = translator.load(translation, locale_dir)
+                if loaded:
+                    self.__translator = translator
+                    ericApp().installTranslator(self.__translator)
+                else:
+                    print(
+                        "Warning: translation file '{0}' could not be"
+                        " loaded.".format(translation)
+                    )
+                    print("Using default.")
+
+    def __activateWidget(self):
+        """
+        Private slot to handle the activation of the pipx interface.
+        """
+        uiLayoutType = self.__ui.getLayoutType()
+
+        if uiLayoutType == "Toolboxes":
+            self.__ui.rToolboxDock.show()
+            self.__ui.rToolbox.setCurrentWidget(self.__widget)
+        elif uiLayoutType == "Sidebars":
+            try:
+                self.__ui.activateLeftRightSidebarWidget(self.__widget)
+            except AttributeError:
+                self.__activateLeftRightSidebarWidget(self.__widget)
+        else:
+            self.__widget.show()
+        self.__widget.setFocus(Qt.FocusReason.ActiveWindowFocusReason)
+
     def getPreferences(self, key):
         """
         Public method to retrieve the various settings values.
@@ -127,7 +188,17 @@
         @return the requested setting value
         @rtype Any
         """
-        # TODO: not implemented yet
+        if key in ("OllamaPort",):
+            return int(
+                Preferences.Prefs.settings.value(
+                    self.PreferencesKey + "/" + key, self.__defaults[key]
+                )
+            )
+        else:
+            return Preferences.Prefs.settings.value(
+                self.PreferencesKey + "/" + key, self.__defaults[key]
+            )
+
         return None
 
     def setPreferences(self, key, value):
@@ -139,8 +210,28 @@
         @param value the value to be set
         @type Any
         """
-        # TODO: not implemented yet
-        pass
+        Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value)
+
+    ############################################################################
+    ## Methods for backward compatibility with eric-ide < 24.9
+    ############################################################################
+
+    def __activateLeftRightSidebarWidget(self, widget):
+        """
+        Private method to activate the given widget in the left or right
+        sidebar.
+
+        @param widget reference to the widget to be activated
+        @type QWidget
+        """
+        # This is for backward compatibility with eric-ide < 24.9.
+        sidebar = (
+            self.__ui.leftSidebar
+            if Preferences.getUI("CombinedLeftRightSidebar")
+            else self.__ui.rightSidebar
+        )
+        sidebar.show()
+        sidebar.setCurrentWidget(widget)
 
 
 def installDependencies(pipInstall):
@@ -152,3 +243,7 @@
     """
     # TODO: not implemented yet
     pass
+
+
+#
+# eflag: noqa = M801, U200
--- a/__init__.py	Sat Aug 03 18:30:37 2024 +0200
+++ b/__init__.py	Sat Aug 03 19:54:43 2024 +0200
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Package implementing the 'ollama' interface plug-in.
+"""
--- a/pyproject.toml	Sat Aug 03 18:30:37 2024 +0200
+++ b/pyproject.toml	Sat Aug 03 19:54:43 2024 +0200
@@ -16,4 +16,4 @@
     "*/Ui_*.py",
 ]
 combine_as_imports = true
-known_first_party = ["PipxInterface", "eric7"]
+known_first_party = ["OllamaInterface", "eric7"]

eric ide

mercurial