From 4952db3b2293c648011e5ada18a5f49fade7926e Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Fri, 2 Mar 2012 00:48:32 +0100 Subject: [PATCH] core/window: implement a new dropfile event, currently used only on macosx. --- kivy/core/window/__init__.py | 16 ++++++++++++++++ kivy/core/window/window_pygame.py | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py index 811be299c..45b59648f 100755 --- a/kivy/core/window/__init__.py +++ b/kivy/core/window/__init__.py @@ -195,6 +195,8 @@ class WindowBase(EventDispatcher): Fired when a key is down `on_key_up`: key, scancode, unicode Fired when a key is up + `on_dropfile`: str + Fired when a file is dropped on the application ''' __instance = None @@ -367,6 +369,7 @@ class WindowBase(EventDispatcher): self.register_event_type('on_keyboard') self.register_event_type('on_key_down') self.register_event_type('on_key_up') + self.register_event_type('on_dropfile') super(WindowBase, self).__init__() @@ -711,6 +714,19 @@ class WindowBase(EventDispatcher): '''Event called when a key is up (same arguments as on_keyboard)''' pass + def on_dropfile(self, filename): + '''Event called when a file is dropped on the application. + + .. warning:: + + This event is actually used only on MacOSX with a patched version of + pygame. But this will be a place for a further evolution (ios, + android etc.) + + .. versionadded:: 1.1.2 + ''' + pass + def configure_keyboards(self): # Configure how to provide keyboards (virtual or not) diff --git a/kivy/core/window/window_pygame.py b/kivy/core/window/window_pygame.py index cea54b3da..bf135782d 100644 --- a/kivy/core/window/window_pygame.py +++ b/kivy/core/window/window_pygame.py @@ -273,6 +273,11 @@ class WindowPygame(WindowBase): elif event.type == pygame.ACTIVEEVENT: pass + # drop file (pygame patch needed) + elif event.type == pygame.USEREVENT and hasattr(pygame, + 'USEREVENT_DROPFILE') and event.code == pygame.USEREVENT_DROPFILE: + self.dispatch('on_dropfile', event.filename) + ''' # unhandled event ! else: