-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lightshowpi_show_manager.py
2426 lines (2263 loc) · 131 KB
/
Lightshowpi_show_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
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
#
# Author: Christian Pizzi
# Ver. 1.0
# Software needed:
# LightShowPi ver. (1.4) Python3
# Remi ver. 2020.8.6
import remi.gui as gui
from remi.gui import *
from remi import *
from remi import start, App
import os
from pathlib import Path
import time
import datetime
import copy
import shutil
from random import randint
class MyFileFolderNavigator(gui.FileFolderNavigator):
"""FileFolderNavigator widget."""
def __init__(self, multiple_selection, selection_folder, allow_file_selection, allow_folder_selection, **kwargs):
super(MyFileFolderNavigator, self).__init__(multiple_selection, selection_folder, allow_file_selection, allow_folder_selection,**kwargs)
def on_folder_item_selected(self, folderitem):
if not folderitem.isFolder:
self.on_file_selected(folderitem.get_text())
super(MyFileFolderNavigator, self).on_folder_item_selected(folderitem)
@gui.decorate_event
def on_file_selected(self, filename):
return (filename, )
class MyFileSelectionDialog(gui.FileSelectionDialog):
"""file selection dialog, it opens a new webpage allows the OK/CANCEL functionality
implementing the "confirm_value" and "cancel_dialog" events."""
def __init__(self, title='File dialog', message='Select files and folders',
multiple_selection=True, selection_folder='.',
allow_file_selection=True, allow_folder_selection=True, **kwargs):
super(MyFileSelectionDialog, self).__init__(title, message, **kwargs)
self.style['width'] = '475px'
self.fileFolderNavigator = MyFileFolderNavigator(multiple_selection, selection_folder,
allow_file_selection,
allow_folder_selection)
self.add_field('fileFolderNavigator', self.fileFolderNavigator)
self.confirm_dialog.do(self.confirm_value)
@gui.decorate_set_on_listener("(self, emitter, fileList)")
@gui.decorate_event
def confirm_value(self, widget):
"""event called pressing on OK button.
propagates the string content of the input field
"""
self.hide()
params = (self.fileFolderNavigator.get_selection_list(),)
return params
class EditorFileSaveDialog(MyFileSelectionDialog, EventSource):
def __init__(self, title='File dialog', message='Select files and folders',
multiple_selection=True, selection_folder='.',
allow_file_selection=True, allow_folder_selection=True, baseAppInstance = None):
super(EditorFileSaveDialog, self).__init__( title, message, multiple_selection, selection_folder,
allow_file_selection, allow_folder_selection)
EventSource.__init__(self)
self.baseAppInstance = baseAppInstance
self.fileFolderNavigator.on_file_selected.do(self.on_file_selection)
def show(self, *args):
super(EditorFileSaveDialog, self).show(self.baseAppInstance)
def add_fileinput_field(self, defaultname='untitled'):
self.txtFilename = gui.TextInput()
## self.txtFilename.onchange.do(self.on_enter_key_pressed)
self.txtFilename.set_text(defaultname)
self.add_field_with_label("filename","Filename",self.txtFilename)
def get_fileinput_value(self):
return self.get_field('filename').get_value()
## def on_enter_key_pressed(self, widget, value):
## self.confirm_value(None)
@gui.decorate_event
def confirm_value(self, widget):
"""event called pressing on OK button.
propagates the string content of the input field
"""
self.hide()
params = (self.fileFolderNavigator.pathEditor.get_text(),)
appo = self.get_fileinput_value()
temp = params[0] + '/' + appo
params = (temp, )
return params
def on_file_selection(self, emitter, filename):
pathInput = self.get_field('filename')
## print("on_file_selection")
if pathInput:
pathInput.set_text(filename)
class MyApp(App):
version = 'Ver. 1.3' #Version of this app used in first page
LightShowPiFolder = '' #LightShowPi folder location
LightShowPiOverrides = '' #LightShowPi Override.cfg file location - can be removed in future
LightShowPiPy = '' #LightShowPi /py folder program used for light show
LightShowPiConfig = '' #LightShowPi config folder location
LightShowPiMusic = '' #Music folder location
LightShowPiShow = '' #Show folder location .cfg or .py
# LightShowPiList = ''
Default_cfg = '' #point to default.cfg
PlayON = False #True if music is ON
PlayNum = 0 #Number of song currently played
PlayNumSelected = '' #Number of the selected song in the list
# PlaySelected = ''
PlayNumMax = 0 #Total number of songs in play list
PlayLoop = 0 #Loop active
PlayRandom = 0 #Random active
NoConfig = 0 #Used if config files are not find when loaded from a saved file
VolumeDef = 75 #Default volume
VolumeOn = 1 #Active if volume is ON
Volume = VolumeDef #Current volume variable
AlsaDevice = "Headphone" #NAME OF YOUR SOUNDCARD OUTPUT !!!!!!!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!!!!!
SchedFileName = '' #Used to store the Scheduler file name
SchedOn = False #True if schedule is ON
DaySched = 0 #Day of the week 1 thru 7 - Mon thru Sun
TimeRange = [] #Time for Sched to turn On and Off the music, set it 00:00 - 00:00
TimeRange.append('00:00')
TimeRange.append('00:00')
TimeIn = False #Used to check if the time is in an active range for the scheduler
logo_sched = gui.Image('/res:sched_off.png', width='30px') #scheduler logo
ConfigList = [] #List of all Config files
SongListDict = {} #dictionary of: integer + song files
SongList = {} #temporari variable to manage visualization of songs list
ListList = {} #dictionary of: song file + config file or NONE
PlayList = {} #copy of ListList used for the Player
SchedList = {} #Scheduler list complete
SchedToday = {} #Scheduler for today
SchedNow = [] #Active scheduler
file_types = [".wav", ".WAV",
".mp1", ".mp2", ".mp3", ".mp4", ".m4a", ".m4b",
".ogg", ".flac", ".oga", ".wma", ".wmv", ".aif"]
file_types_all = [".wav", ".WAV",
".mp1", ".mp2", ".mp3", ".mp4", ".m4a", ".m4b",
".ogg", ".flac", ".oga", ".wma", ".wmv", ".aif",
".cfg"]
# keep here for future version when will be possible pass .py file as parameter
## file_types_all = [".wav", ".WAV",
## ".mp1", ".mp2", ".mp3", ".mp4", ".m4a", ".m4b",
## ".ogg", ".flac", ".oga", ".wma", ".wmv", ".aif",
## ".py", ".cfg"]
#---Used for time simulation---
# TimeStart = datetime.datetime.now()
# print('TimeStart: ', TimeStart)
# TimeStartUp = datetime.datetime.strptime('23:57', "%H:%M")
# print('TimeStartUp: ', TimeStartUp)
def __init__(self, *args):
res_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res')
# res_path = os.path.join(os.getcwd(), 'res')
super(MyApp, self).__init__(*args, static_file_path={'res':res_path})
#idle: check and run the Scheduler and the Player
def idle(self):
#---Time simulator for test purpose---
# TimeNow = datetime.datetime.now()
# TimeDelta = TimeNow - self.TimeStart
# xt = self.TimeStartUp + TimeDelta * 5
# xt = xt.time()
# # print('xt: ', xt)
# xt = str(xt)
# x = xt.split('.')
# TimeSimul = x[0][:5]
# # print('TimeSimul: ', TimeSimul)
#Check if Scheduler is active. If it is active check if the music should start or stop
if self.SchedOn:
DayToday = datetime.datetime.today().weekday()
DayToday += 1
if DayToday == self.DaySched:
#Used for simulation
# TimeNow = TimeSimul
TimeNow = datetime.datetime.now().strftime('%H:%M')
if not (self.TimeRange[0]=='00:00' and self.TimeRange[1]=='00:00'):
if not ((TimeNow >= self.TimeRange[0]) and (TimeNow < self.TimeRange[1])):
self.TimeIn = False
self.TimeRange[0] = '00:00'
self.TimeRange[1] = '00:00'
self.stop_sched_music()
else:
self.TimeIn = False
if len(self.SchedToday):
for x in self.SchedToday:
appo = self.SchedToday[x]
Time1 = appo[0]
Time2 = appo[1]
if (TimeNow >= Time1) and (TimeNow < Time2):
self.SchedNow = appo
self.TimeRange[0] = Time1
self.TimeRange[1] = Time2
self.start_sched_music()
break
else:
self.stop_sched_music()
self.update_today_list()
# if the music is playing, it checks random and loop to choose what to do with the next song or turn the music off
if self.PlayON:
if not self.t.is_alive():
if self.PlayNum < self.PlayNumMax or self.PlayRandom == 1:
if self.PlayRandom == 0:
self.PlayNum = self.PlayNum + 1
else:
self.PlayNum = randint(1, self.PlayNumMax)
self.playSong(self.PlayNum)
elif self.PlayLoop == 1 and self.PlayNum >= self.PlayNumMax:
self.PlayNum = 0
elif self.PlayLoop == 0 and self.PlayNum >= self.PlayNumMax:
self.PlayS.children['lblPlaySDesc'].set_text('MUSIC OFF')
self.PlayS.children['widBtPlayS'].children['btPlaySLoad'].set_text('PLAY')
self.PlayON = False
def main(self):
self.configlistselected = ''
self.songlistselected = ''
self.listlistselected = ''
self.playlistselected = ''
self.schedulerlistselected = ''
# MAIN CONTAINER -----------------------
self.DisplayPage = gui.Container(width='482px', height='672px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'display':'block', 'overflow':'hidden'})
# MENU page ---------------------------------------------------------------------
Menu = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
#Menu bar used in any page
self.widTitle = gui.Container(width='100%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='10px auto')
self.widTitle.style.update({'display':'inline'})
# btMenu = gui.Menu(width='80px', height='30px', style={'position':'relative', 'top':'10px', 'left':'10px', 'display':'inline'})
btMenu = gui.Menu(width='80px', height='30px', style={'position':'relative', 'top':'10px', 'left':'10px', 'display':'inline', 'margin':'0px'})
btmenu = gui.MenuItem('MENU', width='100%', height='100%', style={'line-height':'30px'})
btsettings = gui.MenuItem('SETTINGS', width='170px', height='30px', style={'line-height':'30px'})
btsettings.onclick.do(self.set_page, 'Settings')
btconfig = gui.MenuItem('CONFIG FILES', width='100%', height='30px', style={'line-height':'30px'})
btconfig.onclick.do(self.set_page, 'Config')
btsong = gui.MenuItem('MUSIC LIST', width='100%', height='30px', style={'line-height':'30px'})
btsong.onclick.do(self.set_page, 'Song')
btlist = gui.MenuItem('FINAL MUSIC LIST', width='100%', height='30px', style={'line-height':'30px'})
btlist.onclick.do(self.set_page, 'List')
btplay = gui.MenuItem('PLAY FILES', width='100%', height='30px', style={'line-height':'30px'})
btplay.onclick.do(self.set_page, 'Play')
btsched = gui.MenuItem('SCHEDULER', width='100%', height='30px', style={'line-height':'30px'})
btsched.onclick.do(self.set_page, 'Sched')
btsave = gui.MenuItem('SAVE / LOAD', width='100%', height='30px', style={'line-height':'30px'})
btsave.onclick.do(self.set_page, 'Save')
btquit = gui.MenuItem('QUIT', width='100%', height='30px', style={'line-height':'30px'})
btquit.onclick.do(self.set_page, 'Quit')
btshutdown = gui.MenuItem('SHUTDOWN PI', width='100%', height='30px', style={'line-height':'30px'})
btshutdown.onclick.do(self.set_page, 'Shutdown')
btmenu.append([btsettings, btconfig, btsong, btlist, btplay, btsched, btsave, btquit, btshutdown])
btMenu.append(btmenu)
self.lbl = gui.Label('LIGHTSHOWPI', width='300px', style={'position':'relative', 'top':'10px', 'left':'10px', 'font-size':'25px', 'font-weight':'bold', 'letter-spacing':'1px'})
logo1 = gui.Image('/res:logo30x30.png', width='30px')
logo1.style.update({'position':'relative', 'top':'7px', 'left':'32px'})
self.logo_sched.style.update({'position':'relative', 'top':'7px', 'left':'30px'})
self.widTitle.append([btMenu, self.lbl, self.logo_sched, logo1])
widVersion = gui.Container(width='100%', height='300px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='40px auto 0px')
lbl1 = gui.Label('LIGHTSHOWPI', width='100%', height='40px', margin='200px auto 0px', style={'font-size':'40px', 'font-weight':'bold', 'letter-spacing':'1px'})
lbl2 = gui.Label('SHOW', width='100%', height='40px', margin='20px auto 0px', style={'font-size':'40px', 'font-weight':'bold', 'letter-spacing':'1px'})
lbl3 = gui.Label('MANAGER', width='100%', height='40px', margin='20px auto 0px', style={'font-size':'40px', 'font-weight':'bold', 'letter-spacing':'1px'})
lbl4 = gui.Label(self.version, width='100%', height='30px', margin='20px auto 0px', style={'font-size':'30px', 'font-weight':'bold', 'letter-spacing':'1px'})
widVersion.append([lbl1, lbl2, lbl3, lbl4])
Menu.append(widVersion)
# SETTINGS page ---------------------------------------------------------
Settings = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
FolderLSP = gui.Label('LightShowPi folder - REQUIRED -', width='100%', height='30px', style={'margin':'70px 20px 0px', 'font-style':'italic', 'text-align':'left'})
widFolderLSP = gui.Container(width='100%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='10px auto')
widFolderLSP.style.update({'display':'inline'})
self.FolderLSP = gui.Label('/home/pi/lightshowpi', width='350px', height='30px', margin='0px 0px 0px 10px', style={'padding-left':'5px', 'font-size':'14px', 'text-align':'left', 'line-height':'2', 'border':'1px solid silver', 'border-radius':'5px'})
p = Path('/home/pi/lightshowpi')
if p.exists():
self.FolderLSP.set_text('/home/pi/lightshowpi')
self.LightShowPiFolder = Path('/home/pi/lightshowpi')
self.LightShowPiOverrides = Path(str(self.LightShowPiFolder.absolute())+'/config')
self.LightShowPiPy = Path(str(self.LightShowPiFolder.absolute())+'/py')
else:
self.FolderLSP.set_text('LightShowPi folder not defined')
self.btFolderLSP = gui.Button("Search", width='80px', height='30px', style={'position':'relative', 'top':'0px', 'right':'-25px', 'display':'inline'})
self.btFolderLSP.onclick.do(self.open_fileselection_dialog, 'Select LightShowPi folder', False, False, True, 'FolderLSP')
widFolderLSP.append([self.FolderLSP, self.btFolderLSP])
Settings.append([FolderLSP, widFolderLSP])
FolderConfig = gui.Label('Config file folder', width='100%', height='30px', style={'margin':'60px 20px 0px', 'font-style':'italic', 'text-align':'left'})
widFolderConfig = gui.Container(width='100%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='10px auto')
widFolderConfig.style.update({'display':'inline'})
self.FolderConfig = gui.Label('/home/pi/lightshowpi', width='350px', height='30px', margin='0px 0px 0px 10px', style={'padding-left':'5px', 'font-size':'14px', 'text-align':'left', 'line-height':'2', 'border':'1px solid silver', 'border-radius':'5px'})
p = Path('/home/pi/lightshowpi/config')
if p.exists():
self.FolderConfig.set_text('/home/pi/lightshowpi/config')
self.LightShowPiConfig = Path('/home/pi/lightshowpi/config')
else:
self.FolderConfig.set_text('Config folder not defined')
self.btFolderConfig = gui.Button("Search", width='80px', height='30px', style={'position':'relative', 'top':'0px', 'right':'-25px', 'display':'inline'})
self.btFolderConfig.onclick.do(self.open_fileselection_dialog, 'Select Config file folder', False, False, True, 'FolderConfig')
widFolderConfig.append([self.FolderConfig, self.btFolderConfig])
Settings.append([FolderConfig, widFolderConfig])
FolderMusic = gui.Label('Music folder', width='100%', height='30px', style={'margin':'60px 20px 0px', 'font-style':'italic', 'text-align':'left'})
widFolderMusic = gui.Container(width='100%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='10px auto')
widFolderMusic.style.update({'display':'inline'})
self.FolderMusic = gui.Label('', width='350px', height='30px', margin='0px 0px 0px 10px', style={'padding-left':'5px', 'font-size':'14px', 'text-align':'left', 'line-height':'2', 'border':'1px solid silver', 'border-radius':'5px'})
p = Path('/home/pi/lightshowpi/music')
if p.exists():
self.FolderMusic.set_text('/home/pi/lightshowpi/music')
self.LightShowPiMusic = Path('/home/pi/lightshowpi/music')
else:
self.FolderMusic.set_text('Music folder not defined')
self.btFolderMusic = gui.Button("Search", width='80px', height='30px', style={'position':'relative', 'top':'0px', 'right':'-25px', 'display':'inline'})
self.btFolderMusic.onclick.do(self.open_fileselection_dialog, 'Select Music file folder', False, False, True, 'FolderMusic')
widFolderMusic.append([self.FolderMusic, self.btFolderMusic])
Settings.append([FolderMusic, widFolderMusic])
FolderShow = gui.Label('Shows ".cfg" folder', width='100%', height='30px', style={'margin':'60px 20px 0px', 'font-style':'italic', 'text-align':'left'})
widFolderShow = gui.Container(width='100%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='10px auto')
widFolderShow.style.update({'display':'inline'})
self.FolderShow = gui.Label('', width='350px', height='30px', margin='0px 0px 0px 10px', style={'padding-left':'5px', 'font-size':'14px', 'text-align':'left', 'line-height':'2', 'border':'1px solid silver', 'border-radius':'5px'})
## p = Path('/home/pi/lightshowpi/music')
## if p.exists():
## self.FolderShow.set_text('/home/pi/lightshowpi/music')
## self.LightShowPiShow = Path('/home/pi/lightshowpi/music')
## else:
## self.FolderShow.set_text('Shows folder not defined')
self.FolderShow.set_text('Shows folder not defined')
self.btFolderShow = gui.Button("Search", width='80px', height='30px', style={'position':'relative', 'top':'0px', 'right':'-25px', 'display':'inline'})
self.btFolderShow.onclick.do(self.open_fileselection_dialog, 'Select Shows file folder', False, False, True, 'FolderShow')
widFolderShow.append([self.FolderShow, self.btFolderShow])
Settings.append([FolderShow, widFolderShow])
self.btFolderLoad = gui.Button("Load all configs / songs / shows now", width='350px', height='30px', margin='50px auto 0px')
self.btFolderLoad.onclick.do(self.settings_load)
Settings.append(self.btFolderLoad)
AlsaDev = gui.Label('ALSA Soundcard name', width='100%', height='30px', style={'margin':'40px 20px 0px', 'font-style':'italic', 'text-align':'left'})
widAlsaDev = gui.Container(width='100%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='10px auto')
widAlsaDev.style.update({'display':'inline'})
self.AlsaDev = gui.TextInput(width='350px', height='30px', margin='0px 0px 0px 10px', style={'padding-left':'5px', 'font-size':'14px', 'text-align':'left', 'line-height':'2', 'border':'1px solid silver', 'border-radius':'5px'})
self.AlsaDev.set_text('Headphone')
self.btAlsaDev = gui.Button("Set", width='80px', height='30px', style={'position':'relative', 'top':'0px', 'right':'-25px', 'display':'inline'})
self.btAlsaDev.onclick.do(self.alsa_dev_set)
widAlsaDev.append([self.AlsaDev, self.btAlsaDev])
Settings.append([AlsaDev, widAlsaDev])
# CONFIG page ---------------------------------------------------------
Config = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
lblConfigDesc = gui.Label('The first config file in the list is the "default" one.', width='100%', style={'margin':'60px auto 0px', 'font-size':'20px', 'font-style':'italic'})
Config.append(lblConfigDesc)
self.listConfig = gui.ListView.new_from_list(self.ConfigList, width='460px', height='500px', margin='20px auto 0px')
self.listConfig.onselection.do(self.list_selected, 'config')
Config.append(self.listConfig, 'listConfig')
widBtConfig = gui.Container(width='100%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='10px auto')
widBtConfig.style.update({'display':'inline'})
btConfigLoad = gui.Button("Load", width='85px', height='30px', style={'margin':'15px 5px'})
btConfigLoad.onclick.do(self.open_fileselection_dialog, 'Select config files', True, True, False, 'ConfigLoad')
btConfigDefault = gui.Button("Default", width='85px', height='30px', style={'margin':'15px 5px'})
btConfigDefault.onclick.do(self.config_default)
btConfigRemove = gui.Button("Remove", width='85px', height='30px', style={'margin':'15px 5px'})
btConfigRemove.onclick.do(self.config_remove)
btConfigClear = gui.Button("Clear list", width='85px', height='30px', style={'margin':'15px 5px'})
btConfigClear.onclick.do(self.config_clear)
Config.append([btConfigLoad, btConfigDefault, btConfigRemove, btConfigClear])
# Songs page ---------------------------------------------------------
Song = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
self.listSong = gui.ListView.new_from_list(self.SongList, width='460px', height='560px', margin='50px auto 0px')
self.listSong.onselection.do(self.list_selected, 'song')
Song.append(self.listSong, 'listSong')
btSongLoad = gui.Button("Load", width='70px', height='30px', style={'margin':'15px 4px'})
btSongLoad.onclick.do(self.open_fileselection_dialog, 'Select song files', True, True, False, 'SongLoad')
btSongDup = gui.Button("Dup", width='70px', height='30px', style={'margin':'15px 4px'})
btSongDup.onclick.do(self.song_dup)
btSongUp = gui.Button("Up", width='70px', height='30px', style={'margin':'15px 4px'})
btSongUp.onclick.do(self.song_up)
btSongDn = gui.Button("Down", width='70px', height='30px', style={'margin':'15px 4px'})
btSongDn.onclick.do(self.song_dn)
btSongDel = gui.Button("Del", width='70px', height='30px', style={'margin':'15px 4px'})
btSongDel.onclick.do(self.song_del)
btSongClear = gui.Button("Clear", width='70px', height='30px', style={'margin':'15px 4px'})
btSongClear.onclick.do(self.song_clear)
Song.append([btSongLoad, btSongDup, btSongUp, btSongDn, btSongDel, btSongClear])
# Final list page ---------------------------------------------------------
List = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
self.listList = gui.ListView.new_from_list(self.ListList, width='460px', height='560px', margin='50px auto 0px')
self.listList.onselection.do(self.list_selected, 'list')
List.append(self.listList, 'listList')
btListUpdate = gui.Button("Update list", width='170px', height='30px', style={'margin':'15px 4px'})
btListUpdate.onclick.do(self.list_update)
btListGenerate = gui.Button("Generate play list", width='170px', height='30px', style={'margin':'15px 4px'})
btListGenerate.onclick.do(self.list_generate)
List.append([btListUpdate, btListGenerate])
# PLAY page ---------------------------------------------------------
PlayS = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
lblPlaySDesc = gui.Label('MUSIC OFF', width='100%', style={'margin':'60px auto 0px', 'font-size':'20px', 'font-style':'italic'})
PlayS.append(lblPlaySDesc, 'lblPlaySDesc')
self.listPlayS = gui.ListView.new_from_list('', width='460px', height='450px', margin='20px auto 0px')
self.listPlayS.onselection.do(self.list_selected, 'playS')
PlayS.append(self.listPlayS, 'listPlayS')
self.widBtPlayS = gui.Container(width='98%', height='40px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL)
self.widBtPlayS.style.update({'margin':'10px auto 0px'})
self.btPlaySVolumeM = gui.Button("Vol -", width='60px', height='30px', style={'margin':'5px 5px 0px 50px'})
self.btPlaySVolumeM.onclick.do(self.playS_volumeM)
self.btPlaySPrev = gui.Button("PRV", width='60px', height='30px', style={'margin':'5px 5px 0px'})
self.btPlaySPrev.onclick.do(self.playSprev_dialog)
self.btPlaySLoad = gui.Button("PLAY", width='85px', height='40px', style={'margin':'0px 5px 0px'})
self.btPlaySLoad.onclick.do(self.playS_dialog)
self.btPlaySNext = gui.Button("NXT", width='60px', height='30px', style={'margin':'5px 5px 0px'})
self.btPlaySNext.style.update({'display':'block'})
self.btPlaySNext.onclick.do(self.playSnext_dialog)
self.btPlaySVolumeP = gui.Button("Vol +", width='60px', height='30px', style={'margin':'5px 5px 0px'})
self.btPlaySVolumeP.onclick.do(self.playS_volumeP)
self.widBtPlayS.append(self.btPlaySVolumeM)
self.widBtPlayS.append(self.btPlaySPrev)
self.widBtPlayS.append(self.btPlaySLoad, 'btPlaySLoad')
self.widBtPlayS.append(self.btPlaySNext)
self.widBtPlayS.append(self.btPlaySVolumeP)
PlayS.append(self.widBtPlayS, 'widBtPlayS')
self.widBtPlayS2 = gui.Container(width='98%', height='30px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL)
self.widBtPlayS2.style.update({'margin':'10px auto 0px'})
if self.Volume != 0:
volnum = 'Vol ' + str(self.Volume) + ('%')
else:
volnum = 'Vol OFF'
self.btPlaySVolumeOn = gui.Button(volnum, width='80px', height='30px', style={'margin':'0px 5px 0px'})
self.btPlaySVolumeOn.onclick.do(self.playS_volumeOn)
self.btPlaySelect = gui.Button("Play selected", width='130px', height='30px', style={'margin':'0px 5px 0px'})
self.btPlaySelect.onclick.do(self.playSelect_dialog)
self.btPlaySLoop = gui.Button("Loop OFF", width='90px', height='30px', style={'margin':'0px 5px 0px'})
self.btPlaySLoop.onclick.do(self.playSloop_dialog)
self.btPlaySRand = gui.Button("Random OFF", width='130px', height='30px', style={'margin':'0px 5px 0px'})
self.btPlaySRand.onclick.do(self.playSrand_dialog)
self.widBtPlayS2.append(self.btPlaySVolumeOn, 'btPlaySVolumeOn')
self.widBtPlayS2.append(self.btPlaySelect, 'btPlaySelect')
self.widBtPlayS2.append(self.btPlaySLoop, 'btPlaySLoop')
self.widBtPlayS2.append(self.btPlaySRand, 'btPlaySRand')
PlayS.append(self.widBtPlayS2, 'widBtPlayS2')
# SCHEDULER page ---------------------------------------------------------
Scheduler = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
self.listSched = gui.ListView.new_from_list(self.SchedList, width='460px', height='560px', margin='50px auto 0px')
self.listSched.onselection.do(self.list_selected, 'sched')
Scheduler.append(self.listSched, 'listSched')
btSchedAdd = gui.Button("Add", width='85px', height='30px', style={'margin':'15px 5px'})
btSchedAdd.onclick.do(self.add_sched)
btSchedEdit = gui.Button("Edit", width='85px', height='30px', style={'margin':'15px 5px'})
btSchedEdit.onclick.do(self.edit_sched)
btSchedRemove = gui.Button("Remove", width='85px', height='30px', style={'margin':'15px 5px'})
btSchedRemove.onclick.do(self.scheduler_del)
btSchedClear = gui.Button("Clear list", width='85px', height='30px', style={'margin':'15px 5px'})
btSchedClear.onclick.do(self.sched_clear)
self.btSchedActive = gui.Button("Turn ON", width='85px', height='30px', style={'margin':'15px 5px'})
self.btSchedActive.onclick.do(self.sched_active)
Scheduler.append([btSchedAdd, btSchedEdit, btSchedRemove, btSchedClear, self.btSchedActive])
# SAVE page ---------------------------------------------------------------------
Save = gui.Container(width='480px', height='670px', layout_orientation=gui.Container.LAYOUT_VERTICAL, margin='0px auto', style={'border':'1px solid black', 'border-radius':'10px'})
btSaveS = gui.Button("SAVE SHOW FORMAT", width='240px', height='40px', style={'margin':'60px auto 0px', 'display':'block'})
self.fileSaveAsDialog = EditorFileSaveDialog('Show Save', 'Select the project folder and type a filename', False, '.', True, False, self)
self.fileSaveAsDialog.add_fileinput_field('show.shw')
#self.fileSaveAsDialog.fileFolderNavigator.controlBack.set_size('10%', '100%')
#self.fileSaveAsDialog.fileFolderNavigator.controlGo.set_size('15%', '100%')
#self.fileSaveAsDialog.fileFolderNavigator.pathEditor.set_size('75%', '100%')
self.fileSaveAsDialog.fileFolderNavigator.controlBack.style.update({'height':'30px', 'font-size':'15px'})
self.fileSaveAsDialog.fileFolderNavigator.controlGo.style.update({'height':'30px', 'font-size':'12px'})
self.fileSaveAsDialog.fileFolderNavigator.pathEditor.style.update({'padding-left':'5px', 'font-size':'12px', 'line-height':'2'})
self.fileSaveAsDialog.fileFolderNavigator.itemContainer.style.update({'font-size':'20px'})
self.fileSaveAsDialog.fileFolderNavigator.style.update({'width':'100%'})
self.fileSaveAsDialog.confirm_value.do(self.on_saveas_dialog_confirm)
btSaveS.onclick.do(self.fileSaveAsDialog.show)
btLoadS = gui.Button("LOAD SHOW FORMAT", width='240px', height='40px', style={'margin':'20px auto 0px', 'display':'block'})
btLoadS.onclick.do(self.open_fileselection_dialog, 'Select file to load', False, True, False, 'LoadS')
btSaveSched = gui.Button("SAVE SCHEDULE", width='240px', height='40px', style={'margin':'40px auto 0px', 'display':'block'})
self.schedSaveAsDialog = EditorFileSaveDialog('Schedule Save', 'Select the project folder and type a filename', False, '.', True, False, self)
self.schedSaveAsDialog.add_fileinput_field('schedule.sch')
#self.schedSaveAsDialog.fileFolderNavigator.controlBack.set_size('10%', '100%')
#self.schedSaveAsDialog.fileFolderNavigator.controlGo.set_size('15%', '100%')
#self.schedSaveAsDialog.fileFolderNavigator.pathEditor.set_size('75%', '100%')
self.schedSaveAsDialog.fileFolderNavigator.controlBack.style.update({'height':'30px', 'font-size':'15px'})
self.schedSaveAsDialog.fileFolderNavigator.controlGo.style.update({'height':'30px', 'font-size':'12px'})
self.schedSaveAsDialog.fileFolderNavigator.pathEditor.style.update({'padding-left':'5px', 'font-size':'12px', 'line-height':'2'})
self.schedSaveAsDialog.fileFolderNavigator.itemContainer.style.update({'font-size':'20px'})
self.schedSaveAsDialog.fileFolderNavigator.style.update({'width':'100%'})
self.schedSaveAsDialog.confirm_value.do(self.sched_saveas_dialog_confirm)
btSaveSched.onclick.do(self.schedSaveAsDialog.show)
btLoadSched = gui.Button("LOAD SCHEDULE", width='240px', height='40px', style={'margin':'20px auto 0px', 'display':'block'})
btLoadSched.onclick.do(self.open_fileselection_dialog, 'Select schedule file to load', False, True, False, 'LoadSched')
btRemSpace = gui.Button("REMOVE SPECIAL CHARACTERS", width='320px', height='40px', style={'margin':'60px auto 0px', 'display':'block'})
btRemSpace.onclick.do(self.open_fileselection_dialog, 'Select files or folder', True, True, True, 'RemSpace')
Save.append(btSaveS)
Save.append(btLoadS)
Save.append(btSaveSched)
Save.append(btLoadSched)
Save.append(btRemSpace)
# ---------------------------------------------------------------------
self.Menu = Menu
self.Settings = Settings
self.Config = Config
self.Song = Song
self.List = List
self.PlayS = PlayS
self.Save = Save
self.Scheduler = Scheduler
self.DisplayPage.append(self.widTitle, 'MenuBar')
self.DisplayPage.append(self.Menu, 'pgMenu')
return self.DisplayPage
# Used to display the right page
def set_page(self, emitter, name):
page = self.DisplayPage.children.keys()
# print('Page: ', page)
appo = []
for x in page:
appo.append(x)
if name == 'Menu':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.Menu,'pgMenu')
elif name == 'Settings':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.Settings,'pgSettings')
self.lbl.set_text('SETTINGS')
elif name == 'Config':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.Config,'pgConfig')
self.lbl.set_text('CONFIG FILES')
elif name == 'Song':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.Song,'pgSong')
self.lbl.set_text('MUSIC LIST')
elif name == 'List':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.List,'pgList')
self.lbl.set_text('FINAL MUSIC LIST')
elif name == 'Play':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.PlayS,'pgPlayS')
self.lbl.set_text('PLAY FILES')
self.play_list_update()
elif name == 'Sched':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.Scheduler,'pgSched')
self.lbl.set_text('SCHEDULER')
elif name == 'Save':
self.DisplayPage.remove_child(self.DisplayPage.children[appo[1]])
self.DisplayPage.append(self.Save,'pgSave')
self.lbl.set_text('SAVE / LOAD')
elif name == 'Quit':
self.dialogquit = gui.GenericDialog(title='QUIT', message='Do you want to quit?', width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialogquit.conf.style.update({'margin-right':'100px', 'width':'100px'})
self.dialogquit.confirm_dialog.do(self.quit_confirm)
self.dialogquit.show(self)
elif name == 'Shutdown':
self.dialogshutdown = gui.GenericDialog(title='SHUTDOWN PI', message='Do you want to shutdown the PI?', width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialogshutdown.conf.style.update({'margin-right':'100px', 'width':'100px'})
self.dialogshutdown.confirm_dialog.do(self.shutdown_confirm)
self.dialogshutdown.show(self)
def quit_confirm(self, widget):
if self.PlayON:
os_string = 'sudo kill `pgrep -f lightshowpi`'
self.p = threading.Thread(target=self.sys_thread, args=(os_string,), daemon=True)
self.p.start()
self.PlayON = False
time.sleep(0.5)
self.close()
def shutdown_confirm(self, widget):
if self.PlayON:
os_string = 'sudo kill `pgrep -f lightshowpi`'
self.p = threading.Thread(target=self.sys_thread, args=(os_string,), daemon=True)
self.p.start()
self.PlayON = False
time.sleep(0.5)
os_string = 'sudo shutdown -h now'
self.sys_thread(os_string)
# print ("OUT")
# Open the file manager to select folders or files
# Parameters references:
##(self, title='File dialog', message='Select files and folders',
## multiple_selection=True, selection_folder='.',
##allow_file_selection=True, allow_folder_selection=True, **kwargs):
## (self.open_fileselection_dialog, 'Select LightShowPi folder', False, True, 'FolderLSP')
def open_fileselection_dialog(self, widget, message, mult_select, file_select, fold_select, chiamata):
self.fileselectionDialog = gui.FileSelectionDialog('Selection dialog', message, mult_select, '.', file_select, fold_select)
#self.fileselectionDialog.fileFolderNavigator.controlBack.set_size('10%', '100%')
#self.fileselectionDialog.fileFolderNavigator.controlGo.set_size('15%', '100%')
#self.fileselectionDialog.fileFolderNavigator.pathEditor.set_size('75%', '100%')
self.fileselectionDialog.fileFolderNavigator.controlBack.style.update({'height':'30px', 'font-size':'15px'})
self.fileselectionDialog.fileFolderNavigator.controlGo.style.update({'height':'30px', 'font-size':'12px'})
self.fileselectionDialog.fileFolderNavigator.pathEditor.style.update({'padding-left':'5px', 'font-size':'14px', 'line-height':'2'})
self.fileselectionDialog.confirm_value.do(self.on_fileselection_dialog_confirm, chiamata)
# here is returned the Input Dialog widget, and it will be shown
self.fileselectionDialog.show(self)
# Return file or directories selected, based on who called the file manager it checks different things
def on_fileselection_dialog_confirm(self, widget, filelist, chiamata):
if len(filelist):
# SETTINGS MENU CALLS
if chiamata == 'FolderLSP':
self.LightShowPiFolder = Path(filelist[0])
# Check if LightShowPi is a good folder with /config and /py folders
appo = Path(str(self.LightShowPiFolder.absolute())+'/config')
if appo.exists():
self.LightShowPiOverrides = appo
else:
self.LightShowPiOverrides = []
appo = Path(str(self.LightShowPiFolder.absolute())+'/py')
if appo.exists():
self.LightShowPiPy = appo
else:
self.LightShowPiPy = []
if self.LightShowPiOverrides == []:
msg = 'LightShowPi folder "../config" not found'
self.dialog = gui.GenericDialog(title='ERROR', message=msg, width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialog.cancel.style['display'] = 'none'
self.dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
self.dialog.show(self)
self.FolderLSP.set_text('LightShowPi folder not valid')
self.LightShowPiFolder = []
elif self.LightShowPiPy == []:
msg = 'LightShowPi folder "../py" not found'
self.dialog = gui.GenericDialog(title='ERROR', message=msg, width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialog.cancel.style['display'] = 'none'
self.dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
self.dialog.show(self)
self.FolderLSP.set_text('LightShowPi folder not valid')
self.LightShowPiFolder = []
else:
name = str(self.LightShowPiFolder.absolute())
name = MyApp.cut_name(name)
self.FolderLSP.set_text(name)
elif chiamata == 'FolderConfig':
self.LightShowPiConfig = Path(filelist[0])
name = str(self.LightShowPiConfig.absolute())
name = MyApp.cut_name(name)
self.FolderConfig.set_text(name)
elif chiamata == 'FolderMusic':
self.LightShowPiMusic = Path(filelist[0])
name = str(self.LightShowPiMusic.absolute())
name = MyApp.cut_name(name)
self.FolderMusic.set_text(name)
elif chiamata == 'FolderShow':
self.LightShowPiShow = Path(filelist[0])
name = str(self.LightShowPiShow.absolute())
name = MyApp.cut_name(name)
self.FolderShow.set_text(name)
# CONFIG - add selected .cfg file in config list if not already there
elif chiamata == 'ConfigLoad':
for y in filelist:
y = Path(y)
if y.suffix == ".cfg":
found = 0
for x in self.ConfigList:
if y.name == x.name:
found = 1
if not found:
self.ConfigList.append(y)
appo = []
appo = self.fill_list(self.ConfigList)
self.Config.children['listConfig'].empty()
self.Config.children['listConfig'].append(appo)
# SONG - add selected songs in song list, allow duplicate
elif chiamata == 'SongLoad':
for y in filelist:
y = Path(y)
if y.suffix in self.file_types_all:
key = self.song_key(self.SongListDict)
self.SongListDict[key] = y
self.SongList = {}
for z in self.SongListDict:
temp = self.SongListDict[z]
self.SongList[int(z)] = str(temp.name)
self.Song.children['listSong'].empty()
self.Song.children['listSong'].append(self.SongList)
# SAVE
# replace special characters in file or folder name with "_", made to avoid problem with special characters
elif chiamata == 'RemSpace':
for y in filelist:
y = Path(y)
if y.is_dir():
appo = []
for z in self.file_types:
z = "*" + z
appo += list(y.glob(z))
for w in appo:
Nam = w.name
for ch in [' ','\\','`','*','{','}','[',']','(',')','>','#','+','-','!','$','\'','&']:
Nam = Nam.replace(ch, '_')
if w.name != Nam:
Nam = str(w.parent) + "/" + Nam
OrigNam = w.absolute()
os.rename(OrigNam, Nam)
else:
Nam = y.name
Nam = Nam.replace(" ","_")
Nam = str(y.parent) + "/" + Nam
OrigNam = y.absolute()
if OrigNam != Nam:
os.rename(OrigNam, Nam)
# load show file
elif chiamata == 'LoadS':
y = Path(filelist[0])
if y.suffix != '.shw':
dialog = gui.GenericDialog(title='ERROR', message='Wrong file format!', width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
dialog.cancel.style['display'] = 'none'
dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
dialog.show(self)
else:
y = y.absolute()
with open(y, 'r') as file:
Data = file.read()
Data = Data.split('\n')
if Data[0] == '[SHOW MANAGER]':
## print('FILE OK')
del Data[0]
#Check if songs and config exists
SongExist = []
ConfExist = []
for x in Data:
if x != '':
Name, Conf = x.split('\t')
NameApp = Path(Name)
if NameApp.exists():
SongExist.append(Name)
if Conf != 'none':
ConfApp = Path(Conf)
if ConfApp.exists():
ConfExist.append(Conf)
#If there are no songs nothing is loaded
if len(SongExist):
#Check if exist songs and configs or only songs
if len(ConfExist):
## print('Song and conf exist')
self.SongListDict = {}
self.ListList = {}
self.ConfigList = []
found_all_song = 1
found_all_config = 1
for y in Data:
if y != '':
Name, Conf = y.split('\t')
Name = Path(Name)
if Name.exists():
if Name.suffix in self.file_types_all:
key = self.song_key(self.SongListDict)
self.SongListDict[key] = Name
else:
found_all_song = 0
if Conf != 'none':
Conf = Path(Conf)
if Conf.exists():
found = 0
for x in self.ConfigList:
if Conf.name == x.name:
found = 1
if not found:
self.ConfigList.append(Conf)
else:
found_all_config = 0
if Name.exists():
if Conf != 'none':
Conf = Path(Conf)
if Conf.exists():
appo = []
appo.append(Name)
appo.append(Conf)
self.ListList[key] = appo
else:
appo = []
appo.append(Name)
appo.append('none')
self.ListList[key] = appo
else:
appo = []
appo.append(Name)
appo.append('none')
self.ListList[key] = appo
#Update songs list
self.SongList = {}
for z in self.SongListDict:
temp = self.SongListDict[z]
self.SongList[int(z)] = str(temp.name)
self.Song.children['listSong'].empty()
self.Song.children['listSong'].append(self.SongList)
#Update configs list
appo = []
appo = self.fill_list(self.ConfigList)
self.Config.children['listConfig'].empty()
self.Config.children['listConfig'].append(appo)
#Update music + config list
self.List.children['listList'].empty()
for x in self.ListList:
appo = []
appo = self.ListList[x]
appoSong = appo[0].name
if appo[1] == 'none':
appoConfig = "--> " + appo[1]
else:
appoConfig = "--> " + appo[1].name
temp = {}
temp[int(x)] = appoSong
self.List.children['listList'].append(temp)
temp = {}
temp[int(x+1000)] = appoConfig
self.List.children['listList'].append(temp)
if found_all_song == 1 and found_all_config == 1:
pass
else:
if found_all_song == 1 and found_all_config == 0:
msg = 'Impossible load all config files, LightShowPi default.cfg will be used'
elif found_all_song == 0 and found_all_config == 1:
msg = 'Impossible load some songs!'
else:
msg = 'Impossible load all config files, LightShowPi default.cfg will be used. Impossible load some songs!'
self.dialog = gui.GenericDialog(title='WARNING', message=msg, width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialog.cancel.style['display'] = 'none'
self.dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
self.dialog.show(self)
else:
## print('Only songs exist')
self.SongListDict = {}
self.ListList = {}
found_all = 1
for y in Data:
if y != '':
Name, Conf = y.split('\t')
Name = Path(Name)
if Name.exists():
if Name.suffix in self.file_types_all:
key = self.song_key(self.SongListDict)
self.SongListDict[key] = Name
else:
found_all = 0
#Update songs list
self.SongList = {}
for z in self.SongListDict:
temp = self.SongListDict[z]
self.SongList[int(z)] = str(temp.name)
self.Song.children['listSong'].empty()
self.Song.children['listSong'].append(self.SongList)
#Update music + config list
if str(self.LightShowPiOverrides) != '':
self.Default_cfg = Path(str(self.LightShowPiOverrides.absolute())+'/defaults.cfg')
if self.Default_cfg.exists():
self.NoConfig = 1
if found_all == 1:
msg = 'No config file uploaded, LightShowPi default.cfg will be used'
else:
msg = 'No config file uploaded, LightShowPi default.cfg will be used. Impossible load some songs!'
self.dialog = gui.GenericDialog(title='WARNING', message=msg, width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialog.cancel.style['display'] = 'none'
self.dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
self.dialog.show(self)
self.List.children['listList'].empty()
self.ListList = {}
for x in self.SongListDict:
appo = []
appo.append(self.SongListDict[x])
exten = appo[0].suffix
appo.append('none')
self.ListList[x] = appo
for x in self.ListList:
appo = []
appo = self.ListList[x]
appoSong = appo[0].name
if appo[1] == 'none':
appoConfig = "--> " + appo[1]
else:
appoConfig = "--> " + appo[1].name
temp = {}
temp[int(x)] = appoSong
self.List.children['listList'].append(temp)
temp = {}
temp[int(x+1000)] = appoConfig
self.List.children['listList'].append(temp)
else:
msg = 'No config file found, impossible to create a list! Only songs loaded.'
self.dialog = gui.GenericDialog(title='WARNING', message=msg, width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialog.cancel.style['display'] = 'none'
self.dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
self.dialog.show(self)
else:
msg = 'No config file found, impossible to create a list! Only songs loaded.'
self.dialog = gui.GenericDialog(title='WARNING', message=msg, width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
self.dialog.cancel.style['display'] = 'none'
self.dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
self.dialog.show(self)
else:
dialog = gui.GenericDialog(title='ERROR', message='No valid song paths found!', width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
dialog.cancel.style['display'] = 'none'
dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
dialog.show(self)
else:
dialog = gui.GenericDialog(title='ERROR', message='No show file!', width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
dialog.cancel.style['display'] = 'none'
dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
dialog.show(self)
#SCHEDULER -add or edit
elif chiamata == 'Scheduler':
y = Path(filelist[0])
if y.suffix != '.shw':
dialog = gui.GenericDialog(title='ERROR', message='Wrong file format!', width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
dialog.cancel.style['display'] = 'none'
dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
dialog.show(self)
else:
self.SchedFileName = filelist[0]
appoName = MyApp.cut_name(filelist[0], False, 30)
self.aFolderShow.set_text(appoName)
# SCHEDULER load
elif chiamata == 'LoadSched':
y = Path(filelist[0])
if y.suffix != '.sch':
dialog = gui.GenericDialog(title='ERROR', message='Wrong file format!', width='400px', style={'border':'1px solid black', 'border-radius':'10px', 'position':'relative', 'top':'50px',})
dialog.cancel.style['display'] = 'none'
dialog.conf.style.update({'margin-right':'150px', 'width':'100px'})
dialog.show(self)
else:
y = y.absolute()
with open(y, 'r') as file:
Data = file.read()
Data = Data.split('\n')
if Data[0] == '[SHOW MANAGER SCHEDULE]':
del Data[0]
appo = []
for q in Data:
if q != '':
appo = q.split('\t')
for w in range(2,11):
if appo[w] == 'True':
appo[w] = bool(1)
else:
appo[w] = bool(0)
if len(self.SchedList):
found = 0
for x in self.SchedList:
w = self.SchedList[x]
appoCheck = datetime.datetime.strptime(appo[0], "%H:%M")
tempCheck = datetime.datetime.strptime(w[0], "%H:%M")
if appoCheck < tempCheck:
temp = self.SchedList.copy()
self.SchedList[x] = appo
k = x
q = len(self.SchedList)
while k < q + 1:
self.SchedList[k+1] = temp[k]
k = k + 1