Skip to content

Commit b419413

Browse files
author
Tony Crisci
committed
lint and format
1 parent bbff13b commit b419413

29 files changed

+213
-182
lines changed

.flake8

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[flake8]
2+
ignore=
3+
E501
4+
E126
5+
E402
6+
F722
7+
W503
8+
9+
per-file-ignores=
10+
*/__init__.py:F401

.style.yapf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[style]
2+
column_limit = 100

examples/app-on-ws-init.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
workspace 6.
1414
""")
1515

16-
parser.add_argument('--workspace', metavar='WS_NAME', nargs='+', required=True,
16+
parser.add_argument('--workspace',
17+
metavar='WS_NAME',
18+
nargs='+',
19+
required=True,
1720
help='The name of the workspaces to run the command on')
18-
parser.add_argument('--command', metavar='CMD', required=True,
21+
parser.add_argument('--command',
22+
metavar='CMD',
23+
required=True,
1924
help='The command to run on the newly initted workspace')
2025

2126
args = parser.parse_args()
@@ -25,6 +30,7 @@ def on_workspace(i3, e):
2530
if e.current.props.name in args.workspace and not len(e.current.leaves()):
2631
i3.command('exec {}'.format(args.command))
2732

33+
2834
i3.on('workspace::focus', on_workspace)
2935

3036
i3.main()

examples/asyncio-i3status-wrapper.py

+17-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This module is an example of how to use i3ipc with asyncio event loop. It
33
# implements an i3status wrapper that handles a special keybinding to switch
44
# keyboard layout, while also displaying current layout in i3bar.
5-
#
5+
#
66
# The keyboard layout switcher can be activated by adding something like this
77
# to i3 config:
88
#
@@ -30,7 +30,7 @@
3030
# config file. This is only done for demonstration purposes.
3131
import setproctitle
3232
setproctitle.setproctitle('i3bar')
33-
except ImportError as e:
33+
except ImportError:
3434
# Configure i3status by explicitly setting "i3bar" as output_format
3535
configure_i3_status = True
3636

@@ -67,9 +67,7 @@ def __init__(self):
6767
self.first_write = True
6868
self.layouts = ['us', 'us intl']
6969
self.current_layout = -1
70-
self.command_handlers = {
71-
'switch_layout': lambda: self.switch_layout()
72-
}
70+
self.command_handlers = {'switch_layout': lambda: self.switch_layout()}
7371
# perform a switch now, which will force the keyboard layout to be
7472
# shown before other data
7573
self.switch_layout()
@@ -78,11 +76,7 @@ def switch_layout(self):
7876
self.current_layout = (self.current_layout + 1) % len(self.layouts)
7977
new_layout = self.layouts[self.current_layout]
8078
subprocess.call('setxkbmap {}'.format(new_layout), shell=True)
81-
self.update([{
82-
'name': 'keyboard_layout',
83-
'markup': 'none',
84-
'full_text': new_layout
85-
}])
79+
self.update([{'name': 'keyboard_layout', 'markup': 'none', 'full_text': new_layout}])
8680

8781
def dispatch_command(self, command):
8882
c = command.split(' ')
@@ -101,9 +95,10 @@ def update(self, new_status):
10195
def repaint(self):
10296
template = '{}' if self.first_write else ',{}'
10397
self.first_write = False
104-
sys.stdout.write(template.format(
105-
json.dumps([item for item in self.current_status.values()
106-
if item], separators=(',', ':'))))
98+
sys.stdout.write(
99+
template.format(
100+
json.dumps([item for item in self.current_status.values() if item],
101+
separators=(',', ':'))))
107102
sys.stdout.write('\n')
108103
sys.stdout.flush()
109104

@@ -118,27 +113,23 @@ def handle_i3status_payload(line):
118113
cfg_file = tempfile.NamedTemporaryFile(mode='w+b')
119114
cfg_file.write(I3STATUS_CFG.encode('utf8'))
120115
cfg_file.flush()
121-
create = asyncio.create_subprocess_exec(
122-
'i3status', '-c', cfg_file.name,
123-
stdout=asyncio.subprocess.PIPE)
116+
create = asyncio.create_subprocess_exec('i3status',
117+
'-c',
118+
cfg_file.name,
119+
stdout=asyncio.subprocess.PIPE)
124120
else:
125-
create = asyncio.create_subprocess_exec(
126-
'i3status', stdout=asyncio.subprocess.PIPE)
121+
create = asyncio.create_subprocess_exec('i3status', stdout=asyncio.subprocess.PIPE)
127122
i3status = yield from create
128123
# forward first line, version information
129-
sys.stdout.write(
130-
(yield from i3status.stdout.readline()).decode('utf8'))
124+
sys.stdout.write((yield from i3status.stdout.readline()).decode('utf8'))
131125
# forward second line, an opening list bracket (no idea why this
132126
# exists)
133-
sys.stdout.write(
134-
(yield from i3status.stdout.readline()).decode('utf8'))
127+
sys.stdout.write((yield from i3status.stdout.readline()).decode('utf8'))
135128
# third line is a json payload
136-
handle_i3status_payload(
137-
(yield from i3status.stdout.readline()).decode('utf8'))
129+
handle_i3status_payload((yield from i3status.stdout.readline()).decode('utf8'))
138130
while True:
139131
# all subsequent lines are json payload with a leading comma
140-
handle_i3status_payload(
141-
(yield from i3status.stdout.readline()).decode('utf8')[1:])
132+
handle_i3status_payload((yield from i3status.stdout.readline()).decode('utf8')[1:])
142133

143134

144135
status = Status()

examples/command-on-exit.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
# https://faq.i3wm.org/question/3468/run-a-command-when-i3-exits/
66

77
# This is the command to run
8-
COMMAND = [ 'echo', 'hello, world' ]
8+
COMMAND = ['echo', 'hello, world']
99

1010
from subprocess import Popen
1111
import i3ipc
1212

13+
1314
def on_shutdown(i3):
1415
Popen(COMMAND)
1516

17+
1618
i3 = i3ipc.Connection()
1719

1820
i3.on('ipc_shutdown', on_shutdown)

examples/disable-standby-fs.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
i3 = i3ipc.Connection()
88

99
parser = ArgumentParser(prog='disable-standby-fs',
10-
description='''
10+
description='''
1111
Disable standby (dpms) and screensaver when a window becomes fullscreen
1212
or exits fullscreen-mode. Requires `xorg-xset`.
1313
''')
1414

1515
args = parser.parse_args()
1616

17+
1718
def find_fullscreen(con):
1819
# XXX remove me when this method is available on the con in a release
19-
return [c for c in con.descendents()
20-
if c.type == 'con' and c.fullscreen_mode]
20+
return [c for c in con.descendents() if c.type == 'con' and c.fullscreen_mode]
21+
2122

2223
def set_dpms(state):
2324
if state:
@@ -29,13 +30,16 @@ def set_dpms(state):
2930
call(['xset', 's', 'off'])
3031
call(['xset', '-dpms'])
3132

33+
3234
def on_fullscreen_mode(i3, e):
3335
set_dpms(not len(find_fullscreen(i3.get_tree())))
3436

37+
3538
def on_window_close(i3, e):
3639
if not len(find_fullscreen(i3.get_tree())):
3740
set_dpms(True)
3841

42+
3943
i3.on('window::fullscreen_mode', on_fullscreen_mode)
4044
i3.on('window::close', on_window_close)
4145

examples/focus-last.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212

1313

1414
class FocusWatcher:
15-
1615
def __init__(self):
1716
self.i3 = i3ipc.Connection()
1817
self.i3.on('window::focus', self.on_window_focus)
19-
self.listening_socket = socket.socket(socket.AF_UNIX,
20-
socket.SOCK_STREAM)
18+
self.listening_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
2119
if os.path.exists(SOCKET_FILE):
2220
os.remove(SOCKET_FILE)
2321
self.listening_socket.bind(SOCKET_FILE)
@@ -73,18 +71,22 @@ def run(self):
7371
for t in (t_i3, t_server):
7472
t.start()
7573

74+
7675
if __name__ == '__main__':
7776
parser = ArgumentParser(prog='focus-last.py',
78-
description='''
77+
description='''
7978
Focus last focused window.
8079
8180
This script should be launch from the .xsessionrc without argument.
8281
8382
Then you can bind this script with the `--switch` option to one of your
8483
i3 keybinding.
8584
''')
86-
parser.add_argument('--switch', dest='switch', action='store_true',
87-
help='Switch to the previous window', default=False)
85+
parser.add_argument('--switch',
86+
dest='switch',
87+
action='store_true',
88+
help='Switch to the previous window',
89+
default=False)
8890
args = parser.parse_args()
8991

9092
if not args.switch:

examples/focus-next-visible.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
32
"""
43
focus-next-visible.py - cycles input focus between visible windows on workspace
54
@@ -26,19 +25,17 @@
2625

