Reputation: 541
What I want to achieve:
I want to detect the situation when the user is dragging a file over the Kivy app window.
What I already know:
I know how to detect hovering mouse coursor over widgets (with on_mouse_pos
), I also know how to detect if a file is dropped onto the window (with on_file_drop
).
So, is it possible to see whether the cursor is hovering over the window and "holding" a file? Because then I want to display some prompt (eg. 'Drop HERE'). I hope you get the idea :)
Upvotes: 4
Views: 332
Reputation: 12189
I'm not really sure, because there's this thing with SDL2 (and probably even with old pygame) when the Window
just pauses (try some animation or something) when you e.g. drag it with the window decoration (the thing where title and _ O X
are). That is the behavior if you do something with the Window
directly.
Although, the Window
looks like it behaves normally (doesn't pause itself), when you drag file on top of it (I tried with examples/animation/animate.py
), to do such thing you'd need to do either the hovering behavior + handling the collisions or bind to mouse_pos
.
However, when binding to mouse_pos
, it seems like the Window
still isn't capable of handling the input from outside and at the same time get mouse properties correctly (I think it's similar to the behavior when you click & drag outside of the Window
and Button
remains pressed, but this is kind of inversed).
edited animate.py:
class TestApp(App):
def on_mouse_pos(self, win, args):
print args
...
def build(self):
...
from kivy.core.window import Window
Window.bind(mouse_pos=self.on_mouse_pos)
return button
Therefore if you can't get even mouse position when a mouse button is being held, I don't think such an action is possible. You can however make the areas where you want to drop the file already different (e.g. change background) when you'll expect a user to drop the file - a very dirty workaround from UI side for such a problem.
Side note: Kivy should be able to get most (if not all) SDL2
window events via Cython, therefore if you find such event in SDL2 that would make fetching mouse position possible, such action could be performed, feel free to make a feature request in kivy/kivy or make a pull request.
Upvotes: 2