-
Notifications
You must be signed in to change notification settings - Fork 3
/
pp_web_editor.py
1614 lines (1297 loc) · 68.1 KB
/
pp_web_editor.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
import sys
if sys.version_info[0] != 3:
sys.stdout.write("ERROR: Pi Presents requires python 3\nHint: python3 pp_web_editor.py .......\n")
exit(102)
import os
import configparser
import shutil
import copy
import string
import json
import remi.gui as gui
from remi import start, App
from pp_network import Network
from pp_options import web_ed_options
from remi_plus import OKDialog, OKCancelDialog,AdaptableDialog,FileSelectionDialog,InputDialog,ReportDialog
from pp_web_edititem import WebEditItem, ColourMap
from pp_utils import calculate_relative_path
from pp_medialist import MediaList
from pp_showlist import ShowList
from pp_web_validate import Validator,ViewBackup
from pp_definitions import PPdefinitions
from pp_oscwebconfig import OSCConfig,OSCWebEditor
class PPWebEditor(App):
def __init__(self, *args):
# print 'DOING _INIT do not use'
super(PPWebEditor, self).__init__(*args)
def main(self):
# print 'DOING MAIN executed once when server starts'
# ***************************************
# INIT
# ***************************************
self.editor_issue="1.5.3"
self.force_update= False
self.log=False
# get directory holding the code
self.editor_dir=sys.path[0]
ColourMap().init()
# initialise editor options OSC config class, and OSC editors
self.eo=Options()
self.eo.init_options(self.editor_dir)
self.osc_config=OSCConfig()
# initialise variables
self.init()
# BUILD THE GUI
# frames
root = gui.Container(width=770,height=500, margin='0px auto') #the margin 0px auto centers the main container
bottom_frame=gui.Container(width=770,height=400)#1
bottom_frame.set_layout_orientation(gui.Container.LAYOUT_HORIZONTAL)
# bottom_frame.style['display'] = 'block'
# bottom_frame.style['overflow'] = 'auto'
left_frame=gui.Container(width=300,height=400)#1
# left_frame.set_layout_orientation(gui.Container.LAYOUT_VERTICAL)
left_frame.style['margin']='10px'
middle_frame=gui.VBox(width=50,height=250)#1
middle_frame.style['margin']='10px'
right_frame=gui.Container(width=300,height=400)#1
updown_frame=gui.VBox(width=50,height=400)#1
updown_frame.style['margin']='10px'
#menu
menubar=gui.MenuBar(width='100%', height='30px')
menu = gui.Menu(width='100%', height='30px')
#profile menu
profile_menu = gui.MenuItem('Profile',width=80, height=30)
profile_open_menu = gui.MenuItem('Open',width=120, height=30)
profile_open_menu.set_on_click_listener(self.open_existing_profile)
profile_validate_menu = gui.MenuItem('Validate',width=120, height=30)
profile_validate_menu.set_on_click_listener(self.validate_profile)
profile_copy_to_menu = gui.MenuItem( 'Copy To',width=120, height=30)
profile_copy_to_menu.set_on_click_listener(self.copy_profile)
profile_delete_menu = gui.MenuItem( 'Delete',width=120, height=30)
profile_delete_menu.set_on_click_listener(self.delete_profile)
profile_new_menu = gui.MenuItem('New',width=120, height=30)
profile_menu.append(profile_open_menu)
profile_menu.append(profile_validate_menu)
profile_menu.append(profile_copy_to_menu)
profile_menu.append(profile_delete_menu)
profile_menu.append(profile_new_menu)
pmenu = gui.MenuItem('Exhibit',width=150, height=30)
pmenu.set_on_click_listener(self.new_exhibit_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('Media Show',width=150, height=30)
pmenu.set_on_click_listener(self.new_mediashow_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('Art Media Show',width=150, height=30)
pmenu.set_on_click_listener(self.new_artmediashow_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('Menu',width=150, height=30)
pmenu.set_on_click_listener(self.new_menu_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('Presentation',width=150, height=30)
pmenu.set_on_click_listener(self.new_presentation_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('Interactive',width=150, height=30)
pmenu.set_on_click_listener(self.new_interactive_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('Live Show',width=150, height=30)
pmenu.set_on_click_listener(self.new_liveshow_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('Art Live Show',width=150, height=30)
pmenu.set_on_click_listener(self.new_artliveshow_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem('RadioButton Show',width=150, height=30)
pmenu.set_on_click_listener(self.new_radiobuttonshow_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem( 'Hyperlink Show',width=150, height=30)
pmenu.set_on_click_listener(self.new_hyperlinkshow_profile)
profile_new_menu.append(pmenu)
pmenu = gui.MenuItem( 'Blank',width=150, height=30)
pmenu.set_on_click_listener(self.new_blank_profile)
profile_new_menu.append(pmenu)
# shows menu
show_menu = gui.MenuItem( 'Show',width=80, height=30)
show_delete_menu = gui.MenuItem('Delete',width=120, height=30)
show_delete_menu.set_on_click_listener(self.remove_show)
show_edit_menu = gui.MenuItem('Edit',width=120, height=30)
show_edit_menu.set_on_click_listener(self.m_edit_show)
show_copy_to_menu = gui.MenuItem( 'Copy To',width=120, height=30)
show_copy_to_menu.set_on_click_listener(self.copy_show)
show_add_menu = gui.MenuItem( 'Add',width=120, height=30)
show_viewbackup_menu = gui.MenuItem('View Backup',width=120, height=30)
show_viewbackup_menu.set_on_click_listener(self.view_show_backup)
show_menu.append(show_delete_menu)
show_menu.append(show_edit_menu)
show_menu.append(show_copy_to_menu)
show_menu.append(show_viewbackup_menu)
show_menu.append(show_add_menu)
pmenu = gui.MenuItem('Menu',width=150, height=30)
pmenu.set_on_click_listener(self.add_menushow)
show_add_menu.append(pmenu)
pmenu = gui.MenuItem( 'Media Show',width=150, height=30)
pmenu.set_on_click_listener(self.add_mediashow)
show_add_menu.append(pmenu)
pmenu = gui.MenuItem('Live Show',width=150, height=30)
pmenu.set_on_click_listener(self.add_liveshow)
show_add_menu.append(pmenu)
pmenu = gui.MenuItem('Hyperlink Show',width=150, height=30)
pmenu.set_on_click_listener(self.add_hyperlinkshow)
show_add_menu.append(pmenu)
pmenu = gui.MenuItem('RadioButton Show',width=150, height=30)
pmenu.set_on_click_listener(self.add_radiobuttonshow)
show_add_menu.append(pmenu)
pmenu = gui.MenuItem( 'Art Mediashow Show',width=150, height=30)
pmenu.set_on_click_listener(self.add_artmediashow)
show_add_menu.append(pmenu)
pmenu = gui.MenuItem( 'Art Liveshow Show',width=150, height=30)
pmenu.set_on_click_listener(self.add_artliveshow)
show_add_menu.append(pmenu)
# medialists menu
medialist_menu = gui.MenuItem( 'Medialist',width=80, height=30)
medialist_delete_menu = gui.MenuItem( 'Delete',width=120, height=30)
medialist_delete_menu.set_on_click_listener(self.remove_medialist)
medialist_add_menu = gui.MenuItem( 'Add',width=120, height=30)
medialist_add_menu.set_on_click_listener(self.menu_add_medialist)
medialist_copy_to_menu = gui.MenuItem('Copy To',width=120, height=30)
medialist_copy_to_menu.set_on_click_listener(self.copy_medialist)
medialist_menu.append(medialist_add_menu)
medialist_menu.append(medialist_delete_menu)
medialist_menu.append(medialist_copy_to_menu)
# tracks menu
track_menu = gui.MenuItem('Track',width=80, height=30)
track_delete_menu = gui.MenuItem('Delete',width=120, height=30)
track_delete_menu.set_on_click_listener(self.remove_track)
track_copy_menu = gui.MenuItem('Copy',width=120, height=30)
track_copy_menu.set_on_click_listener(self.copy_track)
track_edit_menu = gui.MenuItem( 'Edit',width=120, height=30)
track_edit_menu.set_on_click_listener(self.m_edit_track)
track_add_from_dir_menu = gui.MenuItem('Add Directory',width=120, height=30)
track_add_from_dir_menu.set_on_click_listener(self.add_tracks_from_dir)
track_add_from_file_menu = gui.MenuItem('Add File',width=120, height=30)
track_add_from_file_menu.set_on_click_listener(self.add_track_from_file)
track_new_menu = gui.MenuItem('New',width=120, height=30)
track_new_mpv_menu = gui.MenuItem('MPV Video',width=120, height=30)
track_new_mpv_menu.set_on_click_listener(self.new_mpv_track)
track_new_audio_menu = gui.MenuItem('Audio',width=120,height=30)
track_new_audio_menu.set_on_click_listener(self.new_audio_track)
track_new_image_menu = gui.MenuItem( 'Image',width=120, height=30)
track_new_image_menu.set_on_click_listener(self.new_image_track)
track_new_chrome_menu = gui.MenuItem( 'Chrome Web',width=120, height=30)
track_new_chrome_menu.set_on_click_listener(self.new_chrome_track)
track_new_message_menu = gui.MenuItem('Message',width=120, height=30)
track_new_message_menu.set_on_click_listener(self.new_message_track)
track_new_show_menu = gui.MenuItem('Show',width=120, height=30)
track_new_show_menu.set_on_click_listener(self.new_show_track)
track_new_menu_menu = gui.MenuItem('Menu',width=120, height=30)
track_new_menu_menu.set_on_click_listener(self.new_menu_track)
track_new_menu.append(track_new_mpv_menu)
track_new_menu.append(track_new_audio_menu)
track_new_menu.append(track_new_image_menu)
track_new_menu.append(track_new_chrome_menu)
track_new_menu.append(track_new_message_menu)
track_new_menu.append(track_new_show_menu)
track_new_menu.append(track_new_menu_menu)
track_menu.append(track_delete_menu)
track_menu.append(track_copy_menu)
track_menu.append(track_edit_menu)
track_menu.append(track_add_from_dir_menu)
track_menu.append(track_add_from_file_menu)
track_menu.append(track_new_menu)
options_menu = gui.MenuItem('Options',width=80, height=30)
options_edit_menu=gui.MenuItem('Edit',width=80, height=30)
options_edit_menu.set_on_click_listener(self.edit_options)
options_menu.append(options_edit_menu)
# osc menu
osc_menu = gui.MenuItem( 'OSC',width=80, height=30)
osc_create_menu = gui.MenuItem( 'Create',width=120, height=30)
osc_create_menu.set_on_click_listener(self.create_osc)
osc_edit_menu = gui.MenuItem( 'Edit',width=120, height=30)
osc_edit_menu.set_on_click_listener(self.edit_osc)
osc_menu.append(osc_create_menu)
osc_menu.append(osc_edit_menu)
config_menu=gui.MenuItem( 'Config',width=80, height=30)
config_menu.append(osc_menu)
# help menu
help_menu = gui.MenuItem( 'Help',width=80, height=30)
help_text_menu = gui.MenuItem( 'Help',width=80, height=30)
help_text_menu.set_on_click_listener(self.show_help)
about_menu = gui.MenuItem( 'About',width=80, height=30)
about_menu.set_on_click_listener(self.show_about)
help_menu.append(help_text_menu)
help_menu.append(about_menu)
update_menu = gui.MenuItem('Update',width=80, height=30)
update_all_menu = gui.MenuItem('Update All',width=80, height=30)
update_all_menu.set_on_click_listener(self.m_update_all)
update_menu.append(update_all_menu)
menu.append(profile_menu)
menu.append(show_menu)
menu.append(medialist_menu)
menu.append(track_menu)
menu.append(config_menu)
menu.append(options_menu)
menu.append(update_menu)
menu.append(help_menu)
menubar.append(menu)
#shows and medialists
shows_label=gui.Label('Shows',width=300, height=20)
shows_label.css_font_weight='bold'
shows_label.style['margin']='5px'
self.shows_display= gui.ListView(width=300, height=150)
self.shows_display.set_on_selection_listener(self.show_selected)
medialists_label=gui.Label('Medialists',width=300, height=25)
medialists_label.css_font_weight='bold'
medialists_label.style['margin']='5px'
self.medialists_display= gui.ListView(width=300, height=150)
self.medialists_display.set_on_selection_listener(self.medialist_selected)
left_frame.append(shows_label)
left_frame.append(self.shows_display)
left_frame.append(medialists_label)
left_frame.append(self.medialists_display)
#edit show button
edit_show = gui.Button('Edit\nShow',width=50, height=50)
edit_show.set_on_click_listener(self.m_edit_show)
middle_frame.append(edit_show)
#tracks
tracks_label=gui.Label('Tracks in Selected Medialist',width=300, height=20)
tracks_label.css_font_weight='bold'
tracks_label.style['margin']='5px'
self.tracks_display= gui.ListView(width=300, height=350)
self.tracks_display.set_on_selection_listener(self.track_selected)
right_frame.append(tracks_label)
right_frame.append(self.tracks_display)
#tracks buttons
add_track = gui.Button('Add',width=50, height=50)
add_track.set_on_click_listener(self.add_track_from_file)
updown_frame.append(add_track)
edit_track = gui.Button('Edit',width=50, height=50)
edit_track.set_on_click_listener(self.m_edit_track)
updown_frame.append(edit_track)
up_track = gui.Button('Up',width=50, height=50)
up_track.set_on_click_listener(self.move_track_up)
updown_frame.append(up_track)
down_track = gui.Button('Down',width=50, height=50)
down_track.set_on_click_listener(self.move_track_down)
updown_frame.append(down_track)
delete_track = gui.Button('Del',width=50, height=50)
delete_track.set_on_click_listener(self.remove_track)
updown_frame.append(delete_track)
root.append(menubar)
self.profile_name_field=gui.Label('\n')
root.append(self.profile_name_field)
bottom_frame.append(left_frame)
bottom_frame.append(middle_frame)
bottom_frame.append(right_frame)
bottom_frame.append(updown_frame)
root.append(bottom_frame)
return root
def init(self):
# print 'init'
self.eo.read_options()
self.pp_home_dir = self.eo.pp_home_dir
self.pp_profiles_offset = self.eo.pp_profiles_offset
self.initial_media_dir = self.eo.initial_media_dir
self.pp_profile_dir=''
self.current_medialist=None
self.current_showlist=None
self.current_show=None
def empty_lists(self):
# print 'empty lists'
self.shows_display.empty()
self.medialists_display.empty()
self.tracks_display.empty()
def show_help (self,widget):
OKDialog("Help","Please Read pipresents/manual.pdf'",width=400,height=200).show(self)
def show_about (self,widget):
helpme=OKDialog("About","",width=400,height=250)
helpme.append_label(gui.Label("Editor for Pi Presents Profiles",width=400,height=30),bold=False)
helpme.append_label(gui.Label("For Pi Presents Version: " + self.editor_issue,width=400,height=30),bold=False)
helpme.append_label(gui.Label("Author: Ken Thompson",width=400,height=30),bold=False)
helpme.append_label(gui.Label("Website: http://pipresents.wordpress.com/",width=400,height=30),bold=False)
helpme.show(self)
def validate_profile(self,widget):
if self.current_showlist != None:
val =Validator('Validation Result')
val.show(self)
val.validate_profile(self.editor_dir,self.pp_home_dir,self.pp_profile_dir,self.editor_issue,True)
# **************
# OPTIONS
# **************
def edit_options(self,widget):
self.eo.edit(self.edit_options_callback)
self.eo.show(self)
def edit_options_callback(self):
self.eo.read_options()
self.init()
self.empty_lists()
# **************
# OSC CONFIGURATION
# **************
def create_osc(self,widget):
if self.pp_profile_dir=='':
OKDialog('Create OSC','Profile must be open to create an OSC configuration file').show(self)
return
# print 'create',OSCConfig.options_file
if self.osc_config.read() is False:
iodir=self.pp_profile_dir+os.sep+'pp_io_config'
if not os.path.exists(iodir):
os.makedirs(iodir)
self.osc_config.create()
OKDialog('Create OSC','OSC Configuration File created').show(self)
else:
OKDialog('Create OSC','OSC Configuration File already exists').show(self)
def edit_osc(self,widget):
if self.pp_profile_dir=='':
OKDialog('Edit OSC','Profile must be open to edit an OSC configuration file').show(self)
return
# print 'edit',OSCConfig.options_file
if self.osc_config.read() is False:
OKDialog('Create OSC','Create an OSC Configuration File first').show(self)
return
self.osc_editor=OSCWebEditor()
self.osc_editor.edit()
self.osc_editor.show(self)
# **************
# PROFILES
# **************
def open_existing_profile(self,widget):
initial_dir=self.pp_home_dir+os.sep+"pp_profiles"+self.pp_profiles_offset
if os.path.exists(initial_dir) is False:
uc=OKDialog('Open Profile','')
uc.append_label(gui.Label("Profiles directory not found: "),bold=False)
uc.append_label(gui.Label(initial_dir),bold=False)
uc.append_label(gui.Label("Hint: Data Home option must end in pp_home"),bold=False)
uc.show(self)
return
open_existing_profile_dialog = FileSelectionDialog('Open Profile','Select profile',False, initial_dir,allow_folder_selection=True,
allow_file_selection=False,
callback=self.open_existing_profile_dialog_confirm) #width=600,height=200,
# open_existing_profile_dialog.set_on_confirm_value_listener(self.open_existing_profile_dialog_confirm)
open_existing_profile_dialog.show(self)
def open_existing_profile_dialog_confirm(self,filelist):
# print 'file list',filelist
if len(filelist)==0:
OKDialog('Open Profile',"Nothing Selected").show(self)
return
# print 'filelist[0]',filelist[0]
self.open_profile(filelist[0])
def open_profile(self,dir_path):
if self.editor_version()!= self.definitions_version():
ev=OKDialog("OpenProfile","",width=400,height=250)
ev.append_label(gui.Label('Incorrect version of Editor: '+self.editor_issue,width=400,height=30),bold=False)
ev.append_label(gui.Label('Definitions are: '+ PPdefinitions.DEFINITIONS_VERSION_STRING,width=400,height=30),bold=False)
ev.show(self)
return
showlist_file = dir_path + os.sep + "pp_showlist.json"
if self.log:
print ('LOG: Open Profile',showlist_file)
if os.path.exists(showlist_file) is False:
OKDialog('Open Profile',"Not a Profile: " + dir_path).show(self)
return
self.pp_profile_dir = dir_path
self.pp_select_offset=os.path.relpath(self.pp_profile_dir,self.pp_home_dir+os.sep+"pp_profiles"+self.pp_profiles_offset)
OSCConfig.options_file=self.pp_profile_dir+ os.sep+'pp_io_config'+os.sep+'osc.cfg'
self.osc_config_file=self.pp_profile_dir+os.sep+'pp_io_config'+os.sep+'osc.cfg'
self.open_showlist(self.pp_profile_dir)
if self.current_showlist.profile_version() == self.definitions_version() and self.force_update is False:
self.profile_finish_open()
return
if self.current_showlist.profile_version()> self.definitions_version():
OKDialog('Open Profile',"ERROR, Version of profile is greater than Pi Presents").show(self)
return
uv = OKCancelDialog("OpenProfile","",self.profile_update_confirm,width=400,height=250)
uv.append_label(gui.Label("Version of Profile is earlier then Pi Presents",width=400,height=30))
uv.append_label(gui.Label("OK to Update?",width=400,height=30))
uv.show(self)
def profile_update_confirm(self,result):
if result is False:
return
self.update_profile()
self.profile_finish_open()
OKDialog('Open Profile','Profile has been updated to '+ PPdefinitions.DEFINITIONS_VERSION_STRING).show(self)
def profile_finish_open(self):
self.current_medialist=None
self.current_showlist=None
self.current_show=None
self.open_showlist(self.pp_profile_dir)
self.refresh_shows_display()
self.open_medialists(self.pp_profile_dir)
self.refresh_tracks_display()
self.profile_name_field.set_text(self.pp_profile_dir)
self.profile_name_field.css_font_weight='bold'
def new_profile(self,profile):
d = InputDialog("New Profile","Name",width=400,height=200,callback=self.new_profile_confirm)
self.new_profile_template=profile
d.show(self)
def new_profile_confirm(self,name):
if name == "":
OKDialog("New Profile","Name is blank").show(self)
return
to = self.pp_home_dir + os.sep + "pp_profiles"+ self.pp_profiles_offset + os.sep + name
if os.path.exists(to) is True:
OKDialog( "New Profile","Profile exists\n(%s)" % to ).show(self)
return
shutil.copytree(self.new_profile_template, to, symlinks=False, ignore=None)
self.open_profile(to)
def new_exhibit_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_exhibit_1p5'
self.new_profile(profile)
def new_interactive_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_interactive_1p5'
self.new_profile(profile)
def new_menu_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_menu_1p5'
self.new_profile(profile)
def new_presentation_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_presentation_1p5'
self.new_profile(profile)
def new_blank_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep +"ppt_blank_1p5"
self.new_profile(profile)
def new_mediashow_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_mediashow_1p5'
self.new_profile(profile)
def new_liveshow_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_liveshow_1p5'
self.new_profile(profile)
def new_artmediashow_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_artmediashow_1p5'
self.new_profile(profile)
def new_artliveshow_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_artliveshow_1p5'
self.new_profile(profile)
def new_radiobuttonshow_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_radiobuttonshow_1p5'
self.new_profile(profile)
def new_hyperlinkshow_profile(self,widget):
profile = self.editor_dir+os.sep+'pp_resources'+os.sep+'pp_templates'+os.sep + 'ppt_hyperlinkshow_1p5'
self.new_profile(profile)
def delete_profile(self,widget,to_file=''):
if self.pp_profile_dir != '':
OKCancelDialog('Delete Profile','Delete Open Profile?',self.delete_profile_confirm).show(self)
def delete_profile_confirm(self,result):
if result is False:
return
shutil.rmtree(self.pp_profile_dir)
self.pp_profile_dir=''
self.current_showlist=None
self.current_show=None
self.current_medialist=None
self.shows_display.empty()
self.medialists_display.empty()
self.tracks_display.empty()
def copy_profile(self,widget,to_file=''):
if self.pp_profile_dir != '':
if to_file == '':
d = InputDialog("Copy Profile","To new Profile",width=400,height=200,callback=self.copy_profile_confirm)
d.show(self)
else:
self.copy_profile_confirm(to_file)
def copy_profile_confirm(self,to_file):
# print self.from_file,to_file
if to_file == "":
OKDialog("Copy Profile","Name is blank").show(self)
return ''
to_dir = self.pp_home_dir + os.sep + "pp_profiles"+ self.pp_profiles_offset+os.sep+to_file
self.copy_profile_dir(self.pp_profile_dir,to_dir)
def copy_profile_dir(self,from_dir,to_dir):
if os.path.exists(to_dir) is True:
OKDialog("Copy Profile","Profile already exists " + to_dir).show(self)
return
if os.path.exists(from_dir) is False:
OKDialog("Copy Profile","Profile not found " + from_dir).show(self)
return
shutil.copytree(from_dir,to_dir)
# ***************************************
# Shows
# ***************************************
def open_showlist(self,profile_dir):
showlist_file = profile_dir + os.sep + "pp_showlist.json"
self.current_showlist=ShowList()
self.current_showlist.open_json(showlist_file)
def save_showlist(self,showlist_dir):
if self.current_showlist is not None:
showlist_file = showlist_dir + os.sep + "pp_showlist.json"
self.current_showlist.save_list(showlist_file)
def add_mediashow(self,widget):
self.add_show(PPdefinitions.new_shows['mediashow'])
def add_liveshow(self,widget):
self.add_show(PPdefinitions.new_shows['liveshow'])
def add_radiobuttonshow(self,widget):
self.add_show(PPdefinitions.new_shows['radiobuttonshow'])
def add_hyperlinkshow(self,widget):
self.add_show(PPdefinitions.new_shows['hyperlinkshow'])
def add_artliveshow(self,widget):
self.add_show(PPdefinitions.new_shows['artliveshow'])
def add_artmediashow(self,widget):
self.add_show(PPdefinitions.new_shows['artmediashow'])
def add_menushow(self,widget):
self.add_show(PPdefinitions.new_shows['menu'])
def add_start(self,widget):
self.add_show(PPdefinitions.new_shows['start'])
def add_show(self,default):
# append it to the showlist and then add the medialist
if self.current_showlist is not None:
self.default_show=default
d = InputDialog("Add Show","Show Reference",width=400,height=200,callback=self.add_show_confirm)
d.show(self)
def add_show_confirm(self,name):
if name == "":
OKDialog("Add Show","Name is blank").show(self)
return
if self.current_showlist.index_of_show(name) != -1:
OKDialog("Add Show","A Show with this name already exists").show(self)
return
# print 'copy show template',self.default_show,name
copied_show=self.current_showlist.copy(self.default_show,name)
# print 'add mediafile from show',name
mediafile=self.add_medialist(name)
if mediafile != '':
copied_show['medialist']=mediafile
self.current_showlist.append(copied_show)
self.save_showlist(self.pp_profile_dir)
self.refresh_shows_display()
if copied_show['type']=='menu':
self.open_medialist_by_name(mediafile)
self.new_track(PPdefinitions.new_tracks['menu'],None)
def remove_show(self,widget):
if self.current_showlist is not None and self.current_showlist.length()>0 and self.current_showlist.show_is_selected():
show=self.current_showlist.selected_show()
OKCancelDialog("Delete Show","Delete "+ show['title']+ " Are you sure?",self.remove_show_confirm).show(self)
def remove_show_confirm(self,result):
if result is True:
index= self.current_showlist.selected_show_index()
self.current_showlist.remove(index)
self.save_showlist(self.pp_profile_dir)
self.refresh_shows_display()
def show_refs(self):
_show_refs=[]
for index in range(self.current_showlist.length()):
if self.current_showlist.show(index)['show-ref'] != "start":
_show_refs.append(copy.deepcopy(self.current_showlist.show(index)['show-ref']))
return _show_refs
def refresh_shows_display(self):
self.shows_display.empty()
key=0
for index in range(self.current_showlist.length()):
value= self.current_showlist.show(index)['title']+" ["+self.current_showlist.show(index)['show-ref']+"]"
obj = gui.ListItem(value,width=300, height=20)
self.shows_display.append(obj,key=key)
key+=1
if self.current_showlist.show_is_selected():
self.shows_display.select_by_key(self.current_showlist.selected_show_index())
# self.shows_display.show()
def show_selected(self,widget,event):
if self.current_showlist is not None and self.current_showlist.length()>0:
mouse_item_index=self.shows_display.get_key()
self.current_showlist.select(mouse_item_index)
self.refresh_shows_display()
if 'medialist' in self.current_showlist.selected_show():
medialist=self.current_showlist.selected_show()['medialist']
if medialist !='':
if os.path.exists(self.pp_profile_dir+os.sep+medialist):
self.open_medialist_by_name(medialist)
else:
#deal with hanging medialist in show
self.open_medialist_by_name('')
OKDialog('Select Show','Medialist '+medialist+' specified in the Show does not exist').show(self)
else:
#deal with start show that does not have a medialist
self.open_medialist_by_name('')
def copy_show(self,widget):
if self.current_showlist is not None and self.current_showlist.show_is_selected():
self.add_show(self.current_showlist.selected_show())
def m_edit_show(self,widget):
self.edit_show(PPdefinitions.show_types,PPdefinitions.show_field_specs)
def edit_show(self,show_types,field_specs):
if self.current_showlist is not None and self.current_showlist.show_is_selected():
show_title=self.current_showlist.selected_show()['title']
show_ref=self.current_showlist.selected_show()['show-ref']
self.edit_show_dialog=WebEditItem("Edit Show - "+show_title + ' ['+show_ref+']',
self.current_showlist.selected_show(),show_types,field_specs,self.show_refs(),
self.initial_media_dir,self.pp_home_dir,self.pp_profile_dir,'show',self.finished_edit_show)
self.edit_show_dialog.show(self)
show_type=self.current_showlist.selected_show()['type']
if show_type=='start':
self.edit_show_dialog.show_tab('sched')
else:
self.edit_show_dialog.show_tab('show')
def finished_edit_show(self):
self.save_showlist(self.pp_profile_dir)
self.refresh_shows_display()
def view_show_backup(self,widget):
if self.current_showlist is not None and self.current_showlist.show_is_selected():
vbs=ViewBackup()
vbs.show(self)
vbs.view_show_backup(self.pp_profile_dir,self.current_showlist.selected_show())
# no medialist in start show
if 'medialist' in self.current_showlist.selected_show():
medialist=self.current_showlist.selected_show()['medialist']
vbs.view_tracks_backup(self.pp_profile_dir,medialist)
# ***************************************
# Medialists
# ***************************************
def open_medialists(self,profile_dir):
self.medialists = []
files = os.listdir(profile_dir)
if files: files.sort()
for this_file in files:
if this_file.endswith(".json") and this_file not in ('pp_showlist.json','schedule.json'):
self.medialists = self.medialists + [this_file]
self.medialists_display.empty()
key=0
for index in range (len(self.medialists)):
obj = gui.ListItem(self.medialists[index],width=300, height=20)
self.medialists_display.append(obj, key=key)
key+=1
self.current_medialists_index=-1
self.current_medialist=None
def menu_add_medialist(self,widget):
self.add_medialist(name=None)
def add_medialist(self,name=None):
if self.current_showlist != None:
if name is None:
d = InputDialog("Add Medialist","File Name",width=400,height=200,callback=self.add_medialist_confirm)
d.show(self)
else:
medialist_name=self.add_medialist_confirm(name)
return medialist_name
def add_medialist_confirm(self,name):
if name == "":
OKDialog("Add Medialist","Name is blank").show(self)
return ''
if not name.endswith(".json"):
name=name+(".json")
path = self.pp_profile_dir + os.sep + name
if os.path.exists(path) is True:
OKDialog("Add Medialist","Medialist file exists: " + name).show(self)
return ''
nfile = open(path,'w')
nfile.write("{")
nfile.write("\"issue\": \""+PPdefinitions.DEFINITIONS_VERSION_STRING+"\",\n")
nfile.write("\"tracks\": [")
nfile.write("]")
nfile.write("}")
nfile.close()
# append it to the list
self.medialists.append(copy.deepcopy(name))
# print 'medialists',self.medialists
# add title to medialists display
# self.medialists_display.insert(END, name)
# and set it as the selected medialist
self.refresh_medialists_display()
# print 'returning medilaist name',name
return name
def copy_medialist(self,widget,to_file=None):
if self.current_showlist != None:
if self.current_medialist is not None:
#from_file= self.current_medialist
self.from_file= self.medialists[self.current_medialists_index]
if to_file is None:
d = InputDialog("Copy Medialist","File",width=400,height=200,callback=self.copy_medialist_confirm)
d.show(self)
else:
self.copy_medialist_confirm(to_file)
def copy_medialist_confirm(self,to_file):
# print self.from_file,to_file
if to_file == "":
OKDialog("Copy Medialist","Name is blank").show(self)
return ''
success_file = self.copy_medialist_file(self.from_file,to_file)
if success_file =='':
return ''
# append it to the list
self.medialists.append(copy.deepcopy(success_file))
# add title to medialists display
# self.medialists_display.insert(END, success_file)
# and reset selected medialist
self.current_medialist=None
self.refresh_medialists_display()
self.refresh_tracks_display()
return success_file
def copy_medialist_file(self,from_file,to_file):
if not to_file.endswith(".json"):
to_file+=(".json")
to_path = self.pp_profile_dir + os.sep + to_file
if os.path.exists(to_path) is True:
OKDialog("Copy Medialist","Medialist file exists\n(%s)" % to_path).show(self)
return ''
from_path= self.pp_profile_dir + os.sep + from_file
if os.path.exists(from_path) is False:
OKDialog("Copy Medialist","Medialist file not found\n(%s)" % from_path).show(self)
return ''
shutil.copy(from_path,to_path)
return to_file
def remove_medialist(self,widget):
if self.current_medialist is not None:
name = self.medialists[self.current_medialists_index]
OKCancelDialog("Delete Medialist","Delete "+ name + " Are you sure?",self.remove_medialist_confirm).show(self)
def remove_medialist_confirm(self,result):
if result is True:
os.remove(self.pp_profile_dir+ os.sep + self.medialists[self.current_medialists_index])
self.open_medialists(self.pp_profile_dir)
self.refresh_medialists_display()
self.refresh_tracks_display()
def open_medialist_by_name(self,name):
if name=='':
self.current_medialist=None
self.refresh_tracks_display()
self.refresh_medialists_display()
else:
self.current_medialist=MediaList('ordered')
if not self.current_medialist.open_list(self.pp_profile_dir+ os.sep + name,self.definitions_version()):
OKDialog(self,"medialist is a different version to showlist: "+ str(self.medialists[self.current_medialists_index])).show(self)
return
self.refresh_tracks_display()
self.refresh_medialists_display()
self.medialists_display.select_by_value(name)
self.current_medialists_index = self.medialists_display.get_key()
def medialist_selected(self,widget,key):
"""
user clicks on a medialst in a profile so try and select it.
"""
# print 'selected',type(self.medialists_display.get_key()),self.medialists_display.get_key()
if len(self.medialists)>0:
self.current_medialists_index=self.medialists_display.get_key()
self.current_medialist=MediaList('ordered')
if not self.current_medialist.open_list(self.pp_profile_dir+ os.sep + self.medialists[self.current_medialists_index],self.definitions_version()):
OKDialog(self,"medialist is a different version to showlist: "+ str(self.medialists[self.current_medialists_index])).show(self)
return
self.refresh_tracks_display()
self.refresh_medialists_display()
self.current_showlist.deselect_all()
self.refresh_shows_display()
def refresh_medialists_display(self):
# print 'refresh medialists'
self.medialists_display.empty()
key=0
for index in range (len(self.medialists)):
obj = gui.ListItem(self.medialists[index],width=300, height=20)
self.medialists_display.append(obj,key=key)
key+=1
if self.current_medialist is not None:
self.medialists_display.select_by_key(self.current_medialists_index)
# self.medialists_display.show(self)
def save_medialist(self):
basefile=self.medialists[self.current_medialists_index]
# print type(basefile)
# basefile=str(basefile)
# print type(basefile)
medialist_file = self.pp_profile_dir+ os.sep + basefile
# print medialist_file
self.current_medialist.save_list(medialist_file)
# ***************************************
# Tracks
# ***************************************
def refresh_tracks_display(self):
self.tracks_display.empty()
if self.current_medialist is not None:
key=0
for index in range(self.current_medialist.length()):
if self.current_medialist.track(index)['track-ref'] != '':
track_ref_string=" ["+self.current_medialist.track(index)['track-ref']+"]"
else:
track_ref_string=""
obj = gui.ListItem(self.current_medialist.track(index)['title']+track_ref_string,width=300, height=20)
self.tracks_display.append(obj,key=key)
key+=1
if self.current_medialist.track_is_selected():
self.tracks_display.select_by_key(self.current_medialist.selected_track_index())
def track_selected(self,widget,key):