ztimer0_1.py

Created by steveg1cmz

Created on March 12, 2024

1.71 KB

Rudimentary timer functionality: No buttons version for Android.


"""Z Timer.
The interval time can be entered or measured.
Interval times can be displayed.
Expressions can be entered (eg 3*60 for minutes).

Note that Numworks has limited io, so there is no easy way to stop a running timer.

This module aims to provide practical results.

Version 0.01: Rudimentary text display
"""

__version__="0.1"

from time import *

zt="Z Timer "+__version__
crid=zt+"\n© 2024 SteveG1CMZ";

#customise
OK="[OK|EXE]" #platform-specific
#end custom

disclaimer="No liability accepted" 
stduration="duration_s:"
stinterval="Interval_s:"
stmeasure="[0:measure]"
stremaining="......._s:"

p0=OK+"[s]: start"
p1=OK+": stop"
  
def about():
  """ Accuracy analysis: 
  Timing of keypresses are rounded to ms.
  
  """
  print(disclaimer)

def display_interval_s(time_s):
  """ display seconds since started and remaining.
  """
  s=0
  while time_s>0:
    sleep(1)
    time_s=time_s-1
    s=s+1
    print(stduration,s,stremaining,time_s)
  #if buttons existed we could return duration
  return s 
  
def measure_interval_s(prompt0,prompt1):
  """Measure an interval (s).
  Accessibility: Seconds can be entered.
  """
  x=input(prompt0)
  if x=="":
    t=monotonic()
    x=input(prompt1)
    t=monotonic()-t
    t=round(t,3) #round key io to ms
  else:
    t=eval(x) #numerical expression
  return t

def ask_display_interval(s):
  if s==0:
    s=float(input(stduration))
  t=display_interval_s(s)
  print(stinterval,t,"s")
  
def ask_measure_interval(stinterval,p0,p1):
  print(stinterval)
  t=measure_interval_s(p0,p1)
  print(t,"s")
  
def examples():
  display_interval_s(30)
  ask_display_interval(0)
  ask_measure_interval(stinterval,p0,p1)
  
  
if __name__=="__main__" or True:
  print(crid)
  examples()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.