diff --git a/Launcher.py b/Launcher.py index 503ad5f8..e26e4afc 100644 --- a/Launcher.py +++ b/Launcher.py @@ -162,6 +162,7 @@ def launch(exe, in_terminal=False): def run_gui(): from kvui import App, ContainerLayout, GridLayout, Button, Label, ScrollBox, Widget + from kivy.core.window import Window from kivy.uix.image import AsyncImage from kivy.uix.relativelayout import RelativeLayout @@ -226,6 +227,8 @@ def run_gui(): if client: client_layout.layout.add_widget(build_button(client[1])) + Window.bind(on_drop_file=self._on_drop_file) + return self.container @staticmethod @@ -235,6 +238,14 @@ def run_gui(): else: launch(get_exe(button.component), button.component.cli) + def _on_drop_file(self, window: Window, filename: bytes, x: int, y: int) -> None: + """ When a patch file is dropped into the window, run the associated component. """ + file, component = identify(filename.decode()) + if file and component: + run_component(component, file) + else: + logging.warning(f"unable to identify component for {filename}") + def _stop(self, *largs): # ran into what appears to be https://groups.google.com/g/kivy-users/c/saWDLoYCSZ4 with PyCharm. # Closing the window explicitly cleans it up. diff --git a/typings/kivy/core/window.pyi b/typings/kivy/core/window.pyi new file mode 100644 index 00000000..c133b986 --- /dev/null +++ b/typings/kivy/core/window.pyi @@ -0,0 +1,15 @@ +from typing import Callable, ClassVar + +from kivy.event import EventDispatcher + + +class WindowBase(EventDispatcher): + width: ClassVar[int] # readonly AliasProperty + height: ClassVar[int] # readonly AliasProperty + + @staticmethod + def bind(**kwargs: Callable[..., None]) -> None: ... + + +class Window(WindowBase): + ... diff --git a/typings/kivy/event.pyi b/typings/kivy/event.pyi new file mode 100644 index 00000000..2e76adab --- /dev/null +++ b/typings/kivy/event.pyi @@ -0,0 +1,2 @@ +class EventDispatcher: + ...