Commit 46e9e5cb authored by Actionless Loveless's avatar Actionless Loveless Committed by chrysn

style: flake8

parent 04b7509e
[flake8]
builtins=_
max-line-length = 120
ignore=E402,E266
......@@ -40,7 +40,7 @@ class BetterList(list):
i = -1
while True:
try:
i = self.index(item, i+1)
i = self.index(item, i + 1)
except ValueError:
break
yield i
......@@ -48,9 +48,9 @@ class BetterList(list):
def split(self, item):
indices = list(self.indices(item))
yield self[:indices[0]]
for x in (self[a+1:b] for (a, b) in zip(indices[:-1], indices[1:])):
for x in (self[a + 1:b] for (a, b) in zip(indices[:-1], indices[1:])):
yield x
yield self[indices[-1]+1:]
yield self[indices[-1] + 1:]
class Size(tuple):
......@@ -139,7 +139,7 @@ class Rotation(str):
if self not in ('left', 'right', 'normal', 'inverted'):
raise Exception("No know rotation.")
is_odd = property(lambda self: self in ('left', 'right'))
_angles = {'left': pi/2, 'inverted': pi, 'right': 3*pi/2, 'normal': 0}
_angles = {'left': pi / 2, 'inverted': pi, 'right': 3 * pi / 2, 'normal': 0}
angle = property(lambda self: Rotation._angles[self])
def __repr__(self):
......
......@@ -60,7 +60,7 @@ def actioncallback(function):
args_out.append(args_in.pop(0))
if len(argnames) == len(args_in): # called directly
args_out.extend(args_in)
elif len(argnames)+1 == len(args_in):
elif len(argnames) + 1 == len(args_in):
if argnames:
args_out.append(args_in[1].props.value)
else:
......@@ -201,10 +201,10 @@ class Application:
script_buffer.set_text("\n".join(self.filetemplate))
script_editor.props.editable = False
#wacom_options = Gtk.Label("FIXME")
# wacom_options = Gtk.Label("FIXME")
notebook = Gtk.Notebook()
#notebook.append_page(wacom_options, Gtk.Label(_("Wacom options")))
# notebook.append_page(wacom_options, Gtk.Label(_("Wacom options")))
notebook.append_page(script_editor, Gtk.Label(_("Script")))
dialog.vbox.pack_start(notebook, expand=False, fill=False, padding=0) # pylint: disable=no-member
......
......@@ -27,23 +27,23 @@ class Snap:
self.vertical = set()
for i in positions:
self.vertical.add(i[0].left)
self.vertical.add(i[0].left+i[1].width)
self.vertical.add(i[0].left + i[1].width)
self.horizontal.add(i[0].top)
self.horizontal.add(i[0].top+i[1].height)
self.horizontal.add(i[0].top + i[1].height)
self.vertical.add(i[0].left-size.width)
self.vertical.add(i[0].left+i[1].width-size.width)
self.horizontal.add(i[0].top-size.height)
self.horizontal.add(i[0].top+i[1].height-size.height)
self.vertical.add(i[0].left - size.width)
self.vertical.add(i[0].left + i[1].width - size.width)
self.horizontal.add(i[0].top - size.height)
self.horizontal.add(i[0].top + i[1].height - size.height)
self.vertical.add((i[0].left + i[1].width/2)-size.width/2)
self.horizontal.add((i[0].top + i[1].height/2)-size.height/2)
self.vertical.add((i[0].left + i[1].width / 2) - size.width / 2)
self.horizontal.add((i[0].top + i[1].height / 2) - size.height / 2)
def suggest(self, position):
vertical = [x for x in self.vertical if abs(
x-position[0]) < self.tolerance]
x - position[0]) < self.tolerance]
horizontal = [y for y in self.horizontal if abs(
y-position[1]) < self.tolerance]
y - position[1]) < self.tolerance]
if vertical:
position = Position((vertical[0], position[1]))
......
......@@ -52,8 +52,9 @@ class ARandRWidget(Gtk.DrawingArea):
self.window = window
self._factor = factor
self.set_size_request(1024//self.factor, 1024 //
self.factor) # best guess for now
self.set_size_request(
1024 // self.factor, 1024 // self.factor
) # best guess for now
self.connect('button-press-event', self.click)
self.set_events(Gdk.EventType.BUTTON_PRESS)
......@@ -110,7 +111,7 @@ class ARandRWidget(Gtk.DrawingArea):
# don't request too large a window, but make sure very possible compination fits
xdim = min(self._xrandr.state.virtual.max[0], usable_size)
ydim = min(self._xrandr.state.virtual.max[1], usable_size)
self.set_size_request(xdim//self.factor, ydim//self.factor)
self.set_size_request(xdim // self.factor, ydim // self.factor)
#################### loading ####################
......@@ -216,8 +217,8 @@ class ARandRWidget(Gtk.DrawingArea):
def do_expose_event(self, _event, context):
context.rectangle(
0, 0,
self._xrandr.state.virtual.max[0]//self.factor,
self._xrandr.state.virtual.max[1]//self.factor
self._xrandr.state.virtual.max[0] // self.factor,
self._xrandr.state.virtual.max[1] // self.factor
)
context.clip()
......@@ -227,8 +228,8 @@ class ARandRWidget(Gtk.DrawingArea):
context.fill()
context.save()
context.scale(1/self.factor, 1/self.factor)
context.set_line_width(self.factor*1.5)
context.scale(1 / self.factor, 1 / self.factor)
context.set_line_width(self.factor * 1.5)
self._draw(self._xrandr, context)
......@@ -251,7 +252,7 @@ class ARandRWidget(Gtk.DrawingArea):
rect = (output.tentative_position if hasattr(
output, 'tentative_position') else output.position) + tuple(output.size)
center = rect[0]+rect[2]/2, rect[1]+rect[3]/2
center = rect[0] + rect[2] / 2, rect[1] + rect[3] / 2
# paint rectangle
context.set_source_rgba(1, 1, 1, 0.7)
......@@ -264,7 +265,7 @@ class ARandRWidget(Gtk.DrawingArea):
# set up for text
context.save()
textwidth = rect[3 if output.rotation.is_odd else 2]
widthperchar = textwidth/len(output_name)
widthperchar = textwidth / len(output_name)
# i think this looks nice and won't overflow even for wide fonts
textheight = int(widthperchar * 0.8)
......@@ -290,7 +291,7 @@ class ARandRWidget(Gtk.DrawingArea):
# position text
layoutsize = layout.get_pixel_size()
layoutoffset = -layoutsize[0]/2, -layoutsize[1]/2
layoutoffset = -layoutsize[0] / 2, -layoutsize[1] / 2
context.move_to(*center)
context.rotate(output.rotation.angle)
context.rel_move_to(*layoutoffset)
......@@ -303,8 +304,8 @@ class ARandRWidget(Gtk.DrawingArea):
# using self.allocation as rect is offset by the menu bar.
self.queue_draw_area(
0, 0,
self._xrandr.state.virtual.max[0]//self.factor,
self._xrandr.state.virtual.max[1]//self.factor
self._xrandr.state.virtual.max[0] // self.factor,
self._xrandr.state.virtual.max[1] // self.factor
)
# this has the side effect of not painting out of the available
# region output_name drag and drop
......@@ -342,15 +343,15 @@ class ARandRWidget(Gtk.DrawingArea):
self._lastclick = (event.x, event.y)
def _get_point_outputs(self, x, y):
x, y = x*self.factor, y*self.factor
x, y = x * self.factor, y * self.factor
outputs = set()
for output_name, output in self._xrandr.configuration.outputs.items():
if not output.active:
continue
if (
output.position[0]-self.factor <= x <= output.position[0]+output.size[0]+self.factor
output.position[0] - self.factor <= x <= output.position[0] + output.size[0] + self.factor
) and (
output.position[1]-self.factor <= y <= output.position[1]+output.size[1]+self.factor
output.position[1] - self.factor <= y <= output.position[1] + output.size[1] + self.factor
):
outputs.add(output_name)
return outputs
......@@ -459,8 +460,8 @@ class ARandRWidget(Gtk.DrawingArea):
Gtk.TargetFlags.SAME_WIDGET, 0)],
0
)
#self.drag_source_set(Gdk.BUTTON1_MASK, [], 0)
#self.drag_dest_set(0, [], 0)
# self.drag_source_set(Gdk.BUTTON1_MASK, [], 0)
# self.drag_dest_set(0, [], 0)
self._draggingfrom = None
self._draggingoutput = None
......@@ -485,8 +486,8 @@ class ARandRWidget(Gtk.DrawingArea):
self._draggingsnap = Snap(
self._xrandr.configuration.outputs[self._draggingoutput].size,
self.factor*5,
[(Position((0, 0)), self._xrandr.state.virtual.max)]+[
self.factor * 5,
[(Position((0, 0)), self._xrandr.state.virtual.max)] + [
(virtual_state.position, virtual_state.size)
for (k, virtual_state) in self._xrandr.configuration.outputs.items()
if k != self._draggingoutput and virtual_state.active
......@@ -501,11 +502,11 @@ class ARandRWidget(Gtk.DrawingArea):
Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
rel = x-self._draggingfrom[0], y-self._draggingfrom[1]
rel = x - self._draggingfrom[0], y - self._draggingfrom[1]
oldpos = self._xrandr.configuration.outputs[self._draggingoutput].position
newpos = Position(
(oldpos[0]+self.factor*rel[0], oldpos[1]+self.factor*rel[1]))
(oldpos[0] + self.factor * rel[0], oldpos[1] + self.factor * rel[1]))
self._xrandr.configuration.outputs[
self._draggingoutput
].tentative_position = self._draggingsnap.suggest(newpos)
......
......@@ -66,7 +66,7 @@ class XRandR:
def _output(self, *args):
proc = subprocess.Popen(
("xrandr",)+args,
("xrandr",) + args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=self.environ
)
ret, err = proc.communicate()
......@@ -127,8 +127,8 @@ class XRandR:
if len(output_argument) % 2 != 0:
raise FileSyntaxError()
parts = [
(output_argument[2*i], output_argument[2*i+1])
for i in range(len(output_argument)//2)
(output_argument[2 * i], output_argument[2 * i + 1])
for i in range(len(output_argument) // 2)
]
for part in parts:
if part[0] == '--mode':
......@@ -242,10 +242,10 @@ class XRandR:
screenline = line
elif line.startswith('\t'):
continue
elif line.startswith(2*' '): # [mode, width, height]
elif line.startswith(2 * ' '): # [mode, width, height]
line = line.strip()
if reduce(bool.__or__, [line.startswith(x+':') for x in "hv"]):
line = line[-len(line):line.index(" start")-len(line)]
if reduce(bool.__or__, [line.startswith(x + ':') for x in "hv"]):
line = line[-len(line):line.index(" start") - len(line)]
items[-1][1][-1].append(line[line.rindex(' '):])
else: # mode
items[-1][1].append([line.split()])
......@@ -282,10 +282,10 @@ class XRandR:
"""
if not template:
template = self.DEFAULTTEMPLATE
template = '\n'.join(template)+'\n'
template = '\n'.join(template) + '\n'
data = {
'xrandr': "xrandr " +" ".join(self.configuration.commandlineargs())
'xrandr': "xrandr " + " ".join(self.configuration.commandlineargs())
}
if additional:
data.update(additional)
......@@ -301,7 +301,7 @@ class XRandR:
for output_name in self.outputs:
output_config = self.configuration.outputs[output_name]
#output_state = self.state.outputs[output_name]
# output_state = self.state.outputs[output_name]
if not output_config.active:
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment