-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_gui.py
1275 lines (907 loc) · 54.3 KB
/
menu_gui.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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import tkinter as tk
from tkinter import font as tkFont
from tkinter import Toplevel
import socket
import os
from utils.menu_utils import menu_labels
from threading import Thread, Event, Lock
import alumia_TCP
import time
import cv2
from threading import Thread, Event
import queue
from PIL import Image, ImageTk
import time
MONITOR_ROOT = "PATH_TO_LOW_RES_FOLDER"
class VideoPlayFrame(tk.Frame):
def __init__(self, parent, upper_class, menu_name):
super().__init__(parent)
self.message_for_action = ""
self.upper_class = upper_class
self.menu_name = menu_name
self["bg"] = "black"
self.button_font = tkFont.Font(size=40, weight='bold')
self.SIDE_B_W = 1
self.SIDE_B_H = 100
self.TOP_B_W = 200
self.TOP_B_H = self.SIDE_B_W
self.HAND_B_W = (1/8)*self.TOP_B_W
self.HAND_B_H = 3*self.SIDE_B_H
self.button_up = tk.Button(self, text="UP", padx=self.TOP_B_W, pady=self.TOP_B_H, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_down = tk.Button(self, text="DOWN", padx=self.TOP_B_W, pady=self.TOP_B_H, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_right = tk.Button(self, text="RIGHT", padx=self.SIDE_B_W, pady=self.SIDE_B_H, wraplength=1, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_left = tk.Button(self, text="LEFT", padx=self.SIDE_B_W, pady=self.SIDE_B_H, wraplength=1, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.move_buttons = [self.button_down, self.button_up, self.button_left, self.button_right]
self.button_hand_1 = tk.Button(self, text="action1", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_2 = tk.Button(self, text="action2", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_3 = tk.Button(self, text="action3", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_4 = tk.Button(self, text="action4", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_1["font"] = self.button_font
self.button_hand_2["font"] = self.button_font
self.button_hand_3["font"] = self.button_font
self.button_hand_4["font"] = self.button_font
self.button_info_rec = tk.Button(self, text="R", bg='black', borderwidth=0, highlightthickness=0)
self.button_info_blue = tk.Button(self, text="B", bg='black', borderwidth=0, highlightthickness=0)
self.button_info_perf = tk.Button(self, text="P", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_2 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_4 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_6 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_7 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_8 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_up.grid(row=0, column=1, columnspan=8, sticky="nesw")
self.button_down.grid(row=3, column=1, columnspan=8, sticky="nesw")
self.button_right.grid(row=1, column=9, rowspan=2, sticky="nesw")
self.button_left.grid(row=1, column=0, rowspan=2, sticky="nesw")
self.button_hand_1.grid(row=1, column=1, columnspan=2, sticky="nesw")
self.button_hand_2.grid(row=1, column=3, columnspan=2, sticky="nesw")
self.button_hand_3.grid(row=1, column=5, columnspan=2, sticky="nesw")
self.button_hand_4.grid(row=1, column=7, columnspan=2, sticky="nesw")
self.button_info_rec.grid(row=2, column=1, columnspan=1, sticky="nesw")
self.button_info_perf.grid(row=2, column=3, columnspan=1, sticky="nesw")
self.button_info_blue.grid(row=2, column=5, columnspan=1, sticky="nesw")
self.button_dummy_2.grid(row=2, column=2, columnspan=1, sticky="nesw")
self.button_dummy_4.grid(row=2, column=4, columnspan=1, sticky="nesw")
self.button_dummy_6.grid(row=2, column=6, columnspan=1, sticky="nesw")
self.button_dummy_7.grid(row=2, column=7, columnspan=1, sticky="nesw")
self.button_dummy_8.grid(row=2, column=8, columnspan=1, sticky="nesw")
self.grid(column=0, row=0, sticky="nesw")
for row_num in range(self.grid_size()[1]):
if row_num == 0 or row_num == 3:
continue
self.rowconfigure(row_num, weight=1)
for col_num in range(self.grid_size()[0]):
if col_num == 0 or col_num == 9:
continue
self.columnconfigure(col_num, weight=1)
# this is a dict with keys: position -> action
self.button_dict = {
"center": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"play_": self.button_hand_1,
"blk_": self.button_hand_2,
"edt_": self.button_hand_3
}
}
self.load_correct_labels()
self.load_correct_invokes()
def frame_update(self):
self.upper_class.present_pos = "center"
self.load_values_to_gui()
return
def frame_release(self):
return
def load_correct_labels(self):
self.button_hand_1['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_1']
self.button_hand_2['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_2']
self.button_hand_3['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_3']
self.button_hand_4['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_4']
def load_correct_invokes(self):
self.button_hand_1["command"] = lambda: self.send_message(self.button_hand_1)
self.button_hand_2["command"] = lambda: self.joystick_moment(self.button_hand_2)
self.button_hand_3["command"] = lambda: self.joystick_moment(self.button_hand_3)
def send_message(self, button):
# we want the button to press and unpress
snippet_number = self.upper_class.video_to_play.path.split("/")[-1].replace("_lores.avi", "").split("_")[1]
main_number = self.upper_class.video_to_play.path.split("/")[-1].replace("_lores.avi", "").split("_")[0]
self.upper_class.client.client_send(self.message_for_action+main_number+"&"+snippet_number)
def joystick_moment(self, button):
button_content = button["text"].splitlines()
if self.message_for_action not in ["up", "down", "loopr", "loopl"]: # we either entered the button or want to exit
if self.upper_class.joystick_mode[0] == False: # we just entered the joystick mode
self.upper_class.joystick_mode = (True, button_content[0], self.message_for_action)
self.upper_class.active_joystick_button = button
#ask for the current value
self.upper_class.client.client_send(self.message_for_action+"0")
button["bg"] ='dark slate gray'
else: # we were in the joystick mode and now we should check if we are pressing the same button
if button_content[0] == self.button_dict[self.upper_class.present_pos][self.message_for_action]["text"].splitlines()[0]: # we want to exit
# here, in play menu, we want to start play here
snippet_number = self.upper_class.video_to_play.path.split("/")[-1].replace("_lores.avi", "").split("_")[1]
main_number = self.upper_class.video_to_play.path.split("/")[-1].replace("_lores.avi", "").split("_")[0]
self.upper_class.client.client_send("play_"+main_number+"&"+snippet_number)
self.upper_class.joystick_mode = (False, "", "")
self.upper_class.active_joystick_button = ""
button["bg"] ='black'
else: # we want to change the value
if self.message_for_action == "up": # we want to up the number
self.upper_class.client.client_send(self.upper_class.joystick_mode[2]+"1")
elif self.message_for_action == "down":
self.upper_class.client.client_send(self.upper_class.joystick_mode[2]+"-1")
def load_values_to_gui(self):
# maybe the best solution is to simulate clicks on the buttons that can be read
self.upper_class.populate_mode = True
for button_key in self.button_dict[self.upper_class.present_pos].keys():
if "msp" in button_key or "fps" in button_key or "blk" in button_key or "exp" in button_key or "edt" in button_key:
self.upper_class.client.client_send(button_key+"0")
# then we wait the reply
while self.upper_class.populate_values_queue.empty():
time.sleep(0.01)
current_value = self.upper_class.populate_values_queue.get()
total_text = self.button_dict[self.upper_class.present_pos][button_key]["text"].splitlines()
self.button_dict[self.upper_class.present_pos][button_key]["text"] = total_text[0] + "\n" + current_value
self.upper_class.populate_mode = False
class VideoCheckFrame(tk.Frame):
#we will start the thread in this class
def __init__(self, parent, upper_class, menu_name):
super().__init__(parent)
self.current_video = ""
self.upper_class = upper_class
self.thumb_frame = tk.Frame(master=self, bg="black", highlightbackground="black", highlightthickness=0)
self.video_dict = {"files": [], "buttons": []}
self.button_dict = {"center": {}}
self.init_thumb_number = 12
self.video_change_button = tk.Button(self, text="", command=self.move_selection, bg='black')
self.video_play_button = tk.Button(self, text="", command=self.play_selection, bg='black')
for i in range(self.init_thumb_number):
new_label = tk.Label(self.thumb_frame, bg="black", highlightbackground="white", borderwidth=0, highlightthickness=2, bd=0, padx=0, pady=0)
self.video_dict["buttons"].append(new_label)
new_label.grid(row=0, column=len(self.video_dict["buttons"]) - 1, sticky="nesw")
self.menu_name = menu_name
self.v1_label = tk.Label(self, bg="black", highlightbackground="white", borderwidth=0, highlightthickness=0, pady=350, height=700, bd=0)
self.grid(column=0, row=0, sticky="nesw")
self.v1_label.grid(row=0, column=0, sticky="nesw")
self.thumb_frame.grid(row=1, column=0, sticky="nesw")
for row_num in range(self.grid_size()[1]):
self.rowconfigure(row_num, weight=1)
for col_num in range(self.grid_size()[0]):
self.columnconfigure(col_num, weight=1)
for row_num in range(self.thumb_frame.grid_size()[1]):
self.thumb_frame.rowconfigure(row_num, weight=1)
for col_num in range(self.thumb_frame.grid_size()[0]):
self.thumb_frame.columnconfigure(col_num, weight=1)
self.frame_update()
self.v1_queue = queue.Queue(maxsize=1)
self.play_event = Event()
self.video_kill = Event()
self.message_for_action = ""
self.start_video_thread()
self.button_dict = {
"center": {
#"up": self.button_up,
"play": self.video_play_button,
"prevv": self.video_change_button,
"nextv": self.video_change_button
#"str_0": self.button_hand_1,
#"bperf_0": self.button_hand_2,
#"eperf_0": self.button_hand_3
}
}
def play_selection(self):
self.upper_class.change_to_menu("video_play")
self.upper_class.video_to_play = self.current_video
self.frame_release()
def move_selection(self):
# this is called everytime we move left or right in this menu. We first have to see if there are any button at all
if len(self.video_dict["files"]) > 0:
for idx, file_ in enumerate(self.video_dict["files"]):
if file_ == self.current_video:
break
if self.message_for_action == "prevv":
if idx > 0:
self.change_selected_video(idx-1)
elif self.message_for_action == "nextv":
if idx < len(self.video_dict["files"]) - 1 :
self.change_selected_video(idx+1)
def frame_update(self):
self.upper_class.present_pos = "center"
self.find_org_folder_videos()
self.refresh_n_thumb_buttons()
self.change_selected_video(-1)
def frame_release(self):
self.play_event.clear()
def change_selected_video(self, new_sel_idx):
if new_sel_idx == -1:
# play last video if there is one
if len(self.video_dict["files"]) > 0:
for button_idx in range(len(self.video_dict["files"])):
self.video_dict["buttons"][button_idx]["bg"] = "black"
self.video_dict["buttons"][len(self.video_dict["files"])-1]["bg"] = "red"
self.current_video = self.video_dict["files"][-1]
self.v1_queue.put(self.current_video.path)
self.play_event.set()
else:
for button_idx in range(len(self.video_dict["files"])):
self.video_dict["buttons"][button_idx]["bg"] = "black"
self.video_dict["buttons"][new_sel_idx]["bg"] = "red"
self.current_video = self.video_dict["files"][new_sel_idx]
self.v1_queue.put(self.video_dict["files"][new_sel_idx].path)
self.play_event.set()
def refresh_n_thumb_buttons(self):
if len(self.video_dict["files"]) > self.init_thumb_number:
while len(self.video_dict["buttons"]) < len(self.video_dict["files"]):
new_label = tk.Label(self.thumb_frame, bg="black", highlightbackground="white", borderwidth=0, highlightthickness=2, bd=0, padx=0, pady=0)
self.video_dict["buttons"].append(new_label)
new_label.grid(row=0, column=len(self.video_dict["buttons"]) - 1, sticky="nesw")
self.v1_label.config(height=700)
else:
# we want to reset to init n buttons, removing the last ones
while len(self.video_dict["buttons"]) > self.init_thumb_number:
self.video_dict["buttons"][-1].destroy()
self.video_dict["buttons"].pop()
for label in self.video_dict["buttons"]:
label.configure(image="", bg="black", highlightbackground="white", borderwidth=0, highlightthickness=2, bd=0, padx=0, pady=0)
self.v1_label.config(height=700)
def find_org_folder_videos(self):
if self.upper_class.current_folder != "":
tmp_videos = []
with os.scandir(self.upper_class.current_folder) as entries:
for entry in entries:
if entry.is_file() and entry.name.endswith(".avi"):
tmp_videos.append(entry)
tmp_videos_sorted = sorted(tmp_videos, key=lambda x: int(x.name[:-10].split("_")[1]), reverse=False)
self.video_dict["files"] = tmp_videos_sorted # i need to organize this list to
def start_video_thread(self):
self.video_thread = Thread(target=self.play_video, args=())
self.video_thread.start()
def play_video(self):
v1_path = ""
while not self.video_kill.is_set() :
if not self.v1_queue.empty():
v1_path = self.v1_queue.get()
cap1 = cv2.VideoCapture(v1_path)
while self.play_event.is_set() and v1_path != "":
if not self.v1_queue.empty():
v1_path = self.v1_queue.get()
cap1 = cv2.VideoCapture(v1_path)
ret1, frame1 = cap1.read()
if not ret1:
cap1 = cv2.VideoCapture(v1_path)
continue
blue1,green1,red1 = cv2.split(frame1)
img1 = cv2.merge((red1,green1,blue1))
im1 = Image.fromarray(img1)
imgtk1 = ImageTk.PhotoImage(image=im1)
imgtk1 = imgtk1._PhotoImage__photo.zoom(2)
self.v1_label.configure(image=imgtk1)
self.v1_label.image = imgtk1
time.sleep(0.1)
v1_path = ""
class NavigationFrame(tk.Frame):
def __init__(self, parent, upper_class, menu_name):
super().__init__(parent)
self.message_for_action = ""
self.upper_class = upper_class
self.menu_name = menu_name
self["bg"] = "black"
self.button_font = tkFont.Font(size=40, weight='bold')
self.SIDE_B_W = 1
self.SIDE_B_H = 100
self.TOP_B_W = 200
self.TOP_B_H = self.SIDE_B_W
self.HAND_B_W = (1/8)*self.TOP_B_W
self.HAND_B_H = 3*self.SIDE_B_H
self.button_up = tk.Button(self, text="UP", padx=self.TOP_B_W, pady=self.TOP_B_H, command=self.go_up, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_down = tk.Button(self, text="DOWN", padx=self.TOP_B_W, pady=self.TOP_B_H, command=self.go_down, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_right = tk.Button(self, text="RIGHT", padx=self.SIDE_B_W, pady=self.SIDE_B_H, wraplength=1, command=self.go_right, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_left = tk.Button(self, text="LEFT", padx=self.SIDE_B_W, pady=self.SIDE_B_H, wraplength=1, command=self.go_left, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.move_buttons = [self.button_down, self.button_up, self.button_left, self.button_right]
self.button_hand_1 = tk.Button(self, text="action1", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_2 = tk.Button(self, text="action2", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_3 = tk.Button(self, text="action3", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_4 = tk.Button(self, text="action4", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_1["font"] = self.button_font
self.button_hand_2["font"] = self.button_font
self.button_hand_3["font"] = self.button_font
self.button_hand_4["font"] = self.button_font
self.button_info_rec = tk.Button(self, text="R", bg='black', borderwidth=0, highlightthickness=0)
self.button_info_blue = tk.Button(self, text="B", bg='black', borderwidth=0, highlightthickness=0)
self.button_info_perf = tk.Button(self, text="P", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_2 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_4 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_6 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_7 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_8 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_up.grid(row=0, column=1, columnspan=8, sticky="nesw")
self.button_down.grid(row=3, column=1, columnspan=8, sticky="nesw")
self.button_right.grid(row=1, column=9, rowspan=2, sticky="nesw")
self.button_left.grid(row=1, column=0, rowspan=2, sticky="nesw")
self.button_hand_1.grid(row=1, column=1, columnspan=2, sticky="nesw")
self.button_hand_2.grid(row=1, column=3, columnspan=2, sticky="nesw")
self.button_hand_3.grid(row=1, column=5, columnspan=2, sticky="nesw")
self.button_hand_4.grid(row=1, column=7, columnspan=2, sticky="nesw")
self.button_info_rec.grid(row=2, column=1, columnspan=1, sticky="nesw")
self.button_info_perf.grid(row=2, column=3, columnspan=1, sticky="nesw")
self.button_info_blue.grid(row=2, column=5, columnspan=1, sticky="nesw")
self.button_dummy_2.grid(row=2, column=2, columnspan=1, sticky="nesw")
self.button_dummy_4.grid(row=2, column=4, columnspan=1, sticky="nesw")
self.button_dummy_6.grid(row=2, column=6, columnspan=1, sticky="nesw")
self.button_dummy_7.grid(row=2, column=7, columnspan=1, sticky="nesw")
self.button_dummy_8.grid(row=2, column=8, columnspan=1, sticky="nesw")
self.grid(column=0, row=0, sticky="nesw")
for row_num in range(self.grid_size()[1]):
if row_num == 0 or row_num == 3:
continue
self.rowconfigure(row_num, weight=1)
for col_num in range(self.grid_size()[0]):
if col_num == 0 or col_num == 9:
continue
self.columnconfigure(col_num, weight=1)
# this is a dict with keys: position -> action
self.button_dict = {
"center": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"str_0": self.button_hand_1,
"bperf_0": self.button_hand_2,
"eperf_0": self.button_hand_3
},
"up": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"msppresetchange_current&": self.button_hand_1,
},
"down": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"mspwavplay_current&": self.button_hand_1,
},
"left": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"fps_": self.button_hand_1,
"blk_": self.button_hand_2,
"exp_": self.button_hand_3
},
"right": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"fps_": self.button_hand_1,
"exp_": self.button_hand_2,
"stop_0": self.button_hand_3
}
}
self.load_correct_labels()
self.load_correct_invokes()
def frame_update(self):
self.go_center()
def frame_release(self):
return
def go_up(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'down':
self.upper_class.present_pos = 'up'
self.change_move_button_state('disabled', self.button_up)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_down(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'up':
self.upper_class.present_pos = 'down'
self.change_move_button_state('disabled', self.button_down)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_left(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'right':
self.upper_class.present_pos = 'left'
self.change_move_button_state('disabled', self.button_left)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_right(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'left':
self.upper_class.present_pos = 'right'
self.change_move_button_state('disabled', self.button_right)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_center(self):
#with this we go to the center layout of the present menu
#change actual position
self.upper_class.present_pos = 'center'
#load center labels for all buttons
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
#change state of all arrows to normal
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
def send_message(self, button):
# we want the button to press and unpress
self.upper_class.client.client_send(self.message_for_action)
def joystick_moment(self, button):
button_content = button["text"].splitlines()
if self.message_for_action not in ["up", "down", "loopr", "loopl"]: # we either entered the button or want to exit
if self.upper_class.joystick_mode[0] == False: # we just entered the joystick mode
self.upper_class.joystick_mode = (True, button_content[0], self.message_for_action)
self.upper_class.active_joystick_button = button
#ask for the current value
self.upper_class.client.client_send(self.message_for_action+"0")
# visual activation
button["bg"] ='dark slate gray'
else: # we were in the joystick mode and now we should check if we are pressing the same button
if button_content[0] == self.button_dict[self.upper_class.present_pos][self.message_for_action]["text"].splitlines()[0]: # we want to exit
self.upper_class.joystick_mode = (False, "", "")
self.upper_class.active_joystick_button = ""
button["bg"] ='black'
if self.upper_class.present_pos == "right": #ISTO ESTÁ HARDCODED!!!
self.upper_class.client.client_send("rec_0")
elif self.upper_class.present_pos == "down": #ISTO ESTÁ HARDCODED!!!
self.upper_class.client.client_send("mspwavplay_current&act")
else: # we want to change to a differnt button
self.upper_class.joystick_mode = (True, self.button_dict[self.upper_class.present_pos][self.message_for_action]["text"].splitlines()[0], self.message_for_action)
self.upper_class.active_joystick_button = self.button_dict[self.upper_class.present_pos][self.message_for_action]
#ask for the current value
self.upper_class.client.client_send(self.message_for_action+"0")
button["bg"] ='black'
self.upper_class.active_joystick_button["bg"] = 'dark slate gray'
elif self.message_for_action in ["up", "down"]: # we want to change the value
if self.message_for_action == "up": # we want to up the number
self.upper_class.client.client_send(self.upper_class.joystick_mode[2]+"1")
elif self.message_for_action == "down":
self.upper_class.client.client_send(self.upper_class.joystick_mode[2]+"-1")
elif self.message_for_action in ["loopr", "loopl"]: # we want to start a loop
send_obj = self.upper_class.joystick_mode[2].split("_")[0] + "_"
if "current" in self.upper_class.joystick_mode[2]: # we only start and end loops inside "current" type buttons
if self.message_for_action == "loopr": # clockwise
self.upper_class.client.client_send(send_obj+"loopr")
elif self.message_for_action == "loopl": # counter clockwise
self.upper_class.client.client_send(send_obj+"loopl")
def load_values_to_gui(self):
# maybe the best solution is to simulate clicks on the buttons that can be read
self.upper_class.populate_mode = True
for button_key in self.button_dict[self.upper_class.present_pos].keys():
if "msp" in button_key or "fps" in button_key or "blk" in button_key or "exp" in button_key or "edt" in button_key:
self.upper_class.client.client_send(button_key+"0")
# then we wait the reply
while self.upper_class.populate_values_queue.empty():
time.sleep(0.01)
current_value = self.upper_class.populate_values_queue.get()
total_text = self.button_dict[self.upper_class.present_pos][button_key]["text"].splitlines()
self.button_dict[self.upper_class.present_pos][button_key]["text"] = total_text[0] + "\n" + current_value
self.upper_class.populate_mode = False
def load_correct_labels(self):
self.button_hand_1['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_1']
self.button_hand_2['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_2']
self.button_hand_3['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_3']
self.button_hand_4['text'] = menu_labels[self.menu_name][self.upper_class.present_pos]['button_hand_4']
def load_correct_invokes(self):
if self.upper_class.present_pos == "center":
self.button_hand_1["command"] = lambda: self.send_message(self.button_hand_1)
self.button_hand_2["command"] = lambda: self.send_message(self.button_hand_2)
self.button_hand_3["command"] = lambda: self.send_message(self.button_hand_3)
self.button_hand_4["command"] = lambda: self.send_message(self.button_hand_4)
elif self.upper_class.present_pos == "left":
self.button_hand_1["command"] = lambda: self.joystick_moment(self.button_hand_1)
self.button_hand_2["command"] = lambda: self.joystick_moment(self.button_hand_2)
self.button_hand_3["command"] = lambda: self.joystick_moment(self.button_hand_3)
elif self.upper_class.present_pos == "right":
self.button_hand_1["command"] = lambda: self.joystick_moment(self.button_hand_1)
self.button_hand_2["command"] = lambda: self.joystick_moment(self.button_hand_2)
self.button_hand_3["command"] = lambda: self.send_message(self.button_hand_3)
elif self.upper_class.present_pos == "down":
self.button_hand_1["command"] = lambda: self.joystick_moment(self.button_hand_1)
elif self.upper_class.present_pos == "up":
self.button_hand_1["command"] = lambda: self.joystick_moment(self.button_hand_1)
def change_move_button_state(self, state, button):
if state == 'normal':
button["state"] = "normal"
button['bg'] = "black"
elif state == 'disabled':
button["state"] = "disabled"
button['bg'] = "red"
class AudioFrame(tk.Frame):
def __init__(self, parent, upper_class, menu_name):
super().__init__(parent)
self.message_for_action = ""
self.upper_class = upper_class
self.menu_name = menu_name
self["bg"] = "black"
self.button_font = tkFont.Font(size=40, weight='bold')
self.SIDE_B_W = 1
self.SIDE_B_H = 100
self.TOP_B_W = 200
self.TOP_B_H = self.SIDE_B_W
self.HAND_B_W = (1/8)*self.TOP_B_W
self.HAND_B_H = 3*self.SIDE_B_H
self.button_up = tk.Button(self, text="UP", padx=self.TOP_B_W, pady=self.TOP_B_H, command=self.go_up, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_down = tk.Button(self, text="DOWN", padx=self.TOP_B_W, pady=self.TOP_B_H, command=self.go_down, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_right = tk.Button(self, text="RIGHT", padx=self.SIDE_B_W, pady=self.SIDE_B_H, wraplength=1, command=self.go_right, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.button_left = tk.Button(self, text="LEFT", padx=self.SIDE_B_W, pady=self.SIDE_B_H, wraplength=1, command=self.go_left, bg='black', activebackground="#18135e", borderwidth=0, highlightthickness=0)
self.move_buttons = [self.button_down, self.button_up, self.button_left, self.button_right]
self.button_hand_1 = tk.Button(self, text="action1", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_2 = tk.Button(self, text="action2", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_3 = tk.Button(self, text="action3", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_4 = tk.Button(self, text="action4", padx=self.HAND_B_W, pady=self.HAND_B_H, bg='black', fg='white', activebackground="#18135e", borderwidth=0, compound="bottom", highlightthickness=0)
self.button_hand_1["font"] = self.button_font
self.button_hand_2["font"] = self.button_font
self.button_hand_3["font"] = self.button_font
self.button_hand_4["font"] = self.button_font
self.button_info_rec = tk.Button(self, text="R", bg='black', borderwidth=0, highlightthickness=0)
self.button_info_blue = tk.Button(self, text="B", bg='black', borderwidth=0, highlightthickness=0)
self.button_info_perf = tk.Button(self, text="P", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_2 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_4 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_6 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_7 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_dummy_8 = tk.Button(self, text="", bg='black', borderwidth=0, highlightthickness=0)
self.button_up.grid(row=0, column=1, columnspan=8, sticky="nesw")
self.button_down.grid(row=3, column=1, columnspan=8, sticky="nesw")
self.button_right.grid(row=1, column=9, rowspan=2, sticky="nesw")
self.button_left.grid(row=1, column=0, rowspan=2, sticky="nesw")
self.button_hand_1.grid(row=1, column=1, columnspan=2, sticky="nesw")
self.button_hand_2.grid(row=1, column=3, columnspan=2, sticky="nesw")
self.button_hand_3.grid(row=1, column=5, columnspan=2, sticky="nesw")
self.button_hand_4.grid(row=1, column=7, columnspan=2, sticky="nesw")
self.button_info_rec.grid(row=2, column=1, columnspan=1, sticky="nesw")
self.button_info_perf.grid(row=2, column=3, columnspan=1, sticky="nesw")
self.button_info_blue.grid(row=2, column=5, columnspan=1, sticky="nesw")
self.button_dummy_2.grid(row=2, column=2, columnspan=1, sticky="nesw")
self.button_dummy_4.grid(row=2, column=4, columnspan=1, sticky="nesw")
self.button_dummy_6.grid(row=2, column=6, columnspan=1, sticky="nesw")
self.button_dummy_7.grid(row=2, column=7, columnspan=1, sticky="nesw")
self.button_dummy_8.grid(row=2, column=8, columnspan=1, sticky="nesw")
self.grid(column=0, row=0, sticky="nesw")
for row_num in range(self.grid_size()[1]):
if row_num == 0 or row_num == 3:
continue
self.rowconfigure(row_num, weight=1)
for col_num in range(self.grid_size()[0]):
if col_num == 0 or col_num == 9:
continue
self.columnconfigure(col_num, weight=1)
# this is a dict with keys: position -> action
self.button_dict = {
"center": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"mspmaingain_current&": self.button_hand_1,
"mspmaingain_umax&": self.button_hand_2,
"mspmaingain_umin&": self.button_hand_3,
"mspmaingain_cycle&": self.button_hand_4
},
"up": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"mspcrossfreq2_current&": self.button_hand_1,
"mspcrossfreq2_umax&": self.button_hand_2,
"mspcrossfreq2_umin&": self.button_hand_3,
"mspcrossfreq2_cycle&": self.button_hand_4
},
"down": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"mspodlevel_current&": self.button_hand_1,
"mspodlevel_umax&": self.button_hand_2,
"mspodlevel_umin&": self.button_hand_3,
"mspodlevel_cycle&": self.button_hand_4
},
"left": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"mspcrossfreq_current&": self.button_hand_1,
"mspcrossfreq_umax&": self.button_hand_2,
"mspcrossfreq_umin&": self.button_hand_3,
"mspcrossfreq_cycle&": self.button_hand_4
},
"right": {
"up": self.button_up,
"down": self.button_down,
"left": self.button_left,
"right": self.button_right,
"mspcrossfreq3_current&": self.button_hand_1,
"mspcrossfreq3_umax&": self.button_hand_2,
"mspcrossfreq3_umin&": self.button_hand_3,
"mspcrossfreq3_cycle&": self.button_hand_4
}
}
self.load_correct_labels()
self.load_correct_invokes()
def frame_update(self):
self.go_center()
def frame_release(self):
return
def go_up(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'down':
self.upper_class.present_pos = 'up'
self.change_move_button_state('disabled', self.button_up)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_down(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'up':
self.upper_class.present_pos = 'down'
self.change_move_button_state('disabled', self.button_down)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_left(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'right':
self.upper_class.present_pos = 'left'
self.change_move_button_state('disabled', self.button_left)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_right(self):
#first check all buttons and see if any is disabled. If so,
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
if self.upper_class.present_pos != 'left':
self.upper_class.present_pos = 'right'
self.change_move_button_state('disabled', self.button_right)
else:
self.upper_class.present_pos = 'center'
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
def go_center(self):
#with this we go to the center layout of the present menu
#change actual position
self.upper_class.present_pos = 'center'
#load center labels for all buttons
self.load_correct_labels()
self.load_correct_invokes()
self.load_values_to_gui()
#change state of all arrows to normal
for button in self.move_buttons:
if button['state'] == 'disabled':
self.change_move_button_state('normal', button)
def send_message(self, button):
# we want the button to press and unpress
self.upper_class.client.client_send(self.message_for_action)
def joystick_moment(self, button):