ETO closing and reopening forms

I have a question about ETO forms. I want to be able to close a form, and the redraw it later. When I run this script it doesn’t allow me to call drawForm() a second time. Looking at the ETO docs, I learned that if I close a form I can reopen a new one, but it doesn’t allow me to reopen a form that has already been opened and closed beforehand. Are there any work arounds to this?

Thanks so much, here is my code:

import rhinoscriptsyntax as rs
from Rhino.UI import *
from Eto.Forms import Form, CheckBox, TableRow, TableCell, Drawable, GroupBox, BorderType, Panel, DynamicLayout, VerticalAlignment, TableLayout, ColorPicker,Dialog, Label, TextBox, StackLayout, StackLayoutItem, Orientation, Button, HorizontalAlignment, MessageBox, ProgressBar, ImageView, TextAlignment
from Eto.Drawing import *
import scriptcontext
import os

dir = os.path.dirname(__file__)
#Initialising form
initialForm = Dialog[bool]()
initialForm.Title = "Automated House Design"
initialForm.Resizable = False

layout = TableLayout()
layout.Spacing = Size(5,5)
layout.Padding = Padding(10,10,10,10)

#Defining textboxes, progress bars and buttons

progressBar = ProgressBar(Value = 0, MaxValue = 50)
addSelectedButton = Button(Text = "Add Selected to Favourites")

#Defining checkboxes for images
checkbox1 = CheckBox()
checkbox2 = CheckBox()
checkbox3 = CheckBox()
checkbox4 = CheckBox()
checkbox5 = CheckBox()
checkbox6 = CheckBox()

favouritesArray = []
unwantedArray = []
#Defining boxes for images
boxArray = []
box1 = ImageView()
box1.Image = Bitmap(os.path.join(dir, 'box.png'))

box2 = ImageView()
box2.Image = Bitmap(os.path.join(dir, 'box.png'))

box3 = ImageView()
box3.Image = Bitmap(os.path.join(dir, 'box.png'))

box4 = ImageView()
box4.Image = Bitmap(os.path.join(dir, 'box.png'))

box5 = ImageView()
box5.Image = Bitmap(os.path.join(dir, 'box.png'))

box6 = ImageView()
box6.Image = Bitmap(os.path.join(dir, 'box.png'))

def L(text):
	return Label(Text = text, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Right)

def drawForm():
    #Drawing objects to form
    layout.Rows.Add(TableRow(TableCell(L("Please choose which houses you like"))))
    layout.Rows.Add(TableRow(TableCell(box1), TableCell(box2), TableCell(box3)))
    layout.Rows.Add(TableRow(TableCell(checkbox1), TableCell(checkbox2), TableCell(checkbox3)))
    layout.Rows.Add(TableRow(TableCell(box4), TableCell(box5), TableCell(box6)))
    layout.Rows.Add(TableRow(TableCell(checkbox4), TableCell(checkbox5), TableCell(checkbox6)))
    initialForm.Content = layout
    initialForm.DefaultButton = addSelectedButton
    result = initialForm.ShowModal(RhinoEtoApp.MainWindow)
    return result
def formclose():
    MessageBox.Show(" close 1")
    MessageBox.Show("close 2")


I suppose you want to re-open the form because you want to restore it to its previous state, showing the same numbers etc. If so, you should use a class that represents the state (typically called a ‘view model’) and use bindings in the Eto Form (the view) to the properties in the view model.
That way, you can keep the view model around, and give it to a new instance of the view. The new instance of the view will then bind to the values in the view model. The result is that the view shows the same values, even though it is a new instance.

For more information on this programming model, search for MVVM or Model-View-ViewModel. There are tons of examples.

Hey menmo,

Thanks for your reply.

I actually want the form to be redrawn, it doesn’t matter whether or not it shows the same numbers. I don’t really follow your answer that well, it’s quite difficult for me to understand.

Is there a simple way to redraw the form?


Why does the form need to be drawn? Updating form controls should take care of any ‘redrawing’…

I’ve resolved this issue, thanks anyway.

Instead I added the initialising stuff
"#Initialising form
initialForm = Dialogbool
initialForm.Title = "Automated House Design"
initialForm.Resizable = False
to the drawForm() method, so it initializes every time it’s run.