working on more stuff for the berry.ui library
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from textual_window import Window
|
||||
from textual.widgets import RichLog
|
||||
from textual.widgets import RichLog, Button
|
||||
from textual import work
|
||||
from lupa import LuaRuntime, lua51
|
||||
from textual.binding import Binding
|
||||
from lupa import lua51
|
||||
|
||||
import os, json, asyncio
|
||||
|
||||
@@ -18,6 +19,30 @@ class PluginLoader(Window):
|
||||
allow_maximize=True
|
||||
)
|
||||
|
||||
def fake_notify(self, message: str, title: str = None, severity: str = "information"):
|
||||
self.app.notify(message=message, title=title, severity=severity)
|
||||
|
||||
def create_sidebar_button(self, icon: str):
|
||||
new_button = Button(icon)
|
||||
self.app.query_one("#sidebar-buttons").mount(new_button)
|
||||
|
||||
def set_theme(self, theme_name: str):
|
||||
self.app.theme = theme_name
|
||||
|
||||
def add_bind(self, action_name: str, key: str, description: str, show: bool = True):
|
||||
# a bit of a sneaky way of doing things
|
||||
self.app.bind(key, action_name, description=description, show=show)
|
||||
self.app.refresh_bindings()
|
||||
|
||||
def fake_run_action(self, action_name: str):
|
||||
getattr(self.app, f"action_{action_name}")()
|
||||
|
||||
def create_action(self, action_name: str, function):
|
||||
def wrapper():
|
||||
function()
|
||||
|
||||
setattr(self.app, f"action_{action_name}", wrapper)
|
||||
|
||||
@work
|
||||
async def find_plugins(self):
|
||||
log = self.query_one(RichLog)
|
||||
@@ -26,9 +51,15 @@ class PluginLoader(Window):
|
||||
|
||||
log.write("[b]Setting up LUA runtime..[/]")
|
||||
self.lua_runtime = lua51.LuaRuntime()
|
||||
|
||||
lua_runtime_stuff = {
|
||||
"ui": {
|
||||
"notify": self.notify
|
||||
"notify": self.fake_notify,
|
||||
"createSidebarButton": self.create_sidebar_button,
|
||||
"setTheme": self.set_theme,
|
||||
"runAction": self.fake_run_action,
|
||||
"addBind": self.add_bind,
|
||||
"createAction": self.create_action
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +140,7 @@ class PluginLoader(Window):
|
||||
executed_code = self.lua_runtime.execute(code)
|
||||
except lua51.LuaError as e:
|
||||
log.write(f"[b red]Error in {lua_file_path}: {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")
|
||||
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
|
||||
|
||||
@@ -120,8 +151,9 @@ class PluginLoader(Window):
|
||||
|
||||
plugin_paths.append(plugin_folder)
|
||||
|
||||
log.write("\n[b]Done loading plugins![/]")
|
||||
if no_errors:
|
||||
log.write("\n[d]Window will automatically close in 5 seconds.[/]")
|
||||
log.write("[d]Window will automatically close in 5 seconds.[/]")
|
||||
await asyncio.sleep(5.0)
|
||||
self.close_window()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user