style: format all code to PEP8 (flake8 clean)
Reformat every module with autopep8 and hand-tune the remaining long lines so that `flake8` passes with default settings (max line length 79). No behavior changes: long f-strings, messages, QSS/Textual CSS rules and argument lists are only wrapped or split, an unused import and an unused local are dropped, and dbus-next D-Bus signature annotations carry targeted `# noqa` comments.
This commit is contained in:
76
mpris.py
76
mpris.py
@@ -19,7 +19,12 @@ try: # pragma: no cover - зависит от окружения
|
||||
from dbus_next import Variant
|
||||
from dbus_next.aio import MessageBus
|
||||
from dbus_next.constants import PropertyAccess
|
||||
from dbus_next.service import ServiceInterface, dbus_property, method, signal
|
||||
from dbus_next.service import (
|
||||
ServiceInterface,
|
||||
dbus_property,
|
||||
method,
|
||||
signal,
|
||||
)
|
||||
|
||||
HAVE_DBUS = True
|
||||
except Exception: # pragma: no cover
|
||||
@@ -31,7 +36,8 @@ OBJECT_PATH = "/org/mpris/MediaPlayer2"
|
||||
|
||||
def track_object_path(track_id: Any) -> str:
|
||||
"""D-Bus object path для mpris:trackid (только [A-Za-z0-9_])."""
|
||||
safe = "".join(ch if ch.isalnum() else "_" for ch in str(track_id)) or "unknown"
|
||||
safe = "".join(ch if ch.isalnum()
|
||||
else "_" for ch in str(track_id)) or "unknown"
|
||||
return f"/mtsmusic/track/{safe}"
|
||||
|
||||
|
||||
@@ -51,31 +57,31 @@ if HAVE_DBUS:
|
||||
self._svc.dispatch("quit")
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def Identity(self) -> "s":
|
||||
def Identity(self) -> "s": # noqa: F821
|
||||
return self._svc.identity
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def DesktopEntry(self) -> "s":
|
||||
def DesktopEntry(self) -> "s": # noqa: F821
|
||||
return self._svc.desktop_entry
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanQuit(self) -> "b":
|
||||
def CanQuit(self) -> "b": # noqa: F821
|
||||
return True
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanRaise(self) -> "b":
|
||||
def CanRaise(self) -> "b": # noqa: F821
|
||||
return True
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def HasTrackList(self) -> "b":
|
||||
def HasTrackList(self) -> "b": # noqa: F821
|
||||
return False
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def SupportedUriSchemes(self) -> "as":
|
||||
def SupportedUriSchemes(self) -> "as": # noqa: F722
|
||||
return []
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def SupportedMimeTypes(self) -> "as":
|
||||
def SupportedMimeTypes(self) -> "as": # noqa: F722
|
||||
return []
|
||||
|
||||
class _PlayerInterface(ServiceInterface):
|
||||
@@ -109,97 +115,97 @@ if HAVE_DBUS:
|
||||
self._svc.dispatch("previous")
|
||||
|
||||
@method()
|
||||
def Seek(self, offset: "x"):
|
||||
def Seek(self, offset: "x"): # noqa: F821
|
||||
self._svc.dispatch("seek", int(offset))
|
||||
|
||||
@method()
|
||||
def SetPosition(self, track_id: "o", position: "x"):
|
||||
def SetPosition(self, track_id: "o", position: "x"): # noqa: F821
|
||||
self._svc.dispatch("set_position", str(track_id), int(position))
|
||||
|
||||
@method()
|
||||
def OpenUri(self, uri: "s"):
|
||||
def OpenUri(self, uri: "s"): # noqa: F821
|
||||
self._svc.dispatch("open_uri", str(uri))
|
||||
|
||||
# -- сигналы -----------------------------------------------------
|
||||
@signal()
|
||||
def Seeked(self, position: "x") -> "x":
|
||||
def Seeked(self, position: "x") -> "x": # noqa: F821
|
||||
return position
|
||||
|
||||
# -- свойства ----------------------------------------------------
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def PlaybackStatus(self) -> "s":
|
||||
def PlaybackStatus(self) -> "s": # noqa: F821
|
||||
return self._svc.playback_status
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def Metadata(self) -> "a{sv}":
|
||||
def Metadata(self) -> "a{sv}": # noqa: F722
|
||||
return self._svc.metadata
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def Position(self) -> "x":
|
||||
def Position(self) -> "x": # noqa: F821
|
||||
return int(self._svc.position)
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def MinimumRate(self) -> "d":
|
||||
def MinimumRate(self) -> "d": # noqa: F821
|
||||
return 1.0
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def MaximumRate(self) -> "d":
|
||||
def MaximumRate(self) -> "d": # noqa: F821
|
||||
return 1.0
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanGoNext(self) -> "b":
|
||||
def CanGoNext(self) -> "b": # noqa: F821
|
||||
return self._svc.can_next
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanGoPrevious(self) -> "b":
|
||||
def CanGoPrevious(self) -> "b": # noqa: F821
|
||||
return self._svc.can_previous
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanPlay(self) -> "b":
|
||||
def CanPlay(self) -> "b": # noqa: F821
|
||||
return self._svc.can_play
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanPause(self) -> "b":
|
||||
def CanPause(self) -> "b": # noqa: F821
|
||||
return self._svc.can_pause
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanSeek(self) -> "b":
|
||||
def CanSeek(self) -> "b": # noqa: F821
|
||||
return self._svc.can_seek
|
||||
|
||||
@dbus_property(access=PropertyAccess.READ)
|
||||
def CanControl(self) -> "b":
|
||||
def CanControl(self) -> "b": # noqa: F821
|
||||
return True
|
||||
|
||||
@dbus_property(access=PropertyAccess.READWRITE)
|
||||
def Volume(self) -> "d":
|
||||
def Volume(self) -> "d": # noqa: F821
|
||||
return float(self._svc.volume)
|
||||
|
||||
@Volume.setter
|
||||
def Volume(self, value: "d"):
|
||||
def Volume(self, value: "d"): # noqa: F821
|
||||
self._svc.dispatch("volume", float(value))
|
||||
|
||||
@dbus_property(access=PropertyAccess.READWRITE)
|
||||
def LoopStatus(self) -> "s":
|
||||
def LoopStatus(self) -> "s": # noqa: F821
|
||||
return self._svc.loop_status
|
||||
|
||||
@LoopStatus.setter
|
||||
def LoopStatus(self, value: "s"):
|
||||
def LoopStatus(self, value: "s"): # noqa: F821
|
||||
self._svc.loop_status = str(value)
|
||||
|
||||
@dbus_property(access=PropertyAccess.READWRITE)
|
||||
def Shuffle(self) -> "b":
|
||||
def Shuffle(self) -> "b": # noqa: F821
|
||||
return self._svc.shuffle
|
||||
|
||||
@Shuffle.setter
|
||||
def Shuffle(self, value: "b"):
|
||||
def Shuffle(self, value: "b"): # noqa: F821
|
||||
self._svc.shuffle = bool(value)
|
||||
|
||||
@dbus_property(access=PropertyAccess.READWRITE)
|
||||
def Rate(self) -> "d":
|
||||
def Rate(self) -> "d": # noqa: F821
|
||||
return float(self._svc.rate)
|
||||
|
||||
@Rate.setter
|
||||
def Rate(self, value: "d"):
|
||||
def Rate(self, value: "d"): # noqa: F821
|
||||
self._svc.rate = float(value)
|
||||
|
||||
|
||||
@@ -290,7 +296,8 @@ class MprisService:
|
||||
def _emit(self, changed: dict[str, Any]):
|
||||
if not (self.enabled and self._loop):
|
||||
return
|
||||
self._loop.call_soon_threadsafe(self._player.emit_properties_changed, changed)
|
||||
self._loop.call_soon_threadsafe(
|
||||
self._player.emit_properties_changed, changed)
|
||||
|
||||
# -- обновление состояния (из основного потока) ----------------------
|
||||
|
||||
@@ -334,7 +341,8 @@ class MprisService:
|
||||
def notify_seeked(self, position_us: int):
|
||||
self.update_position(position_us)
|
||||
if self.enabled and self._loop:
|
||||
self._loop.call_soon_threadsafe(self._player.Seeked, int(position_us))
|
||||
self._loop.call_soon_threadsafe(
|
||||
self._player.Seeked, int(position_us))
|
||||
|
||||
def update_volume(self, volume: float):
|
||||
volume = max(0.0, min(1.0, float(volume)))
|
||||
|
||||
Reference in New Issue
Block a user