I have some controlP5 code in Java that I want to port to Python. It uses tabs and captures the control event when the tab is changed. However, in Python I don’t see these events.
What do I have to do to capture these control events in Python mode?
3 Likes
Also based on wonderful examples by @GoToLoop:
"""
Based on code by GoToLoop
(2018-Jun-20) https://Discourse.Processing.org/t/how-to-active-controlevent-in-controlp5-python-mode/1113/8
"""
add_library('controlP5')
bg = 200
tx = 100
def setup():
size(400, 300)
global slider_a, slider_b
slider_a = (ControlP5(this)
.addSlider('fundo')
.setSize(width / 2, 20)
.setPosition(width / 4, height / 2)
.setRange(0, 255)
.setValue(bg)
.addListener(sliderListener)
)
slider_b = (ControlP5(this)
.addSlider('texto')
.setSize(width / 2, 20)
.setPosition(width / 4, 40 + height / 2)
.setRange(0, 255)
.setValue(tx)
.addListener(sliderListener)
)
def draw():
background(bg)
fill(tx)
text("HELLO SLIDERS", 120, 120)
def sliderListener(evt):
global bg, tx
if evt.isFrom(slider_a):
bg = int(evt.getValue())
if evt.isFrom(slider_b):
tx = int(evt.getValue())
2 Likes
Thank you very much for your answers. Unfortunately my question was not precise enough: I am not asking for control events in Python in general but I am asking for the control event emitted by the tab class when changing from one tab to the other. There is the method “activateEvent” to which I give the parameter “True” which should make the tab send events when you switch from one tab to the other.
While I see button or slider events I don’t see this tab event.
I also tried the lambda way, which also does not see the event.
The third possibility: adding a callback with cp5.addCallback again works on buttons but I don’t see the tab event.
1 Like