Timer to close form

Hi,
I tried many different approaches to get a forms.alert from a hook to close itself after a few seconds:

for the base form

from pyrevit import forms, script, EXEC_PARAMS
warning_window = forms.alert("my message", title="Warning")

tried:

op = script.get_output()
op.self_destruct(2)

and also

from time import sleep
sleep(3)
warning_window.Close()

and this

from time import sleep
sleep(3)
warning_window.exit()

and also

from time import sleep
sleep(3)
EXEC_PARAMS.event_args.Cancel = True

to no avail.
I think I am missing the point.
I am guessing I need to somehow grab the window itself before being able to exit it.

any pointer in the right direction would be greatly appreciated.

Alert forms require interaction by nature as I understand it so you would have to send keys after a time to close it automatically. Would require import of PyAutoGUI or similar and complicate deployment though.

I picked forms.alert at first as it served my purpose well at the time.
Do you have another suggestion fo something that would a similar window where I could use a timer of some sort? @eprunty

I managed to get something out of a wpf.
beware of space at the end of each layout line
the space between the " and ’ is important

blahblah" '
# -*- coding: UTF-8 -*

from pyrevit import forms, script
import time

doc = __eventargs__.Document

### output section
output = script.get_output()
output.close_others(all_open_outputs=True)

layout ='<Window ' \
        'xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ' \
        'xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ' \
        'Title="Test 1 2 1 2 " Height="150" Width="300"> ' \
        '<Grid> ' \
        '<TextBlock x:Name="textBlock" TextWrapping="Wrap" Text="this is the kind of text you might want to input" Margin="0,40,0,44"/> ' \
        '</Grid> ' \
        '</Window>'

w = forms.WPFWindow(layout, literal_string=True)
w.show()
time.sleep(3)
w.hide()
1 Like