diff --git a/extensions/dev.py b/extensions/dev.py index 0d823456..dd8eca44 100644 --- a/extensions/dev.py +++ b/extensions/dev.py @@ -12,13 +12,15 @@ import typing +from biscuit.extensions import Extension + if typing.TYPE_CHECKING: - from biscuit import ExtensionsAPI + from biscuit.api import ExtensionsAPI # 4. Create a class named `Extension` as follows: -class DevMode: +class DevMode(Extension): """Dev Mode extension for Biscuit (author: @billyeatcookies) Contributes: @@ -26,7 +28,11 @@ class DevMode: """ def __init__(self, api: ExtensionsAPI) -> None: - self.api = api + super().__init__(api) + + self.api.logger.info(f"This is a sample log!") + + def install(self) -> None: self.api.notifications.info(f"Dev mode is enabled!") diff --git a/pyproject.toml b/pyproject.toml index 09760523..b5057dcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "biscuit-editor" -version = "2.99.9" +version = "2.99.10" description = "A lightweight, fast, and extensible code editor with a growing community" authors = ["Billy "] license = "MIT" diff --git a/src/biscuit/__init__.py b/src/biscuit/__init__.py index cc781f90..c6c7adb1 100644 --- a/src/biscuit/__init__.py +++ b/src/biscuit/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.99.9" +__version__ = "2.99.10" __version_info__ = tuple([int(num) for num in __version__.split(".")]) from .main import * diff --git a/src/biscuit/api/base.py b/src/biscuit/api/base.py index ed7b2d69..a6fa74ce 100644 --- a/src/biscuit/api/base.py +++ b/src/biscuit/api/base.py @@ -65,4 +65,8 @@ def register(self, name: str, extension: object) -> None: """Register an extension""" self.base.extensions_manager.register_installed(name, extension) - # extension.install() + + def register_extension(self, name: str, extension: object) -> None: + """Register an extension""" + + self.register(name, extension) diff --git a/src/biscuit/extensions/__init__.py b/src/biscuit/extensions/__init__.py index cd6ecc2d..71ad751d 100644 --- a/src/biscuit/extensions/__init__.py +++ b/src/biscuit/extensions/__init__.py @@ -1 +1,2 @@ -from .extensions import * +from .extension import Extension +from .extensions import ExtensionManager diff --git a/src/biscuit/extensions/extensions.py b/src/biscuit/extensions/extensions.py index a113c4bd..cec88527 100644 --- a/src/biscuit/extensions/extensions.py +++ b/src/biscuit/extensions/extensions.py @@ -11,7 +11,7 @@ import requests -from biscuit.views.extensions.extension import Extension +from biscuit.views.extensions.extension import ExtensionGUI if typing.TYPE_CHECKING: from biscuit import App @@ -54,7 +54,7 @@ def install_extension_from_name(self, name: str) -> bool: data = self.fetched[name] t = self.run_fetch_extension( - Extension(self.base.extensions_view.results, name, data) + ExtensionGUI(self.base.extensions_view.results, name, data) ) t.join() @@ -136,7 +136,7 @@ def fetch_extensions(self) -> None: # TODO add further loops for folders self.fetch_queue.put((name, data)) - def run_fetch_extension(self, ext: Extension) -> None: + def run_fetch_extension(self, ext: ExtensionGUI) -> None: """Called from the Extension View to fetch an extension.""" if ext.installed: @@ -148,7 +148,7 @@ def run_fetch_extension(self, ext: Extension) -> None: t.start() return t - def fetch_extension(self, ext: Extension) -> None: + def fetch_extension(self, ext: ExtensionGUI) -> None: """Fetch an extension from the repository.""" try: @@ -158,7 +158,7 @@ def fetch_extension(self, ext: Extension) -> None: except: ext.set_unavailable() - def save_extension(self, ext: Extension, response: requests.Response) -> None: + def save_extension(self, ext: ExtensionGUI, response: requests.Response) -> None: """Save a fetched extension. Saves the extension and loads it.""" with open(ext.file, "w") as fp: @@ -170,7 +170,7 @@ def save_extension(self, ext: Extension, response: requests.Response) -> None: self.base.logger.info(f"Fetching extension '{ext.name}' successful.") self.base.notifications.info(f"Extension '{ext.name}' has been installed!") - def remove_extension(self, ext: Extension) -> None: + def remove_extension(self, ext: ExtensionGUI) -> None: """Remove an extension from the system.""" try: @@ -236,7 +236,7 @@ def load_extensions(self): extension_module.setup(self.base.api) self.base.logger.info(f"Extension '{ext}' loaded.") - except ImportError as e: + except Exception as e: self.base.logger.error(f"Failed to load extension '{ext}': {e}") self.base.notifications.error(f"Extension '{ext}' failed: see logs.") if ext in self.installed: @@ -246,6 +246,12 @@ def register_installed(self, name: str, extension: object) -> None: """Register an installed extension.""" self.installed[name] = extension + try: + extension.install() + except Exception as e: + print("no install method !!!!!!!!!!!!") + # most likely the extension does not implement the install method + ... def queue_installed_extensions(self) -> None: for extension_file in os.listdir(self.base.extensionsdir): diff --git a/src/biscuit/views/extensions/extension.py b/src/biscuit/views/extensions/extension.py index 0228376d..ffa9bbba 100644 --- a/src/biscuit/views/extensions/extension.py +++ b/src/biscuit/views/extensions/extension.py @@ -10,7 +10,7 @@ from .results import Results -class Extension(Frame): +class ExtensionGUI(Frame): """Extension item in the Extensions view. The Extension class represents an extension item in the Extensions view. diff --git a/src/biscuit/views/extensions/results.py b/src/biscuit/views/extensions/results.py index 4b10a3ac..a1d83b73 100644 --- a/src/biscuit/views/extensions/results.py +++ b/src/biscuit/views/extensions/results.py @@ -11,7 +11,7 @@ from biscuit.common.ui import ScrollableFrame from ..drawer_item import NavigationDrawerViewItem -from .extension import Extension +from .extension import ExtensionGUI from .placeholder import ExtensionsPlaceholder if typing.TYPE_CHECKING: @@ -19,7 +19,7 @@ class ExtensionsList(ScrollableFrame): - items: list[Extension] + items: list[ExtensionGUI] def __init__(self, master, *args, **kwargs) -> None: super().__init__(master, *args, **kwargs) @@ -78,7 +78,7 @@ def refresh(self, *_) -> None: def gui_refresh_loop(self) -> None: if not self.fetch_queue.empty(): name, data = self.fetch_queue.get() - ext = Extension(self, name, data) + ext = ExtensionGUI(self, name, data) self.extension_list.add(ext, fill=tk.X) self.after(5, self.gui_refresh_loop) @@ -91,7 +91,7 @@ def clear(self, *_) -> None: self.fetching.set() - def set_selected(self, extension: Extension) -> None: + def set_selected(self, extension: ExtensionGUI) -> None: for widget in self.extension_list.items: if widget == extension: widget.select()