-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBodyCalc.py
334 lines (284 loc) · 12.2 KB
/
BodyCalc.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
from tkinter import *
from tkinter import ttk
from tkinter.font import Font
from tkinter.scrolledtext import *
import math
import os
mainWindow = Tk()
mainWindow.title('BodyCalc')
mainWindow.configure(background='#333')
mainWindow.resizable(False, False)
mainWindow.minsize(390, 260)
if getattr(sys, 'frozen', False):
application_path = sys._MEIPASS
elif __file__:
application_path = os.path.dirname(__file__)
iconFile = 'BodyCalc.ico'
mainWindow.iconbitmap(default=os.path.join(application_path, iconFile))
def get_bmi(weight, height):
global bmi
try:
if not (weight and height):
bmi = 'Error!'
else:
bmi = math.floor(int(weight) / (float(height) * float(height)))
except ValueError:
bmi = 'Error!'
def get_breast_multiplier(bust, cup):
global breast_multiplier
try:
bust = int(bust)
bust_scale = 'Below Average' if bust < 34 else 'Above Average'
except ValueError:
bust_scale = 'Error!'
cup = cup.upper()
if cup is '' and bust_scale is 'Error!':
breast_multiplier = 99
elif cup in ['AA', 'A'] and bust_scale is 'Below Average':
breast_multiplier = 1
elif cup in ['AA', 'A'] and bust_scale is 'Above Average':
breast_multiplier = 2
elif cup in ['B', 'C'] and bust_scale is 'Below Average':
breast_multiplier = 2
elif cup in ['D'] and bust_scale is 'Below Average':
breast_multiplier = 3
elif cup in ['B', 'C', 'D'] and bust_scale is 'Above Average':
breast_multiplier = 3
elif cup in ['DD', 'DDD', 'E', 'EE', 'EEE', 'F', 'FF', 'G'] and bust_scale is 'Below Average':
breast_multiplier = 3
elif cup in ['DD', 'DDD', 'E', 'EE', 'EEE', 'F', 'FF', 'G'] and bust_scale is 'Above Average':
breast_multiplier = 4
elif cup in ['FFF', 'GG', 'GGG', 'H', 'HH', 'I'] and bust_scale is 'Below Average':
breast_multiplier = 4
elif cup in ['FFF', 'GG', 'GGG', 'H', 'HH', 'I'] and bust_scale is 'Above Average':
breast_multiplier = 5
elif cup in ['HHH', 'II', 'III', 'J', 'JJ', 'K'] and bust_scale is 'Below Average':
breast_multiplier = 5
elif cup in ['HHH', 'II', 'III', 'J', 'JJ', 'K'] and bust_scale is 'Above Average':
breast_multiplier = 6
else:
breast_multiplier = 0
# Debugging purposes only!
print(bust_scale, breast_multiplier)
return breast_multiplier
def get_breast_desc(multiplier):
global breast_desc
if multiplier == 1:
breast_desc = 'Tiny'
elif multiplier == 2:
breast_desc = 'Small'
elif multiplier == 3:
breast_desc = 'Medium'
elif multiplier == 4:
breast_desc = 'Large'
elif multiplier == 5:
breast_desc = 'Huge'
elif multiplier == 6:
breast_desc = 'Massive'
elif multiplier == 99 or multiplier == 0:
breast_desc = 'Error!'
def get_butt_desc(hip):
global butt_desc
try:
hip = int(hip)
if hip <= 32:
butt_desc = 'Small'
elif hip in range(33, 40):
butt_desc = 'Medium'
elif hip in range(40, 44):
butt_desc = 'Large'
elif hip in range(44, 48):
butt_desc = 'Huge'
elif hip >= 48:
butt_desc = 'Massive'
except ValueError:
butt_desc = 'Error!'
def get_body_shape(bust, waist, hip):
global body_shape
try:
bust = int(bust)
waist = int(waist)
hip = int(hip)
# Waist is at least 25 percent smaller than Hip AND Bust measurement.
if float(waist) * float(1.25) <= bust & hip:
body_shape = 'Hourglass'
# Hip measurement is more than 5 percent bigger than Bust measurement.
elif float(hip) * float(1.05) > bust:
body_shape = 'Pear'
# Hip measurement is more than 5 percent smaller than Bust measurement.
elif float(hip) * float(1.05) < bust:
body_shape = 'Apple'
# Bust, Waist and Hip measurements are within close range.
high = max(bust, waist, hip)
low = min(bust, waist, hip)
difference = high - low
# Debugging purposes only!
print(high, low, difference)
if difference <= 5:
body_shape = 'Banana'
except ValueError:
body_shape = 'Error!'
def get_body_type(index, shape):
global body_type
type_descriptor = ''
try:
index = int(index)
if index in range(1, 18):
type_descriptor = 'A'
elif index in range(18, 23):
type_descriptor = 'B'
elif index in range(23, 29):
type_descriptor = 'C'
elif index in range(29, 55):
type_descriptor = 'D'
elif index >= 55:
type_descriptor = 'E'
# Debugging purposes only!
print(index, type_descriptor)
if shape == 'Error!':
body_type = 'Error!'
elif type_descriptor == 'A':
body_type = 'Skinny'
elif type_descriptor == 'B':
body_type = 'Petite'
elif type_descriptor == 'C' and shape != 'Hourglass':
body_type = 'Average'
elif type_descriptor == 'C' and shape == 'Hourglass':
body_type = 'Curvy'
elif type_descriptor == 'D' and shape == 'Banana':
body_type = 'BBW'
elif type_descriptor == 'D' and shape == 'Hourglass':
body_type = 'BBW - Curvy'
elif type_descriptor == 'D' and shape == 'Pear':
body_type = 'BBW - Bottom Heavy'
elif type_descriptor == 'D' and shape == 'Apple':
body_type = 'BBW - Top Heavy'
elif type_descriptor == 'E' and shape == 'Banana' or shape == 'Hourglass':
body_type = 'SSBBW'
elif type_descriptor == 'E' and shape == 'Apple':
body_type = 'SSBBW - Top Heavy'
elif type_descriptor == 'E' and shape == 'Pear':
body_type = 'SSBBW - Bottom Heavy'
except ValueError:
body_type = 'Error!'
def calculate(*args):
global bmi
global breast_desc
global butt_desc
global body_shape
global body_type
outputs = [bmiTxt, breastTxt, buttTxt, shapeTxt, typeTxt]
list(map(lambda x: x.configure(state='normal'), outputs))
list(map(lambda y: y.delete(1.0, END), outputs))
get_bmi(weightIn.get(), heightIn.get())
get_breast_multiplier(bustIn.get(), cupIn.get())
get_breast_desc(breast_multiplier)
get_butt_desc(hipIn.get())
get_body_shape(bustIn.get(), waistIn.get(), hipIn.get())
get_body_type(bmi, body_shape)
bmiTxt.insert(END, bmi)
breastTxt.insert(END, breast_desc)
buttTxt.insert(END, butt_desc)
shapeTxt.insert(END, body_shape)
typeTxt.insert(END, body_type)
list(map(lambda z: z.configure(state='disabled'), outputs))
def clear_input(*args):
inputs = [heightIn, weightIn, bustIn, cupIn, waistIn, hipIn]
list(map(lambda x: x.delete(0, 'end'), inputs))
heightIn.focus()
def display_help(*args):
helpWindow = Toplevel()
x = mainWindow.winfo_rootx()
y = mainWindow.winfo_rooty()
geom = "+%d+%d" % (x, y - 20)
helpWindow.geometry(geom)
helpWindow.focus_set()
helpWindow.title('BodyCalc - Help')
helpWindow.configure(background='#333')
helpWindow.resizable(False, False)
helpWindow.minsize(390, 260)
helpWindow.maxsize(390, 260)
helpWindow.columnconfigure(0, weight=1)
helpBtn.config(state='disable')
mainWindow.unbind('<F1>')
def close_help():
helpWindow.destroy()
helpBtn.config(state='normal')
mainWindow.bind('<F1>', display_help)
ttk.Label(helpWindow, text='How to use BodyCalc:', background='#333').grid(row=0, column=0, padx=10, pady=10, sticky=W)
helpTxt = ScrolledText(helpWindow, width=50, height=13, background='#444', foreground='white', font=textFont,
relief='flat')
helpTxt.grid(row=1, column=0, padx=10, sticky=W)
helpTxt.insert(END,
'Enter your measurements on the left side and click '
'<Calculate> to see your results on the right side.\n\n'
'All measurements must be entered to get complete results.\n'
'However, you can calculate some items individually.\n\n'
'To calculate BMI:\nEnter your Height and Weight and click <Calculate>\n\n'
'To calculate Body Shape:\nEnter your Bust / Cup, Waist and Hip and click <Calculate>\n\n'
'To calculate Body Type: All fields must be entered.\n\n'
'Breast size can only be calculated if both the Bust and Cup are entered.\n\n'
'If you are missing the necessary measurements to make a\ncertain calculation "Error!" '
'will appear in the results section for\nthat item.\n\n'
'All measurements must be in Inches, except for Height and\nWeight which need to be in Metric '
'(Meters and Kilograms\nrespectively).\n\n'
'Shortcut Keys:\n\n F1 - <Help>\n Enter - <Calculate>\n \ - <Clear All Inputs>')
helpTxt.configure(state='disabled')
helpWindow.protocol('WM_DELETE_WINDOW', close_help)
frameStyle = ttk.Style()
frameStyle.configure('TFrame', background='#444', foreground='white')
buttonStyle = ttk.Style()
buttonStyle.configure('TButton', background='gray', font=('Arial', '8', 'bold'))
labelStyle = ttk.Style()
labelStyle.configure('TLabel', background='#444', foreground='white', font=('Arial', '9'))
textFont = Font(family='Arial', size=9)
frameInput = ttk.Frame(mainWindow)
ttk.Label(frameInput, text='Height (M)').grid(row=0, column=0, pady=10)
ttk.Label(frameInput, text='Weight (KG)').grid(row=1, column=0, pady=10)
ttk.Label(frameInput, text='Bust / Cup').grid(row=2, column=0, pady=10)
ttk.Label(frameInput, text='Waist').grid(row=3, column=0, pady=10)
ttk.Label(frameInput, text='Hip').grid(row=4, column=0, pady=10)
heightIn = ttk.Entry(frameInput, width=4)
heightIn.grid(row=0, column=1, pady=8)
weightIn = ttk.Entry(frameInput, width=4)
weightIn.grid(row=1, column=1, pady=8)
bustIn = ttk.Entry(frameInput, width=4)
bustIn.grid(row=2, column=1, pady=8)
cupIn = ttk.Entry(frameInput, width=4)
cupIn.grid(row=2, column=2, padx=5, pady=8)
waistIn = ttk.Entry(frameInput, width=4)
waistIn.grid(row=3, column=1, pady=8)
hipIn = ttk.Entry(frameInput, width=4)
hipIn.grid(row=4, column=1, pady=8)
frameOutput = ttk.Frame(mainWindow)
ttk.Label(frameOutput, text='BMI').grid(row=0, column=0, pady=10)
ttk.Label(frameOutput, text='Breasts').grid(row=1, column=0, pady=10)
ttk.Label(frameOutput, text='Butt').grid(row=2, column=0, pady=10)
ttk.Label(frameOutput, text='Body Shape').grid(row=3, column=0, pady=10)
ttk.Label(frameOutput, text='Body Type').grid(row=4, column=0, pady=10)
bmiTxt = Text(frameOutput, state='disabled', width=10, height=1, bg='#444', fg='white', font=textFont, pady=5)
bmiTxt.grid(row=0, column=1, pady=5, sticky=W)
breastTxt = Text(frameOutput, state='disabled', width=10, height=1, bg='#444', fg='white', font=textFont, pady=5)
breastTxt.grid(row=1, column=1, pady=5, sticky=W)
buttTxt = Text(frameOutput, state='disabled', width=10, height=1, bg='#444', fg='white', font=textFont, pady=5)
buttTxt.grid(row=2, column=1, pady=5, sticky=W)
shapeTxt = Text(frameOutput, state='disabled', width=10, height=1, bg='#444', fg='white', font=textFont, pady=5)
shapeTxt.grid(row=3, column=1, pady=5, sticky=W)
typeTxt = Text(frameOutput, state='disabled', width=20, height=1, bg='#444', fg='white', font=textFont, pady=5)
typeTxt.grid(row=4, column=1, pady=5, sticky=W)
frameButtons = Frame(mainWindow)
frameButtons.configure(bg='#333')
ttk.Button(frameButtons, text='Calculate', width=10, command=calculate).grid(row=0, column=0, ipadx=1, padx=4)
ttk.Button(frameButtons, text='Clear', width=7, command=clear_input).grid(row=0, column=1, ipadx=1, padx=4)
frameButtons2 = Frame(mainWindow)
frameButtons2.configure(bg='#333')
helpBtn = ttk.Button(frameButtons2, text='?', width=2, command=display_help)
helpBtn.grid(row=0, column=0, ipadx=1, padx=2)
frameInput.grid(row=0, column=0, padx=10, pady=10)
frameOutput.grid(row=0, column=1, pady=10, ipadx=3)
frameButtons.grid(row=1, column=0, pady=5)
frameButtons2.grid(row=1, column=1, pady=5, sticky=E)
mainWindow.bind('<Return>', calculate)
mainWindow.bind('<\>', clear_input)
mainWindow.bind('<F1>', display_help)
mainWindow.mainloop()