We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Gist: https://gist.github.com/medecau/22cec5853a5f7285ee2f97363bca096c
It took me a bit to get sDrop to work in Python mode. I created this thread so others may take advantage of this.
Comments
Hi @medecau. The sDrop issue you had is exactly the same for OscP5 and others:
https://forum.Processing.org/two/discussion/15995/receive-osc
That is, in Python Mode callbacks from 3rd party libraries fail.
In your case dropEvent(). For OscP5, it's oscEvent().
As a workaround, we can define some listening subclass and define the target callback therein.
Then invoke some method which adds an instance of that subclass as the library's listener.
The Python Mode's developer has already patched fixes for such issue for many other libraries already.
In such a way we don't need to create some listener subclass anymore.
And we can finally go back to define the callback directly in our sketches.
However, there are still many libraries w/o that patch such as sDrop & OscP5 and others.
If you wish, you can request a patch for sDrop too going here:
https://GitHub.com/jdf/Processing.py-Bugs/issues/157
Anyways, I've tweaked your listening workaround in order to resize the canvas w/ the same dimensions as the loaded image. Check it out: :bz
Thanks for your reply @GoToLoop.
My example code is extremely simple. Note that I didn't even bother resizing the image. Those things distract from the purpose of the example code and this post. To show how to get sDrop to work in Processing under Python mode.
Hopefully users can get creative and add other tweaks after that.
Regarding fixes and why things are the way they are I'd rather discuss those on a different thread. Ping me if interested.
My example is indeed more advanced. But many folks would be interested in how to fit the canvas to the image. That's why I've posted an alternative solution as well. :-\"
Although your example is simple, yet it's got some redundancies like importing sDrop 2 times. Just
add_library('Drop')
is enough. ;;)You can also axe out
global
variable drop. It's only used within setup() after all.A bigger canvas and some centralization of the PImage would be gr8 too: O:-)
set(width - img.width >> 1, height - img.height >> 1, img)
Here's my 2nd attempt on it. Now keeping everything as simple as possible + centralization: :D
Just found a another way to simplify my tweaked attempt: filePath():
http://Diskordier.net/drop/reference/drop/DropEvent.html#filePath--
That is, rather than invoking DropEvent's own loadImage() which happens in another Thread:
http://Diskordier.net/drop/reference/drop/DropEvent.html#loadImage--
Get instead dropped File's path w/ DropEvent's filePath() & go w/ PApplet's loadImage()! *-:)