Clean unused code and fix clicks
This commit is contained in:
parent
e525d4fa28
commit
56822a3cec
@ -41,10 +41,6 @@ class MPD(IntervalModule):
|
|||||||
|
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
port = 6600
|
port = 6600
|
||||||
try:
|
|
||||||
s = socket.create_connection((host, port))
|
|
||||||
s.recv(8192)
|
|
||||||
except Exception as e:
|
|
||||||
s = None
|
s = None
|
||||||
format = "{title} {status}"
|
format = "{title} {status}"
|
||||||
format_sparse = None
|
format_sparse = None
|
||||||
@ -64,20 +60,21 @@ class MPD(IntervalModule):
|
|||||||
sock = self.s
|
sock = self.s
|
||||||
sock.recv(8192)
|
sock.recv(8192)
|
||||||
sock.send((command + "\n").encode("utf-8"))
|
sock.send((command + "\n").encode("utf-8"))
|
||||||
|
try:
|
||||||
reply = sock.recv(16384).decode("utf-8")
|
reply = sock.recv(16384).decode("utf-8")
|
||||||
replylines = reply.split("\n")[:-2]
|
replylines = reply.split("\n")[:-2]
|
||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
(line.split(": ", 1)[0], line.split(": ", 1)[1]) for line in replylines
|
(line.split(": ", 1)) for line in replylines
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
return None
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if not self.format_sparse:
|
if not self.format_sparse:
|
||||||
self.format_sparse = self.format
|
self.format_sparse = self.format
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
fdict = {}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status = self._mpd_command(self.s, "status")
|
status = self._mpd_command(self.s, "status")
|
||||||
currentsong = self._mpd_command(self.s, "currentsong")
|
currentsong = self._mpd_command(self.s, "currentsong")
|
||||||
@ -102,19 +99,19 @@ class MPD(IntervalModule):
|
|||||||
self.output = {"full_text": "error connecting MPD"}
|
self.output = {"full_text": "error connecting MPD"}
|
||||||
|
|
||||||
def on_leftclick(self):
|
def on_leftclick(self):
|
||||||
with socket.create_connection(("localhost", self.port)) as s:
|
try:
|
||||||
s.recv(8192)
|
self._mpd_command(self.s, "pause %i" %
|
||||||
|
(0 if self._mpd_command(self.s, "status")["state"] == "pause" else 1))
|
||||||
self._mpd_command(s, "pause %i" %
|
except Exception as e:
|
||||||
(0 if self._mpd_command(s, "status")["state"] == "pause" else 1))
|
pass
|
||||||
|
|
||||||
def on_rightclick(self):
|
def on_rightclick(self):
|
||||||
with socket.create_connection(("localhost", self.port)) as s:
|
try:
|
||||||
s.recv(8192)
|
vol = int(self._mpd_command(self.s, "status")["volume"])
|
||||||
|
|
||||||
vol = int(self._mpd_command(s, "status")["volume"])
|
|
||||||
if vol == 0:
|
if vol == 0:
|
||||||
self._mpd_command(s, "setvol %i" % self.vol)
|
self._mpd_command(self.s, "setvol %i" % self.vol)
|
||||||
else:
|
else:
|
||||||
self.vol = vol
|
self.vol = vol
|
||||||
self._mpd_command(s, "setvol 0")
|
self._mpd_command(self.s, "setvol 0")
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
6
i3pystatus/test.py
Normal file
6
i3pystatus/test.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from i3pystatus import Status
|
||||||
|
status = Status(standalone=True)
|
||||||
|
import mpd
|
||||||
|
status.register(mpd.MPD, format="[({song_elapsed}/{song_length})] [{artist} - ]{title} {status} ♪{volume}", status={"pause": "▷", "play": "▶", "stop": "◾",})
|
||||||
|
status.run()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user