We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I want to add to my sketch (processing python sketch) handling of text area from library G4P, but it doesn't work. Here's my code:
add_library('G4P')
text_area = None
def setup():
size(600, 600)
global text_area
text_area = GTextArea(this, 80, 20, 290, 300, G4P.SCROLLBARS_BOTH | G4P.SCROLLBARS_AUTOHIDE)
text_area.setPromptText("Please enter some text");
def draw():
background(100)
text_area.draw()
Answers
3rd libraries under Python Mode can't find out where their callbacks are by reflection! :-&
So default handleTextEvents() won't work there w/o heavy hacking! :ar!
You're gonna need to ask its dev for it.
However, he doesn't seem fond to fix G4P as you can see below: :-O
https://GitHub.com/jdf/Processing.py-Bugs/issues/106
I've tried to convert this Java Mode attempt I've come up w/:
To Python Mode:
No success though... =((
G4P was created a long time before Python mode appeared so we should not be surprised if they don't work well together.
G4P uses reflection quite extensively in the event handlers and GoToLoop tells us that Python cannot use them so it looks as if using G4P in Python mode is a non-starter.
@quark, I still think it'd be possible to make G4P more compatible w/ Python Mode.
For example, even though ControlP5 relies on reflection a lot, it's still possible to use it under Python Mode w/ some extra effort: #:-S https://GitHub.com/jdf/processing.py/issues/52
In the example from the link above, addListener() accepts a ControlListener instance, which wraps up 1
abstract
method called controlEvent().In Java, those kinda 1-method interfaces are annotated as
@FunctionalInterface
: ~O)http://Docs.Oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html
The problem w/ your addEventHandler() is that it accepts an extra String w/ the name of the method for reflection rather than have 1 already pre-determined name. :-<
Seems like you'd have to create some kinda GListener
@FunctionalInterface
interface w/ 1abstract
method in it, so we can@Override
its method and pass it as a handler for G4P's many controllers. >-)