-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaskSelectorUI.py
More file actions
executable file
·251 lines (190 loc) · 6.96 KB
/
MaskSelectorUI.py
File metadata and controls
executable file
·251 lines (190 loc) · 6.96 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import StringProperty
from kivy.core.window import Window
import pandas as pd
data = pd.read_csv("Fixed_MasksWithFeatures_5_8_2021.csv")
data = data.assign(score=0)
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.label import Label
from kivy.properties import BooleanProperty
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
answerList = ['', '', '', '', '', '', '']
weightingList = [1, 1, 1, 1, 1, 1, 1]
count = 0
topStr = ''
darkMode = True
Window.clearcolor = (.2, .2, .2, .2)
Builder.load_string('''
<SelectableLabel>:
# Draw a background to indicate selection
canvas.before:
Color:
rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
Rectangle:
pos: self.pos
size: self.size
<RV>:
viewclass: 'SelectableLabel'
SelectableRecycleBoxLayout:
padding: "15dp", "360dp", "15dp", "15dp"
default_size: 60, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
spacing: dp(12)
multiselect: True
touch_multiselect: True
''')
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
RecycleBoxLayout):
''' Adds selection and focus behaviour to the view. '''
class SelectableLabel(RecycleDataViewBehavior, Label):
''' Add selection support to the Label '''
index = None
selected = BooleanProperty(False)
selectable = BooleanProperty(True)
def refresh_view_attrs(self, rv, index, data):
''' Catch and handle the view changes '''
self.index = index
return super(SelectableLabel, self).refresh_view_attrs(
rv, index, data)
def on_touch_down(self, touch):
''' Add selection on touch down '''
if super(SelectableLabel, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos) and self.selectable:
return self.parent.select_with_touch(self.index, touch)
def apply_selection(self, rv, index, is_selected):
''' Respond to the selection of items in the view. '''
self.selected = is_selected
if is_selected:
print("selection changed to {0}".format(rv.data[index]))
else:
print("selection removed for {0}".format(rv.data[index]))
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = [{'text': str(df[['link', 'rating']].head(20))}]
class TestApp(App):
def build(self):
return RV()
class StartMenu(Screen):
def theme(self, button):
global darkMode
if darkMode:
darkMode = False
Window.clearcolor = (.9, .9, .9, 1)
elif not darkMode:
darkMode = True
Window.clearcolor = (.2, .2, .2, .2)
class MainWindow(Screen):
def clk(self, button):
answerList[0] = button.text
if button.text == 'Disposable':
answerList[1] = 'none'
print(answerList)
class SecondWindow(Screen):
def clk(self, button):
answerList[1] = button.text
print(answerList)
class ThirdWindow(Screen):
def clk(self, button):
answerList[2] = button.text
print(answerList)
class FourthWindow(Screen):
def clk(self, button):
answerList[3] = button.text
print(answerList)
class FifthWindow(Screen):
def clk(self, button):
answerList[4] = button.text
print(answerList)
class SixthWindow(Screen):
def clk(self, button):
answerList[5] = button.text
print(answerList)
class SeventhWindow(Screen):
def clk(self, button):
answerList[6] = button.text
print(answerList)
class SeventhWindowDisposability(Screen):
def clk(self, button):
disposability = int(button.text)
weightingList[0] = disposability
class SeventhWindowMaterial(Screen):
def clk(self, button):
material = int(button.text)
weightingList[1] = material
class SeventhWindowSize(Screen):
def clk(self, button):
size = int(button.text)
weightingList[2] = size
class SeventhWindowGender(Screen):
def clk(self, button):
gender = int(button.text)
weightingList[3] = gender
class SeventhWindowColor(Screen):
def clk(self, button):
color = int(button.text)
weightingList[4] = color
class SeventhWindowFilterType(Screen):
def clk(self, button):
filterType = int(button.text)
weightingList[5] = filterType
class SeventhWindowEarLoops(Screen):
def clk(self, button):
loops = int(button.text)
weightingList[6] = loops
class EighthWindow(Screen):
def clk(self, button):
global topStr
for item in answerList:
item = item.lower()
for i, row in data.iterrows():
if row[13] == answerList[0]: # disposability
data.at[i, 'score'] += weightingList[0]
if answerList[0] == 'reusable': # pass if disposable
if answerList[1] in str(row[10]): # material
data.at[i, 'score'] += weightingList[1]
if answerList[2] in str(row[8]): # size
data.at[i, 'score'] += weightingList[2]
if row[12] == answerList[3]: # gender
data.at[i, 'score'] += weightingList[3]
if row[9] == answerList[4]: # color
data.at[i, 'score'] += weightingList[4]
if row[11] == answerList[5]: # filtertype
data.at[i, 'score'] += weightingList[5]
if row[14] == answerList[6]: # earloops
data.at[i, 'score'] += weightingList[6]
data.sort_values(by='score', ascending=False, inplace=True)
# fixedData = list(data)
df = pd.DataFrame(data)
class NinthWindow(Screen):
label_text = StringProperty()
global topStr
label_text = topStr
def clk(self, button):
global topStr
n = 0
for i, row in data.iterrows():
topStr += '\nhttps://www.amazon.com' + data.at[i, 'link']
n += 1
if n >= 10:
break
print(topStr)
print('Please give us your feedback at jcampb32@uncc.edu, above are the links for the masks')
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("my.kv")
class MyMainApp(App):
def build(self):
return kv
if __name__ == "__main__":
MyMainApp().run()
TestApp().run()