def populate_tree(self): assert self.tree is None self.createTree() #self.tree.set_row_separator_func(lambda model, iter: model[iter][ROW_NAME] is None) self.tree.set_row_separator_func(self._is_separator) # Restore the tree if we have any to restore, else build new one if self.treeState: self.restore_tree() return paths = self.static_paths[:] music_paths = self.search_music_paths() if music_paths: # Add separator paths.append(None) paths.extend(music_paths) for path in paths: if path is None: # Separator self.tree.appendRow((icons.nullMenuIcon(), None, TYPE_NONE, None), None) else: self.add_dir(path) self.set_info_text()
def set_track_playing(self, iter, playing): if not iter: return track = self.tree.getTrack(iter) if not track: return for parent in self.tree.get_all_parents(iter): parent_label = self.tree.getLabel(parent) parent_label = tools.htmlUnescape(parent_label) is_bold = parent_label.startswith('<b>') and parent_label.endswith('</b>') if playing and not is_bold: parent_label = tools.htmlEscape(parent_label) self.tree.setLabel(parent, '<b>%s</b>' % parent_label) elif not playing and is_bold: parent_label = tools.htmlEscape(parent_label[3:-4]) self.tree.setLabel(parent, parent_label) parent = self.tree.store.iter_parent(iter) parent_label = self.tree.getLabel(parent) if parent else None label = track.get_label(parent_label=parent_label, playing=playing) if playing: self.tree.setLabel(iter, label) self.tree.setItem(iter, ROW_ICO, icons.playMenuIcon()) self.tree.expand(iter) else: self.tree.setLabel(iter, label) icon = self.tree.getItem(iter, ROW_ICO) has_error = (icon == icons.errorMenuIcon()) is_dir = (icon == icons.mediaDirMenuIcon()) if not is_dir and not has_error: self.tree.setItem(iter, ROW_ICO, icons.nullMenuIcon())
def onStopped(self): """ Playback has been stopped """ if self.list.hasMark(): currTrack = self.list.getMark() if self.list.getItem(currTrack, ROW_ICO) != icons.errorMenuIcon(): self.list.setItem(currTrack, ROW_ICO, icons.nullMenuIcon()) self.list.clearMark()
def jumpTo(self, trackIdx, sendPlayMsg = True, forced = True): """ Jump to the track located at the given index """ if self.list.hasMark() and self.list.getItem(self.list.getMark(), ROW_ICO) != icons.errorMenuIcon(): self.list.setItem(self.list.getMark(), ROW_ICO, icons.nullMenuIcon()) self.list.setMark(trackIdx) self.list.scroll_to_cell(trackIdx) self.list.setItem(trackIdx, ROW_ICO, icons.playMenuIcon()) if sendPlayMsg: modules.postMsg(consts.MSG_CMD_PLAY, {'uri': self.list.getItem(trackIdx, ROW_TRK).getURI(), 'forced': forced}) modules.postMsg(consts.MSG_EVT_NEW_TRACK, {'track': self.list.getRow(trackIdx)[ROW_TRK]}) modules.postMsg(consts.MSG_EVT_TRACK_MOVED, {'hasPrevious': self.__hasPreviousTrack(), 'hasNext': self.__hasNextTrack()})
def restoreTreeDump(self, dump, parent=None): """ Recursively restore the dump under the given parent (None for the root of the tree) """ for item in dump: (name, track) = item[0] if track: self.tree.appendRow((icons.nullMenuIcon(), name, track), parent) else: newNode = self.tree.appendRow((icons.mediaDirMenuIcon(), name, None), parent) if item[1] is not None: if len(item[1]) != 0: # We must expand the row before adding the real children, # but this works only if there is already at least one child self.restoreTreeDump(item[1], newNode)
def insert(self, tracks, playNow, position=None): """ Insert some tracks in the tracklist, append them if position is None """ rows = [[icons.nullMenuIcon(), track.getNumber(), track.getTitleOrFilename(), track.getArtist(), track.getExtendedAlbum(), track.getLength(), track.getBitrate(), track.getGenre(), track.getDate(), track.getFilename(), track.getURI(), track] for track in tracks] if len(rows) != 0: self.previousTracklist = [row[ROW_TRK] for row in self.list] for row in rows: self.playtime += row[ROW_LEN] self.list.insertRows(rows, position) if playNow: if position is not None: self.jumpTo(position) else: self.jumpTo(len(self.previousTracklist))
def insertTrack(self, track, target=None, drop_mode=None, highlight=False): ''' Insert a new track into the tracktree under parentPath ''' length = track.getLength() self.playtime += length name = track.get_label() row = (icons.nullMenuIcon(), name, track) new_iter = self.tree.insert(target, row, drop_mode) parent = self.tree.store.iter_parent(new_iter) if parent: # adjust track label to parent parent_label = self.tree.getLabel(parent) new_label = track.get_label(parent_label) self.tree.setLabel(new_iter, new_label) if highlight: self.tree.select(new_iter) return new_iter
tracks = getTracks(['/home/jendrik/Musik/Clearlake - Amber']) columns = ( ('', [(Gtk.CellRendererPixbuf(), GdkPixbuf.Pixbuf), (Gtk.CellRendererText(), GObject.TYPE_STRING)], True), (None, [(None, GObject.TYPE_INT)], False), (None, [(None, GObject.TYPE_STRING)], False), (None, [(None, GObject.TYPE_PYOBJECT)], False), ) tree = TrackTreeView(columns, True) track = None a = tree.appendRow((icons.nullMenuIcon(), 'a', 1, 'something', track), None) b = tree.appendRow((icons.nullMenuIcon(), 'b', 1, 'something', track), a) c = tree.appendRow((icons.nullMenuIcon(), 'c', 1, 'something', track), a) d = tree.appendRow((icons.nullMenuIcon(), 'd', 1, 'something', track), None) for iter in [a, b, c, d]: next_iter = tree.get_next_iter(iter) print(tree.get_nodename(iter), '->', tree.get_nodename(next_iter)) for iter in [a, b, c, d]: uncle = tree.get_next_iter_on_higher_level(iter) print('Uncle(%s) = %s' % (tree.get_nodename(iter), tree.get_nodename(uncle)))
tracks = getTracks(['/home/jendrik/Musik/Clearlake - Amber']) columns = (('', [(gtk.CellRendererPixbuf(), gtk.gdk.Pixbuf), (gtk.CellRendererText(), TYPE_STRING)], True), (None, [(None, TYPE_INT)], False), (None, [(None, TYPE_STRING)], False), (None, [(None, TYPE_PYOBJECT)], False), ) tree = TrackTreeView(columns, True) track = None a = tree.appendRow((icons.nullMenuIcon(), 'a', 1, 'something', track), None) b = tree.appendRow((icons.nullMenuIcon(), 'b', 1, 'something', track), a) c = tree.appendRow((icons.nullMenuIcon(), 'c', 1, 'something', track), a) d = tree.appendRow((icons.nullMenuIcon(), 'd', 1, 'something', track), None) for iter in [a, b, c, d]: next = tree.get_next_iter(iter) print tree.get_nodename(iter), '->', tree.get_nodename(next) for iter in [a, b, c, d]: uncle = tree.get_next_iter_on_higher_level(iter) print 'Uncle(%s) = %s' % (tree.get_nodename(iter), tree.get_nodename(uncle)) for iter in [a, b, c, d]: prev = tree.get_prev_iter(iter) print tree.get_nodename(prev), '<-', tree.get_nodename(iter)