Eto Slider Values don't update dynamically with python

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

class EtoSliderForm(forms.Form):

    def __init__(self):
        self.Title = 'Eto Slider'
        self.Padding = drawing.Padding(10)
        self.Resizable = False
        self.Width = 500
        self.Height = 100

        self.m_slider = forms.Slider()
        self.m_slider.MinValue = 1
        self.m_slider.MaxValue = 50
        self.m_slider.Value = value
        self.m_slider.ValueChanged += self.OnSliderValueChanged

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

        self.Content = layout
        
    def OnSliderValueChanged(self, sender, e):
        ghenv.Component.ExpireSolution(True)

    def GetNumber(self):
        return self.m_slider.Value

if show:
    if 'form' in globals():
        form.Close()
    form = EtoSliderForm();
    form.Show()

if 'form' in globals():
    value = form.GetNumber()
if 'value' not in globals():
    value = 1
a = Rhino.Geometry.Circle(value)

EtoSlider.gh (5.2 KB)

If you want to interact with Rhino, you need to use a modeless form any modal form will block the parent forms.
If you use a modeless form you will face another problem, I don’t know why but it seems that TopMost property of Eto.Forms does not work as it supposes to.
Rhino.UI.EtoExtensions.ShowSemiModal() will allow the user to interact with the main Rhino window while keeping it on top but the problem is it will block grasshopper.
Long story short, there might be better approaches:

  • Human-UI
  • Eto.forms in Rhino Python with ShowSemiModal().
  • WinForms or WPF in GhPython or C# script.
5 Likes