I removed the app.debug statements and pass the form’s load event to the main routine, so it works withe stand-alone forms and embedded forms, with the code embedded in the Base document or in the global scope.
@stinsonpilot,
- Open the Script folder in your profile directory.
- Create a subfolder python.
- Save the script code as a plain text file with suffix .py
- Add a label control named lbl_clock to your data form.
- Assign the main routine to the form’s event When loading
- The form needs to be linked to some record set.
For arbitrary stand-alone Writer documents, use the original version with app.debug statements removed.
# coding: utf-8
from __future__ import unicode_literals
import uno
import datetime
import threading
event = None
def run_in_thread(fn):
def run(*k, **kw):
t = threading.Thread(target=fn, args=k, kwargs=kw)
t.start()
return t
return run
@run_in_thread
def start_clock(form):
global event
event = threading.Event()
label = form['lbl_clock']
while not event.wait(1):
show_clock(label)
return
def show_clock(label):
now = datetime.datetime.now().replace(microsecond=0).time()
label.Label = str(now)
return
def stop_clock():
global event
event.set()
return
def main(ev):
start_clock(ev.Source)
return