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
|
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from plyer import battery
Builder.load_string('''
<BatteryInterface>:
lbl1: lbl1
lbl2: lbl2
FloatLayout:
Button:
size_hint_y: None
pos_hint: {'y': .5}
text: "Battery Status"
on_press: root.get_status()
BoxLayout:
size_hint_y: None
pos_hint: {'y': .1}
Label:
text: "Is Charging?"
Label:
id: lbl1
text:
Label:
text: "Percentage"
Label:
id: lbl2
text:
''')
class BatteryInterface(BoxLayout):
lbl1 = ObjectProperty()
lbl2 = ObjectProperty()
def get_status(self, *args):
self.lbl1.text = str(battery.status['isCharging'])
self.lbl2.text = str(battery.status['percentage']) + "%"
class BatteryApp(App):
def build(self):
return BatteryInterface()
def on_pause(self):
return True
if __name__ == "__main__":
app = BatteryApp()
app.run()
|