2726

2827
def get_windows_on_ws(conn):
29-
return filter(lambda x: x.window,
30-
conn.get_tree().find_focused().workspace().descendents())
28+
return filter(lambda x: x.window, conn.get_tree().find_focused().workspace().descendents())
3129

3230

3331
def find_visible_windows(windows_on_workspace):
3432
visible_windows = []
3533
for w in windows_on_workspace:
36-
34+
3735
try:
3836
xprop = check_output(['xprop', '-id', str(w.window)]).decode()
3937
except FileNotFoundError:
40-
raise SystemExit("The `xprop` utility is not found!"
41-
" Please install it and retry.")
38+
raise SystemExit("The `xprop` utility is not found!" " Please install it and retry.")
4239

4340
if '_NET_WM_STATE_HIDDEN' not in xprop:
4441
visible_windows.append(w)

examples/focused-windows.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55

66
i3 = i3ipc.Connection()
77

8+
89
def focused_windows():
9-
tree = i3.get_tree()
10+
tree = i3.get_tree()
1011

11-
workspaces = tree.workspaces()
12-
for workspace in workspaces:
13-
container = workspace
12+
workspaces = tree.workspaces()
13+
for workspace in workspaces:
14+
container = workspace
1415

15-
while container:
16-
if not hasattr(container, 'focus') \
17-
or not container.focus:
18-
break
16+
while container:
17+
if not hasattr(container, 'focus') or not container.focus:
18+
break
1919

