Message Box That can be turned off after a time

Hello,

I have a python macro that takes a fair amount of time to complete and I’ve been sending messages to the command line asking the user to wait, which they may or may not see.

Is there a way to display a message box that simply says “Please Wait” and then turn it off after finishing the task in Python? It’s never going to be a set amount of time so a timer won’t work.

I thought about writing a text object to the Rhino Screen asking them to wait and then deleting it but I am looking for a cleaner way if possible.

Eric

Hi @eric.bunn,

Popping up a modeless dialog box with a message will probably do the trick.

– Dale

Thanks Dale. How would you close the form with code?

Do you have an example?

Eric

Dale

Here’s an old post that I never got resolution on: ETO Modeless Form Close Button

I cannot figure how to close the form without a crash.

Eric

@eric.bunn - this is quick and dirty. Hopefully you will get the idea:

import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import scriptcontext as sc

class WaitForm(forms.Form):

    def __init__(self):
        self.Title = "Wait!"
        self.Padding = drawing.Padding(5)
        self.Resizable = False
        self.Maximizable = False
        self.Minimizable = False
        self.ShowInTaskbar = False
        self.MinimumSize = drawing.Size(200, 100)
        self.ClientSize = drawing.Size(200, 100)
        label = forms.Label()
        label.Text = "Hold on a second..."
        self.Content = label
        self.Closed += self.OnFormClosed
        #bounds = self.Screen.Bounds
        #self.Location = drawing.Point(bounds.MiddleX - self.ClientSize.Width / 2, bounds.MiddleY - self.ClientSize.Height / 2)
    
    def OnFormClosed(self, sender, e):
        if sc.sticky.has_key('wait_form'):
            form = sc.sticky['wait_form']
            if form:
                form.Dispose()
                form = None
            sc.sticky.Remove('wait_form')
            
def Test():
    if sc.sticky.has_key('wait_form'):
        return

    form = WaitForm()
    form.Owner = Rhino.UI.RhinoEtoApp.MainWindow
    form.Show()
    sc.sticky['wait_form'] = form    
    
    Rhino.RhinoApp.WriteLine('Do something that takes a long time')
    rc, str = Rhino.Input.RhinoGet.GetString("Press Enter when done", True, '')
    
    if sc.sticky.has_key('wait_form'):
        form = sc.sticky['wait_form']
        if form:
            form.Close()
    
if __name__ == "__main__":
    Test()    

– Dale

1 Like

Dale,

Thank you. I think this will work for me. Just for my own edification, can you explain what these lines of code do? Not familiar with sticky?

sc.sticky['wait_form'] = form    

Rhino.RhinoApp.WriteLine('Do something that takes a long time')
rc, str = Rhino.Input.RhinoGet.GetString("Press Enter when done", True, '')

if sc.sticky.has_key('wait_form'):
    form = sc.sticky['wait_form']
    if form:
        form.Close()

Thanks,

Eric

Sticky is just a dictionary that useful for storing Python stuff between script executions.

More on Sticky:

– Dale

Hi Dale,

On a side note, is there a function to remove a sticky? Or do we just set it to a false value and just leave it in?

Hi @christopher.ho,

With the above example, just do:

sc.sticky.Remove('wait_form')

– Dale

Thanks. So your storing the form in there for use later in the script. Correct?

Eric

@Eric,

You display the form when you call show.
The reason for the sticky is so that the form can remove itself after you complete the task in the background.
The form can be closed by the user, after being shown, but will automatically close once the task is complete.

 if sc.sticky.has_key('wait_form'):
     form = sc.sticky['wait_form']
     if form:
         form.Close()

Checks if the form has been closed by the user or not and closes it.

The lines:

Rhino.RhinoApp.WriteLine('Do something that takes a long time')
rc, str = Rhino.Input.RhinoGet.GetString("Press Enter when done", True, '')

are where you perform your task.

Thank you. That makes sense now.

Eric

Please be advised that Eric Clough has died (Aug 2020)
Thank you

Opps,
sorry