Kane_Borg
(Kane Borg)
June 8, 2022, 10:16am
1
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;
I was reading this post on the rhino3d website and I was having problem understanding the way the bound method as described in the post is structure, copied below:
The bound method, listed later in the calss definition is run if the button is clicked.
# Close button click handler
def OnOKButtonClick(self, sender, e):
if self.m_textbox.Text == "":
self.Close(False)
else:
self.Close(True)
where does the sender and e input coming from? Do I ever …
Btw, you can also add a Tag to a control in your __init__ function and get this from the sender:
import Eto
import Rhino
class Form1(Eto.Forms.Dialog[bool]):
def __init__(self):
self.WoodButton = Eto.Forms.Button(Text="Wood", Tag="000")
self.WoodButton.Click += self.OnButtonClick
self.MetalButton = Eto.Forms.Button(Text="Metal", Tag="001")
self.MetalButton.Click += self.OnButtonClick
layout = Eto.Forms.DynamicLayout()
layout.AddRow(self.WoodB…
dale
(Dale Fugier)
June 8, 2022, 4:07pm
2
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.
My mistake was that I was trying to access the sender through the delegate function and not the delegator.