-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeramesa.py
More file actions
executable file
·1727 lines (1419 loc) · 64.3 KB
/
Peramesa.py
File metadata and controls
executable file
·1727 lines (1419 loc) · 64.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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 # For the graphical interface
from tkinter.filedialog import * # For the load/save dialog windows
from tkinter import messagebox # For the window close event
import os # For handling system processes
import socket # For the SOCKET module for network connections
import threading # For running background functions
from tkmacosx import Button # To use mac-style buttons
import math as ma # For the logarithm
from sys import exit # To close the program
import time
import subprocess # To prevent macOS from putting the app to sleep when minimized
import platform
from pathlib import Path # To extract the file name from a file path
# For OSC
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import BlockingOSCUDPServer
fader_length = 150 # Fader length
default_width = 5 # Label width
show = "NEW SHOW" # Show name
# Colors
light_red = "#CD5C5C"
light_green = "#98FB98"
color_no_mod = "gray25"
color_mod = "DarkGoldenrod3"
color_mute = "gray50"
color_on = "DarkOrange2"
color_fondos = "gray40"
# Fonts
default_font = "Helvetica 12 bold" # Default font
med_font = "Helvetica 12 bold" # Medium-size font
small_font = "Helvetica 10 bold" # Extra-small font
# Lists for the data
envios = [] # Create sends list
seq = [] # Create sequence
executor = [] # Create list for executors
listado_de_cues = [] # List of cues shown in the box
envio_actual = 0 # Selected send
cue_actual = 0 # Current cue
exec_actual = 0 # Current executor
autosend_global = False # Indicates whether automatic send is enabled
temp_file_name = "temp_cues"
show_iniciado = 0 # To load the show once
caffeinate_proc = None # Process to keep the app awake on macOS
# Desk network configuration
def_host = "192.168.0.128" # Console default
# host ="172.18.3.10" # Test
# host ="192.168.137.1" # Test
# host = "127.0.0.1" # Test
host = "172.18.3.10" # Console default
port = 49280 # Port selected at startup
def_port = 49280 # Default port, must be 49280
# OSC network configuration
def_host_osc = "127.0.0.1"
host_osc = "127.0.0.1"
def_port_osc = 5005
port_osc = 5005
def show_inicial():
"""Load the show saved as a temporary file"""
global show_iniciado
try:
fichero = open("backup.csv", "r")
datos = fichero.read()
fichero.close()
monta_show(datos)
print_cmd("Loaded last used values")
show_iniciado = 1
except Exception as e:
print(e)
print_cmd("No show could be loaded")
show_iniciado = 1
print_cmd("PERAMESA v3.0")
def show_name_update():
"""Update the label for the show name"""
app.OpcionesNameShowCue.Show_entry.delete(0, 'end')
app.OpcionesNameShowCue.Show_entry.insert(0, show)
def print_cmd(*cadena):
"""Check that the object has already been created and use its function"""
if show_iniciado == 0: # Here it only prints in the terminal
print(*cadena)
else:
app.ventana_comando.print_cmd(*cadena) # Here it prints in the command window
def borra_cmd():
"""Check that the object has already been created and use its function"""
if show_iniciado == 0:
pass
else:
app.ventana_comando.borra_cmd()
def evitar_app_nap():
"""Prevent macOS from pausing the app when minimized (App Nap)."""
global caffeinate_proc
if platform.system() != "Darwin":
return
if caffeinate_proc is not None and caffeinate_proc.poll() is None:
# There is already an active caffeinate process
return
try:
# Keeps the app "active" while this process is alive
caffeinate_proc = subprocess.Popen(
["caffeinate", "-dimsu", "-w", str(os.getpid())]
)
print_cmd("App Nap disabled to keep listening and sending in the background")
except FileNotFoundError:
print_cmd(
"'caffeinate' not found; if macOS pauses the app when minimized, disable App Nap manually"
)
def clear_cue():
"""Clear all values of the current cue"""
for j in range(0, 17):
for i in range(0, 64):
seq[0].cue_list[cue_actual].envio[j].canal[i].ch_value = 0
seq[0].cue_list[cue_actual].envio[j].canal[i].ch_mute = "MUTE"
seq[0].cue_list[cue_actual].envio[j].canal[i].ch_mod = False
def actualiza_executors():
"""Send all values of the current cue to the executors"""
for i in range(0, 64):
executor[i].carga_valores(
seq[0].cue_list[cue_actual].envio[envio_actual].canal[i].ch_value,
seq[0].cue_list[cue_actual].envio[envio_actual].canal[i].ch_mute,
seq[0].cue_list[cue_actual].envio[envio_actual].canal[i].ch_mod)
def gotocue(cue_destino):
"""Jump to the indicated cue"""
# Clear the command box
global cue_actual
cue_actual = cue_destino
listado_de_cues[0].listado_upd()
listado_de_cues[0].listado_cues.selection_set(cue_actual)
actualiza_executors()
print_cmd("Cue actual: ", cue_actual)
print_cmd("Cue name: ", seq[0].cue_list[cue_actual].cue_name)
app.OpcionesNameShowCue.Cue_entry.delete(0, 'end')
app.OpcionesNameShowCue.Cue_entry.insert(0, seq[0].cue_list[cue_actual].cue_name)
root.focus_set() # Set focus on the main window
# Check if auto send is enabled and send to the desk
if autosend_global:
app.OpcionExtraButtons.conectar_directo(0)
else:
pass
def crear_archivo(name):
"""Function to create a file"""
fichero = open(name + ".csv", "w") # Open temporary file in write mode
# Write the title to the file
fichero.write(show + "\n")
# Write values to file
for x in range(0, int(len(seq[0].cue_list))): # Loop per line
fichero.write(str(seq[0].cue_list[x].cue_name) + ";") # Cue name
for i in range(0, 17):
for j in range(0, 64): # Write channel values
fichero.write(str(seq[0].cue_list[x].envio[i].canal[j].ch_value) + ";")
fichero.write(str(seq[0].cue_list[x].envio[i].canal[j].ch_mute) + ";")
fichero.write(str(seq[0].cue_list[x].envio[i].canal[j].ch_mod) + ";")
fichero.write("\n")
fichero.close() # Close file
print_cmd("Number of cues: " + str(len(seq[0].cue_list)))
print_cmd("Saved file '" + str(name) + "'") # Control
def autosave():
"""Save the show every so often"""
crear_archivo(temp_file_name)
root.after(60000 * 5, autosave) # time in milliseconds
def on_closing():
"""Events when closing the program"""
if messagebox.askokcancel("Quit", "Nene... Do you want to quit?"):
crear_archivo("backup") # Create temporary file
root.destroy()
exit()
def monta_show(datos):
"""Build the show"""
global show
global cue_actual
expected_columns = 1 + (17 * 64 * 3) # Cue name + 17 sends * 64 channels * (value, mute, mod)
def to_bool(value):
return str(value).strip().lower() in ("true", "1", "yes", "on")
i_cue = 0
# Build the show with the data
app.new_show() # Clear the current show
lineas = datos.splitlines() # Split the data into lines
if not lineas:
print_cmd("Show file is empty; nothing to load")
return
show = lineas[0] # Update show name
show_name_update() # Update show label
linea = [] # Create a list to store the data
cue_lines = [line for line in lineas[1:] if line.strip()]
for _ in range(len(cue_lines) - 1):
seq[0].cue_list.append(Cue()) # Create a new cue
for raw_line in cue_lines:
linea[:] = [] # Clear the list
columna = 1 # Helper to count the column in the file
linea = raw_line.split(";") # Split the current line into groups
if len(linea) < expected_columns:
print_cmd(
f"Cue {i_cue}: missing {expected_columns - len(linea)} columns; filling with defaults"
)
elif len(linea) > expected_columns:
print_cmd(
f"Cue {i_cue}: ignoring {len(linea) - expected_columns} extra columns from file"
)
seq[0].cue_list[i_cue].cue_name = str(linea[0]) if linea else f"CUE {i_cue}"
# Start loop to fill values in channels
for j in range(0, 17):
for k in range(0, 64):
value = linea[columna] if columna < len(linea) else 0
columna += 1
mute = linea[columna] if columna < len(linea) else "MUTE"
columna += 1
mod_raw = linea[columna] if columna < len(linea) else False
columna += 1
seq[0].cue_list[i_cue].envio[j].canal[k].ch_value = value
seq[0].cue_list[i_cue].envio[j].canal[k].ch_mute = mute
seq[0].cue_list[i_cue].envio[j].canal[k].ch_mod = to_bool(mod_raw)
i_cue += 1
cue_actual = 0
gotocue(cue_actual)
borra_cmd() # Clear the screen
def fader_rango(valor_original):
"""Convert 0-100 values to a logarithmic scale"""
# old_value = float(x)
# old_range = [0.0, 100.0]
# new_range = [-32768.0, 1000.0]
# percent = (old_value - old_range[0])/(old_range[1] - old_range[0])
# resultado = ((new_range[1] - new_range[0]) * percent) + new_range[0]
x = int(valor_original)
resultado = ma.log(((x * 999) / 100) + 1, 1000) * 33768 - 32768 # Convert to logarithmic scale
return int(resultado)
def osc_thread():
"""Start a thread for OSC"""
if show_iniciado:
# Open a parallel thread for listening
hacer = threading.Thread(target=listen)
hacer.daemon = True # To end the thread when closing the application
hacer.start() # Start listening
else:
pass
def listen():
"""Listen"""
dispatcher = Dispatcher()
dispatcher.set_default_handler(default_handler)
try:
# Try to open the OSC server on host_osc:port_osc
server = BlockingOSCUDPServer((host_osc, port_osc), dispatcher)
except PermissionError as e:
# Common permission/firewall/blocked-port error
print_cmd(f"OSC ERROR: could not open {host_osc}:{port_osc}")
print_cmd(f"OSC ERROR detail: {e}")
return
except OSError as e:
# Other socket errors (invalid IP, port in use, etc.)
print_cmd(f"OSC SOCKET ERROR at {host_osc}:{port_osc}: {e}")
return
try:
print_cmd(f"OSC listening on {host_osc}:{port_osc}")
server.serve_forever() # Blocks forever
except Exception as e:
# In case the server crashes while listening
print_cmd(f"OSC ERROR while listening: {e}")
return
def default_handler(address, *args):
"""What the desk does with each OSC message"""
print(f"Received: {address}: {args}")
if address == "/go":
borra_cmd() # Clear the screen
if args[0] == 0:
if show_iniciado:
app.OpcListButtons.prev_cue()
else:
pass
print_cmd("OSC: GOBACK")
else:
if args[0] == 1:
if show_iniciado:
app.OpcListButtons.next_cue()
else:
pass
print_cmd("OSC: GO")
else:
print_cmd("OSC: ** Invalid value for go ** ")
pass
else:
if address == "/goto":
borra_cmd() # Clear the screen
if show_iniciado:
if int(args[0]) >= len(seq[0].cue_list):
print_cmd("CUE does not exist: ", args[0])
else:
gotocue(args[0])
print_cmd("OSC: GOTO CUE ", args[0])
else:
print_cmd("OSC: Received invalid message")
def send_values():
"""Send the values to the desk"""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# sock.setblocking(0)
sock.close()
except:
pass
# Store the connection as a variable (to make it easier to use)
try:
# Open connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
time.sleep(0.05) # Small delay to give the console time after TCP connect
sock.settimeout(5)
print_cmd("Connected to " + str(host) + " on port " + str(port))
print_cmd("Sending:")
# Loop for the Master send
for channel in range(0, 64):
if seq[0].cue_list[cue_actual].envio[0].canal[channel].ch_mod: # Check whether the value should be sent
ch = channel
thelevel = fader_rango(seq[0].cue_list[cue_actual].envio[0].canal[channel].ch_value)
if seq[0].cue_list[cue_actual].envio[0].canal[channel].ch_mute == "ON": # Turn on channel
string_fad_on = "set MIXER:Current/InCh/Fader/On {} 0 1\n".format(ch)
sock.sendall(string_fad_on.encode())
else:
string_fad_off = "set MIXER:Current/InCh/Fader/On {} 0 0\n".format(ch) # Mute channel
sock.sendall(string_fad_off.encode())
# Send fader values
string_level = "set MIXER:Current/InCh/Fader/Level {} 0 {}\n".format(ch, thelevel) # Adjust channel
sock.sendall(string_level.encode())
print_cmd("MASTER Ch ", ch, seq[0].cue_list[cue_actual].envio[0].canal[channel].ch_mute, " at ",
thelevel)
time.sleep(0.002) # Throttle: ~2 ms pause per modified channel on MASTER
else:
pass
time.sleep(0.03) # Throttle: ~30 ms between MASTER and first SEND
# Loop for the rest of the sends
for send in range(1, 17):
for channel in range(0, 64):
if seq[0].cue_list[cue_actual].envio[send].canal[channel].ch_mod: # Check whether it should be sent
ch = channel
thelevel = fader_rango(seq[0].cue_list[cue_actual].envio[send].canal[channel].ch_value)
thesend = send - 1
if seq[0].cue_list[cue_actual].envio[send].canal[channel].ch_mute == "ON": # Turn on channel
string_fad_on = "set MIXER:Current/InCh/ToMix/On {} {} 1\n".format(ch, thesend)
sock.sendall(string_fad_on.encode())
else:
string_fad_off = "set MIXER:Current/InCh/ToMix/On {} {} 0\n".format(ch, thesend) # Mute channel
sock.sendall(string_fad_off.encode())
# Send fader values
string_level = "set MIXER:Current/InCh/ToMix/Level {} {} {}\n".format(ch, thesend, thelevel)
sock.sendall(string_level.encode())
print_cmd("SEND ", send, "Ch ", ch, seq[0].cue_list[cue_actual].envio[send].canal[channel].ch_mute,
" at ", thelevel)
time.sleep(0.002) # Throttle: ~2 ms pause per modified channel on SENDS
else:
pass
time.sleep(0.03) # Throttle: ~30 ms between SENDs
try:
# Receive a message before closing the connection
sock.recv(1500)
except:
print_cmd("The console is not responding")
# ALWAYS close the connection at the end of the script
# sock.setblocking(0)
sock.close()
print_cmd("Connection closed")
time.sleep(0.2) # Throttle: 200 ms pause between full bursts
except ConnectionRefusedError as e:
print(e)
print_cmd("CONNECTION REFUSED")
print_cmd("Could not establish a connection to the console")
print_cmd("IP: " + str(host) + " Port: " + str(port))
except TimeoutError as e:
print(e)
print_cmd("CONNECTION TIMEOUT")
print_cmd("Could not establish a connection to the console")
print_cmd("IP: " + str(host) + " Port: " + str(port))
class Channel:
"""Structure for channels storing value, mute, and modified state"""
# Class constructor
def __init__(self, ch_num, ch_value, ch_mute, ch_mod):
self.ch_num = ch_num
self.ch_value = ch_value
self.ch_mute = ch_mute
self.ch_mod = ch_mod
def __str__(self):
return '{} {} {} {}'.format(self.ch_num, self.ch_value, self.ch_mute, self.ch_mod)
class Send:
"""Structure for sends"""
def __init__(self):
canal = []
self.canal = canal
for i in range(0, 64):
self.canal.append(Channel(i, 0, "MUTE", False))
class Cue:
"""Structure for each cue"""
def __init__(self):
cue_name = ''
envio = []
self.envio = envio
self.cue_name = cue_name
for i in range(0, 17):
self.envio.append(Send())
def mostrar_ch(self):
print_cmd(self.envio[envio_actual].canal[exec_actual].ch_value)
def rename(self, new_name):
self.cue_name = new_name
class Seq:
"""Structure for the sequence"""
def __init__(self):
cue_list = []
self.cue_list = cue_list
self.cue_list.append(Cue())
self.cue_list[0].rename("CUE 0")
class SendsButtons:
"""Create the send buttons"""
def __init__(self, send_num, sends_frame):
self.send_num = send_num
self.send_name = ""
self.sends_frame = sends_frame
if self.send_num == 0:
send_name = "MASTER"
else:
send_name = "SEND " + str(send_num)
self.send_button = tk.Label(sends_frame,
font=small_font,
fg="WHITE",
text=send_name,
bg=self.send_color(send_num),
#borderless=1,
borderwidth=3,
relief="raised",
#overrelief='sunken',
height=3,
width=10,
highlightbackground=color_fondos)
#command=self.selec_send)
self.send_button.grid(sticky="W", row=0, column=0 + send_num, padx=5, pady=5)
self.send_button.bind('<Button-1>', lambda event: self.selec_send(event))
def selec_send(self, event):
"""Select the send"""
global envio_actual
envios[envio_actual].send_button.config(bg=color_no_mod)
# turn_off_send_button(self.send_num)
envio_actual = self.send_num # Update current send
self.send_button.config(bg=color_mod)
self.send_button.config(highlightbackground="WHITE")
actualiza_executors()
if envio_actual == 0:
print_cmd("Master")
else:
print_cmd("Send " + str(envio_actual))
@staticmethod
def send_color(send_num):
if send_num == envio_actual:
color = color_mod
else:
color = color_no_mod
return color
class Exec:
"""Create the executors, buttons, labels, and faders"""
def __init__(self, exec_ch, exec_value, exec_mute, exec_mod, exec_x, exec_y, exec_frame):
label = tk.Label()
fader_label = tk.Label()
mute = tk.Button()
self.label = label
self.mute = mute
self.fader_label = fader_label
self.exec_ch = exec_ch
self.exec_value = exec_value
self.exec_mute = exec_mute
self.exec_mod = exec_mod
self.exec_x = exec_x
self.exec_y = exec_y
self.exec_frame = exec_frame
# ID label
self.label = tk.Label(exec_frame,
font=default_font,
text="CH " + str(exec_ch + 1),
bg=color_fondos)
self.label.grid(row=exec_y, column=exec_x)
self.label.bind('<Double-Button-1>', lambda event: self.test(event))
# Mute button
self.mute = tk.Label(exec_frame,
font=default_font,
text=exec_mute,
bg=color_mute,
# highlightbackground=color_fondos,
fg="BLACK",
relief="ridge",
# borderless=1,
width=default_width)
# command=self.toggle) # Send the button number to toggle
self.mute.grid(row=exec_y + 1, column=exec_x)
self.mute.grid(sticky="nsew")
self.mute.bind('<Button-1>', lambda event: self.toggle(event))
# Fader
self.fader = tk.Scale(exec_frame,
font=default_font,
bg=color_fondos,
bd=3, # Inner border thickness
troughcolor="gray80", # Background color
highlightcolor=color_fondos,
highlightbackground=color_fondos,
activebackground=color_mod,
showvalue=0, # Do not show the value
from_=100,
to=0,
length=fader_length
)
self.fader.config(command=self.actualiza_etiqueta_fader)
self.fader.grid(row=exec_y + 2, column=exec_x)
self.fader.set(self.exec_value) # Initial value
self.fader.bind("<ButtonRelease-1>", self.modifica_fader)
# Label with the fader value. It also indicates if the channel is sent
self.fader_label = tk.Label(exec_frame,
font=default_font,
text=self.actualiza_etiqueta_fader,
bg=color_no_mod, # Normal label color
fg="BLACK",
relief="ridge",
width=default_width)
self.fader_label.grid(row=exec_y + 3, column=exec_x)
self.fader_label.bind('<Double-Button-1>',
lambda event: self.tog_enviar(event)) # Double click toggles sending
# Blank space
self.white = tk.Label(exec_frame,
text="",
bg=color_fondos)
self.white.grid(row=exec_y + 4, column=exec_x)
def actualiza_etiqueta_fader(self, event):
"""Update 0-100 values in dB"""
# print(event)
if self.fader.get() < 1:
sdb = "- inf" # "\u221E"
else:
db = int(fader_rango(self.fader.get()) * 0.01)
if db > 0:
sdb = ("+" + str(db))
else:
sdb = str(db)
self.fader_label.config(text=sdb)
def test(self, event):
"""Utility function to log the value of the pressed channel"""
# print(event)
print("Send: ", envio_actual, "Ch:", (self.exec_ch + 1), "At: ", self.exec_value, self.exec_mute, "Mod: ",
self.exec_mod)
print_cmd("OJETE")
def toggle(self, event):
"""Change the state of the MUTE button"""
# print(event)
self.fader_label.config(bg=color_mod) # Update the value label (modified)
self.exec_mod = True # Update channel as modified
seq[0].cue_list[cue_actual].envio[envio_actual].canal[self.exec_ch].ch_mod = True
if self.exec_mute == "ON":
self.exec_mute = "MUTE"
self.mute.config(bg=color_mute)
self.mute.config(highlightbackground="WHITE")
self.mute.config(text="MUTE")
seq[0].cue_list[cue_actual].envio[envio_actual].canal[self.exec_ch].ch_mute = "MUTE"
else:
self.exec_mute = "ON"
self.mute.config(bg=color_on)
self.mute.config(highlightbackground="WHITE")
self.mute.config(text="ON")
seq[0].cue_list[cue_actual].envio[envio_actual].canal[self.exec_ch].ch_mute = "ON"
def modifica_fader(self, event):
"""Actions performed when modifying the fader"""
# # print(event)
self.exec_value = self.fader.get() # Update executor variable
print_cmd("Fader", (self.exec_ch + 1), "at", self.fader.get(), "%") # Log the data
# Update fader data
seq[0].cue_list[cue_actual].envio[envio_actual].canal[self.exec_ch].ch_value = self.fader.get()
# self.fader_label.config(text=self.fader.get())
self.actualiza_etiqueta_fader(self)
# Mark send as modified
seq[0].cue_list[cue_actual].envio[envio_actual].canal[self.exec_ch].ch_mod = True
self.exec_mod = True
self.fader_label.config(bg=color_mod)
def tog_enviar(self, event):
"""Toggle whether a channel is sent"""
# print(event)
if not self.exec_mod:
self.exec_mod = True
self.fader_label.config(bg=color_mod)
print_cmd("Send values for the selected channel")
seq[0].cue_list[cue_actual].envio[envio_actual].canal[self.exec_ch].ch_mod = True
else:
self.exec_mod = False
self.fader_label.config(bg=color_no_mod)
print_cmd("Do not send values for the selected channel")
seq[0].cue_list[cue_actual].envio[envio_actual].canal[self.exec_ch].ch_mod = False
def carga_valores(self, upd_value, upd_mute, upd_mod):
self.exec_value = upd_value
self.fader_label.config(text=self.actualiza_etiqueta_fader(self)) # Change label text
# Update executor MUTE value
self.exec_mute = upd_mute
if self.exec_mute == "ON":
self.mute.config(bg=color_on)
self.mute.config(highlightbackground="WHITE")
self.mute.config(text=self.exec_mute)
else:
self.mute.config(bg=color_mute)
self.mute.config(highlightbackground="WHITE")
self.mute.config(text=self.exec_mute)
# Update fader modified property
self.exec_mod = upd_mod
if self.exec_mod:
self.fader_label.config(bg=color_mod)
else:
self.fader_label.config(bg=color_no_mod)
self.fader.set(upd_value) # Load value into the executor
class OpcionesNameShowCue:
"""Structure for the show name options and the current cue"""
def __init__(self, option_frame):
self.option_frame = option_frame
self.Show_label = tk.Label
self.Show_entry = tk.Entry
self.Cue_label = tk.Label
self.Cue_entry = tk.Entry
# COLUMN 1 #################################################################
# Show label
self.Show_label = tk.Label(self.option_frame,
font=default_font,
text="SHOW NAME:",
bg=color_fondos,
width=10)
self.Show_label.grid(sticky="W", row=0, column=0, padx=8, pady=0)
# Show name entry
self.Show_entry = tk.Entry(self.option_frame,
font=default_font,
textvariable=show,
bg=color_on,
fg="BLACK",
width=30)
self.Show_entry.grid(sticky="W", row=0, column=1, padx=8, pady=0)
self.Show_entry.insert(0, show)
self.Show_entry.bind('<Return>', self.show_name)
# self.Show_entry.bind('<Leave>', self.show_name)
# Current cue label
self.Cue_label = tk.Label(self.option_frame,
font=default_font,
text="CUE NAME:",
fg="BLACK",
bg=color_fondos,
width=10)
self.Cue_label.grid(sticky="W", row=1, column=0, padx=8, pady=0)
# Cue name entry
self.Cue_entry = tk.Entry(self.option_frame,
font=default_font,
textvariable=seq[0].cue_list[cue_actual].cue_name,
bg=color_mod,
fg="BLACK",
width=30)
self.Cue_entry.grid(sticky="W", row=1, column=1, padx=8, pady=0)
self.Cue_entry.insert(0, seq[0].cue_list[cue_actual].cue_name)
self.Cue_entry.bind('<Return>', self.cue_name)
def show_name(self, event):
"""Update the show name after verifying it is a valid file name"""
# print(event)
global show
safe_string = str()
for c in self.Show_entry.get():
if c.isalnum() or c in [' ', '.', '/']:
safe_string = safe_string + c
valid = safe_string == self.Show_entry.get()
if not valid:
print_cmd("Invalid name.")
else:
show = self.Show_entry.get()
listado_de_cues[0].listado_cues.selection_set(cue_actual)
def cue_name(self, event):
"""Update the cue name"""
# print(event)
seq[0].cue_list[cue_actual].cue_name = self.Cue_entry.get()
listado_de_cues[0].listado_upd()
listado_de_cues[0].listado_cues.selection_set(cue_actual)
class OpcConfigRed:
"""Structure for network selection options"""
def __init__(self, option_frame):
self.option_frame = option_frame
global host
global host_osc
global port
global port_osc
# Network configuration label
self.Label_desk = tk.Label(self.option_frame,
font=default_font,
text="NETWORK CONFIGURATION",
fg="BLACK",
bg=color_fondos,
width=20)
self.Label_desk.grid(row=2, column=0, padx=8, pady=0, columnspan=2, sticky='NSEW')
# HOST label
self.Label_host = tk.Label(self.option_frame,
font=default_font,
text="DESK HOST",
fg="BLACK",
bg=color_fondos,
width=10)
self.Label_host.grid(sticky="W", row=3, column=0, padx=8, pady=0)
# HOST value entry
self.Host_entry = tk.Entry(option_frame,
font=default_font,
textvariable=host,
bg="#ccffff",
fg="BLACK",
width=30)
self.Host_entry.grid(sticky="W", row=3, column=1, padx=8, pady=0)
self.Host_entry.insert(0, host)
self.Host_entry.config(state='disabled')
self.Host_entry.bind('<Double-1>', self.host_enabled)
self.Host_entry.bind('<Return>', self.host_number)
# self.Host_entry.bind('<Leave>', self.host_number)
# PORT label
self.Label_port = tk.Label(self.option_frame,
font=default_font,
text="DESK PORT",
fg="BLACK",
bg=color_fondos,
width=10)
self.Label_port.grid(sticky="W", row=4, column=0, padx=8, pady=0)
# PORT value entry
self.Port_entry = tk.Entry(self.option_frame,
font=default_font,
textvariable=port,
bg="#ccffff",
fg="BLACK",
width=30)
self.Port_entry.grid(sticky="W", row=4, column=1, padx=8, pady=0)
self.Port_entry.insert(0, port)
self.Port_entry.config(state='disabled')
self.Port_entry.bind('<Double-1>', self.port_enabled)
self.Port_entry.bind('<Return>', self.port_number)
# self.Port_entry.bind('<Leave>', self.port_number)
# OSC HOST label
self.Label_host_osc = tk.Label(self.option_frame,
font=default_font,
text="OSC HOST",
fg="BLACK",
bg=color_fondos,
width=10)
self.Label_host_osc.grid(sticky="W", row=5, column=0, padx=8, pady=0)
# OSC HOST value entry
self.host_osc = tk.StringVar(self.option_frame, host_osc)
self.Host_osc_entry = tk.Entry(option_frame,
font=default_font,
textvariable=self.host_osc,
bg="#ccffff",
fg="BLACK",
width=30)
self.Host_osc_entry.grid(sticky="W", row=5, column=1, padx=8, pady=0)
# self.Host_osc_entry.insert(0, self.host_osc)
self.Host_osc_entry.config(state='disabled')
self.Host_osc_entry.bind('<Double-1>', self.host_osc_enabled)
self.Host_osc_entry.bind('<Return>', self.host_osc_number)
# self.Host_osc_entry.bind('<Leave>', self.host_osc_number)
# OSC PORT label
self.Label_osc_port = tk.Label(self.option_frame,
font=default_font,
text="OSC PORT",
fg="BLACK",
bg=color_fondos,
width=10)
self.Label_osc_port.grid(sticky="W", row=6, column=0, padx=8, pady=0)
# OSC PORT value entry
self.port_osc = tk.StringVar(self.option_frame, port_osc)
self.Port_osc_entry = tk.Entry(self.option_frame,
font=default_font,
textvariable=self.port_osc,
bg="#ccffff",
fg="BLACK",
width=30)
self.Port_osc_entry.grid(sticky="W", row=6, column=1, padx=8, pady=0)
# self.Port_osc_entry.insert(0, self.port_osc)
self.Port_osc_entry.config(state='disabled')
self.Port_osc_entry.bind('<Double-1>', self.port_osc_enabled)
self.Port_osc_entry.bind('<Return>', self.port_osc_number)
# self.Port_osc_entry.bind('<Leave>', self.port_osc_number)
def port_enabled(self, event):
"""Unlock the data entry"""
# print(event)
self.Port_entry.configure(state='normal')
def port_number(self, event):
"""Update the PORT"""
# print(event)
global port
if self.Port_entry.get() == "":
port = def_port
else:
try:
aux = self.Port_entry.get()
port = int(aux)
except Exception as e:
print(e)
port = def_port
print_cmd("Invalid port, changed to default")
print_cmd("Current port: " + str(port))
# listado_de_cues[0].selection_set(cue_actual)
self.Port_entry.delete(0, "end") # Update text
self.Port_entry.insert(0, port)
self.Port_entry.configure(state='disabled') # Lock label
root.focus_set()
def host_enabled(self, event):
"""Activate the host field"""
# print(event)
self.Host_entry.configure(state='normal')
def host_number(self, event):
"""Update the HOST"""
# print(event)
global host
if self.Host_entry.get() == "":
host = def_host
else:
host = self.Host_entry.get()
# lista_cues.selection_set(cue_actual)
self.Host_entry.delete(0, "end") # Update text
self.Host_entry.insert(0, host)
self.Host_entry.configure(state='disabled') # Lock label
root.focus_set() # Restore focus
def host_osc_enabled(self, event):
"""Unlock the data entry"""
# print(event)
self.Host_osc_entry.configure(state='normal')
def host_osc_number(self, event):
"""Update the OSC HOST"""
# print(event)