forked from saschaludwig/OnAirScreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
executable file
·972 lines (851 loc) · 39.9 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#############################################################################
##
## OnAirScreen
## Copyright (C) 2014-2016 Sascha Ludwig
## 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 atexit
import os
import sys
import re
from datetime import datetime
from PyQt4.QtGui import QApplication, QWidget, QCursor, QPalette, QColorDialog, QColor, QShortcut, QKeySequence, QDialog, QLineEdit, QVBoxLayout, QLabel, QIcon, QPixmap
from PyQt4.QtCore import SIGNAL, QSettings, QCoreApplication, QTimer, QObject, QVariant, QDate
from PyQt4.QtNetwork import QUdpSocket, QHostAddress, QHostInfo, QNetworkInterface
from mainscreen import Ui_MainScreen
from locale import LC_TIME, setlocale
import ntplib
import signal
import socket
from settings_functions import Settings
class MainScreen(QWidget, Ui_MainScreen):
def __init__(self):
QWidget.__init__(self)
Ui_MainScreen.__init__(self)
self.setupUi(self)
self.settings = Settings()
self.restoreSettingsFromConfig()
# quit app from settings window
self.settings.sigExitOAS.connect(self.exitOAS)
self.settings.sigRebootHost.connect(self.reboot_host)
self.settings.sigShutdownHost.connect(self.shutdown_host)
self.settings.sigConfigFinished.connect(self.configFinished)
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
if settings.value('fullscreen', True).toBool():
self.showFullScreen()
app.setOverrideCursor( QCursor( 10 ) );
settings.endGroup()
self.labelWarning.hide()
# add hotkey bindings
QShortcut(QKeySequence("Ctrl+F"), self, self.toggleFullScreen )
QShortcut(QKeySequence("F"), self, self.toggleFullScreen )
QShortcut(QKeySequence(16777429), self, self.toggleFullScreen ) # 'Display' Key on OAS USB Keyboard
QShortcut(QKeySequence(16777379), self, self.shutdown_host ) # 'Calculator' Key on OAS USB Keyboard
QShortcut(QKeySequence("Ctrl+Q"), self, QCoreApplication.instance().quit )
QShortcut(QKeySequence("Q"), self, QCoreApplication.instance().quit )
QShortcut(QKeySequence("Ctrl+C"), self, QCoreApplication.instance().quit )
QShortcut(QKeySequence("ESC"), self, QCoreApplication.instance().quit )
QShortcut(QKeySequence("Ctrl+S"), self, self.showsettings )
QShortcut(QKeySequence("Ctrl+,"), self, self.showsettings )
QShortcut(QKeySequence(" "), self, self.radioTimerStartStop )
QShortcut(QKeySequence(","), self, self.radioTimerStartStop )
QShortcut(QKeySequence("."), self, self.radioTimerStartStop )
QShortcut(QKeySequence("0"), self, self.radioTimerReset )
QShortcut(QKeySequence("R"), self, self.radioTimerReset )
QShortcut(QKeySequence("1"), self, self.toggleLED1 )
QShortcut(QKeySequence("2"), self, self.toggleLED2 )
QShortcut(QKeySequence("3"), self, self.toggleLED3 )
QShortcut(QKeySequence("4"), self, self.toggleLED4 )
QShortcut(QKeySequence("M"), self, self.toggleAIR1 )
QShortcut(QKeySequence("/"), self, self.toggleAIR1 )
QShortcut(QKeySequence("P"), self, self.toggleAIR2 )
QShortcut(QKeySequence("*"), self, self.toggleAIR2 )
QShortcut(QKeySequence("S"), self, self.toggleAIR4 )
QShortcut(QKeySequence("Enter"), self, self.getTimerDialog )
QShortcut(QKeySequence("Return"), self, self.getTimerDialog )
# Setup and start timers
self.ctimer = QTimer()
QObject.connect(self.ctimer, SIGNAL("timeout()"), self.constantUpdate)
self.ctimer.start(100)
# LED timers
self.timerLED1 = QTimer()
QObject.connect(self.timerLED1, SIGNAL("timeout()"), self.toggleLED1)
self.timerLED2 = QTimer()
QObject.connect(self.timerLED2, SIGNAL("timeout()"), self.toggleLED2)
self.timerLED3 = QTimer()
QObject.connect(self.timerLED3, SIGNAL("timeout()"), self.toggleLED3)
self.timerLED4 = QTimer()
QObject.connect(self.timerLED4, SIGNAL("timeout()"), self.toggleLED4)
# Setup OnAir Timers
self.timerAIR1 = QTimer()
QObject.connect(self.timerAIR1, SIGNAL("timeout()"), self.updateAIR1Seconds)
self.Air1Seconds = 0
self.statusAIR1 = False
self.timerAIR2 = QTimer()
QObject.connect(self.timerAIR2, SIGNAL("timeout()"), self.updateAIR2Seconds)
self.Air2Seconds = 0
self.statusAIR2 = False
self.timerAIR3 = QTimer()
QObject.connect(self.timerAIR3, SIGNAL("timeout()"), self.updateAIR3Seconds)
self.Air3Seconds = 0
self.statusAIR3 = False
self.radioTimerMode = 0 #count up mode
self.timerAIR4 = QTimer()
QObject.connect(self.timerAIR4, SIGNAL("timeout()"), self.updateAIR4Seconds)
self.Air4Seconds = 0
self.statusAIR4 = False
self.streamTimerMode = 0 #count up mode
# Setup check NTP Timer
self.ntpHadWarning = True
self.timerNTP = QTimer()
QObject.connect(self.timerNTP, SIGNAL("timeout()"), self.checkNTPOffset)
# initial check
self.timerNTP.start(5000)
# Setup UDP Socket
self.udpsock = QUdpSocket()
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("Network")
(port, foo) = settings.value('udpport', 3310).toInt()
settings.endGroup()
self.udpsock.bind(port, QUdpSocket.ShareAddress)
self.udpsock.readyRead.connect(self.cmdHandler)
# diplay all host adresses
self.displayAllHostaddresses()
# set NTP warning
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("NTP")
if settings.value('ntpcheck', True).toBool():
self.showWarning("Clock NTP status unknown")
settings.endGroup()
def radioTimerStartStop(self):
self.startStopAIR3()
def radioTimerReset(self):
self.resetAIR3()
self.radioTimerMode = 0 #count up mode
def radioTimerSet(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 getTimerDialog(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.parseTimerInput)
self.getTimeWindow.show()
def parseTimerInput(self):
minutes = 0
seconds = 0
# hide input window
self.sender().parent().hide()
# get timestring
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('^[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.radioTimerSet(seconds)
def streamTimerStartStop(self):
self.startStopAIR4()
def streamTimerReset(self):
self.resetAIR4()
self.streamTimerMode = 0 #count up mode
def showsettings(self):
global app
# un-hide mousecursor
app.setOverrideCursor( QCursor( 0 ) );
self.settings.showsettings()
def displayAllHostaddresses(self):
v4addrs = list()
v6addrs = list()
for address in QNetworkInterface().allAddresses():
if address.protocol() == 0:
v4addrs.append(address.toString())
#if address.protocol() == 1:
# v6addrs.append(address.toString())
self.setCurrentSongText(", ".join(["%s" % (addr) for addr in v4addrs]))
self.setNewsText(", ".join(["%s" % (addr) for addr in v6addrs]))
def cmdHandler(self):
while self.udpsock.hasPendingDatagrams():
data, host, port = self.udpsock.readDatagram(self.udpsock.pendingDatagramSize())
#print "DATA: ", data
lines = data.splitlines()
for line in lines:
(command, value) = line.split(':',1)
#print "command: '" + command + "'"
#print "value: '" + value + "'"
if command == "NOW":
self.setCurrentSongText(value)
if command == "NEXT":
self.setNewsText(value)
if command == "LED1":
if value == "OFF":
self.ledLogic(1, False)
else:
self.ledLogic(1, True)
if command == "LED2":
if value == "OFF":
self.ledLogic(2, False)
else:
self.ledLogic(2, True)
if command == "LED3":
if value == "OFF":
self.ledLogic(3, False)
else:
self.ledLogic(3, True)
if command == "LED4":
if value == "OFF":
self.ledLogic(4, False)
else:
self.ledLogic(4, True)
if command == "WARN":
if value:
self.showWarning(value)
else:
self.hideWarning()
if command == "AIR1":
if value == "OFF":
self.setAIR1(False)
else:
self.setAIR1(True)
if command == "AIR2":
if value == "OFF":
self.setAIR2(False)
else:
self.setAIR2(True)
if command == "AIR3":
if value == "OFF":
self.stopAIR3()
if value == "ON":
self.startAIR3()
if value == "RESET":
self.radioTimerReset()
if value == "TOGGLE":
self.radioTimerStartStop()
if command == "AIR3TIME":
self.radioTimerSet(int(value))
if command == "AIR4":
if value == "OFF":
self.setAIR4(False)
if value == "ON":
self.setAIR4(True)
if value == "RESET":
self.streamTimerReset()
if command == "CMD":
if value == "REBOOT":
self.reboot_host()
if value == "SHUTDOWN":
self.shutdown_host()
if value == "QUIT":
QApplication.quit()
if command == "CONF":
#split group, config and values and apply them
(group, paramvalue) = value.split(':',1)
(param, content) = paramvalue.split('=',1)
#print "CONF:", param, content
if group == "General":
if param == "stationname":
self.settings.StationName.setText(content)
if param == "slogan":
self.settings.Slogan.setText(content)
if param == "stationcolor":
self.settings.setStationNameColor(self.settings.getColorFromName(content))
if param == "slogancolor":
self.settings.setSloganColor(self.settings.getColorFromName(content))
if group == "LED1":
if param == "used":
self.settings.LED1.setChecked(QVariant(content).toBool())
if param == "text":
self.settings.LED1Text.setText(content)
if param == "activebgcolor":
self.settings.setLED1BGColor(self.settings.getColorFromName(content))
if param == "activetextcolor":
self.settings.setLED1FGColor(self.settings.getColorFromName(content))
if param == "autoflash":
self.settings.LED1Autoflash.setChecked(QVariant(content).toBool())
if param == "timedflash":
self.settings.LED1Timedflash.setChecked(QVariant(content).toBool())
if group == "LED2":
if param == "used":
self.settings.LED2.setChecked(QVariant(content).toBool())
if param == "text":
self.settings.LED2Text.setText(content)
if param == "activebgcolor":
self.settings.setLED2BGColor(self.settings.getColorFromName(content))
if param == "activetextcolor":
self.settings.setLED2FGColor(self.settings.getColorFromName(content))
if param == "autoflash":
self.settings.LED2Autoflash.setChecked(QVariant(content).toBool())
if param == "timedflash":
self.settings.LED2Timedflash.setChecked(QVariant(content).toBool())
if group == "LED3":
if param == "used":
self.settings.LED3.setChecked(QVariant(content).toBool())
if param == "text":
self.settings.LED3Text.setText(content)
if param == "activebgcolor":
self.settings.setLED3BGColor(self.settings.getColorFromName(content))
if param == "activetextcolor":
self.settings.setLED3FGColor(self.settings.getColorFromName(content))
if param == "autoflash":
self.settings.LED3Autoflash.setChecked(QVariant(content).toBool())
if param == "timedflash":
self.settings.LED3Timedflash.setChecked(QVariant(content).toBool())
if group == "LED4":
if param == "used":
self.settings.LED4.setChecked(QVariant(content).toBool())
if param == "text":
self.settings.LED4Text.setText(content)
if param == "activebgcolor":
self.settings.setLED4BGColor(self.settings.getColorFromName(content))
if param == "activetextcolor":
self.settings.setLED4FGColor(self.settings.getColorFromName(content))
if param == "autoflash":
self.settings.LED4Autoflash.setChecked(QVariant(content).toBool())
if param == "timedflash":
self.settings.LED4Timedflash.setChecked(QVariant(content).toBool())
if group == "Clock":
if param == "digital":
if content == "True":
self.settings.clockDigital.setChecked(QVariant(content).toBool())
self.settings.clockAnalog.setChecked(not QVariant(content).toBool())
if content == "False":
self.settings.clockAnalog.setChecked(QVariant(content).toBool())
self.settings.clockDigital.setChecked(not QVariant(content).toBool())
if param == "digitalhourcolor":
self.settings.setDigitalHourColor(self.settings.getColorFromName(content))
if param == "digitalsecondcolor":
self.settings.setDigitalSecondColor(self.settings.getColorFromName(content))
if param == "digitaldigitcolor":
self.settings.setDigitalDigitColor(self.settings.getColorFromName(content))
if param == "logopath":
self.settings.setLogoPath(content)
if group == "Network":
if param == "udpport":
self.settings.udpport.setText(content)
if param == "tcpport":
self.settings.tcpport.setText(content)
if group == "CONF":
if param == "APPLY":
if content == "TRUE":
# apply and save settings
self.settings.applySettings()
def toggleLED1(self):
if self.statusLED1:
self.setLED1(False)
else:
self.setLED1(True)
def toggleLED2(self):
if self.statusLED2:
self.setLED2(False)
else:
self.setLED2(True)
def toggleLED3(self):
if self.statusLED3:
self.setLED3(False)
else:
self.setLED3(True)
def toggleLED4(self):
if self.statusLED4:
self.setLED4(False)
else:
self.setLED4(True)
def toggleAIR1(self):
if self.statusAIR1:
self.setAIR1(False)
else:
self.setAIR1(True)
def toggleAIR2(self):
if self.statusAIR2:
self.setAIR2(False)
else:
self.setAIR2(True)
def toggleAIR4(self):
if self.statusAIR4:
self.setAIR4(False)
else:
self.setAIR4(True)
def unsetLED1(self):
self.ledLogic(1, False)
def unsetLED2(self):
self.ledLogic(2, False)
def unsetLED3(self):
self.ledLogic(3, False)
def unsetLED4(self):
self.ledLogic(4, False)
def ledLogic(self, led, state):
if state == True:
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.unsetLED1)
self.setLED1(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.unsetLED2)
self.setLED2(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.unsetLED3)
self.setLED3(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.unsetLED4)
self.setLED4(state)
if state == False:
if led == 1:
self.setLED1(state)
self.timerLED1.stop()
if led == 2:
self.setLED2(state)
self.timerLED2.stop()
if led == 3:
self.setLED3(state)
self.timerLED3.stop()
if led == 4:
self.setLED4(state)
self.timerLED4.stop()
def setStationColor(self, newcolor):
palette = self.labelStation.palette()
palette.setColor(QPalette.WindowText, newcolor)
self.labelStation.setPalette(palette)
def setSloganColor(self, newcolor):
palette = self.labelSlogan.palette()
palette.setColor(QPalette.WindowText, newcolor)
self.labelSlogan.setPalette(palette)
def restoreSettingsFromConfig(self):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
self.labelStation.setText(settings.value('stationname', 'Radio Eriwan').toString())
self.labelSlogan.setText(settings.value('slogan', 'Your question is our motivation').toString())
self.setStationColor(self.settings.getColorFromName(settings.value('stationcolor', '#FFAA00').toString()))
self.setSloganColor(self.settings.getColorFromName(settings.value('slogancolor', '#FFAA00').toString()))
settings.endGroup()
settings.beginGroup("LED1")
self.setLED1Text(settings.value('text', 'ON AIR').toString())
settings.endGroup()
settings.beginGroup("LED2")
self.setLED2Text(settings.value('text', 'PHONE').toString())
settings.endGroup()
settings.beginGroup("LED3")
self.setLED3Text(settings.value('text', 'DOORBELL').toString())
settings.endGroup()
settings.beginGroup("LED4")
self.setLED4Text(settings.value('text', 'ARI').toString())
settings.endGroup()
settings.beginGroup("Clock")
self.clockWidget.setClockMode( settings.value('digital', True).toBool() )
self.clockWidget.setDigiHourColor(self.settings.getColorFromName(settings.value('digitalhourcolor', '#3232FF').toString()))
self.clockWidget.setDigiSecondColor(self.settings.getColorFromName(settings.value('digitalsecondcolor', '#FF9900').toString()))
self.clockWidget.setDigiDigitColor(self.settings.getColorFromName(settings.value('digitaldigitcolor', '#3232FF').toString()))
self.clockWidget.setLogo( settings.value('logopath', ':/astrastudio_logo/astrastudio_transparent.png').toString() )
settings.endGroup()
def constantUpdate(self):
# slot for constant timer timeout
self.updateDate()
self.updateBacktimingText()
self.updateBacktimingSeconds()
def updateDate(self):
now = datetime.now()
self.setLeftText( QDate.currentDate().toString("dddd, dd. MMMM yyyy") )
def updateBacktimingText(self):
now = datetime.now()
hour = now.hour
minute = now.minute
second = now.second
remain_min = 60-minute
if hour > 12:
hour -= 12
if minute > 0 and minute < 25:
string = "%d Minute%s nach %d" % (minute, 'n' if minute>1 else '', hour)
if minute >= 25 and minute < 30:
string = "%d Minute%s vor halb %d" % (remain_min-30, 'n' if remain_min-30>1 else '', hour+1)
if minute >= 30 and minute <= 39:
string = "%d Minute%s nach halb %d" % (30-remain_min, 'n' if 30-remain_min>1 else '', hour+1)
if minute >= 40 and minute <= 59:
string = "%d Minute%s vor %d" % (remain_min, 'n' if remain_min>1 else '', hour+1)
if minute == 30:
string = "halb %d" % (hour+1)
if minute == 0:
string = "%d" % hour
self.setRightText( string )
def updateBacktimingSeconds(self):
now = datetime.now()
second = now.second
remain_seconds = 60-second
self.setBacktimingSecs(remain_seconds)
def toggleFullScreen(self):
global app
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
if not settings.value('fullscreen', 'True').toBool():
self.showFullScreen()
app.setOverrideCursor( QCursor( 10 ) );
settings.setValue('fullscreen', True)
else:
self.showNormal()
app.setOverrideCursor( QCursor( 0 ) );
settings.setValue('fullscreen', False)
settings.endGroup()
def setAIR1(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
self.Air1Seconds = 0
self.AirLabel_1.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirIcon_1.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirLabel_1.setText("Mic\n%d:%02d" % (self.Air1Seconds/60, self.Air1Seconds%60) )
self.statusAIR1 = True
# AIR1 timer
self.timerAIR1.start(1000)
else:
settings.beginGroup("LEDS")
self.AirIcon_1.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
self.AirLabel_1.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusAIR1 = False
self.timerAIR1.stop()
def updateAIR1Seconds(self):
self.Air1Seconds += 1
self.AirLabel_1.setText("Mic\n%d:%02d" % (self.Air1Seconds/60, self.Air1Seconds%60) )
def setAIR2(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
self.Air2Seconds = 0
self.AirLabel_2.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirIcon_2.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirLabel_2.setText("Phone\n%d:%02d" % (self.Air2Seconds/60, self.Air2Seconds%60) )
self.statusAIR2 = True
# AIR2 timer
self.timerAIR2.start(1000)
else:
settings.beginGroup("LEDS")
self.AirIcon_2.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
self.AirLabel_2.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusAIR2 = False
self.timerAIR2.stop()
def updateAIR2Seconds(self):
self.Air2Seconds += 1
self.AirLabel_2.setText("Phone\n%d:%02d" % (self.Air2Seconds/60, self.Air2Seconds%60) )
def resetAIR3(self):
self.timerAIR3.stop()
self.Air3Seconds = 0
self.AirLabel_3.setText("Timer\n%d:%02d" % (self.Air3Seconds/60, self.Air3Seconds%60) )
if self.statusAIR3 == True:
self.timerAIR3.start(1000)
def setAIR3(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
self.AirLabel_3.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirIcon_3.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirLabel_3.setText("Timer\n%d:%02d" % (self.Air3Seconds/60, self.Air3Seconds%60) )
self.statusAIR3 = True
# substract initial second on countdown with display update
if self.radioTimerMode == 1 and self.Air3Seconds > 1:
self.updateAIR3Seconds()
# AIR3 timer
self.timerAIR3.start(1000)
else:
settings.beginGroup("LEDS")
self.AirIcon_3.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
self.AirLabel_3.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusAIR3 = False
self.timerAIR3.stop()
def startStopAIR3(self):
if self.statusAIR3 == False:
self.startAIR3()
else:
self.stopAIR3()
def startAIR3(self):
self.setAIR3(True)
def stopAIR3(self):
self.setAIR3(False)
def updateAIR3Seconds(self):
if self.radioTimerMode == 0: #count up mode
self.Air3Seconds += 1
else:
self.Air3Seconds -= 1
if self.Air3Seconds < 1:
self.stopAIR3()
self.radioTimerMode = 0
self.AirLabel_3.setText("Timer\n%d:%02d" % (self.Air3Seconds/60, self.Air3Seconds%60) )
def resetAIR4(self):
self.timerAIR4.stop()
self.Air4Seconds = 0
self.AirLabel_4.setText("Stream\n%d:%02d" % (self.Air4Seconds/60, self.Air4Seconds%60) )
if self.statusAIR4 == True:
self.timerAIR4.start(1000)
def setAIR4(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
self.AirLabel_4.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirIcon_4.setStyleSheet("color: #000000; background-color: #FF0000")
self.AirLabel_4.setText("Stream\n%d:%02d" % (self.Air4Seconds/60, self.Air4Seconds%60) )
self.statusAIR4 = True
# substract initial second on countdown with display update
if self.streamTimerMode == 1 and self.Air4Seconds > 1:
self.updateAIR4Seconds()
# AIR4 timer
self.timerAIR4.start(1000)
else:
settings.beginGroup("LEDS")
self.AirIcon_4.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
self.AirLabel_4.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusAIR4 = False
self.timerAIR4.stop()
def startStopAIR4(self):
if self.statusAIR4 == False:
self.startAIR4()
else:
self.stopAIR4()
def startAIR4(self):
self.setAIR4(True)
def stopAIR4(self):
self.setAIR4(False)
def updateAIR4Seconds(self):
if self.streamTimerMode == 0: #count up mode
self.Air4Seconds += 1
else:
self.Air4Seconds -= 1
if self.Air4Seconds < 1:
self.stopAIR4()
self.radioTimerMode = 0
self.AirLabel_4.setText("Stream\n%d:%02d" % (self.Air4Seconds/60, self.Air4Seconds%60) )
def checkNTPOffset(self):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("NTP")
ntpcheck = settings.value('ntpcheck', True).toBool()
ntpserver = str(settings.value('ntpcheckserver', 'pool.ntp.org').toString())
settings.endGroup()
if not ntpcheck:
return
self.timerNTP.stop()
max_deviation = 0.3
c = ntplib.NTPClient()
try:
response = c.request(ntpserver)
if response.offset > max_deviation or response.offset < -max_deviation:
print "offset too big: %f while checking %s" % (response.offset, ntpserver)
self.showWarning("Clock not NTP synchronized: offset too big")
self.ntpHadWarning = True
else:
if self.ntpHadWarning == True:
self.ntpHadWarning = False
self.hideWarning()
except socket.timeout:
print "timeout checking NTP %s" % ntpserver
self.showWarning("Clock not NTP synchronized")
self.ntpHadWarning = True
except socket.gaierror:
print "error checking NTP %s" % ntpserver
self.showWarning("Clock not NTP synchronized")
self.ntpHadWarning = True
except:
print "general error checking NTP %s" % ntpserver
self.showWarning("Clock not NTP synchronized")
self.ntpHadWarning = True
self.timerNTP.start(60000)
def setLED1(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
settings.beginGroup("LED1")
self.buttonLED1.setStyleSheet("color:"+settings.value('activetextcolor', '#FFFFFF').toString()+";background-color:"+settings.value('activebgcolor', '#FF0000').toString())
settings.endGroup()
self.statusLED1 = True
else:
settings.beginGroup("LEDS")
self.buttonLED1.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusLED1 = False
def setLED2(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
settings.beginGroup("LED2")
self.buttonLED2.setStyleSheet("color:"+settings.value('activetextcolor', '#FFFFFF').toString()+";background-color:"+settings.value('activebgcolor', '#FF0000').toString())
settings.endGroup()
self.statusLED2 = True
else:
settings.beginGroup("LEDS")
self.buttonLED2.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusLED2 = False
def setLED3(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
settings.beginGroup("LED3")
self.buttonLED3.setStyleSheet("color:"+settings.value('activetextcolor', '#FFFFFF').toString()+";background-color:"+settings.value('activebgcolor', '#FF0000').toString())
settings.endGroup()
self.statusLED3 = True
else:
settings.beginGroup("LEDS")
self.buttonLED3.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusLED3 = False
def setLED4(self, action):
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
if action:
settings.beginGroup("LED4")
self.buttonLED4.setStyleSheet("color:"+settings.value('activetextcolor', '#FFFFFF').toString()+";background-color:"+settings.value('activebgcolor', '#FF0000').toString())
settings.endGroup()
self.statusLED4 = True
else:
settings.beginGroup("LEDS")
self.buttonLED4.setStyleSheet("color:"+settings.value('inactivetextcolor', '#555555').toString()+";background-color:"+settings.value('inactivebgcolor', '#222222').toString())
settings.endGroup()
self.statusLED4 = False
def setStation(self, text):
self.labelStation.setText(text)
def setSlogan(self, text):
self.labelSlogan.setText(text)
def setLeftText(self, text):
self.labelTextLeft.setText(text)
def setRightText(self, text):
self.labelTextRight.setText(text)
def setLED1Text(self, text):
self.buttonLED1.setText(text)
def setLED2Text(self, text):
self.buttonLED2.setText(text)
def setLED3Text(self, text):
self.buttonLED3.setText(text)
def setLED4Text(self, text):
self.buttonLED4.setText(text)
def setCurrentSongText(self, text):
self.labelCurrentSong.setText(text)
def setNewsText(self, text):
self.labelNews.setText(text)
def setBacktimingSecs(self, value):
pass
#self.labelSeconds.setText( str(value) )
def showWarning(self, text):
self.labelCurrentSong.hide()
self.labelNews.hide()
self.labelWarning.setText( text )
font = self.labelWarning.font()
font.setPointSize(45)
self.labelWarning.setFont(font)
self.labelWarning.show()
def hideWarning(self):
self.labelWarning.hide()
self.labelCurrentSong.show()
self.labelNews.show()
self.labelWarning.setText( "" )
self.labelWarning.hide()
def exitOAS(self):
global app
app.exit()
def configFinished(self):
self.restoreSettingsFromConfig()
global app
# hide mousecursor if in fullscreen mode
settings = QSettings( QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("General")
if settings.value('fullscreen', 'True').toBool():
app.setOverrideCursor( QCursor( 10 ) );
settings.endGroup()
def reboot_host(self):
self.showWarning( "SYSTEM REBOOT IN PROGRESS" )
if os.name == "posix":
cmd = "sudo reboot"
os.system(cmd)
if os.name == "nt":
cmd = "shutdown -f -r -t 0"
pass
def shutdown_host(self):
self.showWarning( "SYSTEM SHUTDOWN IN PROGRESS" )
if os.name == "posix":
cmd = "sudo halt"
os.system(cmd)
if os.name == "nt":
cmd = "shutdown -f -t 0"
pass
###################################
## App SIGINT handler
###################################
def sigint_handler(*args):
# Handler for SIGINT signal
sys.stderr.write("\n")
QApplication.quit()
###################################
## App Init
###################################
if __name__ == "__main__":
signal.signal(signal.SIGINT, sigint_handler)
app = QApplication(sys.argv)
icon = QIcon()
icon.addPixmap(QPixmap(":/oas_icon/oas_icon.png"), QIcon.Normal, QIcon.Off)
app.setWindowIcon(icon)
timer = QTimer()
timer.start(100)
timer.timeout.connect(lambda: None)
mainscreen = MainScreen()
mainscreen.setWindowIcon(icon)
for i in range(1,5):
mainscreen.ledLogic(i, False)
mainscreen.setAIR1(False)
mainscreen.setAIR2(False)
mainscreen.setAIR3(False)
mainscreen.setAIR4(False)
mainscreen.show()
sys.exit(app.exec_())