Created
June 5, 2018 18:24
-
-
Save el3/af880ac80212ba61d54ea098075c44b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.uix.label import Label | |
from kivy.lang import Builder | |
from kivy.properties import NumericProperty, ListProperty | |
from kivy.clock import Clock | |
Builder.load_string(""" | |
<Circle>: | |
canvas.before: | |
Color: | |
rgba: .5,.5,.5,.5 | |
Line: | |
circle: [root.center_x, root.center_y, root.radius] | |
width: root.thickness | |
cap: "none" | |
Color: | |
hsv: [1*root.value/100*0.25,1,1] | |
Line: | |
circle: [root.center_x, root.center_y, root.radius, -0.8, (360 * root.value/100 + 0.8) ] | |
width: root.thickness | |
cap: "none" | |
text: "{}%".format(root.value) | |
font_size: "40sp" | |
""") | |
class Circle(Label): | |
value = NumericProperty(0) | |
radius = NumericProperty(100) | |
thickness = NumericProperty(20) | |
def __init__(self, **kwargs): | |
super(Circle, self).__init__(**kwargs) | |
self.pro_range = [] | |
self.event = Clock.schedule_interval(self.set,1/60) | |
def set(self, dt): | |
if len(self.pro_range): | |
self.value = self.pro_range.pop(0) | |
else: | |
self.event.cancel() | |
def set_value(self, value=0, *args): | |
try: | |
value = round(float(value),1) | |
except: | |
return False | |
self.event.cancel() | |
diff = value - self.value | |
self.pro_range = [] | |
if abs(diff) > 0: | |
for pro in range(int(self.value*10), int(value*10), int(diff) or 1): | |
self.pro_range.append(pro/10) | |
self.pro_range.append(value) | |
self.event() | |
from kivy.app import App | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.properties import ObjectProperty | |
class MyLayout(BoxLayout): | |
circle = ObjectProperty(None) | |
KV = """ | |
MyLayout: | |
circle: circle | |
TextInput: | |
font_size: "30sp" | |
text: "0" | |
on_text: | |
circle.set_value(self.text) | |
Circle: | |
id: circle | |
""" | |
class MyApp(App): | |
def build(self): | |
root = Builder.load_string(KV) | |
return root | |
MyApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment