[gnome-music/wip/jfelder/mpris-cleanup: 14/24] mpris: Change naming convention to snake_case
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-cleanup: 14/24] mpris: Change naming convention to snake_case
- Date: Sun, 7 Apr 2019 21:47:25 +0000 (UTC)
commit d9bd3e7d34a29739a98489e3f0f49bacd84f1929
Author: Jean Felder <jfelder src gnome org>
Date: Tue Oct 16 17:01:08 2018 +0200
mpris: Change naming convention to snake_case
Rename previous _get_playlists method to _get_grilo_playlists to avoid
the confusion with the MPRIS method.
gnomemusic/mpris.py | 73 +++++++++++++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 33 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index cb242ea9..e2e8fa07 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -24,6 +24,7 @@
# delete this exception statement from your version.
import logging
+import re
from gi.repository import Gio, GLib
@@ -38,6 +39,11 @@ import gnomemusic.utils as utils
logger = logging.getLogger(__name__)
+def camelcase_to_snake_case(name):
+ s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
+ return '_' + re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
+
+
class DBusInterface:
def __init__(self, con, path):
@@ -78,7 +84,8 @@ class DBusInterface:
fd_list = msg.get_unix_fd_list()
args[i] = fd_list.get(args[i])
- result = getattr(self, method_name)(*args)
+ method_snake_name = camelcase_to_snake_case(method_name)
+ result = getattr(self, method_snake_name)(*args)
# out_args is at least (signature1). We therefore always wrap the
# result as a tuple.
@@ -385,7 +392,7 @@ class MPRIS(DBusInterface):
GLib.Variant('ao', self._path_list),
GLib.Variant('o', current_song_path)))
- self.PropertiesChanged(
+ self._properties_changed(
MPRIS.MEDIA_PLAYER2_TRACKLIST_IFACE,
{'Tracks': GLib.Variant('ao', self._path_list), }, [])
@@ -479,7 +486,7 @@ class MPRIS(DBusInterface):
properties['CanPlay'] = GLib.Variant('b', True)
self._first_song_played = True
- self.PropertiesChanged(
+ self._properties_changed(
MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
self._metadata_timeout = None
self._current_thumbnail = current_song.get_thumbnail()
@@ -502,7 +509,7 @@ class MPRIS(DBusInterface):
if (not self._metadata_timeout
and new_thumbnail != self._current_thumbnail):
metadata = self._get_metadata(self.player.props.current_song)
- self.PropertiesChanged(
+ self._properties_changed(
MPRIS.MEDIA_PLAYER2_PLAYER_IFACE,
{
'Metadata': GLib.Variant('a{sv}', metadata),
@@ -517,7 +524,7 @@ class MPRIS(DBusInterface):
return
self._previous_playback_status = playback_status
- self.PropertiesChanged(MPRIS.MEDIA_PLAYER2_PLAYER_IFACE,
+ self._properties_changed(MPRIS.MEDIA_PLAYER2_PLAYER_IFACE,
{
'PlaybackStatus': GLib.Variant('s', playback_status),
},
@@ -535,7 +542,7 @@ class MPRIS(DBusInterface):
properties['LoopStatus'] = GLib.Variant('s', loop_status)
self._previous_loop_status = loop_status
- self.PropertiesChanged(
+ self._properties_changed(
MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
@log
@@ -552,7 +559,7 @@ class MPRIS(DBusInterface):
self._previous_can_go_previous = has_previous
if properties:
- self.PropertiesChanged(
+ self._properties_changed(
MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
@log
@@ -570,7 +577,7 @@ class MPRIS(DBusInterface):
if (self.player.get_playlist_type() == PlayerPlaylist.Type.PLAYLIST
or self._player_previous_type == PlayerPlaylist.Type.PLAYLIST):
variant = GLib.Variant('(b(oss))', self._get_active_playlist())
- self.PropertiesChanged(
+ self._properties_changed(
MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE,
{'ActivePlaylist': variant, }, [])
@@ -580,7 +587,7 @@ class MPRIS(DBusInterface):
def _reload_playlists(self):
def query_playlists_callback(playlists):
self.playlists = playlists
- self.PropertiesChanged(MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE,
+ self._properties_changed(MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE,
{
'PlaylistCount': GLib.Variant('u', len(playlists)),
},
@@ -605,35 +612,35 @@ class MPRIS(DBusInterface):
def _on_grilo_ready(self, grilo):
self._reload_playlists()
- def Raise(self):
+ def _raise(self):
self.app.do_activate()
- def Quit(self):
+ def _quit(self):
self.app.quit()
- def Next(self):
+ def _next(self):
self.player.next()
- def Previous(self):
+ def _previous(self):
self.player.previous()
- def Pause(self):
+ def _pause(self):
self.player.pause()
- def PlayPause(self):
+ def _play_pause(self):
self.player.play_pause()
- def Stop(self):
+ def _stop(self):
self.player.stop()
- def Play(self):
+ def _play(self):
"""Start or resume playback.
If there is no track to play, this has no effect.
"""
self.player.play()
- def Seek(self, offset_msecond):
+ def _seek(self, offset_msecond):
"""Seek forward in the current track.
Seek is relative to the current player position.
@@ -650,7 +657,7 @@ class MPRIS(DBusInterface):
else:
self.player.next()
- def SetPosition(self, track_id, position_msecond):
+ def _set_position(self, track_id, position_msecond):
"""Set the current track position in microseconds.
:param str track_id: The currently playing track's identifier
@@ -662,34 +669,34 @@ class MPRIS(DBusInterface):
return
self.player.set_position(position_msecond / 1e6)
- def OpenUri(self, uri):
+ def _open_uri(self, uri):
pass
- def GetTracksMetadata(self, track_paths):
+ def _get_tracks_metadata(self, track_paths):
metadata = []
for path in track_paths:
index = self._path_list.index(path)
metadata.append(self._metadata_list[index])
return metadata
- def AddTrack(self, uri, after_track, set_as_current):
+ def _add_track(self, uri, after_track, set_as_current):
pass
- def RemoveTrack(self, path):
+ def _remove_track(self, path):
pass
- def GoTo(self, path):
+ def _go_to(self, path):
current_song_path = self._get_song_dbus_path(
self.player.props.current_song)
current_song_index = self._path_list.index(current_song_path)
goto_index = self._path_list.index(path)
self.player.play(goto_index - current_song_index)
- def ActivatePlaylist(self, playlist_path):
+ def _activate_playlist(self, playlist_path):
playlist_id = self._get_playlist_from_dbus_path(playlist_path).get_id()
self.app._window.views[View.PLAYLIST].activate_playlist(playlist_id)
- def GetPlaylists(self, index, max_count, order, reverse):
+ def _get_playlists(self, index, max_count, order, reverse):
"""Gets a set of playlists (MPRIS Method).
GNOME Music only handles playlists with the Alphabetical order.
@@ -713,10 +720,10 @@ class MPRIS(DBusInterface):
first_index = None
return mpris_playlists[index + max_count - 1:first_index:-1]
- def Get(self, interface_name, property_name):
- return self.GetAll(interface_name)[property_name]
+ def _get(self, interface_name, property_name):
+ return self._get_all(interface_name)[property_name]
- def GetAll(self, interface_name):
+ def _get_all(self, interface_name):
if interface_name == MPRIS.MEDIA_PLAYER2_IFACE:
return {
'CanQuit': GLib.Variant('b', True),
@@ -774,7 +781,7 @@ class MPRIS(DBusInterface):
logger.warning(
"MPRIS does not implement {} interface".format(interface_name))
- def Set(self, interface_name, property_name, new_value):
+ def _set(self, interface_name, property_name, new_value):
if interface_name == MPRIS.MEDIA_PLAYER2_IFACE:
if property_name == 'Fullscreen':
pass
@@ -797,8 +804,8 @@ class MPRIS(DBusInterface):
logger.warning(
"MPRIS does not implement {} interface".format(interface_name))
- def PropertiesChanged(self, interface_name, changed_properties,
- invalidated_properties):
+ def _properties_changed(self, interface_name, changed_properties,
+ invalidated_properties):
self.con.emit_signal(None,
'/org/mpris/MediaPlayer2',
'org.freedesktop.DBus.Properties',
@@ -807,5 +814,5 @@ class MPRIS(DBusInterface):
GLib.Variant('a{sv}', changed_properties),
GLib.Variant('as', invalidated_properties)))
- def Introspect(self):
+ def _introspect(self):
return self.__doc__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]