-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
main.py
150 lines (117 loc) · 5.07 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import kivy
kivy.require('1.0.8')
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from uix.custom_button import AnimatedButton
from kivy.uix.scatter import Scatter
from kivy.properties import ObjectProperty
class gifScatter(Scatter):
def __init__(self, **kwargs):
super(gifScatter, self).__init__()
class zipScatter(Scatter):
def __init__(self, **kwargs):
super(zipScatter, self).__init__()
class jpgScatter(Scatter):
def __init__(self, **kwargs):
super(jpgScatter, self).__init__()
class Right_Frame(GridLayout):
currentObj = ObjectProperty(None)
def __init__(self, **kwargs):
super(Right_Frame, self).__init__()
def on_value(self, *l):
if self.currentObj:
if abs(l[1]) <= 0:
self.currentObj.anim_delay = -1
l[2].text = 'Animation speed: %f FPS' % 0
else:
self.currentObj.anim_delay = 1 / l[1]
l[2].text = 'Animation speed: %f FPS' % (
1 / self.currentObj.anim_delay)
else:
l[0].max = 0
l[2].text = 'No Image selected'
class mainclass(FloatLayout):
currentObj = ObjectProperty(None)
def __init__(self, **kwargs):
super(mainclass, self).__init__()
# initialize variables
self.sign = .10
# setup Layouts
layout = GridLayout(size_hint=(1, 1), cols=3, rows=1)
left_frame = GridLayout(size_hint=(.25, 1), cols=1)
client_frame = FloatLayout(size_hint=(1, 1))
self.right_frame = Right_Frame()
# setup buttons in left frame
but_load_gif = AnimatedButton(text='load gif', halign='center')
but_load_zip_png = AnimatedButton(text='load zipped\n png/s',
halign='center')
but_load_zip_jpg = AnimatedButton(text='load zipped\n jpg/s',
halign='center')
but_animated = AnimatedButton(text='animated button\n'
'made using\nSequenced Images\n press to animate',
halign='center',
background_normal='data/images/button_white.png',
background_down='data/images/button_white_animated.zip')
but_animated_normal = AnimatedButton(text='borderless\n'
'animated button\npress to stop',
halign='center',
background_down='data/images/button_white.png',
background_normal='data/images/button_white_animated.zip')
but_animated_borderless = AnimatedButton(text='Borderless',
background_normal='data/images/info.png',
background_down='data/images/info.zip', halign='center')
but_animated_bordered = AnimatedButton(text='With Border',
background_normal='data/images/info.png',
background_down='data/images/info.zip', halign='center')
# Handle button press/release
def load_images(*l):
if l[0].text == 'load gif' or l[0].text == 'load gif\n from cache':
l[0].text = 'load gif\n from cache'
sctr = gifScatter()
if (l[0].text == 'load zipped\n png/s' or
l[0].text == 'load zipped\n png/s from cache'):
l[0].text = 'load zipped\n png/s from cache'
sctr = zipScatter()
if (l[0].text == 'load zipped\n jpg/s' or
l[0].text == 'load zipped\n jpg/s from cache'):
l[0].text = 'load zipped\n jpg/s from cache'
sctr = jpgScatter()
client_frame.add_widget(sctr, 1)
# position scatter
sctr.pos = (240 + self.sign, 200 + self.sign)
self.sign += 10
if self.sign > 200:
self.sign = 10
sctr.pos = (300, 200 - self.sign)
# bind function on on_release
but_load_gif.bind(on_release=load_images)
but_load_zip_png.bind(on_release=load_images)
but_load_zip_jpg.bind(on_release=load_images)
# add widgets to left frame
left_frame.add_widget(but_load_gif)
left_frame.add_widget(but_load_zip_png)
left_frame.add_widget(but_load_zip_jpg)
left_frame.add_widget(but_animated)
left_frame.add_widget(but_animated_normal)
left_frame.add_widget(but_animated_borderless)
left_frame.add_widget(but_animated_bordered)
# set/remove border for borderless widgets (16,16,16,16) by default
but_animated_normal.border = \
but_animated_borderless.border = (0, 0, 0, 0)
# add widgets to the main layout
layout.add_widget(left_frame)
layout.add_widget(client_frame)
layout.add_widget(self.right_frame)
# add main layout to root
self.add_widget(layout)
def on_currentObj(self, *l):
self.right_frame.currentObj = self.currentObj
class mainApp(App):
def build(self):
upl = mainclass()
upl.size_hint = (1, 1)
upl.pos_hint = {'top': 0, 'right': 1}
return upl
if __name__ == '__main__':
mainApp().run()