2
2
# This module is an example of how to use i3ipc with asyncio event loop. It
3
3
# implements an i3status wrapper that handles a special keybinding to switch
4
4
# keyboard layout, while also displaying current layout in i3bar.
5
- #
5
+ #
6
6
# The keyboard layout switcher can be activated by adding something like this
7
7
# to i3 config:
8
8
#
30
30
# config file. This is only done for demonstration purposes.
31
31
import setproctitle
32
32
setproctitle .setproctitle ('i3bar' )
33
- except ImportError as e :
33
+ except ImportError :
34
34
# Configure i3status by explicitly setting "i3bar" as output_format
35
35
configure_i3_status = True
36
36
@@ -67,9 +67,7 @@ def __init__(self):
67
67
self .first_write = True
68
68
self .layouts = ['us' , 'us intl' ]
69
69
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 ()}
73
71
# perform a switch now, which will force the keyboard layout to be
74
72
# shown before other data
75
73
self .switch_layout ()
@@ -78,11 +76,7 @@ def switch_layout(self):
78
76
self .current_layout = (self .current_layout + 1 ) % len (self .layouts )
79
77
new_layout = self .layouts [self .current_layout ]
80
78
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 }])
86
80
87
81
def dispatch_command (self , command ):
88
82
c = command .split (' ' )
@@ -101,9 +95,10 @@ def update(self, new_status):
101
95
def repaint (self ):
102
96
template = '{}' if self .first_write else ',{}'
103
97
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 = (',' , ':' ))))
107
102
sys .stdout .write ('\n ' )
108
103
sys .stdout .flush ()
109
104
@@ -118,27 +113,23 @@ def handle_i3status_payload(line):
118
113
cfg_file = tempfile .NamedTemporaryFile (mode = 'w+b' )
119
114
cfg_file .write (I3STATUS_CFG .encode ('utf8' ))
120
115
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 )
124
120
else :
125
- create = asyncio .create_subprocess_exec (
126
- 'i3status' , stdout = asyncio .subprocess .PIPE )
121
+ create = asyncio .create_subprocess_exec ('i3status' , stdout = asyncio .subprocess .PIPE )
127
122
i3status = yield from create
128
123
# 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' ))
131
125
# forward second line, an opening list bracket (no idea why this
132
126
# exists)
133
- sys .stdout .write (
134
- (yield from i3status .stdout .readline ()).decode ('utf8' ))
127
+ sys .stdout .write ((yield from i3status .stdout .readline ()).decode ('utf8' ))
135
128
# 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' ))
138
130
while True :
139
131
# 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 :])
142
133
143
134
144
135
status = Status ()
0 commit comments