20-
container_id = container.focus[0]
21-
container = container.find_by_id(container_id)
20+
container_id = container.focus[0]
21+
container = container.find_by_id(container_id)
2222

23-
if container:
24-
coname = container.name
25-
wsname = workspace.name
23+
if container:
24+
coname = container.name
25+
wsname = workspace.name
2626

27-
print('WS', wsname +':', coname)
27+
print('WS', wsname + ':', coname)
2828

2929

3030
if __name__ == '__main__':
31-
parser = ArgumentParser(description = 'Print the names of the focused window of each workspace.')
32-
parser.parse_args()
31+
parser = ArgumentParser(description='Print the names of the focused window of each workspace.')
32+
parser.parse_args()
3333

34-
focused_windows()
34+
focused_windows()

examples/i3-cmd.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import i3ipc
44
from argparse import ArgumentParser
5-
from subprocess import check_output, Popen, PIPE, CalledProcessError
5+
from subprocess import check_output, Popen, CalledProcessError
66
from sys import exit
77
from os.path import basename
88

@@ -42,8 +42,8 @@
4242
cmd = ''
4343

4444
try:
45-
cmd = check_output([ args.menu ] + menu_args,
46-
input=bytes('\n'.join(history), 'UTF-8')).decode('UTF-8').strip()
45+
cmd = check_output([args.menu] + menu_args, input=bytes('\n'.join(history),
46+
'UTF-8')).decode('UTF-8').strip()
4747
except CalledProcessError as e:
4848
exit(e.returncode)
4949

0 commit comments

Comments
 (0)