-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressbar2.py
76 lines (64 loc) · 2.08 KB
/
progressbar2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from kivy.core.text import LabelBase
from kivy.uix.anchorlayout import AnchorLayout
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.properties import ListProperty, StringProperty, NumericProperty
from kivy.core.window import Window
from kivy.clock import Clock
import time
Window.size = (350, 600)
kv = '''
<CircularProgressBar>
canvas.before:
Color:
rgba: root.bar_color + [0.3]
Line:
width: root.bar_width
ellipse: (self.x, self.y, self.width, self.height, 0, 360)
canvas.after:
Color:
rgb: root.bar_color
Line:
width: root.bar_width
ellipse: (self.x, self.y, self.width, self.height, 0, root.set_value*3.6)
MDLabel:
text: root.text
# font_name: "BPoppins"
font_size: "40sp"
pos_hint: {"center_x": .5, "center_y": .5}
halign: "center"
color: root.bar_color
MDFloatLayout:
md_bg_color: 1, 0, 100/255, .1
CircularProgressBar:
size_hint: None, None
size: 200, 200
pos_hint: {"center_x": .5, "center_y": .5}
value: 80
'''
class CircularProgressBar(AnchorLayout):
set_value = NumericProperty(0)
value = NumericProperty(1)
bar_color = ListProperty([1, 0, 100/255])
bar_width = NumericProperty(5)
text = StringProperty("0%")
duration = NumericProperty(1)
counter = 0
def __init__(self, **kwargs):
super(CircularProgressBar, self).__init__(**kwargs)
Clock.schedule_once(self.animate, 0)
def animate(self, *args):
Clock.schedule_interval(self.percent_counter, 0.1)
def percent_counter(self, *args):
if self.counter < self.value:
self.counter += 1
self.text = f"{self.counter}%"
self.set_value = self.counter
else:
Clock.unschedule(self.percent_counter)
class ProgressBar(MDApp):
def build(self):
return Builder.load_string(kv)
if __name__ == '__main__':
# LabelBase.register(name="Poppins", fn_regular="polices/Poppins-Regular.ttf")
ProgressBar().run()