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()