Changing the text of the Eto Button Element Dynamically

Hi,

I am just getting started with Eto.Forms. I wish to access the button object that triggered the method from within the triggered method OnPickPoint method to update the button’s text.

I am creating many button objects dynamically in the form so I do not wish to reference the buttons externally.

    def OnPickPoint(self, sender, e):
        rc, point = Rhino.Input.RhinoGet.GetPoint("Select Constraint Pt", False)
        if rc != Rhino.Commands.Result.Success: 
            return
        sender.Text = "pt" # This

    def OnButtonClick(self, sender, e):
        EtoExtensions.PushPickButton(self, self.OnPickPoint)
        sender.Text = "pt"  #Or This 

I was thinking that the ‘sender’ argument is a reference to the button object but I must be mistaken because it did not work in the method or the delegator method. What is a dynamic way to access to the Button that triggered the event from within these methods?

Related Posts;

Hi @Kane_Borg,

How about something like this?

import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms

class TestButtonDialog(forms.Dialog[bool]):
    
    def __init__(self):
        self.Title = "Brewing Styles"
        self.Padding = drawing.Padding(5)
        self.Resizable = False
        
        layout = forms.DynamicLayout()
        layout.Padding = drawing.Padding(5)
        layout.Spacing = drawing.Size(5, 5)        
        
        label = forms.Label()
        label.Text = 'Pick your coffee brewing style:'
        layout.AddRow(label)
        layout.AddRow(None) # spacer
        
        self.Labels = []
        self.Labels.append('Drip Brew')
        self.Labels.append('Pour Over')
        self.Labels.append('Cold Brew')
        self.Labels.append('Espresso')
        self.Labels.append('Ristretto')
        
        for text in self.Labels:
            button = forms.Button(Text = text)
            button.Tag = text
            button.Click += self.OnButtonClick
            layout.AddRow(button)
        layout.AddRow(None) # spacer
        
        layout.AddRow(self.CreateOKButton())
        layout.AddRow(None) # spacer
        self.Content = layout
    
    def CreateOKButton(self):
        self.DefaultButton = forms.Button(Text = 'OK')
        self.DefaultButton.Click += self.OnOkButtonClick
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(None, self.DefaultButton, None)
        return layout
        
    def OnButtonClick(self, sender, e):
        if isinstance(sender, forms.Button):
            print(sender.Tag)
            sender.Text = sender.Tag + " Picked"

    def OnOkButtonClick(self, sender, e):
        self.Close(True)
    
def test_eto_button_dialog():
    dialog = TestButtonDialog()
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    print(rc)

if __name__ == "__main__":
    test_eto_button_dialog()    

test_eto_button_dialog.py (1.9 KB)

– Dale

1 Like

Hi Dale,
Thanks, worked like a charm.
image
My mistake was that I was trying to access the sender through the delegate function and not the delegator.