~ubuntu-branches/ubuntu/natty/exaile/natty

« back to all changes in this revision

Viewing changes to xl/gui/playlist.py

  • Committer: Bazaar Package Importer
  • Author(s): Nick Ellery
  • Date: 2008-11-04 18:33:00 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20081104183300-e4t9seztl35bdb24
Tags: 0.2.14-0ubuntu1
* New upstream release (LP: #280287)
* debian/control:
  - tighten dependency on python-gtk2 to (>= 2.10)
  - added python-sexy to recommends to add a clear button to filters
  - added python-gnome2-extras to recommends for lyrics, better tray icon,
    etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    """
32
32
    if (caller.rating_width != caller.old_r_w and caller.rating_width != 0):
33
33
        caller.rating_images = []
34
 
        star_size = caller.rating_width / 4
 
34
        star_size = caller.rating_width / 5
35
35
 
36
36
        star = gtk.gdk.pixbuf_new_from_file_at_size(
37
37
            xl.path.get_data('images', 'star.png'), star_size, star_size)
38
38
 
39
 
        star_size -= 1
40
 
 
41
39
        full_image = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, caller.rating_width, star_size)
42
40
        full_image.fill(0xffffff00) # transparent white
43
 
        for x in range(0, 4):
 
41
        for x in range(0, 5):
44
42
            star.copy_area(0, 0, star_size, star_size, full_image, star_size * x, 0)
45
43
        caller.rating_images.insert(0, full_image)
46
 
        for x in range(7, 0, -1):
 
44
        for x in range(5, 0, -1):
47
45
            this_image = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, caller.rating_width, star_size)
48
46
            this_image.fill(0xffffff00) # transparent white
49
 
            full_image.copy_area(0, 0, int(x * star_size / 2.0), star_size, this_image, 0, 0)
 
47
            full_image.copy_area(0, 0, int(x * star_size), star_size, this_image, 0, 0)
50
48
            caller.rating_images.insert(0, this_image)
51
49
        caller.old_r_w = caller.rating_width
52
50
 
75
73
        Column('album', _('Album'), 150),
76
74
        Column('length', _('Length'), 50),
77
75
        Column('disc_id', _('Disc'), 30),
78
 
        Column('rating', _('Rating'), 80),
 
76
        Column('rating', _('Rating'), 64),
79
77
        Column('year', _('Year'), 50),
80
78
        Column('genre', _('Genre'), 100),
81
79
        Column('bitrate', _('Bitrate'), 30),
107
105
        self.exaile = exaile
108
106
        self.list = xlmisc.DragTreeView(self)
109
107
        self.list.set_rules_hint(True)
110
 
        self.list.set_enable_search(False)
 
108
        self.list.set_enable_search(True)
111
109
        self.songs = library.TrackData()
112
110
 
113
111
        self.scroll = gtk.ScrolledWindow()
133
131
        self.tpm = None
134
132
        self.plugins_item = None
135
133
        self.setup_columns()
136
 
 
 
134
        self.setup_events()
 
135
        
137
136
        create_rating_images(self)
138
137
 
139
138
        self.show()
140
 
        
141
 
        self.setup_events()
142
 
 
143
139
 
144
140
    def close_page(self):
145
141
        """
146
142
            Called when this page in the notebook is closed
147
143
        """
148
 
        pass
 
144
        #Save the playlist order to the db
 
145
        cur = self.db.cursor()
 
146
        sort_index = 0;
 
147
        for track in self.songs:
 
148
            if track.type == 'stream': continue
 
149
            path_id = library.get_column_id(self.db, 'paths', 'name', track.loc)
 
150
            self.db.execute("UPDATE playlist_items SET sort_index=? " \
 
151
            "WHERE playlist_items.path=?" 
 
152
                            , (sort_index,path_id) )
 
153
            sort_index = sort_index + 1
 
154
        self.db.commit()
149
155
 
150
156
    def drag_data_received(self, tv, context, x, y, selection, info, etime):
151
157
        """
428
434
        """
429
435
            Called when someone presses a key
430
436
        """
431
 
 
 
437
        
432
438
        selection = self.list.get_selection()
433
439
        (model, pathlist) = selection.get_selected_rows()
434
440
 
451
457
                path = pathlist[0]
452
458
                if path[0] >= len(self.songs): path = (path[0] - 1,)
453
459
                selection.select_path(path)
454
 
        # Q
455
 
        elif event.keyval == gtk.keysyms.q and self.type != 'queue':
456
 
            for path in pathlist:
457
 
                iter = model.get_iter(path)
458
 
                track = model.get_value(iter, 0)
459
 
                if not track in self.exaile.player.queued:
460
 
                    self.exaile.player.queued.append(track)
461
 
                else:
462
 
                    self.exaile.player.queued.remove(track)
463
460
 
464
461
            update_queued(self.exaile)
465
462
            self.queue_draw()
490
487
        self._length_id = -1
491
488
 
492
489
        col_ids = self.exaile.settings.get_list("ui/col_order", None)
 
490
        search_column = self.exaile.settings.get_str("ui/search_column","Title")
 
491
        
493
492
        cols = None
494
493
        if col_ids:
495
494
            cols = []
587
586
 
588
587
                if col_struct.id in ('track', 'playcount'):
589
588
                    cellr.set_property('xalign', 1.0)
590
 
 
 
589
                    
 
590
                # Update which column to search for when columns are changed
 
591
                if col_struct.display == search_column:
 
592
                    self.list.set_search_column(count)
591
593
                col.set_widget(gtk.Label(col_struct.display))
592
594
                col.get_widget().show()
593
595
                self.list.append_column(col)
666
668
 
667
669
    def rating_data_func(self, col, cell, model, iter):
668
670
        item = model.get_value(iter, 0)
669
 
        if not item.rating: return
670
 
        idx = len(item.rating) / 2 - 1
671
 
        cell.set_property('pixbuf', self.rating_images[idx])
 
671
        if not item._rating: return
 
672
        try:
 
673
            idx = item._rating - 1
 
674
            cell.set_property('pixbuf', self.rating_images[idx])
 
675
        except IndexError:
 
676
            if idx > 5: idx = 5
 
677
            elif idx < 0: idx = 0
672
678
 
673
679
    def set_cell_weight(self, cell, item):
674
680
        """
819
825
            Sets the songs in this table (expects a list of tracks)
820
826
        """
821
827
        self.songs = library.TrackData()
822
 
 
 
828
        search_column = self.exaile.settings.get_str("ui/search_column","Title")
823
829
        # save sort indicators, because they get reset when you set the model
824
830
        indicators = {}
825
831
        self.model.clear()
829
835
        self.list.set_model(self.model_blank)
830
836
        if update_playlist: self.playlist_songs = songs
831
837
        for song in songs:
832
 
            self.append_song(song)
 
838
            self.append_song(song,False)
 
839
        self.songs = songs;
833
840
 
834
841
        self.list.set_model(self.model)
 
842
        count = 3
835
843
        for col in self.list.get_columns():
836
844
            col.set_sort_indicator(indicators[col.get_title()])
 
845
            # We have to set search_column here because the model was cleared
 
846
            if col.get_title() == search_column:
 
847
                self.list.set_search_column(count)
 
848
            count = count + 1  
837
849
 
838
850
    def get_ar(self, song):
839
851
        """
844
856
            ar.append(getattr(song, field))
845
857
        return ar
846
858
 
847
 
    def append_song(self, song):
 
859
    def append_song(self, song, append_to_list = True):
848
860
        """
849
861
            Adds a song to this view
850
862
        """
851
863
        ar = self.get_ar(song)
852
864
 
853
865
        self.model.append(ar)
854
 
        if not song in self.songs: self.songs.append(song)
 
866
        if append_to_list: self.songs.append(song)
855
867
 
856
868
    def update_iter(self, iter, song):
857
869
        """
929
941
            editor.TrackEditor(self.exaile, self), 'gtk-edit')
