Here are the examples of the python api lollypop.define.Lp taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
199 Examples
3
Example 1
def __clear(self, clear_albums=False):
"""
Clear the view
"""
for child in self.__view.get_children():
child.destroy()
if clear_albums:
Lp().player.clear_albums()
self.__clear_button.set_sensitive(False)
3
Example 2
def __set_autoload(self, widget):
"""
Mark as autoload
@param widget as Gtk.Widget
"""
self.__timeout_id = None
if self.__signal_id is None:
Lp().settings.set_value('inforeload', GLib.Variant('b', True))
self.__signal_id = Lp().player.connect('current-changed',
self.__on_current_changed)
widget.get_style_context().add_class('selected')
else:
Lp().player.disconnect(self.__signal_id)
self.__signal_id = None
Lp().settings.set_value('inforeload',
GLib.Variant('b', False))
widget.get_style_context().remove_class('selected')
3
Example 3
def __init__(self):
"""
Init dbus objects
"""
# Bus to disable screenlock
self.__bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
self.__cookie = None
self.__flags = []
Lp().player.connect('status-changed', self.__on_status_changed)
3
Example 4
Project: lollypop Source File: player_bin.py
def __update_current_duration(self, reader, track):
"""
Update current track duration
@param reader as TagReader
@param track id as int
"""
try:
duration = reader.get_info(track.uri).get_duration() / 1000000000
if duration != track.duration and duration > 0:
Lp().tracks.set_duration(track.id, duration)
# We modify mtime to be sure not looking for tags again
Lp().tracks.set_mtime(track.id, 1)
self.current_track.set_duration(duration)
GLib.idle_add(self.emit, 'duration-changed', track.id)
except:
pass
3
Example 5
Project: lollypop Source File: miniplayer.py
def _on_button_press(self, button, event):
"""
Show track menu
@param button as Gtk.Button
@param event as Gdk.Event
"""
if Lp().player.current_track.id is not None:
if event.button != 1 and Lp().player.current_track.id >= 0:
popover = TrackMenuPopover(
Lp().player.current_track,
PopToolbarMenu(Lp().player.current_track.id))
popover.set_relative_to(self)
press_rect = Gdk.Rectangle()
press_rect.x = event.x
press_rect.y = event.y
press_rect.width = press_rect.height = 1
popover.set_pointing_to(press_rect)
popover.show()
return True
3
Example 6
def __init__(self):
"""
Init progress controller (for toolbars)
"""
# Prevent updating progress while seeking
self.__seeking = False
# Update pogress position
self.__timeout_id = None
# Show volume control
self._show_volume_control = False
Lp().player.connect('duration-changed', self.__on_duration_changed)
3
Example 7
def __on_unmap(self, widget):
"""
Stop loading
@param widget as Gtk.Widget
"""
# FIXME Not needed with GTK >= 3.18
Lp().window.enable_global_shortcuts(True)
self._widget.stop()
3
Example 8
Project: lollypop Source File: art_widgets.py
def _on_api_entry_changed(self, entry):
"""
Save key
@param entry as Gtk.Entry
"""
value = entry.get_text().strip()
Lp().settings.set_value('cs-api-key', GLib.Variant('s', value))
3
Example 9
Project: lollypop Source File: pop_menu.py
def __set_artists_actions(self):
"""
Set queue actions
"""
go_artist_action = Gio.SimpleAction(name="go_artist_action")
Lp().add_action(go_artist_action)
go_artist_action.connect('activate',
self.__go_to_artists)
self.append(_("Show albums from artist"), 'app.go_artist_action')
3
Example 10
def __update_progress(self, current, total):
"""
Update progress bar status
@param scanned items as int, total items as int
"""
Lp().window.progress.set_fraction(current / total, self)
3
Example 11
Project: lollypop Source File: player.py
def skip_album(self):
"""
Skip current album
"""
# In party or shuffle, just update next track
if Lp().player.is_party or\
Lp().settings.get_enum('shuffle') == Shuffle.TRACKS:
Lp().player.set_next()
# We send this signal to update next popover
Lp().player.emit('queue-changed')
elif self._current_track.id is not None:
pos = self._albums.index(self._current_track.album.id)
if pos + 1 >= len(self._albums):
next_album = self._albums[0]
else:
next_album = self._albums[pos + 1]
self.load(Album(next_album).tracks[0])
3
Example 12
Project: lollypop Source File: mpris_legacy.py
def __init__(self, app):
DBusGMainLoop(set_as_default=True)
name = dbus.service.BusName(self.MPRIS_LOLLYPOP, dbus.SessionBus())
dbus.service.Object.__init__(self, name, self.MPRIS_PATH)
self._app = app
self._metadata = {}
Lp().player.connect('current-changed', self._on_current_changed)
Lp().player.connect('seeked', self._on_seeked)
Lp().player.connect('status-changed', self._on_status_changed)
Lp().player.connect('volume-changed', self._on_volume_changed)
3
Example 13
Project: lollypop Source File: controllers.py
def _on_prev_btn_clicked(self, button):
"""
Previous track on prev button clicked
@param button as Gtk.Button
"""
Lp().player.prev()
3
Example 14
def __init__(self):
"""
Init shuffle player
"""
BasePlayer.__init__(self)
self.reset_history()
# Party mode
self.__is_party = False
Lp().settings.connect('changed::shuffle', self.__set_shuffle)
3
Example 15
Project: lollypop Source File: mpd.py
def _on_party_changed(self, player, enabled):
"""
Add options to idle
@param player as Player
@param enabled as bool
"""
Lp().playlists.clear(Type.MPD, False)
if "options" in self.idle_wanted_strings:
self.idle_strings.append("options")
self.event.set()
3
Example 16
def __on_unmap(self, widget):
"""
Disconnect signals
@param widget as Gtk.Widget
"""
self._stop = True
self._lazy_queue = []
GLib.idle_add(self.__clear)
if self._signal_id1 is not None:
Lp().player.disconnect(self._signal_id1)
self._signal_id1 = None
3
Example 17
Project: lollypop Source File: controllers.py
def _on_progress_release_button(self, scale, event):
"""
Callback for scale release button
Seek player to scale value
@param scale as Gtk.Scale
@param event as Gdk.Event
"""
if self._show_volume_control or event.button != 1:
return
value = scale.get_value()
Lp().player.seek(value/60)
self.__seeking = False
self._update_position(value)
3
Example 18
Project: lollypop Source File: pop_externals.py
def __on_self_unmap(self, widget):
"""
Disconnect signals and destroy
@param widget as Gtk.Widget
"""
if self.__signal_id is not None:
Lp().player.disconnect(self.__signal_id)
GLib.idle_add(self.destroy)
3
Example 19
def _random(self, cmd_args):
"""
Set player random, as MPD can't handle all lollypop random modes,
set party mode
@syntax random [1|0]
@param args as str
@return msg as str
"""
args = self._get_args(cmd_args)
GLib.idle_add(Lp().player.set_party, bool(int(args[0])))
return ""
3
Example 20
def __on_row_activated(self, widget, row):
"""
Play searched item when selected
@param widget as Gtk.ListBox
@param row as AlbumRow
"""
Lp().window.toolbar.search(row.get_child().get_text())
3
Example 21
Project: lollypop Source File: inotify.py
def __run_collection_update(self):
"""
Run a collection update
"""
self.__timeout = None
Lp().window.update_db()
3
Example 22
def do_hide(self):
"""
Remove signal
"""
Gtk.Bin.do_hide(self)
Lp().player.disconnect(self._signal_id)
3
Example 23
def _seek(self, cmd_args):
"""
Seek current
@syntax seek position
@param args as str
@return msg as str
"""
args = self._get_args(cmd_args)
seek = int(args[1])
GLib.idle_add(Lp().player.seek, seek)
return ""
3
Example 24
def __init__(self, app):
self.__app = app
self.__metadata = {}
self.__bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
Gio.bus_own_name_on_connection(self.__bus,
self.__MPRIS_LOLLYPOP,
Gio.BusNameOwnerFlags.NONE,
None,
None)
Server.__init__(self, self.__bus, self.__MPRIS_PATH)
Lp().player.connect('current-changed', self.__on_current_changed)
Lp().player.connect('seeked', self.__on_seeked)
Lp().player.connect('status-changed', self.__on_status_changed)
Lp().player.connect('volume-changed', self.__on_volume_changed)
3
Example 25
def __finish(self):
"""
Notify from main thread when scan finished
"""
Lp().window.progress.set_fraction(1.0, self)
self.stop()
self.emit("scan-finished")
if Lp().settings.get_value('artist-artwork'):
Lp().art.cache_artists_info()
3
Example 26
def __init__(self):
"""
Init player
"""
BinPlayer.__init__(self)
QueuePlayer.__init__(self)
LinearPlayer.__init__(self)
ShufflePlayer.__init__(self)
UserPlaylistPlayer.__init__(self)
RadioPlayer.__init__(self)
ExternalsPlayer.__init__(self)
self.update_crossfading()
self.__do_not_update_next = False
Lp().settings.connect('changed::playback', self.__on_playback_changed)
3
Example 27
Project: lollypop Source File: mpris_legacy.py
@dbus.service.method(dbus_interface=MPRIS_PLAYER_IFACE)
def Play(self):
if Lp().player.current_track.id is None:
Lp().player.set_party(True)
else:
Lp().player.play()
3
Example 28
def __setup_scanner(self):
"""
Run collection update if needed
@return True if hard scan is running
"""
Lp().scanner.connect('scan-finished', self.on_scan_finished)
Lp().scanner.connect('genre-updated', self.__on_genre_updated)
Lp().scanner.connect('artist-updated', self.__on_artist_updated)
3
Example 29
Project: lollypop Source File: player_bin.py
def _on_stream_start(self, bus, message):
"""
On stream start
Emit "current-changed" to notify others components
@param bus as Gst.Bus
@param message as Gst.Message
"""
self._start_time = time()
debug("Player::_on_stream_start(): %s" % self.current_track.uri)
self.emit('current-changed')
# Update now playing on lastfm
if Lp().lastfm is not None and self.current_track.id >= 0:
artists = ", ".join(self.current_track.artists)
Lp().lastfm.now_playing(artists,
self.current_track.album_name,
self.current_track.title,
int(self.current_track.duration))
if not Lp().scanner.is_locked():
Lp().tracks.set_listened_at(self.current_track.id, int(time()))
3
Example 30
def _update(self, cmd_args):
"""
Update database
@syntax update
@param args as str
@return msg as str
"""
Lp().window.update_db()
return ""
3
Example 31
Project: lollypop Source File: player_bin.py
def __on_bus_error(self, bus, message):
"""
Handle first bus error, ignore others
@param bus as Gst.Bus
@param message as Gst.Message
"""
debug("Error playing: %s" % self.current_track.uri)
Lp().window.pulse(False)
if self.__codecs.is_missing_codec(message):
self.__codecs.install()
Lp().scanner.stop()
elif Lp().notify is not None:
Lp().notify.send(message.parse_error()[0].message)
self.emit('current-changed')
return True
3
Example 32
Project: lollypop Source File: controllers.py
def _on_next_btn_clicked(self, button):
"""
Next track on next button clicked
@param button as Gtk.Button
"""
Lp().player.next()
3
Example 33
def __on_delete_clicked(self, button):
"""
Delete album
@param button as Gtk.Button
"""
if Lp().player.current_track.album.id == self.__album.id:
# If not last album, skip it
if len(Lp().player.get_albums()) > 1:
Lp().player.skip_album()
Lp().player.remove_album(self.__album)
# remove it and stop playback by going to next track
else:
Lp().player.remove_album(self.__album)
Lp().player.set_next()
Lp().player.next()
else:
Lp().player.remove_album(self.__album)
self.destroy()
3
Example 34
Project: lollypop Source File: mpd.py
def _findadd(self, cmd_args):
"""
Find tracks and add them to playlist
@syntax findadd filter value
@param args as str
@return msg as str
"""
tracks = []
for track_id in self._find_tracks(cmd_args):
tracks.append(Track(track_id))
if tracks:
Lp().playlists.add_tracks(Type.MPD, tracks, False)
return ""
3
Example 35
def __add_items(self, items, prev_album_id=None):
"""
Add items to the view
@param item ids as [int]
"""
if items and not self._stop:
album_id = items.pop(0)
row = self.__row_for_album_id(album_id)
row.show()
self.__view.add(row)
self._lazy_queue.append(row)
GLib.idle_add(self.__add_items, items, album_id)
else:
GLib.idle_add(self.lazy_loading)
if self._viewport.get_child() is None:
self._viewport.add(self.__view)
if Lp().player.current_track.album.id in Lp().player.get_albums():
self.__jump_button.set_sensitive(True)
3
Example 36
def _on_value_changed(self, scale):
"""
Adjust volume
"""
if not self._show_volume_control:
return
Lp().player.set_volume(scale.get_value())
self._update_position(scale.get_value())
3
Example 37
def __on_map(self, widget):
"""
Resize
@param widget as Gtk.Widget
"""
# FIXME Not needed with GTK >= 3.18
Lp().window.enable_global_shortcuts(False)
size = Lp().window.get_size()
self.set_size_request(size[0]*0.4,
size[1]*0.5)
3
Example 38
Project: lollypop Source File: art_widgets.py
def _on_reset_confirm(self, button):
"""
Reset cover
@param button as Gtk.Button
"""
self._infobar.hide()
if self.__album is not None:
Lp().art.remove_album_artwork(self.__album)
Lp().art.clean_album_cache(self.__album)
Lp().art.emit('album-artwork-changed', self.__album.id)
else:
for suffix in ["lastfm", "wikipedia", "spotify", "deezer"]:
InfoCache.uncache_artwork(self.__artist, suffix,
button.get_scale_factor())
InfoCache.add(self.__artist, None, None, suffix)
Lp().art.emit('artist-artwork-changed', self.__artist)
self.__close_popover()
3
Example 39
def _on_row_activated(self, view, path, column):
"""
Play selected track
@param view as Gtk.TreeView
@param path as Gtk.TreePath
@param column as Gtk.TreeViewColumn
"""
if path is not None:
iterator = self.__model.get_iter(path)
if iterator is not None:
uri = self.__model.get_value(iterator, 0)
Lp().player.play_this_external(uri)
3
Example 40
Project: lollypop Source File: downloader.py
def _get_lastfm_artist_info(self, artist):
"""
Return lastfm artist information
@param artist as str
@return (url as str/None, content as str)
"""
if Lp().lastfm is not None:
return Lp().lastfm.get_artist_info(artist)
else:
return (None, None)
3
Example 41
def should_be_shown():
"""
True if we can show popover
"""
return Lp().lastfm is not None or\
InfoPopover.Wikipedia is not None or\
InfoPopover.WebView is not None
3
Example 42
def _currentsong(self, cmd_args):
"""
Send lollypop current song
@syntax currentsong
@param args as str
@return msg as str
"""
if Lp().player.current_track.id is not None:
msg = self._string_for_track_id(Lp().player.current_track.id)
else:
msg = ""
return msg
3
Example 43
def __on_unmap(self, widget):
"""
Destroy self if needed and disconnect signals
@param widget as Gtk.Widget
"""
self.__current_track = Track()
if self.__signal_id is not None:
Lp().player.disconnect(self.__signal_id)
self.__signal_id = None
3
Example 44
Project: lollypop Source File: inhibitor_legacy.py
def __init__(self):
"""
Init dbus objects
"""
# Just to make pep8/flake8 happy
GdkX11.x11_get_default_root_xwindow()
# Dbus interface to disable screenlock
bus = dbus.SessionBus()
self._sm = None
self._cookie = None
self._flags = []
try:
bus_object = bus.get_object('org.gnome.SessionManager',
'/org/gnome/SessionManager')
self._sm = dbus.Interface(bus_object,
'org.gnome.SessionManager')
except:
self._sm = None
Lp().player.connect('status-changed', self._on_status_changed)
3
Example 45
def __init__(self):
"""
Init charts
"""
if Lp().settings.get_enum('charts') == ChartsProvider.ITUNES:
self.__provider = ItunesCharts()
else:
self.__provider = SpotifyCharts()
3
Example 46
Project: lollypop Source File: mpd.py
def _clear(self, cmd_args):
"""
Clear mpd playlist
@syntax clear
@param args as str
@return msg as str
"""
Lp().playlists.clear(Type.MPD, False)
Lp().player.populate_user_playlist_by_id(Type.NONE)
GLib.idle_add(Lp().player.stop)
Lp().player.current_track = Track()
GLib.idle_add(Lp().player.emit, 'current-changed')
return ""
3
Example 47
Project: lollypop Source File: mpd.py
def _deleteid(self, cmd_args):
"""
Delete track from playlist
@syntax delete track_id
@param args as str
@return msg as str
"""
arg = self._get_args(cmd_args)
Lp().playlists.remove_tracks(Type.MPD, [Track(int(arg[0]))], False)
return ""
3
Example 48
def _setvol(self, cmd_args):
"""
Send stats about db
@syntax setvol value
@param args as str
@return msg as str
"""
args = self._get_args(cmd_args)
vol = float(args[0])
Lp().player.set_volume(vol/100)
return ""
3
Example 49
def save_view_state(self):
"""
Save view state
"""
Lp().settings.set_value(
"list-one-ids",
GLib.Variant('ai',
self.__list_one.selected_ids))
Lp().settings.set_value(
"list-two-ids",
GLib.Variant('ai',
self.__list_two.selected_ids))
3
Example 50
def __init__(self):
"""
Init notification object with lollypop infos
"""
self.__caps = Notify.get_server_caps()
self.__inhibitor = False
self.__notification = Notify.Notification()
self.__notification.set_category('x-gnome.music')
self.__notification.set_hint('desktop-entry',
GLib.Variant('s', 'lollypop'))
self.__set_actions()
Lp().player.connect('current-changed',
self.__on_current_changed)