-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
start.py
executable file
·1548 lines (1369 loc) · 65.1 KB
/
start.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#############################################################################
#
# OnAirScreen
# Copyright (c) 2012-2023 Sascha Ludwig, astrastudio.de
# All rights reserved.
#
# start.py
# This file is part of OnAirScreen
#
# You may use this file under the terms of the BSD license as follows:
#
# "Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
#
#############################################################################
import os
import re
import signal
import socket
import sys
from datetime import datetime
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import unquote
import ntplib
from PyQt5.QtCore import Qt, QSettings, QCoreApplication, QTimer, QDate, QLocale, QThread
from PyQt5.QtGui import QCursor, QPalette, QKeySequence, QIcon, QPixmap, QFont
from PyQt5.QtNetwork import QUdpSocket, QNetworkInterface, QHostAddress
from PyQt5.QtWidgets import QApplication, QWidget, QShortcut, QDialog, QLineEdit, QVBoxLayout, QLabel
from mainscreen import Ui_MainScreen
from settings_functions import Settings, versionString
HOST = '0.0.0.0'
class MainScreen(QWidget, Ui_MainScreen):
getTimeWindow: QDialog
ntpHadWarning: bool
ntpWarnMessage: str
textLocale: str # for text language
languages = {"English": 'en_US',
"German": 'de_DE',
"Dutch": 'nl_NL',
"French": 'fr_FR'}
def __init__(self):
QWidget.__init__(self)
Ui_MainScreen.__init__(self)
self.setupUi(self)
self.settings = Settings()
self.restore_settings_from_config()
# quit app from settings window
self.settings.sigExitOAS.connect(self.exit_oas)
self.settings.sigRebootHost.connect(self.reboot_host)
self.settings.sigShutdownHost.connect(self.shutdown_host)
self.settings.sigConfigFinished.connect(self.config_finished)
self.settings.sigConfigClosed.connect(self.config_closed)
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
if settings.value('fullscreen', True, type=bool):
self.showFullScreen()
app.setOverrideCursor(QCursor(Qt.BlankCursor))
settings.endGroup()
print("Loaded settings from: ", settings.fileName())
self.labelWarning.hide()
# init warning prio array (0-2
self.warnings = ["", "", ""]
# add hotkey bindings
QShortcut(QKeySequence("Ctrl+F"), self, self.toggle_full_screen)
QShortcut(QKeySequence("F"), self, self.toggle_full_screen)
QShortcut(QKeySequence(16777429), self, self.toggle_full_screen) # 'Display' Key on OAS USB Keyboard
QShortcut(QKeySequence(16777379), self, self.shutdown_host) # 'Calculator' Key on OAS USB Keyboard
QShortcut(QKeySequence("Ctrl+Q"), self, self.quit_oas)
QShortcut(QKeySequence("Q"), self, self.quit_oas)
QShortcut(QKeySequence("Ctrl+C"), self, self.quit_oas)
QShortcut(QKeySequence("ESC"), self, self.quit_oas)
QShortcut(QKeySequence("Ctrl+S"), self, self.show_settings)
QShortcut(QKeySequence("Ctrl+,"), self, self.show_settings)
QShortcut(QKeySequence(" "), self, self.radio_timer_start_stop)
QShortcut(QKeySequence(","), self, self.radio_timer_start_stop)
QShortcut(QKeySequence("."), self, self.radio_timer_start_stop)
QShortcut(QKeySequence("0"), self, self.radio_timer_reset)
QShortcut(QKeySequence("R"), self, self.radio_timer_reset)
QShortcut(QKeySequence("1"), self, self.manual_toggle_led1)
QShortcut(QKeySequence("2"), self, self.manual_toggle_led2)
QShortcut(QKeySequence("3"), self, self.manual_toggle_led3)
QShortcut(QKeySequence("4"), self, self.manual_toggle_led4)
QShortcut(QKeySequence("M"), self, self.toggle_air1)
QShortcut(QKeySequence("/"), self, self.toggle_air1)
QShortcut(QKeySequence("P"), self, self.toggle_air2)
QShortcut(QKeySequence("*"), self, self.toggle_air2)
QShortcut(QKeySequence("S"), self, self.toggle_air4)
QShortcut(QKeySequence("I"), self, self.display_ips)
QShortcut(QKeySequence("Alt+S"), self, self.stream_timer_reset)
QShortcut(QKeySequence("Enter"), self, self.get_timer_dialog)
QShortcut(QKeySequence("Return"), self, self.get_timer_dialog)
self.statusLED1 = False
self.statusLED2 = False
self.statusLED3 = False
self.statusLED4 = False
self.LED1on = False
self.LED2on = False
self.LED3on = False
self.LED4on = False
# Setup and start timers
self.ctimer = QTimer()
self.ctimer.timeout.connect(self.constant_update)
self.ctimer.start(100)
# LED timers
self.timerLED1 = QTimer()
self.timerLED1.timeout.connect(self.toggle_led1)
self.timerLED2 = QTimer()
self.timerLED2.timeout.connect(self.toggle_led2)
self.timerLED3 = QTimer()
self.timerLED3.timeout.connect(self.toggle_led3)
self.timerLED4 = QTimer()
self.timerLED4.timeout.connect(self.toggle_led4)
# Setup OnAir Timers
self.timerAIR1 = QTimer()
self.timerAIR1.timeout.connect(self.update_air1_seconds)
self.Air1Seconds = 0
self.statusAIR1 = False
self.timerAIR2 = QTimer()
self.timerAIR2.timeout.connect(self.update_air2_seconds)
self.Air2Seconds = 0
self.statusAIR2 = False
self.timerAIR3 = QTimer()
self.timerAIR3.timeout.connect(self.update_air3_seconds)
self.Air3Seconds = 0
self.statusAIR3 = False
self.radioTimerMode = 0 # count up mode
self.timerAIR4 = QTimer()
self.timerAIR4.timeout.connect(self.update_air4_seconds)
self.Air4Seconds = 0
self.statusAIR4 = False
self.streamTimerMode = 0 # count up mode
# Setup NTP Check Thread
self.checkNTPOffset = CheckNTPOffsetThread(self)
# Setup check NTP Timer
self.ntpHadWarning = True
self.ntpWarnMessage = ""
self.timerNTP = QTimer()
self.timerNTP.timeout.connect(self.trigger_ntp_check)
# initial check
self.timerNTP.start(1000)
self.replacenowTimer = QTimer()
self.replacenowTimer.timeout.connect(self.replace_now_next)
# Setup UDP Socket and join Multicast Group
self.udpsock = QUdpSocket()
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("Network")
port = int(settings.value('udpport', 3310))
multicast_address = settings.value('multicast_address', "239.194.0.1")
settings.endGroup()
self.udpsock.bind(QHostAddress.AnyIPv4, port, QUdpSocket.ShareAddress)
if QHostAddress(multicast_address).isMulticast():
print(multicast_address, "is Multicast, joining multicast group")
self.udpsock.joinMulticastGroup(QHostAddress(multicast_address))
self.udpsock.readyRead.connect(self.udp_cmd_handler)
# Setup HTTP Server
self.httpd = HttpDaemon(self)
self.httpd.start()
# display all host addresses
self.display_all_hostaddresses()
# set NTP warning
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("NTP")
if settings.value('ntpcheck', True, type=bool):
self.ntpHadWarning = True
self.ntpWarnMessage = "waiting for NTP status check"
settings.endGroup()
# do initial update check
self.settings.sigCheckForUpdate.emit()
def quit_oas(self):
# do cleanup here
print("Quitting, cleaning up...")
self.checkNTPOffset.stop()
self.httpd.stop()
QCoreApplication.instance().quit()
def radio_timer_start_stop(self):
self.start_stop_air3()
def radio_timer_reset(self):
self.reset_air3()
self.radioTimerMode = 0 # count up mode
def radio_timer_set(self, seconds):
self.Air3Seconds = seconds
if seconds > 0:
self.radioTimerMode = 1 # count down mode
else:
self.radioTimerMode = 0 # count up mode
self.AirLabel_3.setText("Timer\n%d:%02d" % (self.Air3Seconds / 60, self.Air3Seconds % 60))
def get_timer_dialog(self):
# generate and display timer input window
self.getTimeWindow = QDialog()
self.getTimeWindow.resize(200, 100)
self.getTimeWindow.setWindowTitle("Please enter timer")
self.getTimeWindow.timeEdit = QLineEdit("Enter timer here")
self.getTimeWindow.timeEdit.selectAll()
self.getTimeWindow.infoLabel = QLabel("Examples:\nenter 2,10 for 2:10 minutes\nenter 30 for 30 seconds")
layout = QVBoxLayout()
layout.addWidget(self.getTimeWindow.infoLabel)
layout.addWidget(self.getTimeWindow.timeEdit)
self.getTimeWindow.setLayout(layout)
self.getTimeWindow.timeEdit.setFocus()
self.getTimeWindow.timeEdit.returnPressed.connect(self.parse_timer_input)
self.getTimeWindow.show()
def parse_timer_input(self):
minutes = 0
seconds = 0
# hide input window
self.sender().parent().hide()
# get time string
text = str(self.sender().text())
if re.match('^[0-9]*,[0-9]*$', text):
(minutes, seconds) = text.split(",")
minutes = int(minutes)
seconds = int(seconds)
elif re.match(r'^[0-9]*\.[0-9]*$', text):
(minutes, seconds) = text.split(".")
minutes = int(minutes)
seconds = int(seconds)
elif re.match('^[0-9]*$', text):
seconds = int(text)
seconds = (minutes * 60) + seconds
self.radio_timer_set(seconds)
def stream_timer_start_stop(self):
self.start_stop_air4()
def stream_timer_reset(self):
self.reset_air4()
self.streamTimerMode = 0 # count up mode
def show_settings(self):
global app
# un-hide mouse cursor
app.setOverrideCursor(QCursor(Qt.ArrowCursor))
self.settings.showsettings()
def display_all_hostaddresses(self):
v4addrs = list()
v6addrs = list()
for address in QNetworkInterface().allAddresses():
if address.protocol() == 0:
if address.toString()[:3] != '127':
v4addrs.append(address.toString())
# if address.protocol() == 1:
# v6addrs.append(address.toString())
self.set_current_song_text(", ".join(["%s" % addr for addr in v4addrs]))
self.set_news_text(", ".join(["%s" % addr for addr in v6addrs]))
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
if settings.value('replacenow', True, type=bool):
self.replacenowTimer.setSingleShot(True)
self.replacenowTimer.start(10000)
settings.endGroup()
def parse_cmd(self, data):
try:
(command, value) = data.decode('utf_8').split(':', 1)
except ValueError:
return False
command = str(command)
value = str(value)
# print("command: >" + command + "<")
# print("value: >" + value + "<")
if command == "NOW":
self.set_current_song_text(value)
elif command == "NEXT":
self.set_news_text(value)
elif command == "LED1":
if value == "OFF":
self.led_logic(1, False)
else:
self.led_logic(1, True)
elif command == "LED2":
if value == "OFF":
self.led_logic(2, False)
else:
self.led_logic(2, True)
elif command == "LED3":
if value == "OFF":
self.led_logic(3, False)
else:
self.led_logic(3, True)
elif command == "LED4":
if value == "OFF":
self.led_logic(4, False)
else:
self.led_logic(4, True)
elif command == "WARN":
if value:
self.add_warning(value, 1)
else:
self.remove_warning(1)
elif command == "AIR1":
if value == "OFF":
self.set_air1(False)
else:
self.set_air1(True)
elif command == "AIR2":
if value == "OFF":
self.set_air2(False)
else:
self.set_air2(True)
elif command == "AIR3":
if value == "OFF":
self.stop_air3()
if value == "ON":
self.start_air3()
if value == "RESET":
self.radio_timer_reset()
if value == "TOGGLE":
self.radio_timer_start_stop()
elif command == "AIR3TIME":
try:
self.radio_timer_set(int(value))
except ValueError as e:
print("ERROR: invalid value", e)
elif command == "AIR4":
if value == "OFF":
self.set_air4(False)
if value == "ON":
self.set_air4(True)
if value == "RESET":
self.stream_timer_reset()
elif command == "CMD":
if value == "REBOOT":
self.reboot_host()
if value == "SHUTDOWN":
self.shutdown_host()
if value == "QUIT":
self.quit_oas()
elif command == "CONF":
# split group, config and values and apply them
try:
(group, paramvalue) = value.split(':', 1)
(param, content) = paramvalue.split('=', 1)
# print(F"CONF: {param}, {content}")
except ValueError:
return
if group == "General":
if param == "stationname":
self.settings.StationName.setText(content)
elif param == "slogan":
self.settings.Slogan.setText(content)
elif param == "stationcolor":
self.settings.setStationNameColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "slogancolor":
self.settings.setSloganColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "replacenow":
self.settings.replaceNOW.setChecked(content == "True")
elif param == "replacenowtext":
self.settings.replaceNOWText.setText(content)
elif group == "LED1":
if param == "used":
self.settings.LED1.setChecked(content == "True")
elif param == "text":
self.settings.LED1Text.setText(content)
elif param == "activebgcolor":
self.settings.setLED1BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "activetextcolor":
self.settings.setLED1FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "autoflash":
self.settings.LED1Autoflash.setChecked(content == "True")
elif param == "timedflash":
self.settings.LED1Timedflash.setChecked(content == "True")
elif group == "LED2":
if param == "used":
self.settings.LED2.setChecked(content == "True")
elif param == "text":
self.settings.LED2Text.setText(content)
elif param == "activebgcolor":
self.settings.setLED2BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "activetextcolor":
self.settings.setLED2FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "autoflash":
self.settings.LED2Autoflash.setChecked(content == "True")
elif param == "timedflash":
self.settings.LED2Timedflash.setChecked(content == "True")
elif group == "LED3":
if param == "used":
self.settings.LED3.setChecked(content == "True")
elif param == "text":
self.settings.LED3Text.setText(content)
elif param == "activebgcolor":
self.settings.setLED3BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "activetextcolor":
self.settings.setLED3FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "autoflash":
self.settings.LED3Autoflash.setChecked(content == "True")
elif param == "timedflash":
self.settings.LED3Timedflash.setChecked(content == "True")
elif group == "LED4":
if param == "used":
self.settings.LED4.setChecked(content == "True")
elif param == "text":
self.settings.LED4Text.setText(content)
elif param == "activebgcolor":
self.settings.setLED4BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "activetextcolor":
self.settings.setLED4FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "autoflash":
self.settings.LED4Autoflash.setChecked(content == "True")
elif param == "timedflash":
self.settings.LED4Timedflash.setChecked(content == "True")
elif group == "Timers":
if param == "TimerAIR1Enabled":
self.settings.enableAIR1.setChecked(content == "True")
elif param == "TimerAIR2Enabled":
self.settings.enableAIR2.setChecked(content == "True")
elif param == "TimerAIR3Enabled":
self.settings.enableAIR3.setChecked(content == "True")
elif param == "TimerAIR4Enabled":
self.settings.enableAIR4.setChecked(content == "True")
elif param == "TimerAIR1Text":
self.settings.AIR1Text.setText(content)
elif param == "TimerAIR2Text":
self.settings.AIR2Text.setText(content)
elif param == "TimerAIR3Text":
self.settings.AIR3Text.setText(content)
elif param == "TimerAIR4Text":
self.settings.AIR4Text.setText(content)
elif param == "AIR1activebgcolor":
self.settings.setAIR1BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR1activetextcolor":
self.settings.setAIR1FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR2activebgcolor":
self.settings.setAIR2BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR2activetextcolor":
self.settings.setAIR2FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR3activebgcolor":
self.settings.setAIR3BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR3activetextcolor":
self.settings.setAIR3FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR4activebgcolor":
self.settings.setAIR4BGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR4activetextcolor":
self.settings.setAIR4FGColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "AIR1iconpath":
self.settings.setAIR1IconPath(content)
elif param == "AIR2iconpath":
self.settings.setAIR2IconPath(content)
elif param == "AIR3iconpath":
self.settings.setAIR3IconPath(content)
elif param == "AIR4iconpath":
self.settings.setAIR4IconPath(content)
elif param == "TimerAIRMinWidth":
self.settings.AIRMinWidth.setValue(int(content))
elif group == "Clock":
if param == "digital":
if content == "True":
self.settings.clockDigital.setChecked(True)
self.settings.clockAnalog.setChecked(False)
elif content == "False":
self.settings.clockAnalog.setChecked(False)
self.settings.clockDigital.setChecked(True)
elif param == "showseconds":
if content == "True":
self.settings.showSeconds.setChecked(True)
self.settings.seconds_in_one_line.setChecked(False)
self.settings.seconds_separate.setChecked(True)
elif content == "False":
self.settings.showSeconds.setChecked(False)
self.settings.seconds_in_one_line.setChecked(False)
self.settings.seconds_separate.setChecked(True)
elif param == "secondsinoneline":
if content == "True":
self.settings.showSeconds.setChecked(True)
self.settings.seconds_in_one_line.setChecked(True)
self.settings.seconds_separate.setChecked(False)
elif content == "False":
self.settings.showSeconds.setChecked(False)
self.settings.seconds_in_one_line.setChecked(False)
self.settings.seconds_separate.setChecked(True)
elif param == "staticcolon":
if content == "True":
self.settings.staticColon.setChecked(True)
elif content == "False":
self.settings.staticColon.setChecked(False)
elif param == "digitalhourcolor":
self.settings.setDigitalHourColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "digitalsecondcolor":
self.settings.setDigitalSecondColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "digitaldigitcolor":
self.settings.setDigitalDigitColor(self.settings.getColorFromName(content.replace("0x", "#")))
elif param == "logopath":
self.settings.setLogoPath(content)
elif param == "logoupper":
if content == "True":
self.settings.setLogoUpper(True)
elif content == "False":
self.settings.setLogoUpper(False)
elif group == "Network":
if param == "udpport":
self.settings.udpport.setText(content)
elif group == "CONF":
if param == "APPLY":
if content == "TRUE":
# apply and save settings
self.settings.applySettings()
def udp_cmd_handler(self):
while self.udpsock.hasPendingDatagrams():
data, host, port = self.udpsock.readDatagram(self.udpsock.pendingDatagramSize())
# print("DATA: ", data)
lines = data.splitlines()
for line in lines:
# print("Line:", line)
self.parse_cmd(line)
def manual_toggle_led1(self):
if self.LED1on:
self.led_logic(1, False)
else:
self.led_logic(1, True)
def manual_toggle_led2(self):
if self.LED2on:
self.led_logic(2, False)
else:
self.led_logic(2, True)
def manual_toggle_led3(self):
if self.LED3on:
self.led_logic(3, False)
else:
self.led_logic(3, True)
def manual_toggle_led4(self):
if self.LED4on:
self.led_logic(4, False)
else:
self.led_logic(4, True)
def toggle_led1(self):
if self.statusLED1:
self.set_led1(False)
else:
self.set_led1(True)
def toggle_led2(self):
if self.statusLED2:
self.set_led2(False)
else:
self.set_led2(True)
def toggle_led3(self):
if self.statusLED3:
self.set_led3(False)
else:
self.set_led3(True)
def toggle_led4(self):
if self.statusLED4:
self.set_led4(False)
else:
self.set_led4(True)
def toggle_air1(self):
if self.statusAIR1:
self.set_air1(False)
else:
self.set_air1(True)
def toggle_air2(self):
if self.statusAIR2:
self.set_air2(False)
else:
self.set_air2(True)
def toggle_air4(self):
if self.statusAIR4:
self.set_air4(False)
else:
self.set_air4(True)
def display_ips(self):
self.display_all_hostaddresses()
self.replacenowTimer.setSingleShot(True)
self.replacenowTimer.start(10000)
def unset_led1(self):
self.led_logic(1, False)
def unset_led2(self):
self.led_logic(2, False)
def unset_led3(self):
self.led_logic(3, False)
def unset_led4(self):
self.led_logic(4, False)
def led_logic(self, led, state):
if state:
if led == 1:
if self.settings.LED1Autoflash.isChecked():
self.timerLED1.start(500)
if self.settings.LED1Timedflash.isChecked():
self.timerLED1.start(500)
QTimer.singleShot(20000, self.unset_led1)
self.set_led1(state)
self.LED1on = state
if led == 2:
if self.settings.LED2Autoflash.isChecked():
self.timerLED2.start(500)
if self.settings.LED2Timedflash.isChecked():
self.timerLED2.start(500)
QTimer.singleShot(20000, self.unset_led2)
self.set_led2(state)
self.LED2on = state
if led == 3:
if self.settings.LED3Autoflash.isChecked():
self.timerLED3.start(500)
if self.settings.LED3Timedflash.isChecked():
self.timerLED3.start(500)
QTimer.singleShot(20000, self.unset_led3)
self.set_led3(state)
self.LED3on = state
if led == 4:
if self.settings.LED4Autoflash.isChecked():
self.timerLED4.start(500)
if self.settings.LED4Timedflash.isChecked():
self.timerLED4.start(500)
QTimer.singleShot(20000, self.unset_led4)
self.set_led4(state)
self.LED4on = state
if not state:
if led == 1:
self.set_led1(state)
self.timerLED1.stop()
self.LED1on = state
if led == 2:
self.set_led2(state)
self.timerLED2.stop()
self.LED2on = state
if led == 3:
self.set_led3(state)
self.timerLED3.stop()
self.LED3on = state
if led == 4:
self.set_led4(state)
self.timerLED4.stop()
self.LED4on = state
def set_station_color(self, newcolor):
palette = self.labelStation.palette()
palette.setColor(QPalette.WindowText, newcolor)
self.labelStation.setPalette(palette)
def set_slogan_color(self, newcolor):
palette = self.labelSlogan.palette()
palette.setColor(QPalette.WindowText, newcolor)
self.labelSlogan.setPalette(palette)
def restore_settings_from_config(self):
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
self.labelStation.setText(settings.value('stationname', 'Radio Eriwan'))
self.labelSlogan.setText(settings.value('slogan', 'Your question is our motivation'))
self.set_station_color(self.settings.getColorFromName(settings.value('stationcolor', '#FFAA00')))
self.set_slogan_color(self.settings.getColorFromName(settings.value('slogancolor', '#FFAA00')))
settings.endGroup()
settings.beginGroup("LED1")
self.set_led1_text(settings.value('text', 'ON AIR'))
self.buttonLED1.setVisible(settings.value('used', True, type=bool))
settings.endGroup()
settings.beginGroup("LED2")
self.set_led2_text(settings.value('text', 'PHONE'))
self.buttonLED2.setVisible(settings.value('used', True, type=bool))
settings.endGroup()
settings.beginGroup("LED3")
self.set_led3_text(settings.value('text', 'DOORBELL'))
self.buttonLED3.setVisible(settings.value('used', True, type=bool))
settings.endGroup()
settings.beginGroup("LED4")
self.set_led4_text(settings.value('text', 'EAS ACTIVE'))
self.buttonLED4.setVisible(settings.value('used', True, type=bool))
settings.endGroup()
settings.beginGroup("Clock")
self.clockWidget.set_clock_mode(settings.value('digital', True, type=bool))
self.clockWidget.set_digi_hour_color(
self.settings.getColorFromName(settings.value('digitalhourcolor', '#3232FF')))
self.clockWidget.set_digi_second_color(
self.settings.getColorFromName(settings.value('digitalsecondcolor', '#FF9900')))
self.clockWidget.set_digi_digit_color(
self.settings.getColorFromName(settings.value('digitaldigitcolor', '#3232FF')))
self.clockWidget.set_logo(
settings.value('logopath', ':/astrastudio_logo/images/astrastudio_transparent.png'))
self.clockWidget.set_show_seconds(settings.value('showSeconds', False, type=bool))
self.clockWidget.set_one_line_time(settings.value('showSecondsInOneLine', False, type=bool) &
settings.value('showSeconds', False, type=bool))
self.clockWidget.set_static_colon(settings.value('staticColon', False, type=bool))
self.clockWidget.set_logo_upper(settings.value('logoUpper', False, type=bool))
self.labelTextRight.setVisible(settings.value('useTextClock', True, type=bool))
settings.endGroup()
settings.beginGroup("Formatting")
self.clockWidget.set_am_pm(settings.value('isAmPm', False, type=bool))
self.textLocale = settings.value('textClockLanguage', 'English')
settings.endGroup()
settings.beginGroup("WeatherWidget")
if settings.value('owmWidgetEnabled', False, type=bool):
self.weatherWidget.show()
else:
self.weatherWidget.hide()
settings.endGroup()
settings.beginGroup("Timers")
if not settings.value('TimerAIR1Enabled', True, type=bool):
self.AirLED_1.hide()
else:
label_text = settings.value('TimerAIR1Text', 'Mic')
self.AirLabel_1.setText(F"{label_text}\n0:00")
self.AirLabel_1.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirIcon_1.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirLED_1.show()
if not settings.value('TimerAIR2Enabled', True, type=bool):
self.AirLED_2.hide()
else:
label_text = settings.value('TimerAIR2Text', 'Phone')
self.AirLabel_2.setText(F"{label_text}\n0:00")
self.AirLabel_2.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirIcon_2.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirLED_2.show()
if not settings.value('TimerAIR3Enabled', True, type=bool):
self.AirLED_3.hide()
else:
label_text = settings.value('TimerAIR3Text', 'Timer')
self.AirLabel_3.setText(F"{label_text}\n0:00")
self.AirLabel_3.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirIcon_3.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirLED_3.show()
if not settings.value('TimerAIR4Enabled', True, type=bool):
self.AirLED_4.hide()
else:
label_text = settings.value('TimerAIR4Text', 'Stream')
self.AirLabel_4.setText(F"{label_text}\n0:00")
self.AirLabel_4.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirIcon_4.setStyleSheet(F"color:{settings.value('inactivetextcolor', '#555555')};"
F"background-color:{settings.value('inactivebgcolor', '#222222')}")
self.AirLED_4.show()
# set minimum left LED width
min_width = settings.value('TimerAIRMinWidth', 200, type=int)
self.AirLED_1.setMinimumWidth(min_width)
self.AirLED_2.setMinimumWidth(min_width)
self.AirLED_3.setMinimumWidth(min_width)
self.AirLED_4.setMinimumWidth(min_width)
self.AirIcon_1.setPixmap(QPixmap(settings.value('air1iconpath', ':/mic_icon.png/images/mic_icon.png')))
self.AirIcon_2.setPixmap(QPixmap(settings.value('air2iconpath', ':/phone_icon/images/phone_icon.png')))
self.AirIcon_3.setPixmap(QPixmap(settings.value('air3iconpath', ':/timer_icon/images/timer_icon.png')))
self.AirIcon_4.setPixmap(QPixmap(settings.value('air4iconpath', ':/stream_icon/images/antenna2.png')))
settings.endGroup()
settings.beginGroup("Fonts")
self.buttonLED1.setFont(QFont(settings.value('LED1FontName', "FreeSans"),
settings.value('LED1FontSize', 24, type=int),
settings.value('LED1FontWeight', QFont.Bold, type=int)))
self.buttonLED2.setFont(QFont(settings.value('LED2FontName', "FreeSans"),
settings.value('LED2FontSize', 24, type=int),
settings.value('LED2FontWeight', QFont.Bold, type=int)))
self.buttonLED3.setFont(QFont(settings.value('LED3FontName', "FreeSans"),
settings.value('LED3FontSize', 24, type=int),
settings.value('LED3FontWeight', QFont.Bold, type=int)))
self.buttonLED4.setFont(QFont(settings.value('LED4FontName', "FreeSans"),
settings.value('LED4FontSize', 24, type=int),
settings.value('LED4FontWeight', QFont.Bold, type=int)))
self.AirLabel_1.setFont(QFont(settings.value('AIR1FontName', "FreeSans"),
settings.value('AIR1FontSize', 24, type=int),
settings.value('AIR1FontWeight', QFont.Bold, type=int)))
self.AirLabel_2.setFont(QFont(settings.value('AIR2FontName', "FreeSans"),
settings.value('AIR2FontSize', 24, type=int),
settings.value('AIR2FontWeight', QFont.Bold, type=int)))
self.AirLabel_3.setFont(QFont(settings.value('AIR3FontName', "FreeSans"),
settings.value('AIR3FontSize', 24, type=int),
settings.value('AIR3FontWeight', QFont.Bold, type=int)))
self.AirLabel_4.setFont(QFont(settings.value('AIR4FontName', "FreeSans"),
settings.value('AIR4FontSize', 24, type=int),
settings.value('AIR4FontWeight', QFont.Bold, type=int)))
self.labelStation.setFont(QFont(settings.value('StationNameFontName', "FreeSans"),
settings.value('StationNameFontSize', 24, type=int),
settings.value('StationNameFontWeight', QFont.Bold, type=int)))
self.labelSlogan.setFont(QFont(settings.value('SloganFontName', "FreeSans"),
settings.value('SloganFontSize', 24, type=int),
settings.value('SloganFontWeight', QFont.Bold, type=int)))
settings.endGroup()
def constant_update(self):
# slot for constant timer timeout
self.update_date()
self.update_backtiming_text()
self.update_backtiming_seconds()
self.update_ntp_status()
self.process_warnings()
def update_date(self):
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("Formatting")
set_language = settings.value('textClockLanguage', 'English')
lang = QLocale(self.languages[set_language] if set_language in self.languages else QLocale().name())
self.set_left_text(lang.toString(QDate.currentDate(), settings.value('dateFormat', 'dddd, dd. MMMM yyyy')))
settings.endGroup()
def update_backtiming_text(self):
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("Formatting")
text_clock_language = settings.value('textClockLanguage', 'English')
is_am_pm = settings.value('isAmPm', False, type=bool)
settings.endGroup()
string = ""
now = datetime.now()
hour = now.hour
minute = now.minute
remain_min = 60 - minute
if text_clock_language == "German":
# german textclock
if hour > 12:
hour -= 12
if 0 < minute < 25:
string = F"{minute} Minute{'n' if minute>1 else ''} nach {hour}"
if 25 <= minute < 30:
string = F"{remain_min-30} Minute{'n' if remain_min-30>1 else ''} vor halb {1 if hour==12 else hour+1}"
if 31 <= minute <= 39:
string = F"{30-remain_min} Minute{'n' if 30-remain_min>1 else ''} nach halb {1 if hour==12 else hour+1}"
if 40 <= minute <= 59:
string = F"{remain_min} Minute{'n' if remain_min>1 else ''} vor {1 if hour==12 else hour+1}"
if minute == 30:
string = F"halb {1 if hour==12 else hour+1}"
if minute == 0:
string = F"{hour} Uhr"
elif text_clock_language == "Dutch":
# Dutch textclock
if is_am_pm:
if hour > 12:
hour -= 12
if minute == 0:
string = F"Het is {hour} uur"
if (1 <= minute <= 14) or (16 <= minute <= 29):
string = F"Het is {minute} minu{'ten' if minute>1 else 'ut'} over {hour}"
if minute == 15:
string = F"Het is kwart over {hour}"
if minute == 30:
string = F"Het is half {1 if hour==12 else hour+1}"
if minute == 45:
string = F"Het is kwart voor {1 if hour==12 else hour+1}"
if (31 <= minute <= 44) or (46 <= minute <= 59):
string = F"Het is {remain_min} minu{'ten' if minute>1 else 'ut'} voor {1 if hour==12 else hour+1}"
elif text_clock_language == "French":
# French textclock
if hour > 12:
hour -= 12
if 0 < minute < 60:
string = F"{hour} {'heures' if hour > 1 else 'heure'} {minute}"
if minute == 0:
string = F"{hour} {'heures' if hour > 1 else 'heure'}"
if minute == 15:
string = F"{hour} {'heures' if hour > 1 else 'heure'} et quart"
if minute == 30:
string = F"{hour} {'heures' if hour > 1 else 'heure'} et demie"
if hour == 0:
if 0 < minute < 59:
string = F"minuit {minute}"
if minute == 0:
string = F"minuit"
if minute == 15:
string = F"minuit et quart"
if minute == 30:
string = F"minuit et demie"
else:
# english textclock
if is_am_pm:
if hour > 12:
hour -= 12
if minute == 0:
string = "it's %d o'clock" % hour
if (0 < minute < 15) or (16 <= minute <= 29):
string = "it's %d minute%s past %d" % (minute, 's' if minute > 1 else '', hour)
if minute == 15:
string = "it's a quarter past %d" % hour
if minute == 30:
string = "it's half past %d" % hour
if minute == 45:
string = "it's a quarter to %d" % (hour + 1)
if (31 <= minute <= 44) or (46 <= minute <= 59):
string = "it's %d minute%s to %d" % (
remain_min, 's' if remain_min > 1 else '', 1 if hour == 12 else hour + 1)
self.set_right_text(string)
def update_backtiming_seconds(self):
now = datetime.now()
second = now.second
remain_seconds = 60 - second
self.set_backtiming_secs(remain_seconds)
def update_ntp_status(self):
if self.ntpHadWarning and len(self.ntpWarnMessage):
self.add_warning(self.ntpWarnMessage, 0)
else:
self.ntpWarnMessage = ""
self.remove_warning(0)
def toggle_full_screen(self):
global app
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
if not settings.value('fullscreen', True, type=bool):
self.showFullScreen()