1

I'm trying to run the code posted in the link below to handle drag-drop of files in a Kivy application. Kivy: drag n drop, get file path

from kivy.app import App
from kivy.core.window import Window

class WindowFileDropExampleApp(App):
    def build(self):
        Window.bind(on_dropfile=self._on_file_drop)
        return

def _on_file_drop(self, window, file_path):
    print(file_path)
    return

if __name__ == '__main__':
    WindowFileDropExampleApp().run()

It doesn't seem to be triggering the '_on_file_drop' event function when I drag a file into the application window. Any help getting this working would be great. My entire console output is the following:

$ python main.py
[INFO              ] [Logger      ] Record log in C:\Users\\.kivy\logs\kivy_17-02-10_163.txt
[INFO              ] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO              ] [OSC         ] using <thread> for socket
[INFO              ] [Window      ] Provider: sdl2
[INFO              ] [GL          ] GLEW initialization succeeded
[INFO              ] [GL          ] OpenGL version <b'4.4.0 - Build 20.19.15.4463'>
[INFO              ] [GL          ] OpenGL vendor <b'Intel'>
[INFO              ] [GL          ] OpenGL renderer <b'Intel(R) Iris(TM) Graphics 540'>
[INFO              ] [GL          ] OpenGL parsed version: 4, 4
[INFO              ] [GL          ] Shading version <b'4.40 - Build 20.19.15.4463'>
[INFO              ] [GL          ] Texture max size <16384>
[INFO              ] [GL          ] Texture max units <32>
[INFO              ] [Shader      ] fragment shader: <b"WARNING: 0:7: '' :  #version directive missing">
[INFO              ] [Shader      ] vertex shader: <b"WARNING: 0:7: '' :  #version directive missing">
[INFO              ] [Window      ] auto add sdl2 input provider
[INFO              ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO              ] [Base        ] Start application main loop
[INFO              ] [Base        ] Leaving application in progress...
Community
  • 1
  • 1
KDumont
  • 66
  • 6
  • That exact copy works fine for me. Maybe you aren't dropping the file? Do you see the icon for dropping e.g. that arrow with a plus sign? – Peter Badida Feb 13 '17 at 16:50
  • Yeah, I see the icon change. @KeyWeeUsr are you using the same versions as I have above? It's clear that the dropfile action is not being called. Looking [here](https://github.com/kivy/kivy/commit/ee43d7ebff09e654b5551c71d9840da6bf9cb9f4) I find it strange that only the dropfile enumerator index has a comma, though I don't know if that is relevant. – KDumont Feb 16 '17 at 21:21
  • I ran 1.9.1 with py2 and master with 3.5.2, both cases of [multi_dropfile.py](https://raw.githubusercontent.com/kivy/kivy/master/examples/miscellaneous/multiple_dropfile.py) and that answer example worked correctly. It's either your code's fault (if it's not the exact example), or it might be a corrupted installation (try reinstalling). Afaik, 1.9.1 is supported officially only on 2.7 and 3.4, so there might be something wrong. Try installing the [nightly wheel](https://kivy.org/docs/installation/installation-windows.html). – Peter Badida Feb 16 '17 at 21:59
  • I installed the nightly wheel. Now getting the error `[CRITICAL] [Window ] Unable to find any valuable Window provider. sdl2 - ImportError: DLL load failed: The specified module could not be found. ` Going through [this](https://github.com/kivy/kivy/issues/4656) to try and resolve. – KDumont Feb 16 '17 at 22:20
  • Try to reinstall the deps and run kivy again: `pip install -I kivy.deps.sdl2 kivy.deps.glew` – Peter Badida Feb 16 '17 at 22:23
  • You are a saint. It runs now, but back to my original issue of not calling a dropfile action. Thank you for your help, btw. At least if I can build the source now, I might be able to dig deeper. – KDumont Feb 16 '17 at 22:28
  • I don't believe Python installation is broken and dropfile is handled by SDL2, which works (you have a window). I have the same latest dependency and on both stable and master the exact code from both examples work. So, I'm kind of clueless what's going on here. This might seem as a totally stupid question, but anyway... do you release the mouse button when you drop the file? Also, the `event.drop.file` is correct. You could compile [SDL2 dropfile](https://gist.github.com/aqiank/efa6eefcc81157982acc) example to check if that works, though I think it's just an OS issue. Maybe reboot? – Peter Badida Feb 16 '17 at 22:43
  • Haha, yes. Fair question. I compiled the SDL2 dropfile example you linked to. That worked fine. I installed and ran with Python 2.7 and it still did not work. I also tried it on another PC with Python3.5 with no luck. I'm also at a bit of a loss. This would be a nice feature for my application, but I think I will come back to it in a while and see if anyone else runs into this issue. – KDumont Feb 17 '17 at 20:17
  • Well, this kind of leads us to two options - your code is bad or there's something **really** _**really**_ wrong with your Kivy installation (and I have no clue how to fix that, remotely at least, because the rest of the framework seems to work from the description). Until now I believed you run the exact code from [here](http://stackoverflow.com/a/38854461/5994041), but another user on the #kivy channel made me doubt that thought. Would you please edit the question with the exact code you use on both machines? – Peter Badida Feb 17 '17 at 21:09
  • Sure. The only thing I changed was adding in a print(action) line into the kivy/window/window_sdl2.py file as a debug measure (after I started having issues). I can see all the other action events (mousemotion, windowleave, etc.) but no dropfile. In addition, I have uninstalled, reinstalled multiple times, and run on two different computers, both python 2.7 and 3.5. I also compiled the link you posted above and the drag-drop output works fine in C. So I'm pretty sure action I am doing is correct. I see the arrow[+] cursor. No output to console though. – KDumont Feb 17 '17 at 21:52
  • 1
    Okay! The plot thickens... I got it to run. I have been using git bash as my console, run as admin. I found that when I do NOT run as admin, the dropfile code works. When I run as admin, it doesn't. Can you try to replicate this? - The same thing happens in Windows console. – KDumont Feb 17 '17 at 21:57
  • Perfect, I can reproduce! I'll make an issue in the repo soon and link it here. – Peter Badida Feb 17 '17 at 22:30
  • The same issue occurs with the .c code I compiled. When I run the .exe as admin, it does not acknowledge the dropfile. This appears to be a bug in SDL2. – KDumont Feb 17 '17 at 22:34

1 Answers1

2

This appears to be an issue with SDL2 when running as admin. Will dig further on getting a fix, but this issue is temporarily resolved by running with basic user privileges (no admin).

KDumont
  • 66
  • 6