Hi,
I have been butchering a Rhino example to have a play with making Eto forms but I cannot get the list box to populate with the items to make the selection from. I have tried many variations and have come to a halt, can anyone advise in baby steps as this is all new to me.
My goal is to select which data set of points to select in Rhino model space, select the points and then sort the data by either ptname, X,Y or Z values and write to a file. I can do this in my python script which at present is not linked to any form so the UI is the last bit to do. As I am new to Python I am not really sure if I went about the whole process in the right order but I do at least have a script that works even if it is not as neat as I would like.
import scriptcontext
import rhinoscriptsyntax as rs
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
################################################################################
Sample dialog class extending the Eto Dialog([T])
################################################################################
class CollapsableEtoDialog(forms.Dialog[bool]): # return True or False from ShowModal()
def __init__(self):
self.Title = "Points to 3DIM"
self.Resizable = True
self.Padding = drawing.Padding(5)
# Custom label helper to set alignment
def L(text):
m_label = forms.Label()
m_label.Text = text
m_label.VerticalAlignment = forms.VerticalAlignment.Center
m_label.TextAlignment = forms.TextAlignment.Right
return m_label
# set content of the collapsed section
self.collapsePanel = forms.DynamicLayout(Visible = True, Padding = drawing.Padding(40, 10), DefaultSpacing = drawing.Size(5, 5))
self.collapsePanel.BeginVertical()
self.collapsePanel.EndVertical()
self.collapsePanel.AddRow(None, forms.CheckBox(Text = "Select Measured Points"))
self.collapsePanel.AddRow(None, forms.CheckBox(Text = "Select Nominal Points"))
self.collapsePanel.AddRow(None, L("Sort:"),forms.ListBox())
self.DataStore = ['Name', 'X Value', 'Y Value', 'Z Value']
self.SelectedIndex = 0
# Create Radio Button List Control
self.m_radiobuttonlist = forms.RadioButtonList()
self.m_radiobuttonlist.DataStore = [‘first pick’, ‘second pick’, ‘third pick’]
self.m_radiobuttonlist.Orientation = forms.Orientation.Vertical
self.m_radiobuttonlist.SelectedIndex = 1
# a few buttons always shown at the bottom
self.cancelButton = forms.Button(Text = "Cancel")
self.cancelButton.Click += self.cancelButton_Click;
self.okButton = forms.Button(Text = "OK")
self.okButton.Click += self.okButton_Click
# set default buttons when user presses enter or escape anywhere on the form
self.DefaultButton = self.okButton
self.AbortButton = self.cancelButton
toleranceUpDown = forms.NumericUpDown()
# our main layout
layout = forms.DynamicLayout(DefaultSpacing = drawing.Size(2,2))
layout.AddSeparateRow(None, L(“Tolerance”), toleranceUpDown, L(“millimeters”), self.collapseButton)
layout.AddCentered(self.collapsePanel) # we need this auto-sized so we can get its width to adjust form height
layout.Add(None); # expanding space, in case you want the form re-sizable
layout.AddSeparateRow(None, self.cancelButton, self.okButton);
self.Content = layout;
def cancelButton_Click (self, sender, e):
self.Close(False)
def okButton_Click (self, sender, e):
self.Close(True)
if self.ShowModal():
print "Do something, user clicked OK"
################################################################################
Creating a dialog instance and displaying the dialog.
################################################################################
def TestCollapseEtoDialog():
dialog = CollapsableEtoDialog()
dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
################################################################################
Check to see if this file is being executed as the “main” python
script instead of being used as a module by some other python script
This allows us to use the module which ever way we want.
################################################################################
if name == “main”:
TestCollapseEtoDialog()