Created
November 29, 2013 03:28
-
-
Save cjbarnes18/7701210 to your computer and use it in GitHub Desktop.
2to3 libqtile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- libqtile/bar.py (original) | |
+++ libqtile/bar.py (refactored) | |
@@ -18,12 +18,12 @@ | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
-import command | |
-import confreader | |
-import drawer | |
-import hook | |
-import configurable | |
-import window | |
+from . import command | |
+from . import confreader | |
+from . import drawer | |
+from . import hook | |
+from . import configurable | |
+from . import window | |
import gobject | |
@@ -158,7 +158,7 @@ | |
raise confreader.ConfigError( | |
"Bars must be at the top or the bottom of the screen." | |
) | |
- if len(filter(lambda w: w.width_type == STRETCH, self.widgets)) > 1: | |
+ if len([w for w in self.widgets if w.width_type == STRETCH]) > 1: | |
raise confreader.ConfigError("Only one STRETCH widget allowed!") | |
Gap._configure(self, qtile, screen) | |
--- libqtile/command.py (original) | |
+++ libqtile/command.py (refactored) | |
@@ -22,7 +22,7 @@ | |
import traceback | |
import textwrap | |
import os | |
-import ipc | |
+from . import ipc | |
class CommandError(Exception): | |
@@ -80,7 +80,7 @@ | |
selectors, name, args, kwargs = data | |
try: | |
obj = self.qtile.select(selectors) | |
- except _SelectError, v: | |
+ except _SelectError as v: | |
e = formatSelector([(v.name, v.sel)]) | |
s = formatSelector(selectors) | |
return (ERROR, "No object %s in path '%s'" % (e, s)) | |
@@ -90,9 +90,9 @@ | |
self.qtile.log.info("Command: %s(%s, %s)" % (name, args, kwargs)) | |
try: | |
return (SUCCESS, cmd(*args, **kwargs)) | |
- except CommandError, v: | |
+ except CommandError as v: | |
return (ERROR, v.args[0]) | |
- except Exception, v: | |
+ except Exception as v: | |
return (EXCEPTION, traceback.format_exc()) | |
self.qtile.conn.flush() | |
--- libqtile/config.py (original) | |
+++ libqtile/config.py (refactored) | |
@@ -1,8 +1,8 @@ | |
-import command | |
-import hook | |
+from . import command | |
+from . import hook | |
import sys | |
-import utils | |
-import xcbq | |
+from . import utils | |
+from . import xcbq | |
class Key: | |
@@ -29,7 +29,7 @@ | |
self.keysym = xcbq.keysyms[key] | |
try: | |
self.modmask = utils.translateMasks(self.modifiers) | |
- except KeyError, v: | |
+ except KeyError as v: | |
raise utils.QtileError(v) | |
def __repr__(self): | |
@@ -54,7 +54,7 @@ | |
try: | |
self.button_code = int(self.button.replace('Button', '')) | |
self.modmask = utils.translateMasks(self.modifiers) | |
- except KeyError, v: | |
+ except KeyError as v: | |
raise utils.QtileError(v) | |
def __repr__(self): | |
@@ -72,7 +72,7 @@ | |
try: | |
self.button_code = int(self.button.replace('Button', '')) | |
self.modmask = utils.translateMasks(self.modifiers) | |
- except KeyError, v: | |
+ except KeyError as v: | |
raise utils.QtileError(v) | |
def __repr__(self): | |
@@ -243,7 +243,7 @@ | |
def _items(self, name): | |
if name == "layout": | |
- return (True, range(len(self.group.layouts))) | |
+ return (True, list(range(len(self.group.layouts)))) | |
elif name == "window": | |
return (True, [i.window.wid for i in self.group.windows]) | |
elif name == "bar": | |
@@ -327,7 +327,7 @@ | |
""" | |
def __init__(self, name, matches=None, exclusive=False, | |
spawn=None, layout=None, persist=True, init=True, | |
- layout_opts=None, screen_affinity=None, position=sys.maxint): | |
+ layout_opts=None, screen_affinity=None, position=sys.maxsize): | |
""" | |
:param name: the name of this group | |
:type name: string | |
--- libqtile/confreader.py (original) | |
+++ libqtile/confreader.py (refactored) | |
@@ -26,7 +26,7 @@ | |
import os | |
import sys | |
-import utils | |
+from . import utils | |
import traceback | |
@@ -51,7 +51,7 @@ | |
try: | |
sys.path.insert(0, os.path.dirname(self.fname)) | |
config = __import__(os.path.basename(self.fname)[:-3]) | |
- except Exception, v: | |
+ except Exception as v: | |
# On restart, user potentially has some windows open, but they | |
# screwed up their config. So as not to lose their apps, we | |
# just load the default config here. | |
@@ -84,7 +84,7 @@ | |
# We delay importing here to avoid a circular import issue when | |
# testing. | |
- from resources import default_config | |
+ from .resources import default_config | |
for option in config_options: | |
if hasattr(config, option): | |
v = getattr(config, option) | |
--- libqtile/dgroups.py (original) | |
+++ libqtile/dgroups.py (refactored) | |
@@ -6,6 +6,7 @@ | |
from libqtile.command import lazy | |
from libqtile.config import Group | |
from libqtile.config import Rule | |
+import collections | |
def simple_key_binder(mod, keynames=None): | |
""" | |
@@ -22,7 +23,7 @@ | |
keys = keynames | |
else: | |
# keys 1 to 9 and 0 | |
- keys = map(str, range(1, 10) + [0]) | |
+ keys = list(map(str, list(range(1, 10)) + [0])) | |
# bind all keys | |
for keyname, group in zip(keys, dgroup.qtile.groups): | |
@@ -118,8 +119,8 @@ | |
group_obj = self.qtile.groupMap[rule.group] | |
group = self.groupMap.get(rule.group) | |
if group and group_added: | |
- for k, v in group.layout_opts.iteritems(): | |
- if callable(v): | |
+ for k, v in group.layout_opts.items(): | |
+ if isinstance(v, collections.Callable): | |
v(group_obj.layout) | |
else: | |
setattr(group_obj.layout, k, v) | |
--- libqtile/drawer.py (original) | |
+++ libqtile/drawer.py (refactored) | |
@@ -1,5 +1,5 @@ | |
import collections | |
-import utils | |
+from . import utils | |
import math | |
import pangocairo | |
import cairo | |
--- libqtile/group.py (original) | |
+++ libqtile/group.py (refactored) | |
@@ -1,7 +1,7 @@ | |
-import command | |
-import hook | |
-import window | |
-import utils | |
+from . import command | |
+from . import hook | |
+from . import window | |
+from . import utils | |
import contextlib | |
import xcb | |
import xcb.xproto | |
@@ -238,7 +238,7 @@ | |
def _items(self, name): | |
if name == "layout": | |
- return (True, range(len(self.layouts))) | |
+ return (True, list(range(len(self.layouts)))) | |
elif name == "window": | |
return (True, [i.window.wid for i in self.windows]) | |
elif name == "screen": | |
--- libqtile/hook.py (original) | |
+++ libqtile/hook.py (refactored) | |
@@ -1,4 +1,4 @@ | |
-import utils | |
+from . import utils | |
subscriptions = {} | |
SKIPLOG = set() | |
--- libqtile/log_utils.py (original) | |
+++ libqtile/log_utils.py (refactored) | |
@@ -6,7 +6,7 @@ | |
class ColorFormatter(logging.Formatter): | |
"""Logging formatter adding console colors to the output.""" | |
- black, red, green, yellow, blue, magenta, cyan, white = range(8) | |
+ black, red, green, yellow, blue, magenta, cyan, white = list(range(8)) | |
colors = { | |
'WARNING': yellow, | |
'INFO': green, | |
@@ -32,7 +32,7 @@ | |
message = message.replace('$RESET', self.reset_seq)\ | |
.replace('$BOLD', self.bold_seq)\ | |
.replace('$COLOR', color) | |
- for color, value in self.colors.items(): | |
+ for color, value in list(self.colors.items()): | |
message = message.replace( | |
'$' + color, self.color_seq % (value + 30))\ | |
.replace('$BG' + color, self.color_seq % (value + 40))\ | |
--- libqtile/manager.py (original) | |
+++ libqtile/manager.py (refactored) | |
@@ -19,32 +19,32 @@ | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
-from config import Drag, Click, Screen | |
-from utils import QtileError | |
+from .config import Drag, Click, Screen | |
+from .utils import QtileError | |
from libqtile.log_utils import init_log | |
from libqtile.dgroups import DGroups | |
-from state import QtileState | |
-from group import _Group | |
-from StringIO import StringIO | |
+from .state import QtileState | |
+from .group import _Group | |
+from io import StringIO | |
from xcb.xproto import EventMask, BadWindow, BadAccess, BadDrawable | |
import atexit | |
-import command | |
+from . import command | |
import gobject | |
-import hook | |
+from . import hook | |
import logging | |
import os | |
import os.path | |
import pickle | |
import sys | |
import traceback | |
-import utils | |
-import window | |
+from . import utils | |
+from . import window | |
import xcb | |
import xcb.xinerama | |
import xcb.xproto | |
-import xcbq | |
- | |
-from widget.base import _Widget | |
+from . import xcbq | |
+ | |
+from .widget.base import _Widget | |
class Qtile(command.CommandObject): | |
@@ -295,7 +295,7 @@ | |
self.root.set_property("_NET_CURRENT_DESKTOP", index) | |
def addGroup(self, name, layout=None): | |
- if name not in self.groupMap.keys(): | |
+ if name not in list(self.groupMap.keys()): | |
g = _Group(name, layout) | |
self.groups.append(g) | |
g._configure( | |
@@ -313,7 +313,7 @@ | |
# one group per screen is needed | |
if len(self.groups) == len(self.screens): | |
raise ValueError("Can't delete all groups.") | |
- if name in self.groupMap.keys(): | |
+ if name in list(self.groupMap.keys()): | |
group = self.groupMap[name] | |
if group.screen and group.screen.previous_group: | |
target = group.screen.previous_group | |
@@ -470,7 +470,7 @@ | |
and drag and drop of tabs in chrome | |
""" | |
- windows = [wid for wid, c in self.windowMap.iteritems() if c.group] | |
+ windows = [wid for wid, c in self.windowMap.items() if c.group] | |
self.root.set_property("_NET_CLIENT_LIST", windows) | |
# TODO: check stack order | |
self.root.set_property("_NET_CLIENT_LIST_STACKING", windows) | |
@@ -509,7 +509,7 @@ | |
def grabKeys(self): | |
self.root.ungrab_key(None, None) | |
- for key in self.keyMap.values(): | |
+ for key in list(self.keyMap.values()): | |
self.mapKey(key) | |
def get_target_chain(self, ename, e): | |
@@ -864,17 +864,17 @@ | |
def _items(self, name): | |
if name == "group": | |
- return True, self.groupMap.keys() | |
+ return True, list(self.groupMap.keys()) | |
elif name == "layout": | |
- return True, range(len(self.currentGroup.layouts)) | |
+ return True, list(range(len(self.currentGroup.layouts))) | |
elif name == "widget": | |
- return False, self.widgetMap.keys() | |
+ return False, list(self.widgetMap.keys()) | |
elif name == "bar": | |
return False, [x.position for x in self.currentScreen.gaps] | |
elif name == "window": | |
return True, self.listWID() | |
elif name == "screen": | |
- return True, range(len(self.screens)) | |
+ return True, list(range(len(self.screens))) | |
def _select(self, name, sel): | |
if name == "group": | |
@@ -903,10 +903,10 @@ | |
return utils.lget(self.screens, sel) | |
def listWID(self): | |
- return [i.window.wid for i in self.windowMap.values()] | |
+ return [i.window.wid for i in list(self.windowMap.values())] | |
def clientFromWID(self, wid): | |
- for i in self.windowMap.values(): | |
+ for i in list(self.windowMap.values()): | |
if i.window.wid == wid: | |
return i | |
return None | |
@@ -955,7 +955,7 @@ | |
""" | |
List of all addressible widget names. | |
""" | |
- return self.widgetMap.keys() | |
+ return list(self.widgetMap.keys()) | |
def cmd_nextlayout(self, group=None): | |
""" | |
@@ -1028,7 +1028,7 @@ | |
d.detail = keycode | |
try: | |
d.state = utils.translateMasks(modifiers) | |
- except KeyError, v: | |
+ except KeyError as v: | |
return v.args[0] | |
self.handle_KeyPress(d) | |
@@ -1049,7 +1049,7 @@ | |
buf = StringIO() | |
pickle.dump(QtileState(self), buf) | |
- argv = filter(lambda s: not s.startswith('--with-state'), argv) | |
+ argv = [s for s in argv if not s.startswith('--with-state')] | |
argv.append('--with-state=' + buf.getvalue()) | |
self.cmd_execute(sys.executable, argv) | |
@@ -1107,7 +1107,7 @@ | |
Return info for each client window. | |
""" | |
return [ | |
- i.info() for i in self.windowMap.values() | |
+ i.info() for i in list(self.windowMap.values()) | |
if not isinstance(i, window.Internal) | |
] | |
@@ -1116,7 +1116,7 @@ | |
Return info for each internal window (bars, for example). | |
""" | |
return [ | |
- i.info() for i in self.windowMap.values() | |
+ i.info() for i in list(self.windowMap.values()) | |
if isinstance(i, window.Internal) | |
] | |
@@ -1173,7 +1173,7 @@ | |
def cmd_next_urgent(self): | |
try: | |
- nxt = filter(lambda w: w.urgent, self.windowMap.values())[0] | |
+ nxt = filter(lambda w: w.urgent, list(self.windowMap.values()))[0] | |
nxt.group.cmd_toscreen() | |
nxt.group.focus(nxt, False) | |
except IndexError: | |
@@ -1292,7 +1292,7 @@ | |
try: | |
return (True, str(eval(code))) | |
except SyntaxError: | |
- exec code | |
+ exec(code) | |
return (True, None) | |
except: | |
error = traceback.format_exc().strip().split("\n")[-1] | |
--- libqtile/sh.py (original) | |
+++ libqtile/sh.py (refactored) | |
@@ -28,8 +28,8 @@ | |
import fcntl | |
import termios | |
import struct | |
-import command | |
-import ipc | |
+from . import command | |
+from . import ipc | |
def terminalWidth(): | |
@@ -249,9 +249,9 @@ | |
dict(cmd=cmd) | |
) | |
return val | |
- except SyntaxError, v: | |
+ except SyntaxError as v: | |
return "Syntax error in expression: %s" % v.text | |
- except command.CommandException, val: | |
+ except command.CommandException as val: | |
return "Command exception: %s\n" % val | |
except ipc.IPCError: | |
# on restart, try to reconnect | |
@@ -265,9 +265,9 @@ | |
def loop(self): | |
while True: | |
try: | |
- line = raw_input(self.prompt) | |
+ line = input(self.prompt) | |
except (EOFError, KeyboardInterrupt): | |
+ print() | |
return | |
if not line: | |
continue | |
@@ -285,7 +285,7 @@ | |
val = builtin(args) | |
else: | |
val = self._call(cmd, args) | |
- if isinstance(val, basestring): | |
- print val | |
+ if isinstance(val, str): | |
+ print(val) | |
elif val: | |
pprint.pprint(val) | |
--- libqtile/state.py (original) | |
+++ libqtile/state.py (refactored) | |
@@ -20,8 +20,8 @@ | |
from collections import defaultdict | |
-import command | |
-import hook | |
+from . import command | |
+from . import hook | |
class QtileState(object): | |
@@ -47,13 +47,13 @@ | |
Rearrange the windows in the specified Qtile object according to | |
this QtileState. | |
""" | |
- for (group, layout) in self.groups.iteritems(): | |
+ for (group, layout) in self.groups.items(): | |
try: | |
qtile.groupMap[group].layout = layout | |
except KeyError: | |
pass # group missing | |
- for (screen, group) in self.screens.iteritems(): | |
+ for (screen, group) in self.screens.items(): | |
try: | |
group = qtile.groupMap[group] | |
qtile.screens[screen].setGroup(group) | |
--- libqtile/utils.py (original) | |
+++ libqtile/utils.py (refactored) | |
@@ -23,7 +23,8 @@ | |
import gobject | |
import logging | |
import os | |
-import xcbq | |
+from . import xcbq | |
+from functools import reduce | |
class QtileError(Exception): | |
@@ -148,7 +149,7 @@ | |
else: | |
alpha = 1 | |
return (x[0] / 255.0, x[1] / 255.0, x[2] / 255.0, alpha) | |
- elif isinstance(x, basestring): | |
+ elif isinstance(x, str): | |
if x.startswith("#"): | |
x = x[1:] | |
if "." in x: | |
@@ -193,7 +194,7 @@ | |
def scrub_to_utf8(text): | |
if not text: | |
return "" | |
- elif isinstance(text, unicode): | |
+ elif isinstance(text, str): | |
return text | |
else: | |
return text.decode("utf-8", "ignore") | |
--- libqtile/window.py (original) | |
+++ libqtile/window.py (refactored) | |
@@ -24,9 +24,9 @@ | |
import xcb.xcb | |
from xcb.xproto import EventMask, StackMode, SetMode | |
import xcb.xproto | |
-import command | |
-import utils | |
-import hook | |
+from . import command | |
+from . import utils | |
+from . import hook | |
# ICCM Constants | |
@@ -1136,7 +1136,7 @@ | |
if name == "group": | |
return (True, None) | |
elif name == "layout": | |
- return (True, range(len(self.group.layouts))) | |
+ return (True, list(range(len(self.group.layouts)))) | |
elif name == "screen": | |
return (True, None) | |
--- libqtile/xcbq.py (original) | |
+++ libqtile/xcbq.py (refactored) | |
@@ -4,20 +4,20 @@ | |
""" | |
from xcb.xproto import CW, WindowClass, EventMask | |
import struct | |
-import utils | |
+from . import utils | |
import xcb.randr | |
import xcb.xcb | |
import xcb.xinerama | |
import xcb.xproto | |
-import xkeysyms | |
+from . import xkeysyms | |
# hack xcb.xproto for negative numbers | |
def ConfigureWindow(self, window, value_mask, value_list): | |
- import cStringIO | |
+ import io | |
from struct import pack | |
from array import array | |
- buf = cStringIO.StringIO() | |
+ buf = io.StringIO() | |
buf.write(pack('xx2xIH2x', window, value_mask)) | |
buf.write(str(buffer(array('i', value_list)))) | |
return self.send_request( | |
@@ -185,7 +185,7 @@ | |
values.append(getattr(val, "_maskvalue", val)) | |
del kwargs[s] | |
if kwargs: | |
- raise ValueError("Unknown mask names: %s" % kwargs.keys()) | |
+ raise ValueError("Unknown mask names: %s" % list(kwargs.keys())) | |
return mask, values | |
ConfigureMasks = MaskMap(xcb.xproto.ConfigWindow) | |
@@ -200,7 +200,7 @@ | |
self.reverse = {} | |
# We can change the pre-loads not to wait for a return | |
- for name in WindowTypes.keys(): | |
+ for name in list(WindowTypes.keys()): | |
self.insert(name=name) | |
for i in dir(xcb.xproto.Atom): | |
@@ -394,7 +394,7 @@ | |
data = struct.pack("B" * len(r.value), *(list(r.value))) | |
l = struct.unpack_from("=IIIIIIIII", data) | |
flags = set() | |
- for k, v in HintsFlags.items(): | |
+ for k, v in list(HintsFlags.items()): | |
if l[0] & v: | |
flags.add(k) | |
return dict( | |
@@ -418,7 +418,7 @@ | |
data = struct.pack("B" * len(r.value), *(list(r.value))) | |
l = struct.unpack_from("=IIIIIIIIIIIIII", data) | |
flags = set() | |
- for k, v in NormalHintsFlags.items(): | |
+ for k, v in list(NormalHintsFlags.items()): | |
if l[0] & v: | |
flags.add(k) | |
return dict( | |
@@ -596,10 +596,10 @@ | |
r = self.conn.conn.core.GetProperty( | |
False, self.wid, | |
self.conn.atoms[prop] | |
- if isinstance(prop, basestring) | |
+ if isinstance(prop, str) | |
else prop, | |
self.conn.atoms[type] | |
- if isinstance(type, basestring) | |
+ if isinstance(type, str) | |
else type, | |
0, (2 ** 32) - 1 | |
).reply() | |
@@ -715,9 +715,9 @@ | |
def text_extents(self, s): | |
s = s + "aaa" | |
- print s | |
+ print(s) | |
x = self.conn.conn.core.QueryTextExtents(self.fid, len(s), s).reply() | |
- print x | |
+ print(x) | |
return x | |
@@ -790,7 +790,7 @@ | |
self.code_to_syms[first + count - 1] = l | |
first_sym_to_code = {} | |
- for k, s in self.code_to_syms.items(): | |
+ for k, s in list(self.code_to_syms.items()): | |
if s[0] and not s[0] in first_sym_to_code: | |
first_sym_to_code[s[0]] = k | |
@@ -808,7 +808,7 @@ | |
""" | |
Return the modifier matching keycode. | |
""" | |
- for n, l in self.modmap.items(): | |
+ for n, l in list(self.modmap.items()): | |
if keycode in l: | |
return n | |
return None | |
--- libqtile/layout/__init__.py (original) | |
+++ libqtile/layout/__init__.py (refactored) | |
@@ -1,10 +1,10 @@ | |
-from stack import Stack | |
-from max import Max | |
-from xmonad import MonadTall | |
-from tile import Tile | |
-from floating import Floating | |
-from ratiotile import RatioTile | |
-from slice import Slice | |
-from tree import TreeTab | |
-from zoomy import Zoomy | |
-from matrix import Matrix | |
+from .stack import Stack | |
+from .max import Max | |
+from .xmonad import MonadTall | |
+from .tile import Tile | |
+from .floating import Floating | |
+from .ratiotile import RatioTile | |
+from .slice import Slice | |
+from .tree import TreeTab | |
+from .zoomy import Zoomy | |
+from .matrix import Matrix | |
--- libqtile/layout/base.py (original) | |
+++ libqtile/layout/base.py (refactored) | |
@@ -215,7 +215,7 @@ | |
grouped[lay].append(w) | |
else: | |
grouped[lay] = [w] | |
- for lay, wins in grouped.iteritems(): | |
+ for lay, wins in grouped.items(): | |
lay.layout(wins, mapping[lay]) | |
def remove(self, win): | |
--- libqtile/layout/floating.py (original) | |
+++ libqtile/layout/floating.py (refactored) | |
@@ -1,4 +1,4 @@ | |
-from base import Layout | |
+from .base import Layout | |
from .. import manager, window | |
DEFAULT_FLOAT_WM_TYPES = set([ | |
--- libqtile/layout/matrix.py (original) | |
+++ libqtile/layout/matrix.py (refactored) | |
@@ -1,6 +1,6 @@ | |
import math | |
-from base import Layout | |
+from .base import Layout | |
class Matrix(Layout): | |
@@ -27,7 +27,7 @@ | |
d = Layout.info(self) | |
d["rows"] = [ | |
[win.name for win in self.get_row(i)] | |
- for i in xrange(self.get_num_rows()) | |
+ for i in range(self.get_num_rows()) | |
] | |
d["current_window"] = self.current_window | |
return d | |
@@ -54,7 +54,7 @@ | |
assert column < self.columns | |
return [ | |
self.windows[i] | |
- for i in xrange(column, len(self.windows), self.columns) | |
+ for i in range(column, len(self.windows), self.columns) | |
] | |
def add(self, c): | |
--- libqtile/layout/max.py (original) | |
+++ libqtile/layout/max.py (refactored) | |
@@ -17,7 +17,7 @@ | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
-from base import SingleWindow | |
+from .base import SingleWindow | |
from .. import utils, manager | |
--- libqtile/layout/ratiotile.py (original) | |
+++ libqtile/layout/ratiotile.py (refactored) | |
@@ -1,6 +1,6 @@ | |
import math | |
-from base import Layout | |
+from .base import Layout | |
from .. import utils, manager | |
@@ -330,7 +330,7 @@ | |
nextindex = 0 | |
return self.windows[nextindex] | |
- def next(self): | |
+ def __next__(self): | |
n = self.getPreviousClient() | |
self.group.focus(n, True) | |
@@ -347,10 +347,10 @@ | |
self.previous() | |
def cmd_up(self): | |
- self.next() | |
+ next(self) | |
def cmd_next(self): | |
- self.next() | |
+ next(self) | |
def cmd_previous(self): | |
self.previous() | |
--- libqtile/layout/slice.py (original) | |
+++ libqtile/layout/slice.py (refactored) | |
@@ -3,8 +3,8 @@ | |
Slice layout. Serves as example of delegating layouts (or sublayouts) | |
""" | |
-from base import Layout, SingleWindow, Delegate | |
-from max import Max | |
+from .base import Layout, SingleWindow, Delegate | |
+from .max import Max | |
from .. import manager | |
--- libqtile/layout/stack.py (original) | |
+++ libqtile/layout/stack.py (refactored) | |
@@ -17,7 +17,7 @@ | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
-from base import Layout | |
+from .base import Layout | |
from .. import utils, manager | |
--- libqtile/layout/tile.py (original) | |
+++ libqtile/layout/tile.py (refactored) | |
@@ -1,4 +1,4 @@ | |
-from base import Layout | |
+from .base import Layout | |
from .. import utils, manager | |
@@ -98,7 +98,7 @@ | |
previndex = self.get_previous_index(currentindex) | |
return self.clients[previndex] | |
- def next(self): | |
+ def __next__(self): | |
n = self.getPreviousClient() | |
self.group.focus(n, True) | |
@@ -207,7 +207,7 @@ | |
self.up() | |
def cmd_next(self): | |
- self.next() | |
+ next(self) | |
def cmd_previous(self): | |
self.previous() | |
--- libqtile/layout/tree.py (original) | |
+++ libqtile/layout/tree.py (refactored) | |
@@ -1,11 +1,11 @@ | |
# -*- coding: utf-8 -*- | |
-from base import SingleWindow | |
+from .base import SingleWindow | |
from .. import manager | |
from .. import window | |
from .. import drawer | |
from .. import hook | |
-to_superscript = dict(zip(map(ord, u'0123456789'), map(ord, u'⁰¹²³⁴⁵⁶⁷⁸⁹'))) | |
+to_superscript = dict(list(zip(list(map(ord, '0123456789')), list(map(ord, '⁰¹²³⁴⁵⁶⁷⁸⁹'))))) | |
class TreeNode(object): | |
@@ -44,7 +44,7 @@ | |
def add_superscript(self, title): | |
if not self.expanded and self.children: | |
- return unicode( | |
+ return str( | |
len(self.children) | |
).translate(to_superscript).encode('utf-8') + title | |
return title | |
@@ -72,7 +72,7 @@ | |
while not isinstance(node, Root): | |
parent = node.parent | |
idx = parent.children.index(node) | |
- for i in xrange(idx + 1, len(parent.children)): | |
+ for i in range(idx + 1, len(parent.children)): | |
res = parent.children[i].get_first_window() | |
if res: | |
return res | |
@@ -85,7 +85,7 @@ | |
idx = parent.children.index(node) | |
if idx == 0 and isinstance(parent, Window): | |
return parent | |
- for i in xrange(idx - 1, -1, -1): | |
+ for i in range(idx - 1, -1, -1): | |
res = parent.children[i].get_last_window() | |
if res: | |
return res | |
--- libqtile/layout/xmonad.py (original) | |
+++ libqtile/layout/xmonad.py (refactored) | |
@@ -1,4 +1,4 @@ | |
-from base import SingleWindow | |
+from .base import SingleWindow | |
from .. import manager | |
import math | |
--- libqtile/layout/zoomy.py (original) | |
+++ libqtile/layout/zoomy.py (refactored) | |
@@ -1,4 +1,4 @@ | |
-from base import SingleWindow | |
+from .base import SingleWindow | |
from .. import utils, manager | |
--- libqtile/resources/default_config.py (original) | |
+++ libqtile/resources/default_config.py (refactored) | |
@@ -28,7 +28,7 @@ | |
# Switch window focus to other pane(s) of stack | |
Key( | |
[mod], "space", | |
- lazy.layout.next() | |
+ next(lazy.layout) | |
), | |
# Swap panes of split stack | |
--- libqtile/widget/__init__.py (original) | |
+++ libqtile/widget/__init__.py (refactored) | |
@@ -1,56 +1,56 @@ | |
-from backlight import Backlight | |
-from battery import Battery, BatteryIcon | |
-from clock import Clock | |
-from currentlayout import CurrentLayout | |
-from graph import CPUGraph, MemoryGraph, SwapGraph, NetGraph, HDDGraph, HDDBusyGraph | |
-from groupbox import AGroupBox, GroupBox | |
-from maildir import Maildir | |
-from notify import Notify | |
-from prompt import Prompt | |
-from sensors import ThermalSensor | |
-from sep import Sep | |
-from she import She | |
-from spacer import Spacer | |
-from systray import Systray | |
-from textbox import TextBox | |
-from volume import Volume | |
-from windowname import WindowName | |
-from windowtabs import WindowTabs | |
-from keyboardlayout import KeyboardLayout | |
-from df import DF | |
-from image import Image | |
+from .backlight import Backlight | |
+from .battery import Battery, BatteryIcon | |
+from .clock import Clock | |
+from .currentlayout import CurrentLayout | |
+from .graph import CPUGraph, MemoryGraph, SwapGraph, NetGraph, HDDGraph, HDDBusyGraph | |
+from .groupbox import AGroupBox, GroupBox | |
+from .maildir import Maildir | |
+from .notify import Notify | |
+from .prompt import Prompt | |
+from .sensors import ThermalSensor | |
+from .sep import Sep | |
+from .she import She | |
+from .spacer import Spacer | |
+from .systray import Systray | |
+from .textbox import TextBox | |
+from .volume import Volume | |
+from .windowname import WindowName | |
+from .windowtabs import WindowTabs | |
+from .keyboardlayout import KeyboardLayout | |
+from .df import DF | |
+from .image import Image | |
-from tasklist import TaskList | |
+from .tasklist import TaskList | |
try: | |
- from canto import Canto | |
+ from .canto import Canto | |
except ImportError: | |
pass | |
try: | |
- from mpriswidget import Mpris | |
+ from .mpriswidget import Mpris | |
except ImportError: | |
pass | |
try: | |
- from mpdwidget import Mpd | |
+ from .mpdwidget import Mpd | |
except ImportError: | |
pass | |
try: | |
- from yahoo_weather import YahooWeather | |
- from bitcoin_ticker import BitcoinTicker | |
+ from .yahoo_weather import YahooWeather | |
+ from .bitcoin_ticker import BitcoinTicker | |
except ImportError: | |
# Requires Python >= 2.6 or simplejson | |
pass | |
-from pacman import Pacman | |
-from sensors import ThermalSensor | |
+from .pacman import Pacman | |
+from .sensors import ThermalSensor | |
try: | |
- from wlan import Wlan | |
+ from .wlan import Wlan | |
except ImportError: | |
# Requires python-wifi | |
pass | |
try: | |
- from google_calendar import GoogleCalendar | |
+ from .google_calendar import GoogleCalendar | |
except ImportError: | |
pass | |
--- libqtile/widget/backlight.py (original) | |
+++ libqtile/widget/backlight.py (refactored) | |
@@ -1,7 +1,7 @@ | |
import cairo | |
import os | |
from libqtile import bar | |
-import base | |
+from . import base | |
BACKLIGHT_DIR = '/sys/class/backlight' | |
--- libqtile/widget/battery.py (original) | |
+++ libqtile/widget/battery.py (refactored) | |
@@ -1,7 +1,7 @@ | |
import cairo | |
import os | |
from libqtile import bar | |
-import base | |
+from . import base | |
BAT_DIR = '/sys/class/power_supply' | |
CHARGED = 'Full' | |
@@ -269,7 +269,7 @@ | |
base._TextBox.draw(self) | |
def setup_images(self): | |
- for key, name in self.icons.iteritems(): | |
+ for key, name in self.icons.items(): | |
try: | |
path = os.path.join(self.theme_path, name) | |
img = cairo.ImageSurface.create_from_png(path) | |
--- libqtile/widget/bitcoin_ticker.py (original) | |
+++ libqtile/widget/bitcoin_ticker.py (refactored) | |
@@ -2,9 +2,9 @@ | |
# -*- coding: utf-8 -*- | |
from .. import bar | |
-import base | |
-import urllib | |
-import urllib2 | |
+from . import base | |
+import urllib.request, urllib.parse, urllib.error | |
+import urllib.request, urllib.error, urllib.parse | |
import gobject | |
import threading | |
@@ -55,7 +55,7 @@ | |
return True | |
def fetch_data(self): | |
- res = urllib2.urlopen( | |
+ res = urllib.request.urlopen( | |
self.QUERY_URL % self.currency_code[self.currency] | |
) | |
raw = json.loads(res.read()) | |
--- libqtile/widget/canto.py (original) | |
+++ libqtile/widget/canto.py (refactored) | |
@@ -1,7 +1,7 @@ | |
# -*- coding: utf-8 -*- | |
from .. import bar | |
-import base | |
+from . import base | |
from subprocess import check_output, call | |
--- libqtile/widget/clock.py (original) | |
+++ libqtile/widget/clock.py (refactored) | |
@@ -2,7 +2,7 @@ | |
from datetime import datetime | |
from .. import bar | |
-import base | |
+from . import base | |
import gobject | |
--- libqtile/widget/crashme.py (original) | |
+++ libqtile/widget/crashme.py (refactored) | |
@@ -1,6 +1,6 @@ | |
# -*- coding: utf-8 -*- | |
from .. import bar | |
-import base | |
+from . import base | |
class _CrashMe(base._TextBox): | |
--- libqtile/widget/currentlayout.py (original) | |
+++ libqtile/widget/currentlayout.py (refactored) | |
@@ -1,4 +1,4 @@ | |
-import base | |
+from . import base | |
from .. import bar, hook | |
--- libqtile/widget/df.py (original) | |
+++ libqtile/widget/df.py (refactored) | |
@@ -16,7 +16,7 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
import os | |
-import base | |
+from . import base | |
from .. import bar | |
--- libqtile/widget/google_calendar.py (original) | |
+++ libqtile/widget/google_calendar.py (refactored) | |
@@ -53,7 +53,7 @@ | |
################################################################### | |
from .. import bar, utils | |
-import base | |
+from . import base | |
import httplib2 | |
import logging | |
import os | |
--- libqtile/widget/graph.py (original) | |
+++ libqtile/widget/graph.py (refactored) | |
@@ -300,7 +300,7 @@ | |
@staticmethod | |
def get_main_iface(): | |
filename = "/proc/net/route" | |
- make_route = lambda line: dict(zip(['iface', 'dest'], line.split())) | |
+ make_route = lambda line: dict(list(zip(['iface', 'dest'], line.split()))) | |
routes = [make_route(line) for line in list(open(filename))[1:]] | |
try: | |
return next( | |
--- libqtile/widget/groupbox.py (original) | |
+++ libqtile/widget/groupbox.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import bar, hook, utils | |
-import base | |
+from . import base | |
class _GroupBase(base._TextBox, base.PaddingMixin, base.MarginMixin): | |
@@ -86,10 +86,10 @@ | |
def draw(self): | |
self.drawer.clear(self.background or self.bar.background) | |
- e = ( | |
+ e = next(( | |
i for i in self.qtile.groups | |
if i.name == self.bar.screen.group.name | |
- ).next() | |
+ )) | |
self.drawbox(self.margin_x, e.name, self.border, self.foreground) | |
self.drawer.draw(self.offset, self.width) | |
--- libqtile/widget/image.py (original) | |
+++ libqtile/widget/image.py (refactored) | |
@@ -1,7 +1,7 @@ | |
import os | |
import cairo | |
-import base | |
+from . import base | |
from .. import bar | |
class Image(base._Widget, base.MarginMixin): | |
--- libqtile/widget/keyboardlayout.py (original) | |
+++ libqtile/widget/keyboardlayout.py (refactored) | |
@@ -1,6 +1,6 @@ | |
import subprocess | |
from subprocess import CalledProcessError | |
-import base | |
+from . import base | |
from .. import bar | |
--- libqtile/widget/maildir.py (original) | |
+++ libqtile/widget/maildir.py (refactored) | |
@@ -1,7 +1,7 @@ | |
# -*- coding: utf-8 -*- | |
# vim: set sw=4 et tw=80: | |
-import base | |
+from . import base | |
from .. import bar | |
import os.path | |
@@ -31,7 +31,7 @@ | |
# if it looks like a list of strings then we just convert them | |
# and use the name as the label | |
- if isinstance(subFolders[0], basestring): | |
+ if isinstance(subFolders[0], str): | |
self._subFolders = [ | |
{"path": folder, "label": folder} | |
for folder in subFolders | |
@@ -75,7 +75,7 @@ | |
@return: a string representation of the given state. | |
""" | |
return self._separator.join( | |
- "{}: {}".format(*item) for item in state.iteritems() | |
+ "{}: {}".format(*item) for item in state.items() | |
) | |
def update(self): | |
--- libqtile/widget/mpdwidget.py (original) | |
+++ libqtile/widget/mpdwidget.py (refactored) | |
@@ -11,7 +11,7 @@ | |
from .. import bar, utils | |
from mpd import MPDClient, CommandError | |
import atexit | |
-import base | |
+from . import base | |
import re | |
@@ -280,7 +280,7 @@ | |
elif button == 4: | |
self.client.previous() | |
elif button == 5: | |
- self.client.next() | |
+ next(self.client) | |
elif button == 8: | |
if status: | |
self.client.setvol( | |
--- libqtile/widget/mpriswidget.py (original) | |
+++ libqtile/widget/mpriswidget.py (refactored) | |
@@ -2,7 +2,7 @@ | |
from dbus.mainloop.glib import DBusGMainLoop | |
-import base | |
+from . import base | |
from .. import bar | |
--- libqtile/widget/notify.py (original) | |
+++ libqtile/widget/notify.py (refactored) | |
@@ -3,7 +3,7 @@ | |
from .. import bar, drawer, utils | |
from libqtile.notify import notifier | |
-import base | |
+from . import base | |
class Notify(base._TextBox): | |
@@ -77,7 +77,7 @@ | |
self.current_id -= 1 | |
self.display() | |
- def next(self): | |
+ def __next__(self): | |
if self.current_id < len(notifier.notifications) - 1: | |
self.current_id += 1 | |
self.display() | |
@@ -88,7 +88,7 @@ | |
elif button == 4: | |
self.prev() | |
elif button == 5: | |
- self.next() | |
+ next(self) | |
def cmd_display(self): | |
self.display() | |
@@ -106,4 +106,4 @@ | |
self.prev() | |
def cmd_next(self): | |
- self.next() | |
+ next(self) | |
--- libqtile/widget/pacman.py (original) | |
+++ libqtile/widget/pacman.py (refactored) | |
@@ -15,7 +15,7 @@ | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
-import base | |
+from . import base | |
from .. import bar | |
--- libqtile/widget/prompt.py (original) | |
+++ libqtile/widget/prompt.py (refactored) | |
@@ -2,7 +2,7 @@ | |
import os | |
import string | |
from .. import bar, xkeysyms, xcbq, command | |
-import base | |
+from . import base | |
class NullCompleter: | |
@@ -143,7 +143,7 @@ | |
txt = txt.lower() | |
if not self.lookup: | |
self.lookup = [] | |
- for group in self.qtile.groupMap.keys(): | |
+ for group in list(self.qtile.groupMap.keys()): | |
if group.lower().startswith(txt): | |
self.lookup.append((group, group)) | |
@@ -182,7 +182,7 @@ | |
""" | |
if not self.lookup: | |
self.lookup = [] | |
- for wid, window in self.qtile.windowMap.iteritems(): | |
+ for wid, window in self.qtile.windowMap.items(): | |
if window.group and window.name.lower().startswith(txt): | |
self.lookup.append((window.name, wid)) | |
--- libqtile/widget/sensors.py (original) | |
+++ libqtile/widget/sensors.py (refactored) | |
@@ -2,7 +2,7 @@ | |
# coding: utf-8 | |
from .. import bar | |
-import base | |
+from . import base | |
from subprocess import Popen, PIPE | |
import re | |
@@ -32,7 +32,7 @@ | |
base._TextBox.__init__(self, 'N/A', width=bar.CALCULATED, **config) | |
self.add_defaults(ThermalSensor.defaults) | |
self.sensors_temp = re.compile( | |
- ur""" | |
+ r""" | |
([a-zA-Z]+ #Tag | |
\s?[0-9]+): #Tag number | |
\s+[+-] #Temp signed | |
--- libqtile/widget/sep.py (original) | |
+++ libqtile/widget/sep.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import bar | |
-import base | |
+from . import base | |
class Sep(base._Widget): | |
--- libqtile/widget/she.py (original) | |
+++ libqtile/widget/she.py (refactored) | |
@@ -22,7 +22,7 @@ | |
'0x301': {'name': 'Normal', 'speed': '1.2GHz'}, | |
'0x302': {'name': 'PoswerSave', 'speed': '800MHz'} | |
} | |
- self.modes_index = self.modes.keys().sort() | |
+ self.modes_index = list(self.modes.keys()).sort() | |
self.mode = None | |
self.timeout_add(self.update_delay, self.update) | |
@@ -40,7 +40,7 @@ | |
return True | |
def draw(self): | |
- if self.mode in self.modes.keys(): | |
+ if self.mode in list(self.modes.keys()): | |
self.text = self.modes[self.mode][self.format] | |
else: | |
self.text = self.mode | |
--- libqtile/widget/spacer.py (original) | |
+++ libqtile/widget/spacer.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import bar | |
-import base | |
+from . import base | |
class Spacer(base._Widget): | |
--- libqtile/widget/systray.py (original) | |
+++ libqtile/widget/systray.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import bar, xcbq, window | |
-import base | |
+from . import base | |
import xcb | |
from xcb.xproto import EventMask, SetMode | |
@@ -111,7 +111,7 @@ | |
pass | |
def calculate_width(self): | |
- width = sum([i.width for i in self.icons.values()]) | |
+ width = sum([i.width for i in list(self.icons.values())]) | |
width += self.padding * len(self.icons) | |
return width | |
--- libqtile/widget/tasklist.py (original) | |
+++ libqtile/widget/tasklist.py (refactored) | |
@@ -1,6 +1,6 @@ | |
import cairo | |
from .. import bar, hook | |
-import base | |
+from . import base | |
class TaskList(base._Widget, base.PaddingMixin, base.MarginMixin): | |
@@ -140,11 +140,11 @@ | |
return cache | |
icons = sorted( | |
- window.icons.iteritems(), | |
+ iter(window.icons.items()), | |
key=lambda x: abs(self.icon_size-int(x[0].split("x")[0])) | |
) | |
icon = icons[0] | |
- width, height = map(int, icon[0].split("x")) | |
+ width, height = list(map(int, icon[0].split("x"))) | |
img = cairo.ImageSurface.create_for_data( | |
icon[1], | |
--- libqtile/widget/textbox.py (original) | |
+++ libqtile/widget/textbox.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import bar | |
-import base | |
+from . import base | |
class TextBox(base._TextBox): | |
--- libqtile/widget/volume.py (original) | |
+++ libqtile/widget/volume.py (refactored) | |
@@ -4,7 +4,7 @@ | |
import cairo | |
-import base | |
+from . import base | |
from .. import bar | |
__all__ = [ | |
--- libqtile/widget/windowname.py (original) | |
+++ libqtile/widget/windowname.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import hook, bar | |
-import base | |
+from . import base | |
class WindowName(base._TextBox): | |
--- libqtile/widget/windowtabs.py (original) | |
+++ libqtile/widget/windowtabs.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import hook, bar | |
-import base | |
+from . import base | |
class WindowTabs(base._TextBox): | |
--- libqtile/widget/wlan.py (original) | |
+++ libqtile/widget/wlan.py (refactored) | |
@@ -1,5 +1,5 @@ | |
from .. import hook, bar | |
-import base | |
+from . import base | |
from pythonwifi.iwlibs import Wireless, Iwstats | |
--- libqtile/widget/yahoo_weather.py (original) | |
+++ libqtile/widget/yahoo_weather.py (refactored) | |
@@ -2,9 +2,9 @@ | |
# -*- coding: utf-8 -*- | |
from .. import bar | |
-import base | |
-import urllib | |
-import urllib2 | |
+from . import base | |
+import urllib.request, urllib.parse, urllib.error | |
+import urllib.request, urllib.error, urllib.parse | |
from xml.dom import minidom | |
import gobject | |
import threading | |
@@ -84,12 +84,12 @@ | |
return False | |
def fetch_woeid(self, location): | |
- url = QUERY_URL + urllib.urlencode({ | |
+ url = QUERY_URL + urllib.parse.urlencode({ | |
'q': 'select woeid from geo.places where text="%s"' % location, | |
'format': 'json' | |
}) | |
try: | |
- response = urllib2.urlopen(url) | |
+ response = urllib.request.urlopen(url) | |
data = json.loads(response.read()) | |
if data['query']['count'] > 1: | |
return data['query']['results']['place'][0]['woeid'] | |
@@ -105,10 +105,10 @@ | |
if not self.woeid: | |
return None | |
format = 'c' if self.metric else 'f' | |
- url = WEATHER_URL + urllib.urlencode({'w': self.woeid, 'u': format}) | |
+ url = WEATHER_URL + urllib.parse.urlencode({'w': self.woeid, 'u': format}) | |
try: | |
- response = urllib2.urlopen(url).read() | |
+ response = urllib.request.urlopen(url).read() | |
dom = minidom.parseString(response) | |
except Exception: | |
## Invalid response or couldn't parse XML. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment