-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrc_inspection_manager.py
752 lines (617 loc) · 27.1 KB
/
frc_inspection_manager.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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
import os
import datetime
import wx
import wx.grid
import frc_inspection_manager_wx
from frc_inspection_manager_database import *
def colors_for_team_status(ts: TeamStatus):
if ts == TeamStatus.Absent:
return 0, 0, 0
elif ts == TeamStatus.Weighed:
return 255, 255, 0
elif ts == TeamStatus.Inspected:
return 0, 200, 0
elif ts == TeamStatus.Final_Incomplete:
return 200, 200, 0
elif ts == TeamStatus.Final_Completed:
return 0, 255, 0
else:
return 40, 40, 40
def b_if_n(v):
"""
return a blank if value is None, else the string value of the parameter
:param v:
:return:
"""
if v is None:
return ''
else:
return str(v)
class MainFrame(frc_inspection_manager_wx.MainFrame):
# constructor
def __init__(self, parent, database: Database, status_frame=None):
# initialize parent class
super().__init__(parent)
self.database = database
self.inspector_for_context_menu = None
self.team_for_context_menu = None
self.status_frame = status_frame
self.grid_table = self.team_grid.GetTable()
self.team_grid.ClearGrid()
self.team_grid.AppendRows(len(database.teams))
self.team_to_row_map = {}
self.row_to_team_map = {}
self.inspection_grid.Hide()
for i, t in enumerate(self.database.teams):
self.team_to_row_map[t.number] = i
self.row_to_team_map[i] = t
self.update_team(t)
self.inspection_history_team_choice.Append(str(t.number))
self.team_grid.SetColLabelValue(0, 'Name')
self.team_grid.SetColLabelValue(1, 'Status')
# self.inspector_grid.SetColLabelAlignment(1, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
self.team_grid.SetRowLabelSize(wx.grid.GRID_AUTOSIZE)
self.team_grid.AutoSize()
self.team_panel.Layout()
self.inspector_table = self.inspector_grid.GetTable()
self.inspector_grid.ClearGrid()
self.inspector_grid.AppendRows(len(database.inspectors))
self.inspector_to_row_map = {}
self.row_to_inspector_map = {}
for i, inspector in enumerate(database.inspectors):
self.inspector_to_row_map[inspector.id] = i
self.row_to_inspector_map[i] = inspector
self.update_inspector(inspector)
self.inspector_grid.SetColLabelValue(0, 'status')
self.inspector_grid.SetColLabelValue(1, 'when left')
# self.inspector_grid.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
self.inspector_grid.SetRowLabelSize(wx.grid.GRID_AUTOSIZE)
self.inspector_grid.AutoSize()
self.inspector_panel.Layout()
def set_status_frame(self, status_frame):
self.status_frame = status_frame
def update_team(self, t: Team):
row = self.team_to_row_map[t.number]
self.team_grid.SetRowLabelValue(row, str(t.number))
self.team_grid.SetCellValue(row, 0, t.name)
s = t.status_s
if len(t.inspectors_in_pit) > 0:
inspector_names = []
for inspector_id in t.inspectors_in_pit:
inspector = self.database.fetch_inspector(inspector_id)
inspector_names.append(inspector.name)
s += "; " + ', '.join(inspector_names) + " in pit"
fg_color = colors_for_team_status(t.status)
self.team_grid.SetCellValue(row, 1, s)
self.team_grid.SetCellAlignment(row, 1, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
self.team_grid.SetCellTextColour(row, 1, fg_color)
self.team_grid.AutoSize()
self.team_panel.Layout()
def update_inspector(self, inspector: Inspector):
row = self.inspector_to_row_map[inspector.id]
self.inspector_grid.SetRowLabelValue(row, inspector.name)
self.inspector_grid.SetCellValue(row, 0, inspector.status_s)
self.inspector_grid.SetCellAlignment(row, 0, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
s, c = self.format_away(inspector)
self.inspector_grid.SetCellValue(row, 1, s)
self.update_inspector_out_timer(inspector)
self.inspector_grid.AutoSize()
self.inspector_panel.Layout()
def format_away(self, inspector):
if inspector.time_away_started is None:
return "", None
if inspector.status != InspectorStatus.In_Pit and inspector.status != InspectorStatus.Break:
return "", None
return inspector.time_away_started.strftime('%a %I:%M %p'), None
def update_inspector_out_timer(self, inspector: Inspector):
row = self.inspector_to_row_map[inspector.id]
s = ""
if inspector.time_away_started is not None and (inspector.status == InspectorStatus.In_Pit or inspector.status == InspectorStatus.Break):
out_time = datetime.datetime.now() - inspector.time_away_started
minutes = round(out_time.total_seconds() / 60)
# Formatted only for hours and minutes as requested
s = f"{minutes} minutes"
self.inspector_grid.SetCellValue(row, 2, s)
def on_timer(self, event):
for inspector in self.row_to_inspector_map.values():
self.update_inspector_out_timer(inspector)
def on_team_right_click(self, event):
print(event.GetEventType(), event.GetEventObject(), event.GetCol(), event.GetRow())
row = event.GetRow()
team = self.row_to_team_map[row]
self.display_team_context_menu(event, team)
event.Skip()
def display_team_context_menu(self, event, team):
self.m_t_team.SetItemLabel(str(team.number))
self.team_for_context_menu = team
self.m_t_checkin.Check(team.checked_in)
self.team_panelOnContextMenu(event)
def on_t_context(self, event: wx._core.CommandEvent):
print("got a team context event:" , type(event), event.GetId(), self.team_for_context_menu)
event_id = event.GetId()
team = self.team_for_context_menu
if event_id == frc_inspection_manager_wx.ID_T_CHECKIN:
team.checked_in = not team.checked_in
elif event_id == frc_inspection_manager_wx.ID_T_WEIGHIN:
weighed_in = self.weighin_dialog_box()
return
elif event_id == frc_inspection_manager_wx.ID_T_REINSPECT:
print("reinspect!")
self.reinspect_dialog_box()
return
elif event_id == frc_inspection_manager_wx.ID_T_FINAL_WEIGHIN:
print("final!")
inspection = self.reinspect_dialog_box()
if inspection is not None:
ok = self.check_weight(team, inspection)
inspection.passed = ok
else:
self.SetStatusText("Got funny command!")
print("got funny command")
self.database.mark_dirty()
self.update_team(team)
self.status_frame.update_team(team)
def check_weight(self, team, inspection):
return True
def on_inspector_right_click(self, event):
print(event.GetEventType(), event.GetEventObject(), event.GetCol(), event.GetRow())
row = event.GetRow()
inspector = self.row_to_inspector_map[row]
self.display_inspector_context_menu(event, inspector)
event.Skip()
def display_inspector_context_menu(self, event, inspector):
self.m_i_inspector.SetItemLabel(inspector.name)
self.inspector_for_context_menu = inspector
enable_all = [
self.m_i_off, self.m_i_pit, self.m_i_field, self.m_i_pit_return, self.m_i_available, self.m_i_break
]
enable = enable_all.copy()
enable.remove(self.m_i_pit_return)
if inspector.status == InspectorStatus.Off:
enable.remove(self.m_i_off)
elif inspector.status == InspectorStatus.In_Pit:
enable = [self.m_i_pit_return]
elif inspector.status == InspectorStatus.Field:
enable.remove(self.m_i_field)
elif inspector.status == InspectorStatus.Break:
enable.remove(self.m_i_break)
elif inspector.status == InspectorStatus.Available:
enable.remove(self.m_i_available)
else:
raise Exception("unknown inspector status")
for menuitem in enable_all:
menuitem.Enable(False)
for menuitem in enable:
menuitem.Enable(True)
self.inspector_panelOnContextMenu(event)
def on_i_context(self, event: wx._core.CommandEvent):
print(type(event), event.GetId(), self.inspector_for_context_menu)
event_id = event.GetId()
inspector = self.inspector_for_context_menu
current_status = inspector.status
new_status = None
if event_id == frc_inspection_manager_wx.ID_I_PIT:
# this will take care of setting the new status and updating GUI
# if inspection was started
inspection_started = self.inspection_start_dialog_box(inspector=inspector)
elif event_id == frc_inspection_manager_wx.ID_I_FIELD:
new_status = InspectorStatus.Field
elif event_id == frc_inspection_manager_wx.ID_I_BREAK:
new_status = InspectorStatus.Break
inspector.time_away_started = datetime.datetime.now()
elif event_id == frc_inspection_manager_wx.ID_I_AVAILABLE:
new_status = InspectorStatus.Available
elif event_id == frc_inspection_manager_wx.ID_I_OFF:
new_status = InspectorStatus.Off
elif event_id == frc_inspection_manager_wx.ID_I_PIT_RETURN:
# this will update the inspector status
self.inspection_end_dialog_box()
else:
self.SetStatusText("Got funny command!")
if new_status != None:
if new_status != current_status:
inspector.status = new_status
self.database.mark_dirty()
self.update_inspector(inspector)
def inspection_start_dialog_box(self, inspector: Inspector = None, team: Team = None):
choices = None
if team is None:
choices = [str(t.number) for t in self.database.teams]
prompt = "Which team is " + inspector.name + " + inspecting?"
elif inspector is None:
choices = [i.name for i in self.database.inspectors]
prompt = "Which inspector is going to team " + str(team.number) + ", " + team.name
else:
prompt = "huh, programmer should have filled in either team or inspector"
inspection_started = False
if choices is not None:
# "with" statement will do implicit destroy on dlg
with wx.SingleChoiceDialog(self, prompt, "Start Inspection", choices, wx.CHOICEDLG_STYLE) as dlg:
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
if inspector is None:
inspector = self.database.inspectors[i]
else:
team = self.database.teams[i]
inspector.status = InspectorStatus.In_Pit
inspector.inspection_team_number = team.number
inspector.time_away_started = datetime.datetime.now()
team.inspectors_in_pit.add(inspector.id)
self.update_team(team)
self.status_frame.update_team(team)
self.update_inspector(inspector)
self.database.mark_dirty()
return inspection_started
def inspection_end_dialog_box(self):
inspector = self.inspector_for_context_menu
inspection = Inspection()
inspection.inspection_reason = InspectionReason.Initial
inspection.when = datetime.datetime.now()
inspection.inspector_id = inspector.id
with InspectionDialog(self, inspection, self.database) as dlg:
# show as modal dialog
result = dlg.ShowModal()
print(f"weighin dialog box {result}")
if result == wx.ID_OK:
# user has hit OK -> read text control value
print('OK!', vars(inspection))
team_id = inspector.inspection_team_number
team: Team = self.database.fetch_team(team_id)
team.inspections.append(inspection)
team.inspectors_in_pit.remove(inspector.id)
inspector.status = InspectorStatus.Available
inspector.inspection_team_number = None
self.database.mark_dirty()
self.update_team(team)
self.status_frame.update_team(team)
self.update_inspector(inspector)
def weighin_dialog_box(self):
team = self.team_for_context_menu
weighin = Inspection()
weighin.inspection_reason = InspectionReason.Weighin
weighin.when = datetime.datetime.now()
with InspectionDialog(self, weighin, self.database) as dlg:
# show as modal dialog
result = dlg.ShowModal()
print(f"weighin dialog box {result}")
if result == wx.ID_OK:
# user has hit OK -> read text control value
print('OK!', vars(weighin))
team.inspections.append(weighin)
self.database.mark_dirty()
self.update_team(team)
self.status_frame.update_team(team)
def reinspect_dialog_box(self):
print("making reinspect dialog")
team = self.team_for_context_menu
inspection = Inspection()
inspection.inspection_reason = InspectionReason.Reinspect
inspection.when = datetime.datetime.now()
with InspectionDialog(self, inspection, self.database) as dlg:
# show as modal dialog
result = dlg.ShowModal()
print(f"reinspect dialog box {result}")
if result == wx.ID_OK:
# user has hit OK -> read text control value
print('OK!', vars(inspection))
team.inspections.append(inspection)
self.database.mark_dirty()
self.update_team(team)
self.status_frame.update_team(team)
return inspection
def my_on_close(self, event):
print(event.GetEventType(), event.GetEventObject())
event.Skip()
"""
this is obsolete, but keeping for reference purposes
"""
def xx_my_on_close(self, event):
print(event.GetEventType(), event.GetEventObject())
if event.CanVeto():
if wx.MessageBox("The file has not been saved... continue closing?",
"Please confirm",
wx.ICON_QUESTION | wx.YES_NO) != wx.YES:
event.Veto()
return
event.Skip()
def on_inspection_history_team_pick(self, event):
selection = self.inspection_history_team_choice.GetSelection()
team_id = int(self.inspection_history_team_choice.GetString(selection))
print(f"pulling up history for {team_id}")
self.update_inspection_history(team_id)
event.Skip()
def update_inspection_history(self, team_id):
if self.inspection_grid.GetNumberRows() > 0:
self.inspection_grid.DeleteRows(0, self.inspection_grid.GetNumberRows())
team = self.database.fetch_team(team_id)
inspection_count = len(team.inspections)
if inspection_count == 0:
self.inspection_grid.Hide()
else:
self.inspection_grid.Show()
self.inspection_grid.AppendRows(len(team.inspections))
for i, inspection in enumerate(team.inspections):
self.inspection_grid.SetRowLabelValue(i, inspection.when.strftime('%a %I:%M %p'))
self.inspection_grid.SetCellValue(i, 0, inspection.inspection_reason_s)
self.inspection_grid.SetCellValue(i, 1, b_if_n(inspection.robot_weight))
self.inspection_grid.SetCellValue(i, 2, b_if_n(inspection.red_bumper_weight))
self.inspection_grid.SetCellValue(i, 3, b_if_n(inspection.blue_bumper_weight))
self.inspection_grid.SetCellValue(i, 4, b_if_n(inspection.passed))
self.inspection_grid.SetRowLabelSize(wx.grid.GRID_AUTOSIZE)
self.inspection_grid.AutoSize()
self.inspection_history.Layout()
class TeamStatusFrame(frc_inspection_manager_wx.TeamStatusFrame):
# constructor
def __init__(self, parent, database: Database, main_frame=None):
# initialize parent class
super().__init__(parent)
self.database = database
self.main_frame = main_frame
self.team_to_gui_map = {}
s = wx.GridSizer(8, 8, 2, 2)
for t in self.database.teams:
p = frc_inspection_manager_wx.TeamStatusPanel(self)
self.team_to_gui_map[t.number] = p
self.update_team(t)
s.Add(p, 1, wx.EXPAND | wx.ALL, 2)
s.SetSizeHints(self)
self.SetSizer(s, deleteOld=True)
self.Layout()
def set_main_frame(self, main_frame):
self.main_frame = main_frame
def update_team(self, t: Team):
p = self.team_to_gui_map[t.number]
p.team_number.SetLabel(str(t.number))
fg_color = colors_for_team_status(t.status)
p.team_number.SetForegroundColour(fg_color)
s = t.status_s
if len(t.inspectors_in_pit) > 0:
s += "; inspector in pit"
p.team_status.SetLabel(s)
def my_on_close(self, event):
"""
really not needed; no close button!
"""
if event.CanVeto():
event.Veto()
else:
event.Skip()
class InspectionDialog(frc_inspection_manager_wx.InspectionDialog):
def __init__(self, parent, inspection, db):
# initialize parent class
super().__init__(parent)
self.inspection = inspection
self.database = db
self.robot_weight.SetValidator(WeightValidator(data=self.inspection, key='robot_weight', must_have_value=False))
self.red_bumper_weight.SetValidator(WeightValidator(data=self.inspection, key='red_bumper_weight', must_have_value=False))
self.blue_bumper_weight.SetValidator(WeightValidator(data=self.inspection, key='blue_bumper_weight', must_have_value=False))
self.robot_weight_with_red.SetValidator(WeightValidator(data=self.inspection, key='robot_weight_with_red', must_have_value=False))
self.robot_weight_with_blue.SetValidator(WeightValidator(data=self.inspection, key='robot_weight_with_blue', must_have_value=False))
self.inspector.SetValidator(InspectorValidator(data=self.inspection, key='inspector_id', inspectors=self.database.inspectors))
self.passed.SetValidator(PassedInspectionValidator(data=self.inspection, key='passed'))
self.comments.SetValidator(CommentsValidator(data=self.inspection, key='comments'))
print(f"inspection reason {inspection.inspection_reason}")
if inspection.inspection_reason == InspectionReason.Weighin:
self.robot_weight.GetValidator().must_have_value = True
self.enable_robot_weight_with_red(False)
self.enable_robot_weight_with_blue(False)
self.enable_passed(False)
elif inspection.inspection_reason == InspectionReason.Initial:
self.enable_robot_weight(False)
self.enable_red_bumper_weight(False)
self.enable_blue_bumper_weight(False)
self.enable_robot_weight_with_red(False)
self.enable_robot_weight_with_blue(False)
elif inspection.inspection_reason == InspectionReason.Reinspect:
pass
elif inspection.inspection_reason == InspectionReason.Final:
pass
else:
raise Exception("need to have a reason to inspect!")
def enable_robot_weight(self, enabled):
self.robot_weight_label.Enable(enabled)
self.robot_weight.Enable(enabled)
def enable_red_bumper_weight(self, enabled):
self.red_bumper_weight_label.Enable(enabled)
self.red_bumper_weight.Enable(enabled)
def enable_blue_bumper_weight(self, enabled):
self.blue_bumper_weight_label.Enable(enabled)
self.blue_bumper_weight.Enable(enabled)
def enable_robot_weight_with_red(self, enabled):
self.robot_weight_with_red_label.Enable(enabled)
self.robot_weight_with_red.Enable(enabled)
def enable_robot_weight_with_blue(self, enabled):
self.robot_weight_with_blue_label.Enable(enabled)
self.robot_weight_with_blue.Enable(enabled)
def enable_inspector(self, enabled):
print(f"setting inspector enabled = {enabled}")
self.inspector_label.Enable(enabled)
self.inspector.Enable(enabled)
print(f"inspector enabled = {self.inspector.IsEnabled()}")
def enable_passed(self, enabled):
self.passed_label.Enable(enabled)
self.passed.Enable(enabled)
def on_OK_button(self, event):
print("Event handler 'on_button_OK' called")
# don't call Skip if you want to keep the dialog open
if False: # maybe also check self.validate_contents()
print("Checkbox not checked -> don't close the dialog")
wx.Bell()
else:
print("Checkbox checked -> close the dialog")
event.Skip()
class WeightValidator(wx.Validator):
def __init__(self, must_have_value=False, data=None, key=None):
super().__init__()
if data is None:
raise Exception("must specify data=")
if key is None:
raise Exception("must specify key=")
self.must_have_value = must_have_value
self.data = data
self.key = key
self.value = None
def Clone(self):
return WeightValidator(must_have_value=self.must_have_value, data=self.data, key=self.key)
def Validate(self, win):
textCtrl = self.GetWindow()
text = textCtrl.GetValue().strip()
ok = True
self.value = None
if len(text) > 0:
try:
self.value = float(text)
except ValueError:
pass
if self.value is None and self.must_have_value:
# wx.MessageBox("This field must contain some text!", "Error")
ok = False
if ok:
textCtrl.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
textCtrl.Refresh()
else:
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return ok
def TransferToWindow(self):
textCtrl = self.GetWindow()
self.value = getattr(self.data, self.key)
if self.value is None:
textCtrl.SetValue('')
else:
textCtrl.SetValue(str(self.value))
return True
def TransferFromWindow(self):
setattr(self.data, self.key, self.value)
return True
class InspectorValidator(wx.Validator):
def __init__(self, data=None, key=None, inspectors=None):
super().__init__()
if data is None:
raise Exception("must specify data=")
if key is None:
raise Exception("must specify key=")
if inspectors is None:
raise Exception("must specify inspectors=")
self.data = data
self.key = key
self.inspectors = inspectors
def Clone(self):
return InspectorValidator(data=self.data, key=self.key, inspectors=self.inspectors)
def Validate(self, win):
return True
def TransferToWindow(self):
inspector_choice: wx.Choice = self.GetWindow()
current_inspector_id = getattr(self.data, self.key)
inspector_list = []
inspector_choice.Clear()
inspector_index = 0
inspector_choice.Append('-- none --')
inspector_list.append(None)
for i, inspector in enumerate(self.inspectors):
inspector_choice.Append(inspector.name)
inspector_list.append(inspector)
if current_inspector_id is not None:
if inspector.id == current_inspector_id:
inspector_index = i + 1
inspector_choice.SetSelection(inspector_index)
print(current_inspector_id, inspector_list, inspector_index)
return True
def TransferFromWindow(self):
choice: wx.Choice = self.GetWindow()
selection_index = choice.GetSelection()
print('selection', selection_index, self.inspectors)
if selection_index == 0:
inspector_id = None
else:
inspector = self.inspectors[selection_index-1]
print('inspector choice', inspector)
inspector_id = inspector.id
setattr(self.data, self.key, inspector_id)
return True
class PassedInspectionValidator(wx.Validator):
def __init__(self, data=None, key=None):
super().__init__()
if data is None:
raise Exception("must specify data=")
if key is None:
raise Exception("must specify key=")
self.data = data
self.key = key
def Clone(self):
return PassedInspectionValidator(data=self.data, key=self.key)
def Validate(self, win):
return True
def TransferToWindow(self):
passed_choice: wx.Choice = self.GetWindow()
passed_choice.Clear()
passed_choice.Append('-- no change --')
passed_choice.Append('Passed')
passed_choice.Append('Not passed')
passed_index = 0
v = getattr(self.data, self.key)
if v is not None:
passed_index = 1 if v else 0
passed_choice.SetSelection(passed_index)
return True
def TransferFromWindow(self):
choice: wx.Choice = self.GetWindow()
selection_index = choice.GetSelection()
if selection_index == 0:
passed = None
else:
passed = selection_index == 1
setattr(self.data, self.key, passed)
return True
class CommentsValidator(wx.Validator):
def __init__(self, data=None, key=None):
super().__init__()
if data is None:
raise Exception("must specify data=")
if key is None:
raise Exception("must specify key=")
self.data = data
self.key = key
def Clone(self):
return CommentsValidator(data=self.data, key=self.key)
def Validate(self, win):
return True
def TransferToWindow(self):
textctrl: wx.TextCtrl = self.GetWindow()
v = getattr(self.data, self.key)
if v is None:
v = ''
textctrl.SetValue(v)
return True
def TransferFromWindow(self):
textctrl: wx.TextCtrl = self.GetWindow()
v = textctrl.GetValue()
v = v.rstrip()
if len(v) == 0:
v = None
setattr(self.data, self.key, v)
return True
if __name__ == '__main__':
database = Database()
fn = 'misjo.imd'
with open(fn, 'r') as fp:
j = fp.read()
database.from_json(j)
print(database)
app = wx.App()
frm1 = MainFrame(None, database)
frm1.Show()
frm2 = TeamStatusFrame(frm1, database, main_frame=frm1)
frm1.set_status_frame(frm2)
frm2.Iconize(True)
frm2.Show()
app.MainLoop()
if database.is_dirty:
j = database.as_json()
with open(fn + '.tmp', 'w') as fp:
fp.write(j)
if os.path.isfile(fn):
ts = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
os.rename(fn, fn + '_' + ts)
os.rename(fn + '.tmp', fn)