Eto Buton Argument sender, e

i’ve got one buton on my form,
behind this button there is:

    def OnbspieceClick(self,sender,e):

but i would like to use this buton 4 times with an arguments more for change the arguments of the self.close(2)

    def OnbspieceClick(self,sender,e,argumentmore):
        if argumentmore==0:
        if argumentmore==1:
        if argumentmore==2:
        if argumentmore==3:

is it possible?
because when i try it asked me the value of sender and e.

No idea?

Perhaps you could subclass a button and add your argument to e, but how will the button get argumentmore? Can it not be accessed by the callback?

Sorry I don’t understand… “Subclass”?

Yes that’s the question…
I learned that in programming, if you repeat the same code, it is that there is necessarily simpler.
I have a button which launches a command, for example, calculates the surface of the object that I select and places the value in a variable A, and well I would like to have 4 buttons, each for a different variable.

I’m not familiar with ETO or python, but if it’s similar to C# and winforms, you can’t change the delegate, because it’s like a contract between the sender of the event (the button) and whoever wants to subscribe to it (the method that will call when the button is activated). However, this pattern is often made with conventions, for example, sender is the actor of the event and e or args the parameters. Then check the properties and methods of both, it is possible that sender has an Tag property of type object? in that case, this is usually used for this task, before the event is called you assign your data to that property of the sender instance and then inside the callback you can access it.

If you have 4 different buttons why don’t you declare a separate handler for each of them?
By the way, if you want to attach all of them to the same event handler, you can distinguish them by their Text properties:

import Rhino
import Eto.Forms as forms
import Eto.Drawing as drawing
class EtoButtons(forms.Dialog[bool]):
    def __init__(self):
        self.Title = 'EtoButtons'
        self.Padding = drawing.Padding(10)
        self.Resizable = False

        self.FirstButton = forms.Button(Text = 'First')
        self.FirstButton.Click += self.OnButtonClick

        self.SecondButton = forms.Button(Text = 'Second')
        self.SecondButton.Click += self.OnButtonClick

        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.FirstButton, self.SecondButton)

        self.Content = layout

    def OnButtonClick(self, sender, e):
        print(sender.Text + " is clicked!")

dialog = EtoButtons();

ok!! i’ll try this, thank you… but how can i find this solution by myself, where can i find a simple explanation for sender and e, does it exist in every script language?

Is there other property for sender?

1 Like