-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAAmain.py
469 lines (366 loc) · 16.3 KB
/
AAmain.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
import wx
import wx.lib.intctrl
import json
import math
import time
p_top = None #top
p_bottom = None #bottom
p_side = None #side
p_front = None #front
class bucky(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title="profiel calculator", pos=wx.DefaultPosition, size=(600, 400))
self.panel = wx.Panel(self)
self.Bind(wx.EVT_CLOSE, self.on_close)
self.data_window = None
self.render = None
#size button
self.ButtonSize7 = wx.RadioButton(self.panel, label = "7mm")
self.ButtonSize10 = wx.RadioButton(self.panel, label = "10mm")
self.ButtonSize7.SetValue(True)
self.input_names = ["height top", "height bottom", "width", "depth"]
#next for what input
self.HeightTop = wx.StaticText(self.panel, label="height top:")
self.HeightBottom = wx.StaticText(self.panel, label="height bottom:")
self.Width = wx.StaticText(self.panel, label="width:")
self.Depth = wx.StaticText(self.panel, label="depth:")
self.CalcText = wx.StaticText(self.panel, label="calculations:")
self.inputs = [0] * 4
self.calc = [0] * 4
for i, input in enumerate(self.inputs):
self.inputs[i] = wx.lib.intctrl.IntCtrl(self.panel, value=0, allow_none=False, allow_long=False, size=(70, -1))
#calculations display at:
for i, calc in enumerate(self.calc):
self.calc[i] = wx.StaticText(self.panel, label="")
#calculate button
self.button = wx.Button(self.panel, size=(70,-1), label="calculate")
self.pre_button = wx.Button(self.panel, size=(70,-1), label="History")
#error Text
self.error = wx.StaticText(self.panel, label="")
# self.error.SetForegroundColour(wx.RED)
#sizer setup
self.windowSizer = wx.BoxSizer()
self.windowSizer.Add(self.panel, 1, wx.ALL | wx.EXPAND)
self.sizer = wx.GridBagSizer(5, 5)
for i, input in enumerate(self.inputs):
self.sizer.Add(input,(i+1,1))
for i, input in enumerate(self.calc):
self.sizer.Add(input,(i+1,2))
self.sizer.Add(self.ButtonSize7, (0,0))
self.sizer.Add(self.ButtonSize10, (0,1))
self.sizer.Add(self.CalcText, (0,2))
self.sizer.Add(self.HeightTop, (1,0))
self.sizer.Add(self.HeightBottom, (2,0))
self.sizer.Add(self.Depth, (3,0))
self.sizer.Add(self.Width, (4,0))
self.sizer.Add(self.error, (5,0))
self.sizer.Add(self.button, (5,1))
self.sizer.Add(self.pre_button,(5,2))
#border for sizer
self.border = wx.BoxSizer()
self.border.Add(self.sizer, 1, wx.ALL | wx.EXPAND, 5)
#Use the sizers
self.panel.SetSizerAndFit(self.border)
self.SetSizerAndFit(self.windowSizer)
#button
self.button.Bind(wx.EVT_BUTTON, self.OnButton)
self.Bind(wx.EVT_BUTTON, self.on_show_data, self.pre_button)
#define button
def OnButton(self, e):
self.clean()
# if self.render:
# self.render.Close()
self.values = []
buttonValue = self.ButtonSize7.GetValue()
for input in self.inputs:
self.values.append(input.GetValue())
#calculations dictionary
calculations = {
"7mm": [-36,-36,-41,8], #7mm
"10mm": [-32,-32,-39,0] #10mm
}
if buttonValue:
profile_type = "7mm"
elif not buttonValue:
profile_type = "10mm"
else:
print("error")
return
self.answer = [0] * 4
for i, value in enumerate(self.values):
self.answer[i] = self.values[i] + calculations[profile_type][i]
calculation_data = {
"ProfileType": profile_type,
"Values": self.values
}
db_function(calculation_data)
errorCheck = False
#error check
for i, calc in enumerate(self.calc):
if self.answer[i] < 1:
errorCheck = True
self.error.SetLabel(f"error")
self.calc[i].SetForegroundColour(wx.RED)
self.error.SetForegroundColour(wx.RED)
self.calc[i].SetLabel(str(self.answer[i]))
#if no error
else:
self.calc[i].SetLabel(str(self.answer[i]))
self.calc[i].SetForegroundColour(wx.WHITE)
if not errorCheck:
self.render = DrawingFrame(parent = None, id = -1)
x, y = self.GetPosition()
self.render.SetPosition((x, y + 197))
self.render.Show()
self.render.SetSize((512, 394))
self.render.SetMaxSize((512, 394))
self.render.SetMinSize((512, 394))
p_top = self.answer[0] #top
p_bottom = self.answer[1] #bottom
p_side = self.answer[2] #side
p_front = self.answer[3] #front
def on_show_data(self, event,):
# Create a new window to display data
self.data_window = DataWindow(parent = None, id = -1)
first_window_size = self.GetSize()
x, y = self.GetPosition()
self.data_window.SetPosition((x + first_window_size[0], y))
self.data_window.Show()
self.data_window.SetSize((256, 197))
self.data_window.SetMaxSize((256, 197))
self.data_window.SetMinSize((256, 197))
def on_close(self, event):
# Close the second window if it's open
if self.data_window:
self.data_window.Close()
if self.render:
self.render.Close()
event.Skip()
#text clearen
def clean(self):
self.error.SetLabel("")
for i, calc in enumerate(self.calc):
self.calc[i].SetLabel("")
#-------------------------------------------------------------------------------#
#history window
class DataWindow(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title="history", pos=wx.DefaultPosition, size=(600, 400))
self.panel = wx.Panel(self)
fileDir = "fcc/data/BackLog.json"
data = get_data(fileDir)
self.previous = len(data['calculations'])
self.prev_button = wx.Button(self.panel, size=(24,-1), label="<")
self.next_button = wx.Button(self.panel, size=(24,-1), label=">")
self.ButtonSize7 = wx.RadioButton(self.panel, label = "7mm")
self.ButtonSize10 = wx.RadioButton(self.panel, label = "10mm")
self.ButtonSize7.SetValue(True)
self.math = {
"7mm": [-36,-36,-41,8], #7mm
"10mm": [-32,-32,-39,0] #10mm
}
self.dspl = [0] * 4
for i, dspl in enumerate(self.dspl):
self.dspl[i] = wx.StaticText(self.panel, label="")
self.history = wx.StaticText(self.panel, label="history:")
self.HeightTop = wx.StaticText(self.panel, label="height top:")
self.HeightBottom = wx.StaticText(self.panel, label="height bottom:")
self.Width = wx.StaticText(self.panel, label="width:")
self.Depth = wx.StaticText(self.panel, label="depth:")
self.id = wx.StaticText(self.panel, label="id: " + (str(self.previous)))
self.back = [0] * 4
for i, back in enumerate(self.back):
self.back[i] = wx.StaticText(self.panel, label="")
#sizer setup
self.windowSizer = wx.BoxSizer()
self.windowSizer.Add(self.panel, 1, wx.ALL | wx.EXPAND)
self.sizer = wx.GridBagSizer(5, 5)
self.sizer.Add(self.ButtonSize7, (0,0))
self.sizer.Add(self.ButtonSize10, (0,1))
self.sizer.Add(self.id, (1,2))
self.sizer.Add(self.history, (1,0))
self.sizer.Add(self.HeightTop, (2,0))
self.sizer.Add(self.HeightBottom, (3,0))
self.sizer.Add(self.Depth, (4,0))
self.sizer.Add(self.Width, (5,0))
self.sizer.Add(self.prev_button,(6,2))
self.sizer.Add(self.next_button,(6,3))
for i, input in enumerate(self.back):
self.sizer.Add(input,(i+2,2))
fileDir = "fcc/data/BackLog.json"
data = get_data(fileDir)
self.previous -= 1
self.id.SetLabel("id: " + (str(self.previous)))
calculations = data['calculations']
values = calculations[self.previous]['Values']
p_type = calculations[self.previous]['ProfileType']
if p_type == "7mm":
self.ButtonSize7.SetValue(True)
else:
self.ButtonSize10.SetValue(True)
answer = [0] * 4
for i, value in enumerate(values):
answer[i] = values[i] + self.math[p_type][i]
for i, back in enumerate(self.back):
self.back[i].SetLabel(str(answer[i]))
#button binding
self.Bind(wx.EVT_BUTTON, self.on_show_prev, self.prev_button)
self.Bind(wx.EVT_BUTTON, self.on_show_next, self.next_button)
self.ButtonSize7.Bind(wx.EVT_RADIOBUTTON, self.on_radio_select)
self.ButtonSize10.Bind(wx.EVT_RADIOBUTTON, self.on_radio_select)
#border for sizer
self.border = wx.BoxSizer()
self.border.Add(self.sizer, 1, wx.ALL | wx.EXPAND, 5)
#Use the sizers
self.panel.SetSizerAndFit(self.border)
self.SetSizerAndFit(self.windowSizer)
#change number when radio change
def on_radio_select(self, event):
fileDir = "fcc/data/BackLog.json"
data = get_data(fileDir)
radio_button = event.GetEventObject()
calculations = data['calculations']
values = calculations[self.previous]['Values']
p_type = radio_button.GetLabel()
self.answer = [0] * 4
for i, value in enumerate(values):
self.answer[i] = values[i] + self.math[p_type][i]
for i, back in enumerate(self.back):
self.back[i].SetLabel(str(self.answer[i]))
#function previus button
def on_show_prev(self, e):
fileDir = "fcc/data/BackLog.json"
data = get_data(fileDir)
if self.previous > 0:
self.previous -= 1
self.id.SetLabel("id: " + (str(self.previous)))
calculations = data['calculations']
p_type = calculations[self.previous]['ProfileType']
values = calculations[self.previous]['Values']
self.answer = [0] * 4
for i, value in enumerate(values):
self.answer[i] = values[i] + self.math[p_type][i]
if p_type == "7mm":
self.ButtonSize7.SetValue(True)
else:
self.ButtonSize10.SetValue(True)
for i, back in enumerate(self.back):
self.back[i].SetLabel(str(self.answer[i]))
#function next button
def on_show_next(self, e):
fileDir = "fcc/data/BackLog.json"
data = get_data(fileDir)
calculations = data['calculations']
if self.previous < len(calculations) - 1:
self.previous += 1
self.id.SetLabel("id: " + (str(self.previous)))
p_type = calculations[self.previous]['ProfileType']
values = calculations[self.previous]['Values']
self.answer = [0] * 4
for i, value in enumerate(values):
self.answer[i] = values[i] + self.math[p_type][i]
if p_type == "7mm":
self.ButtonSize7.SetValue(True)
else:
self.ButtonSize10.SetValue(True)
for i, back in enumerate(self.back):
self.back[i].SetLabel(str(self.answer[i]))
#-------------------------------------------------------------------------------#
p_top = 48 #top
p_bottom = 60 #bottom
p_side = 200 #side
p_front = 320 #front
class DrawingFrame(wx.Frame):
# print(p_bottom, p_front, p_side, p_top)
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title="wxPython Drawing", pos=wx.DefaultPosition, size=(512, 394))
self.Bind(wx.EVT_PAINT, self.on_paint)
self.Centre()
self.Show()
fileDir = "fcc/data/BackLog.json"
self.data = get_data(fileDir)
self.calculations = self.data['calculations']
self.previous = len(self.data['calculations'])
self.previous =- 1
values = self.calculations[self.previous]['Values']
print(values)
def calculate_scale(self):
# Calculate the scale factor based on the maximum of p_bottom, p_top, p_side, and p_front
max_value = (p_side/0.8) #max(p_bottom, p_top, p_side, p_front)
# print(200 / max_value)
return 200 / max_value
def draw_line(self, dc, length, angle, line_width):
"""Draw a line in the direction of the angle for a certain length."""
x, y = self.start_x, self.start_y
corrected_angle = 360 - angle
rad_angle = math.radians(corrected_angle)
end_x = x + length * math.cos(rad_angle)
end_y = y + length * math.sin(rad_angle)
pen = wx.Pen(wx.WHITE, int(line_width))
dc.SetPen(pen)
dc.DrawLine(int(x), int(y), int(end_x), int(end_y))
self.start_x, self.start_y = end_x, end_y
def on_paint(self, event):
dc = wx.ClientDC(self)
gc = wx.GraphicsContext.Create(dc)
# Calculate the dynamic scale factor
scale_factor = self.calculate_scale()
# Set the logical scale based on the scale factor
dc.SetLogicalScale(scale_factor, scale_factor)
# Calculate the starting position
self.start_x = (p_side / 5)
self.start_y = (p_side / 0.6)
line_thickness = 2 / scale_factor # Scale the line thickness inversely
# Set the pen color to white
gc.SetPen(wx.Pen(wx.WHITE, int(line_thickness)))
# Drawing the shape using setheading angles
self.draw_line(dc, p_bottom, 90, line_thickness)
self.draw_line(dc, p_side, 320, line_thickness)
self.draw_line(dc, p_bottom, 270, line_thickness)
self.draw_line(dc, p_side, 140, line_thickness)
self.draw_line(dc, p_front, 10, line_thickness)
self.draw_line(dc, p_bottom, 90, line_thickness)
self.draw_line(dc, p_side, 320, line_thickness)
self.draw_line(dc, p_bottom, 270, line_thickness)
self.draw_line(dc, p_side, 140, line_thickness)
self.draw_line(dc, p_side, 320, line_thickness)
self.draw_line(dc, p_front, 190, line_thickness)
self.draw_line(dc, p_bottom, 90, line_thickness)
self.draw_line(dc, p_front, 10, line_thickness)
self.draw_line(dc, p_side, 140, line_thickness)
self.draw_line(dc, p_front, 190, line_thickness)
self.draw_line(dc, p_top, 115, line_thickness)
self.draw_line(dc, p_front, 10, line_thickness)
self.draw_line(dc, p_top, 295, line_thickness)
self.draw_line(dc, p_side, 45, line_thickness)
self.draw_line(dc, p_top, 115, line_thickness)
self.draw_line(dc, -p_side, 45, line_thickness)
self.draw_line(dc, -p_front, 10, line_thickness)
self.draw_line(dc, p_side, 45, line_thickness)
self.draw_line(dc, -p_top, 115, line_thickness)
self.draw_line(dc, -p_side, 45, line_thickness)
self.draw_line(dc, p_side, 45, line_thickness)
self.draw_line(dc, p_front, 10, line_thickness)
self.draw_line(dc, p_top, 115, line_thickness)
self.draw_line(dc, -p_front, 10, line_thickness)
#-------------------------------------------------------------------------------#
#database
def db_function(new_calculation):
fileDir = "fcc/data/BackLog.json"
data = get_data(fileDir)
data["calculations"].append(new_calculation)
write_data(fileDir,data)
def get_data(fileDir):
with open(fileDir, "r") as json_file:
data = json.load(json_file)
return data
def write_data(fileDir, data):
with open(fileDir, "w") as json_file:
json.dump(data, json_file, indent=4)
#run program
if __name__ == "__main__":
app = wx.App()
frame = bucky(parent = None, id = -1,)
frame.SetMaxSize((256, 197))
frame.Show()
app.MainLoop()