-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain2.py
150 lines (127 loc) · 6.54 KB
/
main2.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 random
from kivywidgets import Widgets, FlyScatter
from kivy.app import App
from kivy.properties import NumericProperty
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.slider import Slider
from kivy.uix.checkbox import CheckBox
from kivy.uix.scatter import Scatter
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics import Color, Rectangle
WhiteBackColor = True
__version__ = '0.0.2.2'
def get_textcolor():
return [0, 0, 0, 1] if WhiteBackColor else [1, 1, 1, 1]
def get_hor_boxlayout(orientation='horizontal', padding=10, spacing=10):
return BoxLayout(orientation=orientation, padding=padding, spacing=spacing)
class MainApp(App):
sm = ScreenManager()
rows = NumericProperty(5)
cols = NumericProperty(5)
def __init__(self, **kwargs):
super(MainApp, self).__init__(**kwargs)
self.title = 'Adaptive Mobile UI'
self.rows_slider = Slider(min=1, max=10, value=5, step=1)
self.cols_slider = Slider(min=1, max=10, value=5, step=1)
self.flyscatter = CheckBox(active=False, size_hint_x=None, on_press=self.on_flyscatter_checkbox_click)
def build(self):
# PROPERTIES LAYOUT
self.root2 = BoxLayout(orientation='vertical', padding=10)
self.root2.add_widget(Label(text='Image, TextInput, Label,\nButton, CheckBox, Slider,\nSwitch, Spinner, ProgressBar', color=get_textcolor()))
hor = get_hor_boxlayout()
hor.add_widget(Label(text='ROWS:', color=get_textcolor(), size_hint_x=None))
hor.add_widget(self.rows_slider)
self.root2.add_widget(hor)
hor = get_hor_boxlayout()
hor.add_widget(Label(text='COLUMNS:', color=get_textcolor(), size_hint_x=None))
hor.add_widget(self.cols_slider)
self.root2.add_widget(hor)
hor = get_hor_boxlayout()
hor.add_widget(Label(text='FLY SCATTER:', color=get_textcolor(), size_hint_x=None))
hor.add_widget(self.flyscatter)
self.root2.add_widget(hor)
hor = BoxLayout(orientation='horizontal', padding=0, spacing=0, size_hint_y=None, height='10dp')
hor.add_widget(Button(text='mainscreen', size_hint_y=None, height='30dp', on_press=self.to_scr1_btn_click))
hor.add_widget(Button(text='sandbox', size_hint_y=None, height='30dp', on_press=self.to_scr3_btn_click))
self.root2.add_widget(hor)
self.add_screen('properties', self.root2)
# SANDBOX LAYOUT
self.root3 = BoxLayout(orientation='vertical', padding=10, spacing=0)
self.root3.add_widget(Button(text='rebuild', size_hint_y=None, height='30dp', on_press=self.sandbox_rebuild_btn_click))
self.sandbox_widgets = BoxLayout(orientation='vertical', padding=0, spacing=0)
self.sandbox_rebuild_btn_click(self)
self.root3.add_widget(self.sandbox_widgets)
hor = BoxLayout(orientation='horizontal', padding=0, spacing=0, size_hint_y=None, height='30dp')
hor.add_widget(Button(text='mainscreen', size_hint_y=None, height='30dp', on_press=self.to_scr1_btn_click_left))
hor.add_widget(Button(text='properties', size_hint_y=None, height='30dp', on_press=self.to_scr2_btn_click))
self.root3.add_widget(hor)
self.add_screen('sandbox', self.root3)
# MAINSCREEN LAYOUT
self.root1 = BoxLayout(orientation='vertical', padding=10, spacing=0)
self.root1.add_widget(Button(text='rebuild', size_hint_y=None, height='30dp', on_press=self.mainscreen_rebuild_btn_click))
self.mainscreen_widgets = BoxLayout(orientation='vertical', padding=0, spacing=0)
self.mainscreen_rebuild_btn_click(self)
self.root1.add_widget(self.mainscreen_widgets)
hor = BoxLayout(orientation='horizontal', padding=0, spacing=0, size_hint_y=None, height='30dp')
hor.add_widget(Button(text='sandbox', size_hint_y=None, height='30dp', on_press=self.to_scr3_btn_click))
hor.add_widget(Button(text='properties', size_hint_y=None, height='30dp', on_press=self.to_scr2_btn_click))
self.root1.add_widget(hor)
self.add_screen('mainscreen', self.root1)
self.to_scr1_btn_click(self)
if WhiteBackColor:
self.sm.bind(size=self._update_rect, pos=self._update_rect)
with self.sm.canvas.before:
Color(1, 1, 1)
self.rect = Rectangle(size=self.sm.size, pos=self.sm.pos)
return self.sm
def on_flyscatter_checkbox_click(self, instance):
self.sandbox_rebuild_btn_click(self)
def add_screen(self, name, widget):
scr = Screen(name=name)
scr.add_widget(widget)
self.sm.add_widget(scr)
def _update_rect(self, instance, value):
self.rect.pos = instance.pos
self.rect.size = instance.size
def mainscreen_rebuild_btn_click(self, instance):
self.mainscreen_widgets.clear_widgets()
for i in range(self.rows_slider.value):
hor = get_hor_boxlayout()
for j in range(random.randint(1,self.cols_slider.value-1)):
hor.add_widget(Widgets.get_random_widget())
self.mainscreen_widgets.add_widget(hor)
def sandbox_rebuild_btn_click(self, instance):
self.sandbox_widgets.clear_widgets()
for i in range(self.rows_slider.value):
hor = get_hor_boxlayout('horizontal')
for j in range(self.cols_slider.value):
if self.flyscatter.active:
s = FlyScatter(do_rotation=False, do_scale=False, auto_bring_to_front=False)
else:
s = Scatter(do_rotation=False, do_scale=False, auto_bring_to_front=False)
hor.add_widget(s)
w = Widgets.get_random_widget()
w.width = f'{550//self.cols_slider.value}dp'
w.height = f'{300//self.rows_slider.value}dp'
s.add_widget(w)
self.sandbox_widgets.add_widget(hor)
def to_scr1_btn_click(self, instance):
self.sm.transition.direction = 'right'
self.sm.current = 'mainscreen'
def to_scr1_btn_click_left(self, instance):
self.sm.transition.direction = 'left'
self.sm.current = 'mainscreen'
def to_scr2_btn_click(self, instance):
self.sm.transition.direction = 'left'
self.sm.current = 'properties'
def to_scr3_btn_click(self, instance):
self.sm.transition.direction = 'right'
self.sm.current = 'sandbox'
def on_btn_click(self, instance):
freq = int(instance.text) + 1
instance.text = str(freq)
if __name__ == "__main__":
app = MainApp()
app.run()