-
Notifications
You must be signed in to change notification settings - Fork 1
/
threedplayer.py
executable file
·3172 lines (2750 loc) · 118 KB
/
threedplayer.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/python2
'''message_player-0.2.py
retrieves message info from database.
Displays message types as buttons on left pane.
displays messages of a given type on centre pane
Displays selected/dragged messages ona left pane
Functioning scheduler
playback working from preview and broadcast
implements broadcast from serial signal
using subprocess and dbus
has 'join' feature to link tracks. integrates with dnd
'''
import fcntl, sys
pid_file = 'threedplayer.pid'
fp = open(pid_file, 'w')
try:
fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
# another instance is running
sys.exit(0)
import pygtk
import gtk
import gobject
import pango
import sys
import psycopg2
import subprocess
import datetime
import os
import time
import gst
import pygst
import socket
import threading
import thread
import dbus
import ConfigParser
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from subprocess import Popen
from operator import itemgetter
from lxml import etree
tup_day = ("Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday")
#lists
select_items = (
"cdtrack.trackid",
"cdtrack.cdid",
"cdtrack.tracknum",
"cdtrack.tracktitle",
"cdtrack.trackartist",
"cd.artist",
"cd.title",
"cd.company",
"cdtrack.tracklength"
)
where_items = (
"trackartist",
"tracktitle",
"cd.title",
"cd.artist"
)
### Styles ###
header_font = pango.FontDescription("Sans Bold 18")
subheader_font = pango.FontDescription("Sans Bold 14")
subheader_font_1 = pango.FontDescription("Sans Bold 12")
subheader_font_2 = pango.FontDescription("Sans Bold 11")
#get variables from config file
config = ConfigParser.SafeConfigParser()
config.read('/usr/local/etc/threedradio.conf')
#the serialwatch script to be run as a subprocess
dir_serialwatch = config.get('Paths', 'dir_serialwatch')
file_serialwatch = config.get('ThreeDPlayer', 'file_serialwatch')
dir_pl3d = config.get('Paths', 'dir_pl3d')
dir_msg = config.get('Paths', 'dir_msg')
dir_mus = config.get('Paths', 'dir_mus')
dir_img = config.get('Paths', 'dir_img')
logo = config.get('Images', 'logo')
query_limit = config.getint('ThreeDPlayer', 'query_limit')
pg_server = config.get('Common', 'pg_server')
pg_cat_user = config.get('ThreeDPlayer', 'pg_cat_user')
pg_cat_password = config.get('ThreeDPlayer', 'pg_cat_password')
pg_cat_database = config.get('Common', 'pg_cat_database')
pg_msg_user = config.get('ThreeDPlayer', 'pg_msg_user')
pg_msg_password = config.get('ThreeDPlayer', 'pg_msg_password')
pg_msg_database = config.get('Common', 'pg_msg_database')
#image files for the 'join' feature
img_blank = config.get('Images', 'img_blank')
img_top = config.get('Images', 'img_top')
img_mid = config.get('Images', 'img_mid')
img_btm = config.get('Images', 'img_btm')
class CellRendererPixbufXt(gtk.CellRendererPixbuf):
'''
A special class of cell to be used in treeview rows. It will
activate a signal when clicked which can be connected to a method.
It is used for the 'join' feature.
'''
__gproperties__ = { 'active-state' :
(gobject.TYPE_STRING, 'pixmap/active widget state',
'stock-icon name representing active widget state',
None, gobject.PARAM_READWRITE) }
__gsignals__ = { 'clicked' :
(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()) , }
def __init__( self ):
gtk.CellRendererPixbuf.__init__( self )
self.set_property( 'mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE )
def do_get_property( self, property ):
if property.name == 'active-state':
return self.active_state
else:
raise AttributeError, 'unknown property %s' % property.name
def do_set_property( self, property, value ):
if property.name == 'active-state':
self.active_state = value
else:
raise AttributeError, 'unknown property %s' % property.name
def do_activate( self, event, widget, path, background_area, cell_area,
flags ):
if event.type == gtk.gdk.BUTTON_PRESS:
self.emit('clicked')
def do_clicked(self):
#print "do_clicked"
pass
gobject.type_register(CellRendererPixbufXt)
class MyDbus(dbus.service.Object):
'''
This enable a dbus signal to activate the broadcast player.
The serialwatch script is used to send the signal.
'''
@dbus.service.method('com.threedradio.MessagePlayer')
def signal_received(self):
'''
specify the dbus service for threedplayer
'''
self.tdp = ThreeD_Player()
tdp.serial_signal()
class Preview_Player:
'''
Adapted from Benny Malev's DamnSimplePlayer.
Plays the selected track, outputs to the souncard with the
alias 'preview' as defined in /etc/asound.conf
'''
def __init__(self, time_label, hscale, reset_playbutton):
'''
Calls the class with arguments.
Creates the pipe using a playbin and
specifies the alsa pcm device as 'preview'
'''
self.player = gst.element_factory_make("playbin2", "player")
fakesink = gst.element_factory_make("fakesink", "fakesink")
alsa_card0 = gst.element_factory_make("alsasink", "preview")
alsa_card0.set_property("device", "preview")
self.player.set_property("video-sink", fakesink)
self.player.set_property("audio-sink", alsa_card0)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
self.time_format = gst.Format(gst.FORMAT_TIME)
#set statusbar ref.
self.time_label = time_label
self.hscale = hscale
self.reset_playbutton = reset_playbutton
#to hold place on change event in gui
self.place_in_file = None
self.progress_updatable = True
def set_place_in_file(self,place_in_file):
self.place_in_file = place_in_file
def start(self, filepath):
'''
Start playing an audio file
'''
self.player.set_property("uri", "file://" + filepath)
self.player.set_state(gst.STATE_PLAYING)
self.play_thread_id = thread.start_new_thread(self.play_thread, ())
def stop(self):
'''
Stop playing
'''
self.play_thread_id = None
self.player.set_state(gst.STATE_NULL)
self.reset_components()
def pause(self):
'''
Pause playing
'''
self.player.set_state(gst.STATE_PAUSED)
def on_message(self, bus, message):
'''
resets the state when reaching the end of the audio file
'''
t = message.type
if t == gst.MESSAGE_EOS:
self.play_thread_id = None
self.player.set_state(gst.STATE_NULL)
self.reset_components()
elif t == gst.MESSAGE_ERROR:
self.play_thread_id = None
self.player.set_state(gst.STATE_NULL)
err, debug = message.parse_error()
print ("Error: {0}").format (err, debug)
self.reset_components()
def convert_ns(self, time_int):
'''
Changes the time fraction to human readable minutes and seconds.
'''
s,ns = divmod(time_int, 1000000000)
m,s = divmod(s, 60)
if m < 60:
str_dur = "%02i:%02i" %(m,s)
return str_dur
else:
h,m = divmod(m, 60)
str_dur = "%i:%02i:%02i" %(h,m,s)
return str_dur
def get_duration(self):
'''
Get the length of the file
'''
dur_int = self.player.query_duration(self.time_format, None)[0]
return self.convert_ns(dur_int)
def set_updateable_progress(self,flag):
self.progress_updatable = flag
def rewind_callback(self):
pos_int = self.player.query_position(self.time_format, None)[0]
seek_ns = pos_int - (10 * 1000000000)
self.player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, seek_ns)
def forward_callback(self):
pos_int = self.player.query_position(self.time_format, None)[0]
seek_ns = pos_int + (10 * 1000000000)
self.player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, seek_ns)
def get_state(self):
play_state = self.player.get_state(1)[1]
#for item in play_state:
# print(item)
return play_state
#duration updating func
def play_thread(self):
play_thread_id = self.play_thread_id
while play_thread_id == self.play_thread_id:
try:
time.sleep(0.2)
dur_int = self.player.query_duration(self.time_format, None)[0]
dur_str = self.convert_ns(dur_int)
self.duration_time = dur_int / 1000000000
gtk.gdk.threads_enter()
self.time_label.set_text("00:00 / " + dur_str)
#set hscale
self.hscale.set_range(0,self.duration_time)
gtk.gdk.threads_leave()
break
except:
pass
time.sleep(0.2)
while play_thread_id == self.play_thread_id:
#update position
if self.place_in_file:
self.player.seek_simple(self.time_format ,gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_KEY_UNIT | gst.SEEK_TYPE_SET ,self.place_in_file*1000000000)
self.place_in_file = None
#let the seek enough time to complete
time.sleep(0.1)
pos_int = self.player.query_position(self.time_format, None)[0]
pos_str = self.convert_ns(pos_int)
self.current_time = pos_int / 1000000000
if play_thread_id == self.play_thread_id:
gtk.gdk.threads_enter()
if self.progress_updatable:
#update hscale
self.hscale.set_value(self.current_time)
self.time_label.set_text(pos_str + " / " + dur_str)
gtk.gdk.threads_leave()
time.sleep(1)
def reset_components(self):
self.time_label.set_text("00:00 / 00:00")
self.hscale.set_value(0)
self.reset_playbutton()
class Broadcast_Player:
'''
adapted from Benny Malev's DamnSimplePlayer
Plays the selected track, outputs to the souncard with the
alias 'broadcast' as defined in /etc/asound.conf
'''
def __init__(self, time_label, progressbar, label_air_warning, check_join):
self.player = gst.element_factory_make("playbin2", "player")
fakesink = gst.element_factory_make("fakesink", "fakesink")
alsa_card0 = gst.element_factory_make("alsasink", "broadcast")
alsa_card0.set_property("device", "broadcast")
self.player.set_property("video-sink", fakesink)
self.player.set_property("audio-sink", alsa_card0)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
self.time_format = gst.Format(gst.FORMAT_TIME)
#set statusbar ref.
self.time_label = time_label
self.progressbar = progressbar
self.label_air_warning = label_air_warning
self.check_join = check_join
#to hold place on change event in gui
self.place_in_file = None
self.progress_updatable = True
def set_place_in_file(self,place_in_file):
self.place_in_file = place_in_file
def start(self, filepath):
self.player.set_property("uri", "file://" + filepath)
self.player.set_state(gst.STATE_PLAYING)
self.play_thread_id = thread.start_new_thread(self.play_thread, ())
def stop(self):
self.play_thread_id = None
self.player.set_state(gst.STATE_NULL)
self.reset_components()
def pause(self):
self.player.set_state(gst.STATE_PAUSED)
def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
self.play_thread_id = None
self.player.set_state(gst.STATE_NULL)
self.reset_components()
self.check_join()
elif t == gst.MESSAGE_ERROR:
self.play_thread_id = None
self.player.set_state(gst.STATE_NULL)
err, debug = message.parse_error()
print ("Error: {0}").format (err, debug)
self.reset_components()
def convert_ns(self, time_int):
s,ns = divmod(time_int, 1000000000)
m,s = divmod(s, 60)
if m < 60:
str_dur = "%02i:%02i" %(m,s)
return str_dur
else:
h,m = divmod(m, 60)
str_dur = "%i:%02i:%02i" %(h,m,s)
return str_dur
def get_duration(self):
dur_int = self.player.query_duration(self.time_format, None)[0]
return self.convert_ns(dur_int)
def set_updateable_progress(self,flag):
self.progress_updatable = flag
def get_state(self):
play_state = self.player.get_state(1)[1]
return play_state
#progress updating func
def play_thread(self):
play_thread_id = self.play_thread_id
while play_thread_id == self.play_thread_id:
try:
time.sleep(0.2)
dur_int = self.player.query_duration(self.time_format, None)[0]
dur_str = self.convert_ns(dur_int)
self.duration_time = dur_int / 1000000000
gtk.gdk.threads_enter()
self.time_label.set_text(dur_str)
#set progressbar
self.progressbar.set_fraction(0)
gtk.gdk.threads_leave()
break
except:
pass
time.sleep(0.2)
while play_thread_id == self.play_thread_id:
#update position
if self.place_in_file:
self.player.seek_simple(self.time_format ,gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_KEY_UNIT | gst.SEEK_TYPE_SET ,self.place_in_file*1000000000)
self.place_in_file = None
#let the seek enough time to complete
time.sleep(0.1)
pos_int = self.player.query_position(self.time_format, None)[0]
rem_int = dur_int - pos_int
rem_str = self.convert_ns(rem_int)
self.current_time = pos_int / 1000000000
if play_thread_id == self.play_thread_id:
gtk.gdk.threads_enter()
if self.progress_updatable:
#update progressbar
fraction = float(pos_int) / dur_int
self.progressbar.set_fraction(fraction)
self.time_label.set_text(rem_str)
gtk.gdk.threads_leave()
time.sleep(1)
def reset_components(self):
self.time_label.set_text("00:00")
self.progressbar.set_fraction(0)
self.progressbar.set_text("")
self.label_air_warning("not playing")
class ThreeD_Player():
def delete_event(self, widget, event, data=None):
return False
def destroy(self, widget, data=None):
gtk.main_quit()
def main(self):
'''
the GUI layout, connections and dnd.
'''
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_position(gtk.WIN_POS_CENTER)
filepath_logo = dir_img + logo
window.set_icon_from_file(filepath_logo)
window.set_resizable(False)
window.set_size_request(1240, 880)
### create containers - boxes and scrolled windows ###
#top level vbox - holds menubar, messages scheduler/preview and air list
vbox_main = gtk.VBox(False, 0)
#top level hbox holds messages scheduler/preview and air list
hbox_main = gtk.HBox(False, 0)
#vbox to hold the notebook and the scheduler/preview
vbox_nb = gtk.VBox(False, 0)
#notebook for tabbed interface
notebook = gtk.Notebook()
#notebook.set_size_request(940, 600)
#hbox for message buttons and list
hbox_msg = gtk.HBox(False, 5)
#vbox for label and message buttons
vbox_msg_btn = gtk.VBox(False, 0)
vbox_msg_btn.set_size_request(240, 460)
#vbox for buttons inside the scroll window
self.vbox_sw_msg_btn = gtk.VBox(False, 0)
#scrolled window for buttons
sw_msg_btn = gtk.ScrolledWindow(hadjustment=None)
sw_msg_btn.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_msg_btn.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
#vbox for message list
vbox_msg_lst = gtk.VBox(False, 0)
#scrolled window for message list treeview
sw_msg_lst = gtk.ScrolledWindow()
sw_msg_lst.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_msg_lst.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
#hbox for music catalogue
hbox_cat = gtk.HBox(False, 5)
#vbox for catalogue search
vbox_cat_search = gtk.VBox(False, 5)
#table for music catalogue search
table_cat = gtk.Table(20, 2, False)
#hbox for catalogue creator selection
hbox_cat_creator = gtk.HBox(False, 5)
#vbox for catalogue list
vbox_cat_lst = gtk.VBox(False, 0)
#scrolled window for catalogue list treeview
sw_cat_lst = gtk.ScrolledWindow()
sw_cat_lst.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_cat_lst.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
#hbox for list import
hbox_pl3d = gtk.HBox(False, 5)
# vbox for buttons and option for list import
vbox_pl3d_opt = gtk.VBox(False, 5)
#vbox for the imported list
vbox_pl3d_lst = gtk.VBox(False, 5)
#scrolled window for browsing pl3d files
sw_pl3d_opt = gtk.ScrolledWindow()
sw_pl3d_opt.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_pl3d_opt.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
#scrolled window for imported list
sw_pl3d_lst = gtk.ScrolledWindow()
sw_pl3d_lst.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_pl3d_lst.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
#hbox for the copy buttons below the imported list
hbox_pl3d_btn = gtk.HBox(False, 5)
#hbox for scheduler and preview
hbox_sch_pre = gtk.HBox(False, 0)
#vbox for the playing and queued messages
vbox_bc = gtk.VBox(False, 5)
#hbox for progress label and skip button in the broadcast pane
hbox_bc_0 = gtk.HBox(False, 0)
#hbox for list option buttons in the broadcast pane
hbox_bc_1 = gtk.HBox(False, 0)
#scrolled holder for the broadcast message treelist
sw_bc = gtk.ScrolledWindow()
sw_bc.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_bc.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
#hbox for displaying total time of listed tracks
hbox_bc_time = gtk.HBox(False, 0)
# hbox for scheduler and preview
hbox_sch_pre = gtk.HBox(False, 5)
# vbox for buttons and drop-down list
vbox_sch_move = gtk.VBox(False, 0)
#scrolled window for the schedule list
sw_sch = gtk.ScrolledWindow()
sw_sch.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_sch.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
# vbox for preview section
vbox_pre = gtk.VBox(False, 0)
# hbox for preview player buttons
hbox_pre_btn = gtk.HBox(False, 0)
### ----------------Message List Section---------------- ###
# images for buttons
self.image_play = gtk.Image()
self.image_play.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
self.image_play.set_name("play")
self.image_pause = gtk.Image()
self.image_pause.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_BUTTON)
self.image_pause.set_name("pause")
image_stop = gtk.Image()
image_stop.set_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_BUTTON)
#label for buttons
label_msg_btn = gtk.Label(" Messages ")
label_msg_btn.modify_font(header_font)
#label_msg_btn.set_size_request(180, 26)
#make the buttons
self.make_buttons()
#make the list
store_msg = gtk.ListStore(str, str, str, str, str, str, str, str, str)
self.treeview_msg = gtk.TreeView(store_msg)
self.treeview_msg.set_rules_hint(True)
treeselection_msg = self.treeview_msg.get_selection()
self.add_msg_columns(self.treeview_msg)
### ----------------Music Catalogue Section---------------- ###
label_cat = gtk.Label(" Music Catalogue ")
label_cat.modify_font(header_font)
sep_cat_0 = gtk.HSeparator()
label_cat_simple = gtk.Label("Simple Search")
label_cat_simple.modify_font(subheader_font_1)
self.entry_cat_simple = gtk.Entry(50)
btn_cat_simple = gtk.Button("Search")
btn_cat_simple.set_tooltip_text("Simple search")
btn_cat_simple.set_size_request(80, 30)
self.label_result_simple = gtk.Label()
self.label_result_simple.set_size_request(80, 40)
sep_cat_1 = gtk.HSeparator()
label_cat_adv = gtk.Label("Advanced Search")
label_cat_adv.modify_font(subheader_font_1)
label_cat_artist = gtk.Label("Artist")
self.entry_cat_artist = gtk.Entry(50)
label_cat_album = gtk.Label("Album")
self.entry_cat_album = gtk.Entry(50)
label_cat_title = gtk.Label("Title")
self.entry_cat_title = gtk.Entry(50)
label_cat_cmpy = gtk.Label("Company")
self.entry_cat_cmpy = gtk.Entry(50)
label_cat_genre = gtk.Label("Genre")
self.entry_cat_genre = gtk.Entry(50)
label_cat_com = gtk.Label("Comments")
self.entry_cat_com = gtk.Entry(50)
label_cat_creator = gtk.Label("Created by")
self.cb_cat_creator = gtk.combo_box_new_text()
self.cb_creator_add()
self.chk_cat_comp = gtk.CheckButton("Compilation", True)
self.chk_cat_demo = gtk.CheckButton("Demo", True)
self.chk_cat_local = gtk.CheckButton("Local", True)
self.chk_cat_fem = gtk.CheckButton("Female", True)
label_cat_order = gtk.Label("Order by")
self.cb_cat_order = gtk.combo_box_new_text()
self.cb_order_add()
btn_cat_adv = gtk.Button("Search")
btn_cat_adv.set_tooltip_text("Advanced Search")
self.label_result_adv = gtk.Label()
self.label_result_adv.set_size_request(80, 40)
### ----------- Search Results Section -----------###
label_results = gtk.Label("Search Results")
label_results.modify_font(subheader_font_1)
label_results.set_size_request(80, 30)
#make the list
self.store_cat = gtk.TreeStore(str ,str ,str ,str ,str ,str ,str, str, str)
self.treeview_cat = gtk.TreeView(self.store_cat)
self.treeview_cat.set_rules_hint(True)
treeselection_cat = self.treeview_cat.get_selection()
self.add_cat_columns(self.treeview_cat)
### ----------- Playlist Import Section -----------###
label_pl3d = gtk.Label(" Import List ")
label_pl3d.modify_font(header_font)
label_pl3d_browse = gtk.Label("Select a Playlist")
label_pl3d_browse.set_size_request(220, 28)
label_pl3d_browse.modify_font(subheader_font_1)
# treeview for browsing playlists
self.store_pl3d_browse = gtk.TreeStore(str)
self.treeview_pl3d_browse = gtk.TreeView(self.store_pl3d_browse)
self.treeview_pl3d_browse.set_rules_hint(True)
treeselection_pl3d_browse = self.treeview_pl3d_browse.get_selection()
column = gtk.TreeViewColumn('Select a Playlist', gtk.CellRendererText(),
text=0)
column.set_sort_column_id(0)
column.set_clickable(False)
self.treeview_pl3d_browse.append_column(column)
self.get_pl3d_browse(None)
btn_pl3d_refresh = gtk.Button("Refresh")
btn_pl3d_select = gtk.Button("Browse for a pl3d playlist")
#treeview to display playlist
store_pl3d_lst = gtk.ListStore(str ,str ,str ,str ,str ,str ,str, str, str)
self.treeview_pl3d_lst = gtk.TreeView(store_pl3d_lst)
self.treeview_pl3d_lst.set_rules_hint(True)
self.treeview_pl3d_lst.set_rubber_banding(True)
treeselection_pl3d_lst = self.treeview_pl3d_lst.get_selection()
treeselection_pl3d_lst.set_mode(gtk.SELECTION_MULTIPLE)
self.add_pl3d_columns(self.treeview_pl3d_lst)
btn_pl3d_copysel = gtk.Button("Copy selected tracks to the broadcast list")
btn_pl3d_copyall = gtk.Button("Copy all tracks to the broadcast list")
### ----------------Broadcast section---------------- ###
#Set up track joining
path_blank = dir_img + img_blank
pix_blank = gtk.gdk.pixbuf_new_from_file(path_blank)
path_top = dir_img + img_top
pix_top = gtk.gdk.pixbuf_new_from_file(path_top)
path_mid = dir_img + img_mid
pix_mid = gtk.gdk.pixbuf_new_from_file(path_mid)
path_btm = dir_img + img_btm
pix_btm = gtk.gdk.pixbuf_new_from_file(path_btm)
#reference to be set by click on pix cell and used by selected row
self.joinme = False
#label
label_bc = gtk.Label("Broadcast to Air")
label_bc.set_size_request(30, 30)
#make the list
bc_store = gtk.ListStore(str ,str ,str ,str ,str ,str ,str, str, str,
gobject.TYPE_BOOLEAN, gtk.gdk.Pixbuf)
self.treeview_bc = gtk.TreeView(bc_store)
self.treeview_bc.set_rules_hint(True)
treeselection_bc = self.treeview_bc.get_selection()
self.add_bc_columns(self.treeview_bc)
label_bc = gtk.Label("Broadcast List")
label_bc.modify_font(header_font)
self.label_air = gtk.Label("")
self.label_air.set_size_request(50, 50)
self.label_air_warning("not playing")
btn_testing = gtk.Button("Testing")
self.progressbar = gtk.ProgressBar()
self.progressbar.set_size_request(280, 20)
self.label_bc_time = gtk.Label("00:00")
self.label_bc_time.modify_font(subheader_font)
self.player_bc = Broadcast_Player(self.label_bc_time,
self.progressbar, self.label_air_warning, self.check_join)
btn_inf = gtk.Button("Info")
btn_rem = gtk.Button("Remove")
btn_hist = gtk.Button("History")
btn_hist.set_tooltip_text("Show details of the music tracks played for back-announcing")
btn_skip = gtk.Button("Skip to End")
adj_spin = gtk.Adjustment(3, 1, 120, 1, 5, 0)
self.spinbutton = gtk.SpinButton(adj_spin, 0, 0)
self.spinbutton.set_numeric(True)
self.spinbutton.set_tooltip_text("How many tracks to be shown in the history")
btn_msg_3hr = gtk.Button("Msg 3hr")
label_time_0 = gtk.Label("Playlist Total Time - ")
self.label_time_1 = gtk.Label("00:00 ")
### ----------------Scheduler Section ---------------- ###
# drop down list (combobox)
self.cb_sch_prg = gtk.combo_box_new_text()
# Label
label_sch = gtk.Label("Schedule")
label_sch.modify_font(header_font)
label_sch.set_size_request(200, 30)
# Buttons
btn_sch_refresh = gtk.Button(stock=gtk.STOCK_REFRESH)
btn_sch_now = gtk.Button("now")
btn_sch_add = gtk.Button("Add to Broadcast List")
# make the scheduler list display
self.store_sch = gtk.ListStore(str ,str, str, str, str, str, str, str, str)
self.treeview_sch = gtk.TreeView(self.store_sch)
self.treeview_sch.set_rules_hint(True)
treeselection_sch = self.treeview_sch.get_selection()
self.add_sch_columns(self.treeview_sch)
self.set_up_sch()
### ----------------Preview Section---------------- ###
#preview Label
label_pre = gtk.Label("Preview")
label_pre.modify_font(header_font)
label_pre.set_size_request(200, 30)
# preview player buttons
self.btn_pre_play_pause = gtk.Button()
self.btn_pre_play_pause.set_image(self.image_play)
btn_pre_stop = gtk.Button()
btn_pre_stop.set_image(image_stop)
#Label of track to preview
self.str_dur="00:00"
self.label_pre_play = gtk.Label()
self.label_pre_play.set_width_chars(30)
self.label_pre_play.set_tooltip_text("")
self.label_pre_time = gtk.Label("00:00 / 00:00")
#create a list for holding details of message to play
#[Message Title, Message Type, filename, msg/mus]
self.list_pre = ["", "", "", ""]
#hscale slider fer position in track
#both lambdas toggle progressbar to be not updatable by player_pre while valve is dragged
self.progress_pressed = lambda widget, param: self.player_pre.set_updateable_progress(False)
self.hscale_pre = gtk.HScale()
self.hscale_pre.set_range(0, 100)
self.hscale_pre.set_increments(1, 10)
self.hscale_pre.set_digits(0)
self.hscale_pre.set_draw_value(False)
self.hscale_pre.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
# the preview player
self.player_pre = Preview_Player(self.label_pre_time, self.hscale_pre, self.reset_playbutton)
### Date and Time ###
# date label
self.label_date = gtk.Label()
self.label_date.modify_font(subheader_font)
#time label
self.label_time = gtk.Label()
self.label_time.modify_font(header_font)
self.date_and_time()
### dnd and connections ###
self.treeview_cat.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[("copy-row", 0, 0)],
gtk.gdk.ACTION_COPY)
self.treeview_pl3d_lst.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[("copy-row", 0, 0)],
gtk.gdk.ACTION_COPY)
self.treeview_msg.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[("copy-row", 0, 0)],
gtk.gdk.ACTION_COPY)
self.treeview_bc.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[("copy-row", 0, 0)],
gtk.gdk.ACTION_COPY)
self.treeview_bc.enable_model_drag_dest([("copy-row", 0, 0)],
gtk.gdk.ACTION_COPY)
self.treeview_msg.connect("drag_data_get", self.msg_drag_data_get_data)
self.treeview_cat.connect("drag_data_get", self.cat_drag_data_get_data)
self.treeview_pl3d_lst.connect("drag_data_get", self.pl3d_drag_data_get_data)
self.treeview_bc.connect("drag_data_get", self.bc_drag_data_get_data)
self.treeview_sch.connect("drag_data_get", self.sch_drag_data_get_data)
self.treeview_bc.connect("drag_data_received",
self.drag_data_received_data)
self.treeview_sch.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[("copy-row", 0, 0)],
gtk.gdk.ACTION_COPY)
window.connect("delete_event", self.delete_event)
window.connect("destroy", self.destroy)
treeselection_msg.connect('changed', self.msg_selection_changed)
treeselection_cat.connect('changed', self.cat_selection_changed)
treeselection_pl3d_browse.connect('changed', self.pl3d_browse_selection_changed)
treeselection_pl3d_lst.connect('changed', self.cat_selection_changed)
btn_cat_simple.connect("clicked", self.simple_search)
self.entry_cat_simple.connect("activate", self.simple_search)
btn_cat_adv.connect("clicked", self.advanced_search)
self.entry_cat_simple.connect("activate", self.simple_search)
self.entry_cat_artist.connect("activate", self.advanced_search)
self.entry_cat_album.connect("activate", self.advanced_search)
self.entry_cat_title.connect("activate", self.advanced_search)
self.entry_cat_cmpy.connect("activate", self.advanced_search)
self.entry_cat_genre.connect("activate", self.advanced_search)
self.entry_cat_com.connect("activate", self.advanced_search)
btn_pl3d_refresh.connect("clicked", self.get_pl3d_browse)
btn_pl3d_select.connect("clicked", self.get_pl3d)
btn_pl3d_copysel.connect("clicked", self.copy_pl3d_sel)
btn_pl3d_copyall.connect("clicked", self.copy_pl3d_all)
treeselection_bc.connect('changed', self.bc_selection_changed)
btn_testing.connect("clicked", self.test_bc)
btn_inf.connect("clicked", self.info_row)
btn_rem.connect("clicked", self.remove_row)
btn_hist.connect("clicked", self.show_history)
btn_skip.connect("clicked", self.skip_track)
btn_msg_3hr.connect("clicked", self.show_msg_3hr)
self.cb_sch_prg.connect("changed", self.go_to_programme)
btn_sch_refresh.connect("clicked", self.refresh_sch)
btn_sch_now.connect("clicked",self.go_to_now)
btn_sch_add.connect("clicked",self.add_sch_sel)
self.btn_pre_play_pause.connect("clicked", self.play_pause_clicked)
btn_pre_stop.connect("clicked", self.on_stop_clicked)
treeselection_sch.connect('changed', self.sch_selection_changed)
self.hscale_pre.connect("button-release-event", self.on_seek_changed)
self.hscale_pre.connect("button-press-event", self.progress_pressed)
### do the packing ###
sw_msg_lst.add(self.treeview_msg)
sw_bc.add(self.treeview_bc)
vbox_msg_btn.pack_end(sw_msg_btn, True)
sw_msg_btn.add_with_viewport(self.vbox_sw_msg_btn)
hbox_msg.pack_start(vbox_msg_btn, False)
vbox_msg_lst.add(sw_msg_lst)
hbox_msg.add(vbox_msg_lst)
table_cat.attach(label_cat_artist, 0, 1, 0, 1, False, False, 5, 0)
table_cat.attach(self.entry_cat_artist, 1, 2, 0, 1, False, False, 5, 0)
table_cat.attach(label_cat_album, 0, 1, 1, 2, False, False, 5, 0)
table_cat.attach(self.entry_cat_album, 1, 2, 1, 2, False, False, 5, 0)
table_cat.attach(label_cat_title, 0, 1, 2, 3, False, False, 5, 0)
table_cat.attach(self.entry_cat_title, 1, 2, 2, 3, False, False, 5, 0)
table_cat.attach(label_cat_cmpy, 0, 1, 3, 4, False, False, 5, 0)
table_cat.attach(self.entry_cat_cmpy, 1, 2, 3, 4, False, False, 5, 0)
table_cat.attach(label_cat_com, 0, 1, 4, 5, False, False, 5, 0)
table_cat.attach(self.entry_cat_com, 1, 2, 4, 5, False, False, 5, 0)
table_cat.attach(label_cat_genre, 0, 1, 5, 6, False, False, 5, 0)
table_cat.attach(self.entry_cat_genre, 1, 2, 5, 6, False, False, 5, 0)
hbox_cat_creator.pack_start(label_cat_creator, False)
hbox_cat_creator.pack_start(self.cb_cat_creator, False)
vbox_cat_search.pack_start(sep_cat_0, False)
vbox_cat_search.pack_start(label_cat_simple, False)
vbox_cat_search.pack_start(self.entry_cat_simple, False)
vbox_cat_search.pack_start(btn_cat_simple, False)
vbox_cat_search.pack_start(self.label_result_simple, False)
vbox_cat_search.pack_start(sep_cat_1, False)
vbox_cat_search.pack_start(label_cat_adv, False)
vbox_cat_search.pack_start(table_cat, False)
vbox_cat_search.pack_start(hbox_cat_creator, False)
vbox_cat_search.pack_start(self.chk_cat_comp, False)
vbox_cat_search.pack_start(self.chk_cat_demo, False)
vbox_cat_search.pack_start(self.chk_cat_local, False)
vbox_cat_search.pack_start(self.chk_cat_fem, False)
vbox_cat_search.pack_start(btn_cat_adv, False)
vbox_cat_search.pack_start(self.label_result_adv, False)
hbox_cat.pack_start(vbox_cat_search, False)
sw_cat_lst.add(self.treeview_cat)
vbox_cat_lst.add(sw_cat_lst)
hbox_cat.pack_start(vbox_cat_lst, True, True, 0)
vbox_pl3d_opt.pack_start(label_pl3d_browse, False)
sw_pl3d_opt.add(self.treeview_pl3d_browse)
vbox_pl3d_opt.pack_start(sw_pl3d_opt, True)
vbox_pl3d_opt.pack_start(btn_pl3d_refresh, False)
vbox_pl3d_opt.pack_start(btn_pl3d_select, False)
hbox_pl3d_btn.pack_start(btn_pl3d_copysel, False)
hbox_pl3d_btn.pack_start(btn_pl3d_copyall, False)
hbox_pl3d.pack_start(vbox_pl3d_opt, False)
sw_pl3d_lst.add(self.treeview_pl3d_lst)
vbox_pl3d_lst.pack_end(hbox_pl3d_btn, False)
vbox_pl3d_lst.add(sw_pl3d_lst)
hbox_pl3d.pack_start(vbox_pl3d_lst, True)
sw_sch.add(self.treeview_sch)
vbox_sch_move.pack_start(label_sch, False)
vbox_sch_move.pack_start(btn_sch_refresh, False)
#vbox_sch_move.pack_start(self.cb_sch_prg, False)
vbox_sch_move.pack_start(btn_sch_now, False)
vbox_sch_move.pack_end(btn_sch_add, False)
hbox_sch_pre.pack_start(vbox_sch_move, False)
hbox_sch_pre.pack_start(sw_sch, True, True, 0)
hbox_pre_btn.pack_start(self.btn_pre_play_pause, False)
hbox_pre_btn.pack_start(btn_pre_stop, False)
vbox_pre.pack_start(label_pre, False)
vbox_pre.pack_start(hbox_pre_btn, False)
vbox_pre.pack_start(self.label_pre_play, False, False, 5)
vbox_pre.pack_start(self.hscale_pre)
vbox_pre.pack_start(self.label_pre_time, False)
vbox_pre.pack_start(self.label_date)
vbox_pre.pack_start(self.label_time)
hbox_sch_pre.pack_end(vbox_pre, False, False, 0)
vbox_nb.pack_start(notebook, False, False, 5)
notebook.append_page(hbox_msg, label_msg_btn)
notebook.append_page(hbox_cat, label_cat)
notebook.append_page(hbox_pl3d, label_pl3d)
vbox_nb.pack_start(hbox_sch_pre, True, True, 0)
vbox_bc.pack_start(label_bc, False)
vbox_bc.pack_start(self.label_air, False)
#vbox_bc.pack_start(btn_testing, False)
vbox_bc.pack_start(self.progressbar, False)
hbox_bc_0.pack_start(self.label_bc_time, True)
hbox_bc_0.pack_end(btn_skip, False)
hbox_bc_1.pack_start(btn_inf, False)
hbox_bc_1.pack_start(btn_rem, False)
hbox_bc_1.pack_start(btn_msg_3hr, False)
hbox_bc_1.pack_start(btn_hist, False)
hbox_bc_1.pack_start(self.spinbutton, False)
hbox_bc_time.pack_end(self.label_time_1, False)
hbox_bc_time.pack_end(label_time_0, False)
#hbox_bc_2.pack_start(sw_bc, False, True, 0)
vbox_bc.pack_start(hbox_bc_0, False)
vbox_bc.pack_start(hbox_bc_1, False)
#vbox_bc.pack_start(hbox_bc_2, True)
vbox_bc.pack_start(sw_bc, True)
vbox_bc.pack_start(hbox_bc_time, False)
hbox_main.pack_start(vbox_nb, True, True, 0)
hbox_main.pack_end(vbox_bc, False, False, 0)
vbox_main.add(hbox_main)
window.add(vbox_main)