# cpy Thonny - guizero shuttle simulation - signal
# provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-01-03  initial release

# tools |  manage packages | guizero : search on pypi | install
# drawing: https://lawsie.github.io/guizero/drawing/

import	time
from 	guizero import App, Drawing

# ==================== GUI setup =========================

app = App('Shuttle simulation', width=800, height=200)
ctx = Drawing(app, width='fill', height='fill')

# ======================= Widgets ========================

# draw 2 aspect signal, centre at x, y
def aspect2(x=0, y=0, green=False):
    x0 = 400+x; y0=100+y
    ctx.line     (x0-30, y0-2,  x0-10, y0-2,  width=2)
    ctx.line     (x0-30, y0+2,  x0-10, y0+2,  width=2)
    ctx.line     (x0-30, y0-10, x0-30, y0+10, width=5)
    ctx.rectangle(x0-10, y0-10, x0+30, y0+10, color='black')
    if green:
        ctx.oval(x0+14, y0-6, x0+26, y0+6, color='lime')
    else:
        ctx.oval(x0-6,  y0-6, x0+6,  y0+6, color='red')


# draw layout:  signals, track and train
def layout(col):
    ctx.clear()					# clear context
    aspect2(green=col)
    
# ======================= Timer =========================

signal_green = True
# application sequencer
def onTimer():
    global signal_green
    
    layout(signal_green)
    signal_green = not signal_green
    
# ========================= main =========================

    
aspect2()
ctx.repeat(1000, onTimer)			# sequencer @ 1 Sec
app.display()						# start GUI loop
    
# ========================== end =========================    
