-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrealbutton.py
98 lines (77 loc) · 3.1 KB
/
realbutton.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# KIVY
from kivy.uix.image import Image
from kivy.uix.behaviors import ButtonBehavior
from kivy.properties import *
from kivy.uix.behaviors import ToggleButtonBehavior
from kivy.clock import Clock
'''
custom button mechanics due to problems with texture scaling in kivy buttons.
Uses Image and ButtonBehavior mixin class, problem with normal kivy button was
that textures of cicular buttons had been strangely transformed into
non-circular which looked awful.
'''
# XXX: clear usage of source for images against realtexture to avoid mentioning
# the same texture twice in constructor
class RealButton(ButtonBehavior, Image):
def __init__(self, realtexture, realtexture_pressed, function, **kwargs):
super(RealButton, self).__init__(**kwargs)
self.realtexture = realtexture
self.realtexture_pressed = realtexture_pressed
self.function = function
def on_press(self):
self.source = self.realtexture_pressed
self.reload()
self.function(self)
def on_release(self):
self.source = self.realtexture
self.reload()
class RealTimedButton(ButtonBehavior, Image):
def __init__(self, realtexture, realtexture_pressed, function, **kwargs):
super(RealTimedButton, self).__init__(**kwargs)
self.realtexture = realtexture
self.realtexture_pressed = realtexture_pressed
self.function = function
def on_press(self):
self.source = self.realtexture_pressed
self.reload()
Clock.schedule_interval(self.function, 1.0 / 10.0)
def on_release(self):
Clock.unschedule(self.function)
self.source = self.realtexture
self.reload()
class RealToggleButton(ButtonBehavior, Image):
pressed = BooleanProperty(False)
def __init__(self, realtexture, realtexture_pressed, function, **kwargs):
super(RealToggleButton, self).__init__(**kwargs)
self.realtexture = realtexture
self.realtexture_pressed = realtexture_pressed
self.function = function
def on_press(self):
if self.pressed:
self.source = self.realtexture
self.reload()
self.pressed = False
else:
self.source = self.realtexture_pressed
self.reload()
self.pressed = True
self.function(self.pressed)
def on_release(self):
pass
class RealMenuToggleButton(ToggleButtonBehavior, Image):
def __init__(self, realtexture, realtexture_pressed, keyword,
default_mode='zoom', **kwargs):
super(RealMenuToggleButton, self).__init__(**kwargs)
self.realtexture = realtexture
self.realtexture_pressed = realtexture_pressed
self.keyword = keyword
self.default_mode = default_mode
def on_state(self, widget, value):
if self.parent is not None:
if value == 'down':
self.parent.cur_mode = self.keyword
self.source = self.realtexture_pressed
elif value == 'normal':
self.parent.cur_mode = self.default_mode
self.source = self.realtexture
self.reload()