The code of the final version of the multi-touch enabled ClockWidget:
Kivy ClockWidget on a Lenovo X220T
ClockWidget.py:
import kivy
kivy.require('1.2.0')
import time
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty, StringProperty, NumericProperty
from kivy.clock import Clock
from kivy.uix.scatter import Scatter
from kivy.config import Config
Config.set('modules', 'touchring', '')
Weekday = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
def getDayOfWeek(dateString):
t1 = time.strptime(dateString,"%m/%d/%Y")
t2 = time.mktime(t1)
return(time.localtime(t2)[6])
class ClockWidget(Scatter):
uxTime = StringProperty('')
uxSeconds = NumericProperty(0)
uxSecondsStr = StringProperty('')
uxDate = StringProperty('')
uxDay = StringProperty('')
def update(self, dt):
self.uxTime = time.strftime("%H:%M", time.localtime())
self.uxSecondsStr = time.strftime("%S", time.localtime())
self.uxSeconds = int(self.uxSecondsStr)
self.uxDate = time.strftime("%d %B %Y", time.localtime())
self.uxDay = Weekday[getDayOfWeek(time.strftime("%m/%d/%Y", time.localtime()))]
class ClockWidgetApp(App):
def build(self):
clockWidget = ClockWidget()
Clock.schedule_interval(clockWidget.update, 1)
return clockWidget
if __name__ == '__main__':
ClockWidgetApp().run()
ClockWidget.kv:
#:kivy 1.0
<ClockWidget>:
scale_max: 100
size_hint: None, None
size: (512, 512)
pos: (50, 50)
FloatLayout:
canvas:
Color:
rgb: 1, 1, 1
Ellipse:
size: 150, 150
pos: 430, 240
Color:
rgb: 0, 0, 1
Ellipse:
size: 150, 150
angle_start: 0
angle_end: root.uxSeconds * 6
pos: 430, 240
Color:
rgb: 0, 0, 0
Ellipse:
size: 130, 130
pos: 440, 250
Label:
text: root.uxSecondsStr
font_size: 70
pos: 455, 260
FloatLayout:
size: root.width, root.height
Label:
id: time_label
text: root.uxTime
font_size: 100
pos: 0, 50
Label:
id: date_label
text: root.uxDate
font_size: 30
pos: 40, -20
Label:
id: day_label
text: root.uxDay
font_size: 30
pos: 160, -60