-
Notifications
You must be signed in to change notification settings - Fork 1
/
listmaker.py
2457 lines (2126 loc) · 83.3 KB
/
listmaker.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/python3
'''
listmaker
search for tracks and add them to a list which can be saved
for loading into the studio player
'''
import datetime
import pickle
import os
import time
import base64
import threading
import configparser
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gst', '1.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gst
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Pango
import psycopg2
import psycopg2.extras
from psycopg2 import sql
import json
from lxml import etree
import pydub
import gst_player
from gst_player import Player
#get variables from config file
config = configparser.ConfigParser()
config.read('/usr/local/etc/threedradio.conf')
dir_pl3d = config.get('Paths', 'dir_pl3d')
dir_mus = config.get('Paths', 'dir_mus')
dir_img = config.get('Paths', 'dir_img')
logo = config.get('Images', 'logo')
query_limit = config.getint('Listmaker', 'query_limit')
pg_user = config.get('Listmaker', 'pg_user')
pg_password = config.get('Listmaker', 'pg_password')
pg_server = config.get('Common', 'pg_server')
pg_cat_database = config.get('Common', 'pg_cat_database')
#other variables
sfx = ".p3d"
sfx_old = ".pl3d"
#lists and dictionaries
unys = ("unknown", "no", "yes", "some")
select_items = (
"cd.title",
"cd.artist",
"cd.company",
"cd.year",
"cd.arrivaldate",
"cd.demo",
"cd.local",
"cd.female",
"cd.compilation",
"cd.createwho",
"cd.createwhen",
"cd.genre",
"cd.cpa",
"cdtrack.trackid",
"cdtrack.cdid",
"cdtrack.tracknum",
"cdtrack.tracktitle",
"cdtrack.trackartist",
"cdtrack.tracklength",
"cdcomment.comment"
)
order_results = {
"Newest Albums First": (("year", "DESC"), ("id", "DESC")),
"Oldest Albums First": (("year", "ASC"), ("id", "ASC")),
"Artist Alphabetical": (("artist", "ASC"), ("id", "DESC")),
"Album Alphabetical": (("title", "ASC"), ("id", "DESC")),
"Most Recently Added": (("createwhen", "DESC"), ("id", "DESC"))
}
class SpinnerDialog(Gtk.Dialog):
'''
show spinner and run export
'''
def __init__(self, parent, filelist, export_file):
Gtk.Dialog.__init__(self, "Working...", parent, 0, None)
box = self.get_content_area()
spinner = Gtk.Spinner()
spinner.start()
box.add(spinner)
label = Gtk.Label(label="Exporting playlist, please wait")
box.add(label)
# Connect to the 'delete-event' signal
self.connect('delete-event', Gtk.main_quit)
# Run the time-consuming task in a separate thread
self.task_thread = threading.Thread(target=self.combine_export, args=[filelist, export_file])
self.task_thread.start()
# Set the dialog to be modal
self.set_modal(True)
# Show the dialog
self.show_all()
def combine_export(self, filelist, export_file):
'''
subfunction run in thread to create combined export
'''
#print("exporting")
combined = pydub.AudioSegment.empty()
for song in filelist:
audiosegment = pydub.AudioSegment.from_file(song, format="mp3")
combined = combined + audiosegment
combined.export(export_file, format="mp3")
#print("export completed")
GLib.idle_add(self.destroy)
class List_Maker():
def delete_event(self, widget, event, data=None):
'''
Check for confirmation or need to save before application quits.
'''
if self.changed:
response = self.save_change()
if response == Gtk.ResponseType.ACCEPT:
self.save(None)
self.window.destroy()
return False
elif response == Gtk.ResponseType.REJECT:
self.window.destroy()
return False
elif response == Gtk.ResponseType.CANCEL:
return True
else:
response = self.confirm_close()
return response
def destroy(self, widget, data=None):
Gtk.main_quit()
def main(self):
'''defines the layout of the graphical interface
and the events connected to the widgets
'''
super().__init__()
self.window = Gtk.Window()
self.window.set_position(Gtk.WindowPosition.CENTER)
filepath_logo = dir_img + logo
self.window.set_icon_from_file(filepath_logo)
self.window.set_title("Listmaker")
### create containers - boxes and scrolled windows ###
# hbox for music catalogue
hbox_cat = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
hbox_cat.set_margin_top(5)
# vbox for catalogue search
vbox_cat_search = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
vbox_cat_search.set_margin_start(5)
# table for music catalogue search
grid_cat = Gtk.Grid(hexpand=False, vexpand=False)
grid_cat.set_valign(Gtk.Align.FILL)
grid_cat.set_margin_top(margin=5)
grid_cat.set_margin_end(margin=5)
grid_cat.set_margin_bottom(margin=5)
grid_cat.set_margin_start(margin=5)
grid_cat.set_row_spacing(spacing=5)
grid_cat.set_column_spacing(spacing=5)
grid_cat.set_row_homogeneous(False)
grid_cat.set_column_homogeneous(False)
# vbox for catalogue list
vbox_cat_lst = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
vbox_cat_lst.set_halign(Gtk.Align.FILL)
vbox_cat_lst.set_valign(Gtk.Align.FILL)
# scrolled window for catalogue list treeview
self.sw_cat_lst = Gtk.ScrolledWindow()
self.sw_cat_lst.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
self.sw_cat_lst.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.sw_cat_lst.set_propagate_natural_width(True)
# hbox for preview player buttons
hbox_pre_btn = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
# vbox for playlist
vbox_pl = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
vbox_pl.set_margin_end(5)
# hbox for list option buttons in the playlist
hbox_pl = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
# scrolled holder for the playlist treelist
sw_pl = Gtk.ScrolledWindow()
sw_pl.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
sw_pl.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
# hbox for Total Time
hbox_pl_time = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
### ----------------Music Catalogue Search ---------------- ###
label_search = Gtk.Label(label="")
label_search.set_markup("<span font='Sans Bold 14'> Search </span>")
label_search.set_halign(Gtk.Align.START)
label_search_artist = Gtk.Label(label="Artist")
label_search_artist.set_halign(Gtk.Align.END)
self.entry_search_artist = Gtk.Entry()
label_search_album = Gtk.Label(label="Album")
label_search_album.set_halign(Gtk.Align.END)
self.entry_search_album = Gtk.Entry()
label_search_track = Gtk.Label(label="Track")
label_search_track.set_halign(Gtk.Align.END)
self.entry_search_track = Gtk.Entry()
label_search_cmpy = Gtk.Label(label="Company")
label_search_cmpy.set_halign(Gtk.Align.END)
self.entry_search_cmpy = Gtk.Entry()
label_search_genre = Gtk.Label(label="Genre")
label_search_genre.set_halign(Gtk.Align.END)
self.entry_search_genre = Gtk.Entry()
label_search_com = Gtk.Label(label="Comments")
label_search_com.set_halign(Gtk.Align.END)
self.entry_search_com = Gtk.Entry()
label_search_cpa = Gtk.Label(label="Country")
label_search_cpa.set_halign(Gtk.Align.END)
self.entry_search_cpa = Gtk.Entry()
label_search_year = Gtk.Label(label="Release year")
label_search_year.set_halign(Gtk.Align.END)
self.entry_search_year = Gtk.Entry()
self.entry_search_year.set_max_length(4)
label_search_creator = Gtk.Label(label="Added by")
label_search_creator.set_halign(Gtk.Align.END)
self.cb_search_creator = Gtk.ComboBoxText()
self.cb_search_creator = Gtk.ComboBoxText()
self.cb_search_creator.set_name('mycombo')
self.dict_creator = self.get_dict_creator()
self.cb_creator_add(self.dict_creator)
self.chk_search_comp = Gtk.CheckButton.new_with_label("Compilation")
self.chk_search_comp.set_active(False)
self.chk_search_aus = Gtk.CheckButton.new_with_label("Australian")
self.chk_search_aus.set_active(False)
self.chk_search_demo = Gtk.CheckButton.new_with_label("Demo")
self.chk_search_demo.set_active(False)
self.chk_search_local = Gtk.CheckButton.new_with_label("Local")
self.chk_search_local.set_active(False)
self.chk_search_fem = Gtk.CheckButton.new_with_label("Female")
self.chk_search_fem.set_active(False)
self.chk_search_nr = Gtk.CheckButton.new_with_label("New Entries")
self.chk_search_nr.set_active(False)
label_search_order = Gtk.Label(label="Order by")
label_search_order.set_halign(Gtk.Align.END)
self.cb_search_order = Gtk.ComboBoxText()
self.cb_order_add()
label_search_max = Gtk.Label(label="Maximum Results")
label_search_max.set_halign(Gtk.Align.END)
query_limit = config.getint('Listmaker', 'query_limit')
adjustment_max = Gtk.Adjustment(
value=query_limit,
lower=1,
upper=10000,
step_increment=50,
page_increment=500,
page_size=50)
self.spin_search_max = Gtk.SpinButton()
self.spin_search_max.set_adjustment(adjustment_max)
self.spin_search_max.set_value(query_limit)
btn_search = Gtk.Button(label="Search")
btn_search.set_halign(Gtk.Align.START)
self.label_search_result = Gtk.Label()
### ----------- Search Results Section -----------###
label_results = Gtk.Label()
label_results.set_halign(Gtk.Align.START)
label_results.set_markup("<span font='Sans Bold 14'> Results </span>")
#make the list
self.store_cat = Gtk.TreeStore(str ,str ,str, str, str)
self.treeview_cat = Gtk.TreeView(model = self.store_cat)
self.treeview_cat.set_name("cat")
self.treeview_cat.set_halign(Gtk.Align.FILL)
treeselection_cat = self.treeview_cat.get_selection()
self.add_cat_columns(self.treeview_cat)
self.dict_results = {}
# button to expand or collapse all in treeview
self.button_expand = Gtk.Button(
label="Expand All",
halign=Gtk.Align.START
)
self.button_expand.connect("clicked", self.expand_collapse)
### ------------ Preview Section ------------ ###
self.btn_pre_play_pause = Gtk.Button()
self.image_play = Gtk.Image.new_from_icon_name("media-playback-start", Gtk.IconSize.BUTTON)
self.image_pause = Gtk.Image.new_from_icon_name("media-playback-pause", Gtk.IconSize.BUTTON)
self.btn_pre_play_pause.set_image(self.image_play)
btn_pre_stop = Gtk.Button()
image_stop = Gtk.Image.new_from_icon_name("media-playback-stop", Gtk.IconSize.BUTTON)
btn_pre_stop.set_image(image_stop)
btn_pre_stop.connect("clicked", self.on_stop_clicked)
#Label of track to preview
self.str_dur="00:00"
self.label_pre_time = Gtk.Label(label="00:00 / 00:00")
self.hscale_pre = Gtk.HScale(
halign=Gtk.Align.FILL,
hexpand=True)
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)
# the preview player
soundcard = "default"
self.player = Player(
self.label_pre_time, self.hscale_pre, soundcard)
### ---------- Playlist Section ---------- ###
self.changed = False
self.dict_pl = {}
label_pl = Gtk.Label()
label_pl.set_markup("<span font='Sans Bold 14'> Playlist </span>")
label_pl.set_valign(Gtk.Align.START)
label_pl.set_halign(Gtk.Align.START)
# Create a menu and items
menu = Gtk.Menu()
item_detail = Gtk.MenuItem(label="Details")
item_remove = Gtk.MenuItem(label="Remove")
item_new = Gtk.MenuItem(label="New")
item_open = Gtk.MenuItem(label="Open")
item_save = Gtk.MenuItem(label="Save")
item_saveas = Gtk.MenuItem(label="Save as")
item_export = Gtk.MenuItem(label="Export")
item_quit = Gtk.MenuItem(label="Quit")
# Add items to the menu
menu.append(item_detail)
menu.append(item_remove)
menu.append(item_new)
menu.append(item_open)
menu.append(item_save)
menu.append(item_saveas)
menu.append(item_export)
menu.append(item_quit)
# Show the menu items
menu.show_all()
# Create a MenuButton with icon
menu_button = Gtk.MenuButton()
menu_button.set_popup(menu)
menu_image = Gtk.Image.new_from_icon_name(
"open-menu-symbolic",
Gtk.IconSize.BUTTON
)
menu_button.add(menu_image)
# create treeview with store model
self.store_pl = Gtk.ListStore(str, str, str)
self.treeview_pl = Gtk.TreeView(model=self.store_pl)
self.treeview_pl.set_name("pl")
treeselection_pl = self.treeview_pl.get_selection()
self.add_pl_columns(self.treeview_pl)
# total track time
label_time_0 = Gtk.Label(label="Playlist Total Time - ")
self.label_time_1 = Gtk.Label(label="00:00 ")
### dnd and connections ###
self.treeview_cat.enable_model_drag_source(
Gdk.ModifierType.BUTTON1_MASK,
[("text/plain", 0, 0)],
Gdk.DragAction.COPY
)
self.treeview_pl.enable_model_drag_source(
Gdk.ModifierType.BUTTON1_MASK,
[("text/plain", 0, 0)],
Gdk.DragAction.MOVE
)
self.treeview_pl.enable_model_drag_dest(
[("text/plain", 0, 0)],
Gdk.DragAction.MOVE | Gdk.DragAction.COPY
)
self.treeview_cat.connect("drag_data_get", self.cat_drag_data_get_data)
self.treeview_pl.connect("drag_data_get", self.pl_drag_data_get_data)
self.treeview_pl.connect("drag_data_received",
self.drag_data_received_data)
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
treeselection_cat.connect('changed', self.cat_selection_changed)
self.entry_search_artist.connect("activate", self.search_catalogue)
self.entry_search_album.connect("activate", self.search_catalogue)
self.entry_search_track.connect("activate", self.search_catalogue)
self.entry_search_cmpy.connect("activate", self.search_catalogue)
self.entry_search_genre.connect("activate", self.search_catalogue)
self.entry_search_com.connect("activate", self.search_catalogue)
self.entry_search_cpa.connect("activate", self.search_catalogue)
self.entry_search_year.connect("activate", self.search_catalogue)
self.cb_search_order.connect("changed", self.search_catalogue)
btn_search.connect("clicked", self.search_catalogue)
self.btn_pre_play_pause.connect("clicked", self.play_pause_clicked)
btn_pre_stop.connect("clicked", self.on_stop_clicked)
item_detail.connect("activate", self.info_row)
item_remove.connect("activate", self.remove_row)
item_new.connect("activate", self.new)
item_open.connect("activate", self.open_dialog)
item_save.connect("activate", self.save)
item_saveas.connect("activate", self.saveas)
item_export.connect("activate", self.export)
item_quit.connect("activate", self.delete_event, None)
self.treeview_cat.connect('button-release-event' , self.right_click_cat_list_menu)
self.treeview_pl.connect('button-release-event' , self.right_click_pl_list_menu)
### do the packing ###
hbox_pre_btn.pack_start(self.button_expand, False, False, 5)
hbox_pre_btn.pack_start(self.btn_pre_play_pause, False, False, 0)
hbox_pre_btn.pack_start(btn_pre_stop, False, False, 0)
hbox_pre_btn.pack_start(self.hscale_pre, True, True, 0)
hbox_pre_btn.pack_start(self.label_pre_time, False, False, 0)
grid_cat.attach(
child=label_search_artist,
left=0,
top=0,
width=1,
height=1)
grid_cat.attach(
child=self.entry_search_artist,
left=1,
top=0,
width=2,
height=1)
grid_cat.attach(
child=label_search_track,
left=0,
top=1,
width=1,
height=1
)
grid_cat.attach(
child=self.entry_search_track,
left=1,
top=1,
width=2,
height=1
)
grid_cat.attach(
child=label_search_album,
left=0,
top=2,
width=1,
height=1
)
grid_cat.attach(
child=self.entry_search_album,
left=1,
top=2,
width=2,
height=1
)
grid_cat.attach(
child=label_search_cmpy,
left=0,
top=3,
width=1,
height=1
)
grid_cat.attach(
child=self.entry_search_cmpy,
left=1,
top=3,
width=2,
height=1
)
grid_cat.attach(
child=label_search_com,
left=0,
top=4,
width=1,
height=1
)
grid_cat.attach(
child=self.entry_search_com,
left=1,
top=4,
width=2,
height=1
)
grid_cat.attach(
child=label_search_genre,
left=0,
top=5,
width=1,
height=1
)
grid_cat.attach(
child=self.entry_search_genre,
left=1,
top=5,
width=2,
height=1
)
grid_cat.attach(
child=label_search_cpa,
left=0,
top=6,
width=1,
height=1
)
grid_cat.attach(
child=self.entry_search_cpa,
left=1,
top=6,
width=2,
height=1
)
grid_cat.attach(
child=label_search_year,
left=0,
top=7,
width=1,
height=1
)
grid_cat.attach(
child=self.entry_search_year,
left=1,
top=7,
width=2,
height=1
)
grid_cat.attach(
child=label_search_creator,
left=0,
top=8,
width=1,
height=1
)
grid_cat.attach(
child=self.cb_search_creator,
left=1,
top=8,
width=2,
height=1
)
grid_cat.attach(
child=self.chk_search_local,
left=0,
top=9,
width=1,
height=1
)
#grid_cat.attach(
# child=self.chk_search_aus,
# left=1,
# top=9,
# width=2,
# height=1
# )
grid_cat.attach(
child=self.chk_search_fem,
left=0,
top=10,
width=1,
height=1
)
grid_cat.attach(
child=self.chk_search_nr,
left=1,
top=9,
width=2,
height=1
)
grid_cat.attach(
child=self.chk_search_demo ,
left=0,
top=11,
width=1,
height=1
)
grid_cat.attach(
child=self.chk_search_comp ,
left=1,
top=10,
width=2,
height=1
)
grid_cat.attach(
child=label_search_order,
left=0,
top=12,
width=1,
height=1
)
grid_cat.attach(
child=self.cb_search_order,
left=1,
top=12,
width=2,
height=1
)
grid_cat.attach(
child=label_search_max,
left=0,
top=13,
width=2,
height=1
)
grid_cat.attach(
child=self.spin_search_max,
left=2,
top=13,
width=1,
height=1
)
vbox_cat_search.pack_start(label_search, False, False, 0)
vbox_cat_search.pack_start(grid_cat, False, False, 0)
vbox_cat_search.pack_start(btn_search, False, False, 0)
vbox_cat_search.pack_start(self.label_search_result, False, False, 0)
self.sw_cat_lst.add(self.treeview_cat)
sw_pl.add(self.treeview_pl)
vbox_cat_lst.pack_start(label_results, False, False, 0)
vbox_cat_lst.pack_start(self.sw_cat_lst, True, True, 0)
vbox_cat_lst.pack_start(hbox_pre_btn, False, False, 0)
hbox_pl_time.pack_end(self.label_time_1, False, False, 0)
hbox_pl_time.pack_end(label_time_0, False, False, 0)
hbox_pl.pack_start(label_pl, False, False, 0)
hbox_pl.pack_end(menu_button, False, False, 5)
vbox_pl.pack_start(hbox_pl, False, False, 0)
vbox_pl.pack_start(sw_pl, True, True, 0)
vbox_pl.pack_start(hbox_pl_time, False, False, 0)
hbox_cat.pack_start(vbox_cat_search, False, False, 0)
hbox_cat.pack_start(vbox_cat_lst, True, True, 0)
hbox_cat.pack_start(vbox_pl, False, False, 0)
self.window.add(hbox_cat)
self.window.show_all()
self.Saved = False
self.name_of_open_file = None
Gtk.main()
# columns for the lists
def add_cat_columns(self, treeview):
'''
Columns for the list of search results. The first column is hidden
and contains all the information about the track/CD in that row
'''
#Column ONE
column = Gtk.TreeViewColumn('ID', Gtk.CellRendererText(),
text=0)
column.set_sort_column_id(0)
column.set_visible(False)
treeview.append_column(column)
#Column TWO
column = Gtk.TreeViewColumn('Artist', Gtk.CellRendererText(),
text=1)
column.set_sort_column_id(1)
column.set_clickable(False)
column.set_expand(True)
column.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY)
column.set_fixed_width(120)
treeview.append_column(column)
#Column THREE
column = Gtk.TreeViewColumn('Album/Title', Gtk.CellRendererText(),
text=2)
column.set_sort_column_id(2)
column.set_clickable(False)
column.set_expand(True)
column.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY)
column.set_fixed_width(120)
treeview.append_column(column)
#Column FOUR
column = Gtk.TreeViewColumn('Quota', Gtk.CellRendererText(),
text=3)
column.set_sort_column_id(3)
column.set_clickable(False)
column.set_expand(False)
column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
column.set_fixed_width(66)
treeview.append_column(column)
#Column FIVE
column = Gtk.TreeViewColumn('Length', Gtk.CellRendererText(),
text=4)
column.set_sort_column_id(4)
column.set_expand(False)
column.set_clickable(False)
column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
column.set_fixed_width(68)
treeview.append_column(column)
def add_pl_columns(self, treeview):
'''
Columns for the playlist of tracks. The first column is hidden
and contains all the information about the track in that row
'''
# Column ONE
column = Gtk.TreeViewColumn('ID', Gtk.CellRendererText(),
text=0)
column.set_sort_column_id(0)
column.set_visible(False)
treeview.append_column(column)
# Column TWO
column = Gtk.TreeViewColumn('Title/Artist', Gtk.CellRendererText(),
text=1)
column.set_sort_column_id(1)
column.set_clickable(False)
column.set_max_width(360)
column.set_fixed_width(180)
column.set_expand(True)
column.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY)
treeview.append_column(column)
# Column THREE
column = Gtk.TreeViewColumn('Time', Gtk.CellRendererText(),
text=2)
column.set_sort_column_id(3)
column.set_clickable(False)
treeview.append_column(column)
# dnd
def cat_drag_data_get_data(self, treeview, context, selection, target_id,
etime):
'''
copy the track id from the hidden first column of the selected
row for drag n drop from the search results list. If the
track length, it is a CD and set the track_id to "0"
'''
treeselection = treeview.get_selection()
model, tree_iter = treeselection.get_selected()
track_id = model.get_value(tree_iter, 0)
title = model.get_value(tree_iter, 2)
artist = model.get_value(tree_iter, 1)
duration = model.get_value(tree_iter, 4)
title_artist = title + '\n' + artist
drag_data = (track_id, title_artist, duration)
text = str(drag_data)
selection.set_text(text, -1)
def pl_drag_data_get_data(self, treeview, context, selection, target_id,
etime):
'''
copy the track id from the hidden first column of the selected
row for drag n drop within the playlist.
'''
treeselection = treeview.get_selection()
model, tree_iter = treeselection.get_selected()
track_id = model.get_value(tree_iter, 0)
title_artist = model.get_value(tree_iter, 1)
duration = model.get_value(tree_iter, 2)
items = (track_id, title_artist, duration)
text = str(items)
selection.set_text(text, -1)
#model.remove(tree_iter)
def drag_data_received_data(self, treeview, context, x, y, selection,
info, etime):
'''
add or move a row in the playlist using details copied with drag n drop.
'''
actions = context.get_actions()
model = treeview.get_model()
str_drag_data = selection.get_text()
track_id, title_artist, duration = eval(str_drag_data)
if "copy" in actions.value_nicks:
dict_track = self.dict_results[track_id]
cdid = str(format(dict_track['cdid'], '07d'))
tracknum = str(format(dict_track['tracknum'], '02d'))
filename = cdid + "-" + tracknum
#print(filename)
filepath = self.get_filepath(filename)
if not filepath:
str_error = "Unable to add to the list, file does not exist. That track has probably not yet been ripped into the music store"
self.error_dialog(str_error)
return
treeview_name = treeview.get_name()
drop_list = (track_id, title_artist, duration)
path, position = treeview.get_dest_row_at_pos(x, y) or (
None, None)
if path:
tree_iter = model.get_iter(path)
if (position == Gtk.TreeViewDropPosition.BEFORE
or position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
tree_iter = model.insert_before(model.get_iter(path), drop_list)
else:
tree_iter = model.insert_after(model.get_iter(path), drop_list)
else:
tree_iter = model.append(drop_list)
#If moving, delete originating row
if "move" in actions.value_nicks:
source_liststore = treeview.get_model()
source_selection = treeview.get_selection()
source_model, source_treeiter = source_selection.get_selected()
source_liststore.remove(source_treeiter)
else:
self.dict_pl[track_id] = self.dict_results[track_id]
path = model.get_path(tree_iter)
treeview.set_cursor(path)
self.update_time_total()
self.changed = True
return
# music catalogue section
def pg_connect_cat(self):
'''
initiate a connection to the catalogue database
'''
conn_string = 'dbname={0} user={1} host={2} password={3}'.format (
pg_cat_database, pg_user, pg_server, pg_password)
conn = psycopg2.connect(conn_string)
return conn
def search_catalogue(self, widget):
'''
run functions which query the database and display the results as a list
'''
search_terms = self.get_search_terms()
query = self.create_query(search_terms)
result = self.execute_query(query, search_terms)
if result:
int_res = len(result)
self.update_result_label(int_res)
self.length_check(result)
list_dict_data = self.process_result(result)
self.add_to_cat_store(list_dict_data)
self.button_expand.set_label("Expand All")
else:
self.clear_cat_list()
int_res = 0
self.update_result_label(int_res)
self.button_expand.set_label("Expand All")
def get_search_terms(self):
'''
Make a query to the catalogue database based on the user input.
Return the results.
'''
#obtain text from entries and combos and add to parameter dictionary
search_terms = {}
artist = self.entry_search_artist.get_text()
if artist:
artist = self.add_percent(artist)
search_terms["cd.artist"] = artist
album = self.entry_search_album.get_text()
if album:
album = self.add_percent(album)
search_terms["cd.title"] = album
track = self.entry_search_track.get_text()
if track:
track = self.add_percent(track)
search_terms["cdtrack.tracktitle"] = track
company = self.entry_search_cmpy.get_text()
if company:
company = self.add_percent(company)
search_terms["cd.company"] = company
comments = self.entry_search_com.get_text()
if comments:
comments = self.add_percent(comments)
search_terms["cdcomment.comment"] = comments
genre = self.entry_search_genre.get_text()
if genre:
genre = self.add_percent(genre)
search_terms["cd.genre"] = genre
cpa = self.entry_search_cpa.get_text()
if cpa:
cpa = self.add_percent(cpa)
search_terms["cd.cpa"] = cpa
year = self.entry_search_year.get_text()
if year:
try:
year = int(year)
search_terms["cd.year"] = year
except ValueError:
str_error = '''
Not a valid year
'''
self.error_dialog(str_error)
creator = self.cb_search_creator.get_active_text()
if creator:
# let's hope for the interim that we do not get
# two members who have the same name ...
for id in self.dict_creator.keys():
if self.dict_creator[id] == creator:
created_by = id
search_terms["cd.createwho"] = created_by
compil = self.chk_search_comp.get_active()
if compil:
search_terms["cd.compilation"] = 2
demo = self.chk_search_demo .get_active()
if demo:
search_terms["cd.demo"] = 2
local = self.chk_search_local.get_active()
if local:
search_terms["cd.local"] = 2
female = self.chk_search_fem.get_active()
if female:
search_terms["cd.female"] = 2
new_release = self.chk_search_nr.get_active()
if new_release:
today = datetime.date.today()
nr_delta = datetime.timedelta(days=60)
nr = today - nr_delta
search_terms["cd.arrivaldate"] = nr
str_error_none = "I can't see what you are searching for"
str_error_len = "Please enter more than one character in your search"
if not (artist or
album or
track or
company or
comments or
creator or
genre or
new_release or
year or
cpa):
self.error_dialog(str_error_none)
return False
return search_terms
def create_query(self, search_terms):
select_statement = sql.SQL("SELECT")
for i, item in enumerate(select_items):
table, column = item.split(".")
table = sql.Identifier(table)
column = sql.Identifier(column)