From 5ee67aaefd1814b4779a744eb1bd29d5ac742cd4 Mon Sep 17 00:00:00 2001 From: enkore Date: Thu, 18 Jul 2013 22:36:52 +0200 Subject: [PATCH] 3.16: MPD: stop state bugfix, mute/unmute on rightclick Yes, I currently just increase the minor version number on every fix --- i3pystatus/mpd.py | 21 +++++++++++++++++---- setup.py | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/i3pystatus/mpd.py b/i3pystatus/mpd.py index de6e1b0..dff3a2c 100644 --- a/i3pystatus/mpd.py +++ b/i3pystatus/mpd.py @@ -17,6 +17,8 @@ class MPD(IntervalModule): * pos (Position of current song in playlist, one-based) * len (Length of current playlist) * status + + Left click on the module play/pauses, right click (un)mutes. """ interval = 1 @@ -27,7 +29,6 @@ class MPD(IntervalModule): ) port = 6600 - format = "{title} {status}" status = { "pause": "▷", @@ -35,10 +36,11 @@ class MPD(IntervalModule): "stop": "◾", } + vol = 100 + def _mpd_command(self, sock, command): sock.send((command + "\n").encode("utf-8")) - reply = sock.recv(16384) - reply = reply.decode("utf-8") + reply = sock.recv(16384).decode("utf-8") replylines = reply.split("\n")[:-2] return dict( @@ -56,7 +58,7 @@ class MPD(IntervalModule): fdict["status"] = self.status[status["state"]] currentsong = self._mpd_command(s, "currentsong") - fdict["title"] = currentsong["Title"] + fdict["title"] = currentsong.get("Title", "") fdict["album"] = currentsong.get("Album", "") fdict["artist"] = currentsong.get("Artist", "") @@ -74,3 +76,14 @@ class MPD(IntervalModule): s.recv(8192) self._mpd_command(s, "pause %i" % (0 if self._mpd_command(s, "status")["state"] == "pause" else 1)) + + def on_rightclick(self): + with socket.create_connection(("localhost", self.port)) as s: + s.recv(8192) + + vol = int(self._mpd_command(s, "status")["volume"]) + if vol == 0: + self._mpd_command(s, "setvol %i" % self.vol) + else: + self.vol = vol + self._mpd_command(s, "setvol 0") diff --git a/setup.py b/setup.py index 8f5b050..8826687 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name="i3pystatus", - version="3.15", + version="3.16", description="Like i3status, this generates status line for i3bar / i3wm", url="http://github.com/enkore/i3pystatus", license="MIT",