本文整理汇总了Python中lollypop.objects.Track类的典型用法代码示例。如果您正苦于以下问题:Python Track类的具体用法?Python Track怎么用?Python Track使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Track类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next
def next(self):
"""
Return next radio name, uri
@return Track
"""
track = Track()
if self.current_track.id != Type.RADIOS:
return track
radios_manager = Radios()
radios = radios_manager.get()
i = 0
for (name, url) in radios:
i += 1
if self.current_track.album_artist == name:
break
# Get next radio
if i >= len(radios):
i = 0
name = radios[i][0]
url = radios[i][1]
if url:
track.set_radio(name, url)
return track
示例2: next
def next(self):
"""
Return next radio name, uri
@return Track
"""
track = Track()
if self.current_track.id != Type.RADIOS:
return track
radios_manager = RadiosManager()
radios = radios_manager.get()
i = 0
for (radio_id, name) in radios:
i += 1
if self.current_track.album_artist == name:
break
# Get next radio
if i >= len(radios):
i = 0
name = radios[i][1]
uris = radios_manager.get_tracks(name)
if len(uris) > 0:
track.set_radio(name, uris[0])
return track
示例3: __init__
def __init__(self, name, radios_manager):
"""
Init Popover
@param name as string
@param radios_manager as RadiosManager
"""
Gtk.Popover.__init__(self)
self.connect('map', self.__on_map)
self.connect('unmap', self.__on_unmap)
self.__name = name
self.__radios_manager = radios_manager
self.__start = 0
self.__orig_pixbufs = {}
self.__stack = Gtk.Stack()
self.__stack.set_transition_duration(1000)
self.__stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
self.__stack.show()
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Lollypop/RadioPopover.ui')
builder.connect_signals(self)
self.__view = Gtk.FlowBox()
self.__view.set_selection_mode(Gtk.SelectionMode.NONE)
self.__view.connect('child-activated', self.__on_activate)
self.__view.set_max_children_per_line(100)
self.__view.set_property('row-spacing', 10)
self.__view.show()
builder.get_object('viewport').add(self.__view)
self.__name_entry = builder.get_object('name')
self.__uri_entry = builder.get_object('uri')
self.__btn_add_modify = builder.get_object('btn_add_modify')
self.__spinner = builder.get_object('spinner')
self.__stack.add_named(builder.get_object('spinner-grid'), 'spinner')
self.__stack.add_named(builder.get_object('notfound'), 'notfound')
self.__stack.add_named(builder.get_object('logo'), 'logo')
self.__stack.add_named(builder.get_object('widget'), 'widget')
self.__stack.set_visible_child_name('widget')
self.add(self.__stack)
track = Track()
track.set_radio(name, '')
rating = RatingWidget(track)
rating.show()
builder.get_object('widget').attach(rating, 0, 2, 2, 1)
if self.__name == '':
# Translators: radio context
builder.get_object('btn_add_modify').set_label(_("Add"))
else:
# Translators: radio context
builder.get_object('btn_add_modify').set_label(_("Modify"))
builder.get_object('btn_delete').show()
self.__name_entry.set_text(self.__name)
url = self.__radios_manager.get_url(self.__name)
if url:
self.__uri_entry.set_text(url)
示例4: prev
def prev(self):
"""
Return prev radio name, uri
@return Track
"""
track = Track()
if self.current_track.id != Type.RADIOS:
return track
radios_manager = RadiosManager()
radios = radios_manager.get()
i = len(radios) - 1
for (radio_id, name) in reversed(radios):
i -= 1
if self.current_track.album_artist == name:
break
# Get prev radio
if i < 0:
i = len(radios) - 1
name = radios[i][1]
uris = radios_manager.get_tracks(name)
if len(uris) > 0:
track.set_radio(name, uris[0])
return track
示例5: set_albums
def set_albums(self, track_id, artist_ids, genre_ids):
"""
Set album list (for next/prev)
@param track id as int
@param artist id as int
@param genre id as int
"""
# Invalid track
if track_id is None:
return
album = Track(track_id).album
self._albums = []
ShufflePlayer.reset_history(self)
# We are not playing a user playlist anymore
self._user_playlist = []
self._user_playlist_id = None
# We are in all artists
if (genre_ids and genre_ids[0] == Type.ALL) or\
(artist_ids and artist_ids[0] == Type.ALL):
self._albums = Lp().albums.get_compilations()
self._albums += Lp().albums.get_ids()
# We are in populars view, add popular albums
elif genre_ids and genre_ids[0] == Type.POPULARS:
if self._shuffle in [Shuffle.TRACKS_ARTIST, Shuffle.ALBUMS_ARTIST]:
self._albums = []
self.next_track = Track()
for album_id in Lp().albums.get_populars():
if Lp().albums.get_artist_id(album_id) == \
album.artist_id:
self._albums.append(album_id)
else:
self._albums = Lp().albums.get_populars()
# We are in recents view, add recent albums
elif genre_ids and genre_ids[0] == Type.RECENTS:
self._albums = Lp().albums.get_recents()
# We are in randoms view, add random albums
elif genre_ids and genre_ids[0] == Type.RANDOMS:
self._albums = Lp().albums.get_cached_randoms()
# We are in compilation view without genre
elif genre_ids and genre_ids[0] == Type.COMPILATIONS:
self._albums = Lp().albums.get_compilations()
# Random tracks/albums for artist
elif self._shuffle in [Shuffle.TRACKS_ARTIST, Shuffle.ALBUMS_ARTIST]:
self._albums = Lp().albums.get_ids([album.artist_id], genre_ids)
# Add all albums for genre
else:
if not artist_ids:
self._albums = Lp().albums.get_compilations(genre_ids)
self._albums += Lp().albums.get_ids(artist_ids, genre_ids)
album.set_genre(genre_ids)
if track_id in album.tracks_ids:
self.context.artist_ids = artist_ids
self.context.genre_ids = genre_ids
# Shuffle album list if needed
self._shuffle_albums()
else: # Error
self.stop()
示例6: __init__
def __init__(self, name, radios_manager):
"""
Init Popover
@param name as string
@param radios_manager as RadiosManager
"""
Gtk.Popover.__init__(self)
self.connect("map", self._on_map)
self.connect("unmap", self._on_unmap)
self._name = name
self._radios_manager = radios_manager
self._start = 0
self._orig_pixbufs = {}
self._stack = Gtk.Stack()
self._stack.set_transition_duration(1000)
self._stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
self._stack.show()
builder = Gtk.Builder()
builder.add_from_resource("/org/gnome/Lollypop/RadioPopover.ui")
builder.connect_signals(self)
self._view = Gtk.FlowBox()
self._view.set_selection_mode(Gtk.SelectionMode.NONE)
self._view.connect("child-activated", self._on_activate)
self._view.set_max_children_per_line(100)
self._view.set_property("row-spacing", 10)
self._view.show()
builder.get_object("viewport").add(self._view)
self._name_entry = builder.get_object("name")
self._uri_entry = builder.get_object("uri")
self._btn_add_modify = builder.get_object("btn_add_modify")
self._spinner = builder.get_object("spinner")
self._stack.add_named(builder.get_object("spinner-grid"), "spinner")
self._stack.add_named(builder.get_object("notfound"), "notfound")
self._stack.add_named(builder.get_object("logo"), "logo")
self._stack.add_named(builder.get_object("widget"), "widget")
self._stack.set_visible_child_name("widget")
self.add(self._stack)
track = Track()
track.set_radio(name, "")
rating = RatingWidget(track)
rating.show()
builder.get_object("widget").attach(rating, 0, 2, 2, 1)
if self._name == "":
builder.get_object("btn_add_modify").set_label(_("Add"))
else:
builder.get_object("btn_add_modify").set_label(_("Modify"))
builder.get_object("btn_delete").show()
self._name_entry.set_text(self._name)
url = self._radios_manager.get_url(self._name)
if url:
self._uri_entry.set_text(url)
示例7: restore_state
def restore_state(self):
"""
Restore player state
"""
if Lp().settings.get_value('save-state'):
track_id = Lp().settings.get_value('track-id').get_int32()
playlist_ids = Lp().settings.get_value('playlist-ids')
if playlist_ids and playlist_ids[0] == Type.RADIOS:
radios = Radios()
track = Track()
name = radios.get_name(track_id)
url = radios.get_url(name)
track.set_radio(name, url)
self.load(track)
elif Lp().tracks.get_path(track_id) != "":
track = Track(track_id)
self._load_track(track)
if playlist_ids:
try:
pids = []
for playlist_id in playlist_ids:
pids.append(int(playlist_id))
track_ids = []
for playlist_id in playlist_ids:
if playlist_id == Type.POPULARS:
tracks = Lp().tracks.get_populars()
elif playlist_id == Type.RECENTS:
tracks = Lp().tracks.get_recently_listened_to()
elif playlist_id == Type.NEVER:
tracks = Lp().tracks.get_never_listened_to()
elif playlist_id == Type.RANDOMS:
tracks = Lp().tracks.get_randoms()
else:
tracks = Lp().playlists.get_tracks_ids(
playlist_id)
for track_id in tracks:
if track_id not in track_ids:
track_ids.append(track_id)
self.populate_user_playlist_by_tracks(track_ids,
pids)
except:
pass # User set non int in gsettings
else:
self._albums = Lp().artists.get_albums(
track.album_artist_ids)
for album_id in self._albums:
self.context.genre_ids[album_id] = []
self.context.artist_ids[album_id] = []
self.set_next()
self.set_prev()
if Lp().settings.get_value('repeat'):
self.context.next = NextContext.NONE
else:
self.context.next = NextContext.STOP_ALL
self.emit('current-changed')
else:
print("Player::restore_state(): track missing")
示例8: _on_play_press_event
def _on_play_press_event(self, widget, event):
"""
Play radio
@param: widget as Gtk.EventBox
@param: event as Gdk.Event
"""
url = self._radios_manager.get_url(self._name)
if url:
track = Track()
track.set_radio(self._name, url)
Lp().player.load(track)
示例9: _on_album_activated
def _on_album_activated(self, flowbox, child):
"""
Play album
@param flowbox as Gtk.Flowbox
@child as Gtk.FlowboxChild
"""
name = child.get_child().get_name()
uris = self._radios_manager.get_tracks(name)
if len(uris) > 0:
track = Track()
track.set_radio(name, uris[0])
Lp.player.load(track)
示例10: _on_album_activated
def _on_album_activated(self, flowbox, child):
"""
Play album
@param flowbox as Gtk.Flowbox
@child as Gtk.FlowboxChild
"""
name = child.get_child().get_name()
url = self._radios_manager.get_url(name)
if url:
track = Track()
track.set_radio(name, url)
Lp().player.load(track)
示例11: set_albums
def set_albums(self, track_id, artist_id, genre_id):
"""
Set album list (for next/prev)
@param track id as int
@param artist id as int
@param genre id as int
"""
# Invalid track
if track_id is None:
return
album = Track(track_id).album
self._albums = None
ShufflePlayer.reset_history(self)
# We are not playing a user playlist anymore
self._user_playlist = None
self._user_playlist_id = None
# We are in all artists
if genre_id == Type.ALL or artist_id == Type.ALL:
self._albums = Lp.albums.get_compilations(Type.ALL)
self._albums += Lp.albums.get_ids()
# We are in populars view, add popular albums
elif genre_id == Type.POPULARS:
self._albums = Lp.albums.get_populars()
# We are in recents view, add recent albums
elif genre_id == Type.RECENTS:
self._albums = Lp.albums.get_recents()
# We are in randoms view, add random albums
elif genre_id == Type.RANDOMS:
self._albums = Lp.albums.get_cached_randoms()
# We are in compilation view without genre
elif genre_id == Type.COMPILATIONS:
self._albums = Lp.albums.get_compilations(None)
# Random tracks/albums for artist
elif self._shuffle in [Shuffle.TRACKS_ARTIST, Shuffle.ALBUMS_ARTIST]:
self._albums = Lp.albums.get_ids(artist_id, genre_id)
# Add all albums for genre
else:
self._albums = Lp.albums.get_compilations(genre_id)
self._albums += Lp.albums.get_ids(None, genre_id)
album.set_genre(genre_id)
if track_id in album.tracks_ids:
self.context.position = album.tracks_ids.index(track_id)
self.context.genre_id = genre_id
# Shuffle album list if needed
self._shuffle_albums()
else: # Error
self.stop()
示例12: _load_web
def _load_web(self, track, play=True):
"""
Load track url and play it
@param track as Track
@param play as bool
@return True if loading
"""
if not get_network_available():
# Force widgets to update (spinners)
self.emit('current-changed')
return False
try:
from lollypop.web import Web
if play:
self.emit('loading-changed', True)
t = Thread(target=Web.play_track,
args=(track, play, self.__set_gv_uri))
t.daemon = True
t.start()
return True
except Exception as e:
self._current_track = Track()
self.stop()
self.emit('current-changed')
if Lp().notify is not None:
Lp().notify.send(str(e), track.uri)
print("PlayerBin::_load_web()", e)
示例13: __init__
def __init__(self, rowid, num):
"""
Init row widgets
@param rowid as int
@param num as int
@param show loved as bool
"""
# We do not use Gtk.Builder for speed reasons
Gtk.ListBoxRow.__init__(self)
self.set_sensitive(False)
self._track = Track(rowid)
self._number = num
self._indicator = IndicatorWidget(self._track.id)
self.set_indicator(Lp().player.current_track.id == self._track.id,
utils.is_loved(self._track.id))
self.set_sensitive(True)
self._row_widget = Gtk.EventBox()
self._row_widget.connect('button-press-event', self._on_button_press)
self._row_widget.connect('enter-notify-event', self._on_enter_notify)
self._grid = Gtk.Grid()
self._grid.set_column_spacing(5)
self._row_widget.add(self._grid)
self._title_label = Gtk.Label.new(self._track.formated_name())
self._title_label.set_use_markup(True)
self._title_label.set_property('has-tooltip', True)
self._title_label.connect('query-tooltip',
self._on_title_query_tooltip)
self._title_label.set_property('hexpand', True)
self._title_label.set_property('halign', Gtk.Align.START)
self._title_label.set_ellipsize(Pango.EllipsizeMode.END)
self._duration_label = Gtk.Label.new(
seconds_to_string(self._track.duration))
self._duration_label.get_style_context().add_class('dim-label')
self._num_label = Gtk.Label()
self._num_label.set_ellipsize(Pango.EllipsizeMode.END)
self._num_label.set_property('valign', Gtk.Align.CENTER)
self._num_label.set_width_chars(4)
self._num_label.get_style_context().add_class('dim-label')
self.update_num_label()
self._menu_image = Gtk.Image.new()
self._menu_image.set_opacity(0.2)
self._menu_button = Gtk.Button.new()
self._menu_button.set_relief(Gtk.ReliefStyle.NONE)
self._menu_button.get_style_context().add_class('menu-button')
self._menu_button.get_style_context().add_class('track-menu-button')
self._menu_button.set_image(self._menu_image)
self._menu_button.connect('clicked', self._on_button_clicked)
self._grid.add(self._num_label)
self._grid.add(self._title_label)
self._grid.add(self._duration_label)
# TODO Remove this later
if Gtk.get_minor_version() > 16:
self._grid.add(self._menu_button)
else:
self.connect('map', self._on_map)
self.add(self._row_widget)
self.get_style_context().add_class('trackrow')
示例14: load_external
def load_external(self, uri, name=''):
"""
Load external tracks
@param uri as str
@param name as string
"""
track = Track()
track.set_album_artists([name])
track.set_uri(uri)
if track.uri.startswith('file://'):
track.id = Type.EXTERNALS
track.name = GLib.path_get_basename(GLib.filename_from_uri(uri)[0])
else:
track.name = uri
track.id = Type.RADIOS
self._external_tracks.append(track)
示例15: _sticker
def _sticker(self, cmd_args):
"""
Send stickers
@syntax sticker [get|set] song rating
@param args as str
@return msg as str
"""
args = self._get_args(cmd_args)
msg = ""
if args[0].find("get song ") != -1 and\
args[2].find("rating") != -1:
track_id = Lp().tracks.get_id_by_path(args[1])
track = Track(track_id)
msg = "sticker: rating=%s\n" % int(track.get_popularity()*2)
elif args[0].find("set song") != -1 and\
args[2].find("rating") != -1:
track_id = Lp().tracks.get_id_by_path(args[1])
track = Track(track_id)
track.set_popularity(int(args[3])/2)
return msg