Skip to content

Commit

Permalink
Core: Launcher: can drag-and-drop patch on Launcher window (#3442)
Browse files Browse the repository at this point in the history
* Core: Launcher: can drag-and-drop patch on Launcher window

* doc string for `_on_drop_file`
  • Loading branch information
beauxq authored Jun 4, 2024
1 parent 3cc391e commit 76266f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -226,6 +227,8 @@ def build_button(component: Component) -> Widget:
if client:
client_layout.layout.add_widget(build_button(client[1]))

Window.bind(on_drop_file=self._on_drop_file)

return self.container

@staticmethod
Expand All @@ -235,6 +238,14 @@ def component_action(button):
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.
Expand Down
15 changes: 15 additions & 0 deletions typings/kivy/core/window.pyi
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions typings/kivy/event.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class EventDispatcher:
...

0 comments on commit 76266f2

Please sign in to comment.