diff --git a/dmenu-win.py b/dmenu-win.py index 7b84d8162d1e741301949d0dc11343116ea8db7b..fb9ac6144b186d373450dd5f456927279908985a 100755 --- a/dmenu-win.py +++ b/dmenu-win.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys @@ -9,7 +9,7 @@ def main(argv): sock = ipc.i3() windows = ipc.getwin(sock.command(ipc.TREE), activews=False) dmwindows = {} - for w in windows.itervalues(): + for w in windows.values(): line = "%2d: %s" % (w["wsnum"], w["name"]) dup = 2 while line in dmwindows: @@ -17,9 +17,9 @@ def main(argv): dup += 1 dmwindows[line] = w["window"] dmenu = subprocess.Popen(['dmenu']+argv[1:], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - dmenulist = "\n".join(sorted(dmwindows.iterkeys())).encode("utf-8") + dmenulist = "\n".join(sorted(dmwindows.keys())).encode("utf-8") dmenustdout = dmenu.communicate(dmenulist)[0] - picked = dmenustdout.rstrip("\n").decode("utf-8") + picked = dmenustdout.rstrip(b"\n").decode("utf-8") if picked: sock.command(ipc.COMMAND, '[id="%d"] focus' % dmwindows[picked]) diff --git a/dmenu-xdg.py b/dmenu-xdg.py index b8694ad3645a1a187aa36fa1f3ad3722dbb1d164..6d5c03173d9da1f699375df8761a77fd067d1de3 100755 --- a/dmenu-xdg.py +++ b/dmenu-xdg.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- import os @@ -26,7 +26,7 @@ def uniq_list(l): def quote(s): - res = re.sub(r'[`$\\]', lambda(match): '\\'+match.group(0) , s) + res = re.sub(r'[`$\\]', lambda match: '\\'+match.group(0) , s) res = u"\"" + res + u"\"" if res!=s or s==u"" else s return res @@ -55,10 +55,10 @@ def main(argv): continue generic = dsk.getGenericName() - if not isinstance(generic, unicode): + if not isinstance(generic, str): generic = generic.decode("utf-8") name = dsk.getName() - if not isinstance(name, unicode): + if not isinstance(name, str): name = name.decode("utf-8") dsk.name = name # ugly, sure label = name @@ -72,9 +72,9 @@ def main(argv): pick[label] = dsk dmenu = subprocess.Popen(['dmenu']+argv[1:], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - dmenulist = "\n".join(sorted(pick.iterkeys())).encode("utf-8") + dmenulist = "\n".join(sorted(pick.keys())).encode("utf-8") dmenustdout = dmenu.communicate(dmenulist)[0] - picked = dmenustdout.rstrip("\n").decode("utf-8") + picked = dmenustdout.rstrip(b"\n").decode("utf-8") if picked: try: dsk = pick[picked] diff --git a/i3-switcher.py b/i3-switcher.py index b0451e5bd4c5262fd2de24d32c814ba749e2fb12..3a44fa5b7ca57d27b8c22fe31284d998d82252fd 100755 --- a/i3-switcher.py +++ b/i3-switcher.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys @@ -58,11 +58,12 @@ def main(argv=None): clients = ipc.getwin(i3command.command(ipc.TREE)) sortedclients = sorted(clients.values(), key=itemgetter("wsnum", "order"), reverse=True) for c in sortedclients: + name = c.get("name") or str(c) out.append({ u"name": u"client", u"instance": str(c["id"]), - u"full_text": unicode(c["name"]), - u"short_text": unicode(c["name"])[0:20]+u"…", + u"full_text": name, + u"short_text": name[0:20]+u"…", u"color": u"#FFFFFF" if c["focused"] else u"#AAAAAA" }) diff --git a/ipc.py b/ipc.py index 7a1d44c5d636a6d0f2e0496f77f3cdd331c63f11..9ff3fd4b14a3e39839b91bbc84ec81d5c4f54f89 100755 --- a/ipc.py +++ b/ipc.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- import socket @@ -25,7 +25,7 @@ class i3(object): def send(self, msg_type, payload=''): pld = payload.encode('utf-8') - msg = 'i3-ipc' + struct.pack('II', len(pld), msg_type) + pld + msg = b'i3-ipc' + struct.pack('II', len(pld), msg_type) + pld self.socket.sendall(msg) @@ -43,7 +43,7 @@ class i3(object): chunk = self.socket.recv(rest) data.append(chunk) rest -= len(chunk) - return "".join(data) + return b"".join(data) def close(self): @@ -75,14 +75,14 @@ def getwin(tree, activews=True): stack.extend(node.get("floating_nodes", [])) stack.extend(node.get("list", [])) if activews: - for w in winlist.keys(): + for w in list(winlist.keys()): if winlist[w]["wsnum"] != wsactive: del winlist[w] return winlist def printjson(d): - print json.dumps(d, indent=2, sort_keys=True) + print(json.dumps(d, indent=2, sort_keys=True)) if __name__=='__main__':