This repository was archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapplayout.py
More file actions
65 lines (55 loc) · 1.83 KB
/
applayout.py
File metadata and controls
65 lines (55 loc) · 1.83 KB
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
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.properties import StringProperty, ObjectProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.utils import platform
from qrreader import QRReader
class AppLayout(FloatLayout):
qr_reader = ObjectProperty()
class ButtonsLayout(RelativeLayout):
normal = StringProperty()
down = StringProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.normal = 'icons/flash-off.png'
if platform == 'android':
self.down = 'icons/flash.png'
else:
self.down = 'icons/flash-off.png'
def on_size(self, layout, size):
if Window.width < Window.height:
self.pos = (0 , 0)
self.size_hint = (1 , 0.2)
self.ids.torch.pos_hint = {'center_x':.5,'center_y':.5}
self.ids.torch.size_hint = (.2, None)
else:
self.pos = (Window.width * 0.8, 0)
self.size_hint = (0.2 , 1)
self.ids.torch.pos_hint = {'center_x':.5,'center_y':.5}
self.ids.torch.size_hint = (None, .2)
def enable_torch(self, state):
if platform == 'android':
if state == 'down':
torch = 'on'
else:
torch = 'off'
self.parent.qr_reader.torch(torch)
Builder.load_string("""
<AppLayout>:
qr_reader: self.ids.preview
QRReader:
letterbox_color: 'steelblue'
aspect_ratio: '16:9'
id:preview
ButtonsLayout:
id:buttons
<ButtonsLayout>:
ToggleButton:
id:torch
on_press: root.enable_torch(self.state)
height: self.width
width: self.height
background_normal: root.normal
background_down: root.down
""")