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:
parent
3cc391e9a1
commit
76266f25ef
11
Launcher.py
11
Launcher.py
|
@ -162,6 +162,7 @@ def launch(exe, in_terminal=False):
|
||||||
|
|
||||||
def run_gui():
|
def run_gui():
|
||||||
from kvui import App, ContainerLayout, GridLayout, Button, Label, ScrollBox, Widget
|
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.image import AsyncImage
|
||||||
from kivy.uix.relativelayout import RelativeLayout
|
from kivy.uix.relativelayout import RelativeLayout
|
||||||
|
|
||||||
|
@ -226,6 +227,8 @@ def run_gui():
|
||||||
if client:
|
if client:
|
||||||
client_layout.layout.add_widget(build_button(client[1]))
|
client_layout.layout.add_widget(build_button(client[1]))
|
||||||
|
|
||||||
|
Window.bind(on_drop_file=self._on_drop_file)
|
||||||
|
|
||||||
return self.container
|
return self.container
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -235,6 +238,14 @@ def run_gui():
|
||||||
else:
|
else:
|
||||||
launch(get_exe(button.component), button.component.cli)
|
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):
|
def _stop(self, *largs):
|
||||||
# ran into what appears to be https://groups.google.com/g/kivy-users/c/saWDLoYCSZ4 with PyCharm.
|
# ran into what appears to be https://groups.google.com/g/kivy-users/c/saWDLoYCSZ4 with PyCharm.
|
||||||
# Closing the window explicitly cleans it up.
|
# Closing the window explicitly cleans it up.
|
||||||
|
|
|
@ -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):
|
||||||
|
...
|
|
@ -0,0 +1,2 @@
|
||||||
|
class EventDispatcher:
|
||||||
|
...
|
Loading…
Reference in New Issue