930
942
 
931
943
        rm = xlmisc.Menu()
932
 
        self.rating_ids = []
933
944
 
934
 
        for i in range(0, 8):
935
 
            item = rm.append_image(self.rating_images[i],
936
 
                lambda w, e, i=i: editor.update_rating(self, i))
 
945
        for i in range(0, 5):
 
946
            if i == 0:
 
947
                item = rm.append('-', lambda w, e, i=i:
 
948
                    editor.update_rating(self, i))
 
949
            else:
 
950
                item = rm.append_image(self.rating_images[i],
 
951
                    lambda w, e, i=i: editor.update_rating(self, i))
937
952
 
938
953
        star_icon = gtk.gdk.pixbuf_new_from_file_at_size(
939
954
            xl.path.get_data('images', 'star.png'), 16, 16)
1070
1085
            The popup menu that is displayed when you right click in the
1071
1086
            playlist
1072
1087
        """
1073
 
        if not event.button == 3: return
 
1088
        if not event.button == 3: 
 
1089
            try: path, col, cellx, celly = self.list.get_path_at_pos(int(event.x),
 
1090
            int(event.y))
 
1091
            except: 
 
1092
                xlmisc.log_exception()
 
1093
                return True
 
1094
 
 
1095
            if col.get_title() == _('Rating'):
 
1096
                count = int(float(cellx + 5) / (float(self.rating_width / 5)))
 
1097
                print count
 
1098
            return True
 
1099
            print path, col, cellx, celly, col.get_title()
 
1100
            
1074
1101
        selection = self.list.get_selection()
1075
1102
        self.setup_tracks_menu()
1076
1103