DroidScript / Docs

DroidScript Documentation
Apache License 2.0
81 stars 29 forks source link

CreateOverlay example Python #211

Open Al4He6 opened 2 months ago

Al4He6 commented 2 months ago

https://github.com/DroidScript/Docs/blob/63145db940b0ace9ef88855f7e3a4ec9c6c4576c/files/markup/en/app/CreateOverlay.js#L130

Cannot access local variable lst

Al4He6 commented 1 month ago

Adding global list inside Update function fixes syntax error (not sure the overlay works)

cfg.Portrait

from native import app

def OnStart(): global img app.ToBack() lay = app.CreateLayout("Linear")

img = app.CreateImage(None, 0.3, 0.1)
img.SetBackColor("#66333333")
img.SetAutoUpdate(False)
lay.AddChild(img)

ovl = app.CreateOverlay()
ovl.AddLayout(lay, 0,0)

app.Animate(Update, 1)

lst = [1e5] * 100

def Update(time, dtime): mem = app.GetMemoryInfo() global lst lst.append(round(100 * mem.avail / mem.total) - 50) lst = lst[-100:]

img.Clear()
img.SetPaintColor("red")
img.DrawLine(0, mem.threshold / mem.total, 1, mem.threshold / mem.total)

img.SetPaintColor("white")
img.DrawSamples(lst, 50)
img.Update()