Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Last active February 20, 2022 21:34
Show Gist options
  • Save tshirtman/004de0ac5fea954c5c45411a8f4b984a to your computer and use it in GitHub Desktop.
Save tshirtman/004de0ac5fea954c5c45411a8f4b984a to your computer and use it in GitHub Desktop.
'''
'''
from datetime import datetime
from kivy.app import App
from kivy.lang import Builder
from kivy import properties as P
from kivy.clock import Clock
KV = '''
#:import AT kivy.animation.AnimationTransition
<OdoDigit@StencilView>:
value: 0.0
progress: 0
size_hint: None, None
size: '50dp', '50dp'
joint_pos: self.top - self.height * self.progress
font_size: '50dp'
max: 10
Label:
text: str(int(root.value))
size: root.size
x: root.x
top: root.joint_pos
font_size: root.font_size
Label:
text: str(int(root.value + 1) % root.max)
size: root.size
x: root.x
y: root.joint_pos
font_size: root.font_size
FloatLayout:
BoxLayout:
size_hint: None, None
size: self.minimum_size
pos_hint: {'center': (.5, .5)}
canvas.before:
Line:
rectangle: self.pos + self.size
OdoDigit:
id: h1
value: app.hours / 10
progress: m2.progress if 9 == app.hours % 10 else 0
max: 3
OdoDigit:
id: h2
value: app.hours % 10
progress: m1.progress if 59 == app.minutes else 0
Label:
text: ':'
OdoDigit:
id: m1
value: app.minutes / 10
progress: m2.progress if 9 == app.minutes % 10 else 0
max: 6
OdoDigit:
id: m2
value: app.minutes % 10
progress: s1.progress if 59 == app.seconds else 0
Label:
text: ':'
OdoDigit:
id: s1
value: app.seconds / 10
progress: s2.progress if 9 == app.seconds % 10 else 0
max: 6
OdoDigit:
id: s2
value: app.seconds % 10
# progress: AT.out_quad(app.second_frac) # for something more conventional
progress: AT.out_quint(app.second_frac)
'''
class Application(App):
hours = P.NumericProperty()
minutes = P.NumericProperty()
seconds = P.NumericProperty()
second_frac = P.NumericProperty()
def update_time(self, dt):
time = datetime.now()
self.hours = time.hour
self.minutes = time.minute
self.seconds = time.second
self.second_frac = time.microsecond / 1000_000
def build(self):
Clock.schedule_interval(self.update_time, 0)
return Builder.load_string(KV)
if __name__ == "__main__":
Application().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment