implementing more plugin functionality

This commit is contained in:
SpookyDervish
2025-10-27 21:27:50 +11:00
parent 155cff8b43
commit 63614988f2
2 changed files with 33 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
from textual_window import Window
from textual.widgets import RichLog, Button
from textual import work
from textual.binding import Binding
from textual import work, on
import textual.widgets
from traceback import format_exception
from lupa import lua51
import os, json, asyncio
@@ -45,6 +47,12 @@ class PluginLoader(Window):
function()
setattr(self.app, f"action_{action_name}", wrapper)
def create_widget(self, widget_type: str, *args):
return getattr(textual.widgets, widget_type)(*args)
def run_on_event(self, event, function):
raise NotImplementedError("runOnEvent is not implemented yet.")
def create_window(self, title: str, icon: str = "", show_title: bool = True, can_close: bool = True, can_maximize: bool = True, can_resize: bool = True, start_horizontal: str = "center", start_vertical: str = "middle"):
new_window = Window(
@@ -58,7 +66,7 @@ class PluginLoader(Window):
starting_horizontal=start_horizontal,
starting_vertical=start_vertical
)
self.app.mount(new_window)
#self.app.mount(new_window)
return new_window
# endregion
@@ -76,12 +84,15 @@ class PluginLoader(Window):
"ui": {
"notify": self.fake_notify,
#"createSidebarButton": self.create_sidebar_button,
"setTheme": self.set_theme,
#"setTheme": self.set_theme,
"runAction": self.fake_run_action,
"addBind": self.add_bind,
"createAction": self.create_action,
"createWindow": self.create_window
}
"createWindow": self.create_window,
"createWidget": self.create_widget,
"app": self.app,
"runOnEvent": self.run_on_event
},
}
log.write("[b]Finding plugins...[/]")
@@ -160,15 +171,19 @@ class PluginLoader(Window):
try:
executed_code = self.lua_runtime.execute(code)
except lua51.LuaError as e:
log.write(f"[b red]Error in {lua_file_path}: {e}[/]")
log.write(f"[b red]Error in {lua_file_path}:\n" + '\n'.join(format_exception(e)) + "[/]")
self.notify("There was Lua error while loading one your installed plugins. Check the Plugin Loader window for more details.", title="Lua Error", severity="error", timeout=10)
no_errors = False
continue
if executed_code.init:
executed_code.init()
if executed_code.main:
self.run_worker(thread=True, work=executed_code.main)
if executed_code.run:
try:
executed_code.run()
except Exception as e:
log.write(f"[b red]Runtime error in {lua_file_path}:\n" + "\n".join(format_exception(e)) + "[/]")
self.notify("A plugin has created an error. Check the log for more details.", title="Lua Error", severity="error", timeout=10)
no_errors = False
continue
plugin_paths.append(plugin_folder)

View File

@@ -1,12 +1,14 @@
local plugin = {}
function testAction()
function plugin.run()
local window = berry.ui.createWindow("test window")
end
berry.ui.app.mount(window)
berry.ui.runOnEvent(window.Initialized, function()
local test = berry.ui.createWidget("Static", "the absolute minimal experience")
window.mount_in_window(test)
end)
function plugin.init()
berry.ui.createAction("test", testAction)
berry.ui.addBind("test", "ctrl+d", "Test")
end
return plugin