Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Synchronize values in Eto forms

$
0
0

I’m working on a custom Eto form with GhPython and looking to synchronize values from both controls, in this case a slider and a numeric updown
Snag_21890ad0
When slider value is changed, the numeric should update as well as the oposite, when the numeric value changes, the slider updates too, keeping them syncronized.
So far I’ve created the controls but not sure how to syscronize both, does anyone knows how to achieve this?
Here’s the code

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

class OptionsPanel(forms.Form):

    def __init__(self):
        self.Padding = drawing.Padding(10)
        self.Size = drawing.Size(350,100)
        self.m_slider = forms.Slider()
        self.m_slider.MinValue = 1
        self.m_slider.MaxValue = 100
        self.m_slider.Value = 1
        self.m_slider.ValueChanged += self.OnSliderValueChanged
        self.m_numeric_updown = forms.NumericUpDown()
        self.m_numeric_updown.DecimalPlaces = 0
        self.m_numeric_updown.Increment = 1
        self.m_numeric_updown.MaxValue = 100.0
        self.m_numeric_updown.MinValue = 1.0
        self.m_numeric_updown.Value = 1
        self.m_numeric_updown.ValueChanged += self.OnSliderValueChanged
        
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.m_slider, self.m_numeric_updown)
        layout.AddRow(None)
        self.Content = layout
 
    def OnSliderValueChanged(self, sender, e):
        ghenv.Component.ExpireSolution(True)

    def GetNumber1(self):
        return self.m_slider.Value
 
    def GetNumber2(self):
        return self.m_numeric_updown.Value

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

if 'form' in globals():
    value1 = form.GetNumber1()
    value2 = form.GetNumber2()

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles