New Python user - GUI on a Mac?

I tried the sample again, and it seems iron python is having trouble importing some types from the Eto.Forms namespace. I fixed it by importing the used types directly. I’m sure these types of issues will be flushed out when this is supported, but I’ve updated the sample with a bit more functionality so you can see how to layout controls and get a value from a text box:

import clr
clr.AddReference("Eto")
clr.AddReference("Rhino.UI")

from Rhino.UI import *
from Eto.Forms import Form, Dialog, Label, TextBox, StackLayout, StackLayoutItem, Orientation, Button, HorizontalAlignment, MessageBox
from Eto.Drawing import *

dlg = Dialog[bool](Title = "Some Dialog", Padding = Padding(10))

label = Label(Text = "Enter a value:")

textBox = TextBox()

entry = StackLayout(Spacing = 5, Orientation = Orientation.Horizontal)
entry.Items.Add(label)
entry.Items.Add(textBox)

apply = Button(Text = "Apply")
def apply_click(sender, e): dlg.Close(True) # true is return value
apply.Click += apply_click

cancel = Button(Text = "Cancel")
def cancel_click(sender, e): dlg.Close(False)
cancel.Click += cancel_click

buttons = StackLayout(Spacing = 5, Orientation = Orientation.Horizontal)
buttons.Items.Add(cancel)
buttons.Items.Add(apply)


content = StackLayout(Spacing = 5) # default orientation is vertical
content.Items.Add(entry)
content.Items.Add(StackLayoutItem(buttons, HorizontalAlignment.Right))

dlg.DefaultButton = apply
dlg.AbortButton = cancel
dlg.Content = content;
result = dlg.ShowModal(RhinoEtoApp.MainWindow)

if result:
	# Do something
	MessageBox.Show("You entered: " + textBox.Text)

Hope this helps!
Curtis.

2 Likes