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 -*-
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])
......
#!/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]
......
#!/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"
})
......
#!/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__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment