Core: Launcher: can drag-and-drop patch on Launcher window (#3442)

* Core: Launcher: can drag-and-drop patch on Launcher window

* doc string for `_on_drop_file`
This commit is contained in:
Doug Hoskisson 2024-06-04 16:54:21 -07:00 committed by GitHub
parent 3cc391e9a1
commit 76266f25ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View File

@ -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.

View File

@ -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):
...

2
typings/kivy/event.pyi Normal file
View File

@ -0,0 +1,2 @@
class EventDispatcher:
...