Skip to content
Snippets Groups Projects
Commit 22ef0dd5 authored by Pavel Kácha's avatar Pavel Kácha
Browse files

Bring the code to Py 3

parent 3d3a3bd3
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
...@@ -9,7 +9,7 @@ def main(argv): ...@@ -9,7 +9,7 @@ def main(argv):
sock = ipc.i3() sock = ipc.i3()
windows = ipc.getwin(sock.command(ipc.TREE), activews=False) windows = ipc.getwin(sock.command(ipc.TREE), activews=False)
dmwindows = {} dmwindows = {}
for w in windows.itervalues(): for w in windows.values():
line = "%2d: %s" % (w["wsnum"], w["name"]) line = "%2d: %s" % (w["wsnum"], w["name"])
dup = 2 dup = 2
while line in dmwindows: while line in dmwindows:
...@@ -17,9 +17,9 @@ def main(argv): ...@@ -17,9 +17,9 @@ def main(argv):
dup += 1 dup += 1
dmwindows[line] = w["window"] dmwindows[line] = w["window"]
dmenu = subprocess.Popen(['dmenu']+argv[1:], stdin=subprocess.PIPE, stdout=subprocess.PIPE) 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] dmenustdout = dmenu.communicate(dmenulist)[0]
picked = dmenustdout.rstrip("\n").decode("utf-8") picked = dmenustdout.rstrip(b"\n").decode("utf-8")
if picked: if picked:
sock.command(ipc.COMMAND, '[id="%d"] focus' % dmwindows[picked]) sock.command(ipc.COMMAND, '[id="%d"] focus' % dmwindows[picked])
......
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
...@@ -26,7 +26,7 @@ def uniq_list(l): ...@@ -26,7 +26,7 @@ def uniq_list(l):
def quote(s): 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 res = u"\"" + res + u"\"" if res!=s or s==u"" else s
return res return res
...@@ -55,10 +55,10 @@ def main(argv): ...@@ -55,10 +55,10 @@ def main(argv):
continue continue
generic = dsk.getGenericName() generic = dsk.getGenericName()
if not isinstance(generic, unicode): if not isinstance(generic, str):
generic = generic.decode("utf-8") generic = generic.decode("utf-8")
name = dsk.getName() name = dsk.getName()
if not isinstance(name, unicode): if not isinstance(name, str):
name = name.decode("utf-8") name = name.decode("utf-8")
dsk.name = name # ugly, sure dsk.name = name # ugly, sure
label = name label = name
...@@ -72,9 +72,9 @@ def main(argv): ...@@ -72,9 +72,9 @@ def main(argv):
pick[label] = dsk pick[label] = dsk
dmenu = subprocess.Popen(['dmenu']+argv[1:], stdin=subprocess.PIPE, stdout=subprocess.PIPE) 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] dmenustdout = dmenu.communicate(dmenulist)[0]
picked = dmenustdout.rstrip("\n").decode("utf-8") picked = dmenustdout.rstrip(b"\n").decode("utf-8")
if picked: if picked:
try: try:
dsk = pick[picked] dsk = pick[picked]
......
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
...@@ -58,11 +58,12 @@ def main(argv=None): ...@@ -58,11 +58,12 @@ def main(argv=None):
clients = ipc.getwin(i3command.command(ipc.TREE)) clients = ipc.getwin(i3command.command(ipc.TREE))
sortedclients = sorted(clients.values(), key=itemgetter("wsnum", "order"), reverse=True) sortedclients = sorted(clients.values(), key=itemgetter("wsnum", "order"), reverse=True)
for c in sortedclients: for c in sortedclients:
name = c.get("name") or str(c)
out.append({ out.append({
u"name": u"client", u"name": u"client",
u"instance": str(c["id"]), u"instance": str(c["id"]),
u"full_text": unicode(c["name"]), u"full_text": name,
u"short_text": unicode(c["name"])[0:20]+u"", u"short_text": name[0:20]+u"",
u"color": u"#FFFFFF" if c["focused"] else u"#AAAAAA" u"color": u"#FFFFFF" if c["focused"] else u"#AAAAAA"
}) })
......
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import socket import socket
...@@ -25,7 +25,7 @@ class i3(object): ...@@ -25,7 +25,7 @@ class i3(object):
def send(self, msg_type, payload=''): def send(self, msg_type, payload=''):
pld = payload.encode('utf-8') 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) self.socket.sendall(msg)
...@@ -43,7 +43,7 @@ class i3(object): ...@@ -43,7 +43,7 @@ class i3(object):
chunk = self.socket.recv(rest) chunk = self.socket.recv(rest)
data.append(chunk) data.append(chunk)
rest -= len(chunk) rest -= len(chunk)
return "".join(data) return b"".join(data)
def close(self): def close(self):
...@@ -75,14 +75,14 @@ def getwin(tree, activews=True): ...@@ -75,14 +75,14 @@ def getwin(tree, activews=True):
stack.extend(node.get("floating_nodes", [])) stack.extend(node.get("floating_nodes", []))
stack.extend(node.get("list", [])) stack.extend(node.get("list", []))
if activews: if activews:
for w in winlist.keys(): for w in list(winlist.keys()):
if winlist[w]["wsnum"] != wsactive: if winlist[w]["wsnum"] != wsactive:
del winlist[w] del winlist[w]
return winlist return winlist
def printjson(d): def printjson(d):
print json.dumps(d, indent=2, sort_keys=True) print(json.dumps(d, indent=2, sort_keys=True))
if __name__=='__main__': if __name__=='__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment