Python eto ValueChanged in a class

hi everyone,

I am setting up a NumericUpDown with python eto in a class.
the following is a part of my code

class MyEtoClass(forms.Form):
    def __init__(self):
        self.Title = 'My Title'
    
        def addnumeric(name='myslider'):
            setattr(self, name, forms.Slider())
            setattr(getattr(self, name), 'Value', 1)
            setattr(getattr(self, name), 'MinValue', 0)            
            setattr(getattr(self, name), 'MaxValue', 10)
            setattr(getattr(self, name), 'ValueChanged', getattr(getattr(self, name), 'ValueChanged')+self.onvaluechanged)

however python doesn’t allow me to set the ValueChanged attribute like this
the original one should be:
self.myslider.ValueChanged += self.onvaluechanged

The error is:
Runtime error (TypeErrorException): unsupported operand type(s) for +: ‘BoundEvent’ and ‘instancemethod’

Traceback:
line 25, in addnumeric, “”
line 28, in init, “”
line 45, in script

Actually, I don’t know how this line works.
The Idea is to create multiple sliders within the init function so that i don’t have to repeat myself.

Could anyone explain the idea of the line or give me some other ways to do this?

Thanks

Hi @raylee14, i guess you cannot tread an Event like an attribute and assign it that way.

Below is an example, multiple sliders are added in a loop, all with the same event. Note that i Tag the sliders to detect them in the event code. I guess you can do the same with NumericStepper.

ETO_SliderSample.py (2.9 KB)

_
c.

2 Likes

thank you so much. let me dive into this first :laughing:
btw, what ValueChanged and OnValueChanged actually do?
and is there any other source to learn python eto?
I only found a few of it, make my job very very hard :cry:

slider.ValueChanged is the event which occurs if the slider property Value is changed. You can connect a function to this event by calling eg.:

 slider.ValueChanged += self.OnSliderValueChanged

The name of the function can be any name, the arguments are fixed. A good general introduction to form events can be found in the Windows Forms docs

For Eto controls you might start here and for all other things with the Eto docs

_
c.

1 Like

I got it. What about OnValueChanged? is it doing the same thing as ValueChanged?

ValueChanged is the event which notifies any subscriber that the value has changed.
To explain it more understandable:
A cook saying the meal is ready for instance could name this event FoodIsReady.

Any subscriber to this event can have unique response to this. Usually calling the method responsible ‚On‘- or ‚Handle‘- .
So a waiter would have a response OnFoodIsReady which does something like Go to the kitchen, grab the food bring it to the guest.
So the OnValueChanged is a individual response to the ValueChanged event.

1 Like

Amazing. Clear explanation. Thanks again dude :heart_eyes: