3.15: mpd, add status and leftclick for play/pause

This commit is contained in:
enkore 2013-07-09 22:31:30 +02:00
parent c5153ae12a
commit eb44638b87
3 changed files with 20 additions and 25 deletions

View File

@ -112,6 +112,7 @@ __Settings:__
* `alert_format_body` — (default: `Battery {battery_ident} has only {percentage:.2f}% ({remaining_hm}) remaining!`)
* `alert_percentage` — (default: `10`)
* `path` — (default: `None`)
* `status` — A dictionary mapping ('DIS', 'CHR', 'FULL') to alternative names (default: `{'FULL': 'FULL', 'CHR': 'CHR', 'DIS': 'DIS'}`)
@ -285,12 +286,14 @@ Available formatters:
* playtime_s (Playtime, seconds)
* pos (Position of current song in playlist, one-based)
* len (Length of current playlist)
* status
__Settings:__
* `port` — MPD port (default: `6600`)
* `format` — (default: `{title} [{playtime_h}:{playtime_m}:{playtime_s}]`)
* `format` — (default: `{title} {status}`)
* `status` — Dictionary mapping pause, play and stop to output (default: `{'pause': '▷', 'play': '▶', 'stop': '◾'}`)
@ -446,18 +449,6 @@ __Settings:__
### xrandr
Do Not Publish, private hack of it's own
__Settings:__
## Contribute

View File

@ -16,17 +16,24 @@ class MPD(IntervalModule):
* playtime_s (Playtime, seconds)
* pos (Position of current song in playlist, one-based)
* len (Length of current playlist)
* status
"""
interval = 1
settings = (
("port", "MPD port"),
"format",
("status", "Dictionary mapping pause, play and stop to output")
)
port = 6600
format = "{title} [{playtime_h}:{playtime_m}:{playtime_s}]"
format = "{title} {status}"
status = {
"pause": "",
"play": "",
"stop": "",
}
def _mpd_command(self, sock, command):
sock.send((command + "\n").encode("utf-8"))
@ -46,6 +53,7 @@ class MPD(IntervalModule):
status = self._mpd_command(s, "status")
fdict["pos"] = int(status["song"])+1
fdict["len"] = int(status["playlistlength"])
fdict["status"] = self.status[status["state"]]
currentsong = self._mpd_command(s, "currentsong")
fdict["title"] = currentsong["Title"]
@ -60,3 +68,9 @@ class MPD(IntervalModule):
self.output = {
"full_text": self.format.format(**fdict).strip(),
}
def on_leftclick(self):
with socket.create_connection(("localhost", self.port)) as s:
s.recv(8192)
self._mpd_command(s, "pause %i" % (0 if self._mpd_command(s, "status")["state"] == "pause" else 1))

View File

@ -3,7 +3,7 @@
from setuptools import setup
setup(name="i3pystatus",
version="3.14",
version="3.15",
description="Like i3status, this generates status line for i3bar / i3wm",
url="http://github.com/enkore/i3pystatus",
license="MIT",
@ -25,14 +25,4 @@ setup(name="i3pystatus",
entry_points={
"console_scripts": ["i3pystatus = i3pystatus:main"],
},
# install_requires=[
# "gobject",
# ],
# install_requires=[
# "Jinja2",
# "lxml",
# "markdown",
# "PyRSS2Gen",
# ]
)