5 |
5 |
6 """ |
6 """ |
7 Module implementing the ollama Interface plug-in. |
7 Module implementing the ollama Interface plug-in. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import QObject |
10 import os |
|
11 |
|
12 from PyQt6.QtCore import QObject, Qt, QTranslator |
11 |
13 |
12 from eric7 import Preferences |
14 from eric7 import Preferences |
|
15 from eric7.EricWidgets.EricApplication import ericApp |
13 |
16 |
14 # Start-Of-Header |
17 # Start-Of-Header |
15 __header__ = { |
18 __header__ = { |
16 "name": "ollama Interface", |
19 "name": "ollama Interface", |
17 "author": "Detlev Offenbach <detlev@die-offenbachs.de>", |
20 "author": "Detlev Offenbach <detlev@die-offenbachs.de>", |
94 @param ui reference to the user interface object |
99 @param ui reference to the user interface object |
95 @type UI.UserInterface |
100 @type UI.UserInterface |
96 """ |
101 """ |
97 super().__init__(ui) |
102 super().__init__(ui) |
98 self.__ui = ui |
103 self.__ui = ui |
99 # TODO: not implemented yet |
104 self.__initialize() |
|
105 |
|
106 self.__defaults = { |
|
107 "OllamaScheme": "http", |
|
108 "OllamaHost": "localhost", |
|
109 "OllamaPort": 11434, |
|
110 } |
|
111 |
|
112 self.__translator = None |
|
113 self.__loadTranslator() |
|
114 |
|
115 def __initialize(self): |
|
116 """ |
|
117 Private slot to (re)initialize the plugin. |
|
118 """ |
|
119 self.__widget = None |
100 |
120 |
101 def activate(self): |
121 def activate(self): |
102 """ |
122 """ |
103 Public method to activate this plug-in. |
123 Public method to activate this plug-in. |
104 |
124 |
115 """ |
135 """ |
116 Public method to deactivate this plug-in. |
136 Public method to deactivate this plug-in. |
117 """ |
137 """ |
118 # TODO: not implemented yet |
138 # TODO: not implemented yet |
119 pass |
139 pass |
|
140 |
|
141 def __loadTranslator(self): |
|
142 """ |
|
143 Private method to load the translation file. |
|
144 """ |
|
145 if self.__ui is not None: |
|
146 loc = self.__ui.getLocale() |
|
147 if loc and loc != "C": |
|
148 locale_dir = os.path.join( |
|
149 os.path.dirname(__file__), "OllamaInterface", "i18n" |
|
150 ) |
|
151 translation = "ollama_{0}".format(loc) |
|
152 translator = QTranslator(None) |
|
153 loaded = translator.load(translation, locale_dir) |
|
154 if loaded: |
|
155 self.__translator = translator |
|
156 ericApp().installTranslator(self.__translator) |
|
157 else: |
|
158 print( |
|
159 "Warning: translation file '{0}' could not be" |
|
160 " loaded.".format(translation) |
|
161 ) |
|
162 print("Using default.") |
|
163 |
|
164 def __activateWidget(self): |
|
165 """ |
|
166 Private slot to handle the activation of the pipx interface. |
|
167 """ |
|
168 uiLayoutType = self.__ui.getLayoutType() |
|
169 |
|
170 if uiLayoutType == "Toolboxes": |
|
171 self.__ui.rToolboxDock.show() |
|
172 self.__ui.rToolbox.setCurrentWidget(self.__widget) |
|
173 elif uiLayoutType == "Sidebars": |
|
174 try: |
|
175 self.__ui.activateLeftRightSidebarWidget(self.__widget) |
|
176 except AttributeError: |
|
177 self.__activateLeftRightSidebarWidget(self.__widget) |
|
178 else: |
|
179 self.__widget.show() |
|
180 self.__widget.setFocus(Qt.FocusReason.ActiveWindowFocusReason) |
120 |
181 |
121 def getPreferences(self, key): |
182 def getPreferences(self, key): |
122 """ |
183 """ |
123 Public method to retrieve the various settings values. |
184 Public method to retrieve the various settings values. |
124 |
185 |
125 @param key the key of the value to get |
186 @param key the key of the value to get |
126 @type str |
187 @type str |
127 @return the requested setting value |
188 @return the requested setting value |
128 @rtype Any |
189 @rtype Any |
129 """ |
190 """ |
130 # TODO: not implemented yet |
191 if key in ("OllamaPort",): |
|
192 return int( |
|
193 Preferences.Prefs.settings.value( |
|
194 self.PreferencesKey + "/" + key, self.__defaults[key] |
|
195 ) |
|
196 ) |
|
197 else: |
|
198 return Preferences.Prefs.settings.value( |
|
199 self.PreferencesKey + "/" + key, self.__defaults[key] |
|
200 ) |
|
201 |
131 return None |
202 return None |
132 |
203 |
133 def setPreferences(self, key, value): |
204 def setPreferences(self, key, value): |
134 """ |
205 """ |
135 Public method to store the various settings values. |
206 Public method to store the various settings values. |
137 @param key the key of the setting to be set |
208 @param key the key of the setting to be set |
138 @type str |
209 @type str |
139 @param value the value to be set |
210 @param value the value to be set |
140 @type Any |
211 @type Any |
141 """ |
212 """ |
142 # TODO: not implemented yet |
213 Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value) |
143 pass |
214 |
|
215 ############################################################################ |
|
216 ## Methods for backward compatibility with eric-ide < 24.9 |
|
217 ############################################################################ |
|
218 |
|
219 def __activateLeftRightSidebarWidget(self, widget): |
|
220 """ |
|
221 Private method to activate the given widget in the left or right |
|
222 sidebar. |
|
223 |
|
224 @param widget reference to the widget to be activated |
|
225 @type QWidget |
|
226 """ |
|
227 # This is for backward compatibility with eric-ide < 24.9. |
|
228 sidebar = ( |
|
229 self.__ui.leftSidebar |
|
230 if Preferences.getUI("CombinedLeftRightSidebar") |
|
231 else self.__ui.rightSidebar |
|
232 ) |
|
233 sidebar.show() |
|
234 sidebar.setCurrentWidget(widget) |
144 |
235 |
145 |
236 |
146 def installDependencies(pipInstall): |
237 def installDependencies(pipInstall): |
147 """ |
238 """ |
148 Function to install dependencies of this plug-in. |
239 Function to install dependencies of this plug-in. |