ETO dropdown question


(Nico de Meester) #1

image

I try to preset and update the text fields in the ETO panel for the door Width / Height and Sill height.
I want to use of the dropdown box with predefined door dimensions, But I stuck.
Is it possible to update these values right away in the panel when I select from the dropdownbox one of the definitions?

Doors.py (3.9 KB)


#2

I think you just want to change the text boxes based on the dropdown selection. If that is the case:

If you have just a static set of door types, I wouldn’t use the DataStore with ironpython as it seems like it requires a bit of overhead. According to this example, you need to make objects for each door type and then put them in a .net ObservableCollection. If you need to use the DataStore for some reason maybe that example will help. Otherwise…

I would just use a dictionary to hold your door types and populate the dropdown with the keys of that dictionary. Then add an event handler for a change in dropdown value, look up the door size in the dictionary, and change the text boxes.

This is working here, at least the dropbox part. I put changes between ############################ lines, and commented out things that caused issues.

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
# from Frames import FrameGrid
import Eto.Drawing as drawing
import Eto.Forms as forms

# SampleEtoDoorSize dialog class
class DoorDialog(forms.Dialog[bool]):

    # Dialog box Class initializer
    def __init__(self):
        # Initialize dialog box
        self.Title = 'Door dimensions'
        self.Padding = drawing.Padding(10)
        self.Resizable = False
        #######################################
        # make a door size dictionary
        self.door_sizes = {'type_1': (1, 2, 3),
                           'type_2': (4, 5, 6),
                           'type_3': (7, 8, 9),
                           }
        #######################################
        

        # Create controls for the dialog
        self.m_label4 = forms.Label(Text = 'Door Type:')
        self.m_label1 = forms.Label(Text = 'Door Width:')
        self.m_textbox1 = forms.TextBox(Text = str(2050-600))
        self.m_label2 = forms.Label(Text = 'Door Height:')
        self.m_textbox2 = forms.TextBox(Text = "700")
        self.m_label3 = forms.Label(Text = 'Sill Height:')
        self.m_textbox3 = forms.TextBox(Text = "600")
        
        #Create combobox
        self.m_combobox1 = forms.DropDown()
        #self.m_combobox1.DataStore = ['External', 'A(Steel)', 'B(Cabin)']
        #########################################
        # set items to keys of dictionary
        for k in self.door_sizes.keys():
            self.m_combobox1.Items.Add(k)
        #########################################
        
        
        # self.m_combobox1.SelectedIndex = 0
        # if self.m_combobox1.DropDownClosed : self.OnComboBox1Change  # ?
        #forms.ComboBox.MouseDownEvent
        
        
        #########################################
        # add event for change in dropbox
        self.m_combobox1.SelectedValueChanged += self.handle_value_change
        # and now I would set the index to make the text boxes update
        # rather than set them manually as above
        self.m_combobox1.SelectedIndex = 0
        #########################################
        

        
        
        
        # Create the default button
        self.DefaultButton = forms.Button(Text = 'OK')
        self.DefaultButton.Click += self.OnOKButtonClick

        # Create the abort button
        self.AbortButton = forms.Button(Text = 'Cancel')
        self.AbortButton.Click += self.OnCloseButtonClick

        # Create a table layout and add all the controls
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.m_combobox1)
        layout.AddRow(self.m_label1, self.m_textbox1)
        layout.AddRow(self.m_label2, self.m_textbox2)
        layout.AddRow(self.m_label3, self.m_textbox3)
        layout.AddRow(None) # spacer
        layout.AddRow(self.DefaultButton, self.AbortButton)

        # Set the dialog content
        self.Content = layout

    # Start of the class functions

    # Get the value of the textbox
    def GetText(self):
        Height = self.m_textbox2.Text
        Width = self.m_textbox3.Text
        Sill = self.m_textbox3.Text
        DropboxValue = self.m_combobox1.DataStore[self.m_combobox1.SelectedIndex]
        return Height, Width, Sill, DropboxValue

    # Modify the textbox values
    def OnComboBox1Change(self, sender, e):
        self.layout.Visible = False
        if self.m_combobox1.Text=="External":
            self.m_combobox1.SelectedIndex = 0
            self.m_textbox1.Text = str(2050-600); self.m_textbox2.Text = "700"; self.m_textbox3.Text = "600"
        elif self.m_combobox1.Text=="A(Steel)":
            self.m_combobox1.SelectedIndex = 1
            self.m_textbox1.Text = "2000"; self.m_textbox2.Text = "700"; self.m_textbox3.Text = "50"
        else :
            self.m_combobox1.SelectedIndex = 2
            self.m_textbox1.Text = "2050"; self.m_textbox2.Text = "700"; self.m_textbox3.Text = "0"
        self.layout.Visible = True
        self.Close(False)
        
    #############################################
    # function to update the text boxes
    def handle_value_change(self, sender, e):
        dropbox_value = str(self.m_combobox1.SelectedValue)  # this returns a 'ListItem', not a string, so change it.
        size = self.door_sizes.get(dropbox_value, None)
        if size:
            self.m_textbox1.Text = str(size[0])  # these are numbers, so have to make strings for textbox
            self.m_textbox2.Text = str(size[1])
            self.m_textbox3.Text = str(size[2])
    #############################################

    # Close button click handler
    def OnCloseButtonClick(self, sender, e):
        self.m_textbox1.Text = ""
        self.m_textbox2.Text = ""
        self.m_textbox3.Text = ""
        self.Close(False)

    # OK button click handler
    def OnOKButtonClick(self, sender, e):
        if self.m_textbox1.Text == "" or self.m_textbox2.Text=="" or self.m_textbox3.Text=="":
            self.Close(False)
        else:
            self.Close(True)


def DoorOpening():
    dialog = DoorDialog();
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    if (rc):
        print "Door Type = "+dialog.GetText()[3]
        print "Door Height = "+dialog.GetText()[0]
        print "Door Width = "+dialog.GetText()[1]
        print "Door Sill Height = "+dialog.GetText()[2]

if __name__ == "__main__":
    DoorOpening()

(Nico de Meester) #3

Hi Nathan,

Thanks for your replay. Its exactly what I wanted.
I tried to find a way to control the dropdown event but I couldn’t find the right one.
May be I interpreted the API ETO documentation in the wrong way.
I looked to http://api.etoforms.picoe.ca/html/T_Eto_Forms_DropDown.htm page and didn’t saw the .SelectedValueChanged option.

Now I think I found the link to the Listcontrol class (because the dropdown option is a member of it?)


#4

Ok glad it helped. Yes I agree the eto documentation isn’t the best. Also expand the tree in the rhino python editor for eto and you can find a condensed list of methods/events for a given control.


#5

hi guys. Wich development enviroment are you using for making those UI with ETO? I found discouraging to write all that code for just a simple windows with a pair of components. VS graphical edition functionalitiy is so helpful when woking with winforms. Is is out there anything similar for ETO?

thanks
aitor


#6

I use only the Rhino python editor. One does have to think about the gui from a code perspective, rather than visual, but I think it is the only option for using iron python; at least with the quick iteration cycle of using the built in editor. If you are prepared to give that up then you might as well use c# + wpf. I’m not sure how c# + eto works out in Visual Studio, but I don’t think eto is as complete as wpf, so I would jump to wpf in that case.


(Nico de Meester) #7

To me its the same. I am not a software engineer and I never used VS before . By use of the rhino python editor and ETO I have the possibility to write my own macros and now also my own panels within Rhino. It can’t be easier for me.


#8

ok, thanks! I guess I will stick to good old winforms