1
1
import re
2
2
import sys
3
- from collections import deque
4
3
from .model import Rect , Gaps
4
+ from . import replies
5
+ from collections import deque
6
+ from typing import List , Optional
5
7
6
8
7
9
class Con :
@@ -158,7 +160,7 @@ def __iter__(self):
158
160
queue .extend (con .nodes )
159
161
queue .extend (con .floating_nodes )
160
162
161
- def root (self ):
163
+ def root (self ) -> 'Con' :
162
164
"""Gets the root container.
163
165
164
166
:returns: The root container.
@@ -175,7 +177,7 @@ def root(self):
175
177
176
178
return con
177
179
178
- def descendants (self ):
180
+ def descendants (self ) -> List [ 'Con' ] :
179
181
"""Gets a list of all child containers for the container in
180
182
breadth-first order.
181
183
@@ -184,7 +186,7 @@ def descendants(self):
184
186
"""
185
187
return [c for c in self ]
186
188
187
- def descendents (self ):
189
+ def descendents (self ) -> List [ 'Con' ] :
188
190
"""Gets a list of all child containers for the container in
189
191
breadth-first order.
190
192
@@ -197,7 +199,7 @@ def descendents(self):
197
199
print ('WARNING: descendents is deprecated. Use `descendants()` instead.' , file = sys .stderr )
198
200
return self .descendants ()
199
201
200
- def leaves (self ):
202
+ def leaves (self ) -> List [ 'Con' ] :
201
203
"""Gets a list of leaf child containers for this container in
202
204
breadth-first order. Leaf containers normally contain application
203
205
windows.
@@ -213,25 +215,25 @@ def leaves(self):
213
215
214
216
return leaves
215
217
216
- def command (self , command ) :
218
+ def command (self , command : str ) -> List [ replies . CommandReply ] :
217
219
"""Runs a command on this container.
218
220
219
221
.. seealso:: https://i3wm.org/docs/userguide.html#list_of_commands
220
222
221
223
:returns: A list of replies for each command in the given command
222
224
string.
223
- :rtype: list(CommandReply)
225
+ :rtype: list(:class:` CommandReply <i3ipc.CommandReply>` )
224
226
"""
225
227
return self ._conn .command ('[con_id="{}"] {}' .format (self .id , command ))
226
228
227
- def command_children (self , command ) :
229
+ def command_children (self , command : str ) -> List [ replies . CommandReply ] :
228
230
"""Runs a command on the immediate children of the currently selected
229
231
container.
230
232
231
233
.. seealso:: https://i3wm.org/docs/userguide.html#list_of_commands
232
234
233
235
:returns: A list of replies for each command that was executed.
234
- :rtype: list(CommandReply)
236
+ :rtype: list(:class:` CommandReply <i3ipc.CommandReply>` )
235
237
"""
236
238
if not len (self .nodes ):
237
239
return
@@ -242,11 +244,11 @@ def command_children(self, command):
242
244
243
245
self ._conn .command (' ' .join (commands ))
244
246
245
- def workspaces (self ):
247
+ def workspaces (self ) -> List [ 'Con' ] :
246
248
"""Gets a list of workspace containers for this tree.
247
249
248
250
:returns: A list of workspace containers.
249
- :rtype: List of :class:`Con`.
251
+ :rtype: list( :class:`Con`)
250
252
"""
251
253
workspaces = []
252
254
@@ -261,7 +263,7 @@ def collect_workspaces(con):
261
263
collect_workspaces (self .root ())
262
264
return workspaces
263
265
264
- def find_focused (self ):
266
+ def find_focused (self ) -> Optional [ 'Con' ] :
265
267
"""Finds the focused container under this container if it exists.
266
268
267
269
:returns: The focused container if it exists.
@@ -273,7 +275,7 @@ def find_focused(self):
273
275
except StopIteration :
274
276
return None
275
277
276
- def find_by_id (self , id ) :
278
+ def find_by_id (self , id : int ) -> Optional [ 'Con' ] :
277
279
"""Finds a container with the given container id under this node.
278
280
279
281
:returns: The container with this container id if it exists.
@@ -285,7 +287,7 @@ def find_by_id(self, id):
285
287
except StopIteration :
286
288
return None
287
289
288
- def find_by_window (self , window ) :
290
+ def find_by_window (self , window : int ) -> Optional [ 'Con' ] :
289
291
"""Finds a container with the given window id under this node.
290
292
291
293
:returns: The container with this window id if it exists.
@@ -297,7 +299,7 @@ def find_by_window(self, window):
297
299
except StopIteration :
298
300
return None
299
301
300
- def find_by_role (self , pattern ) :
302
+ def find_by_role (self , pattern : str ) -> List [ 'Con' ] :
301
303
"""Finds all the containers under this node with a window role that
302
304
matches the given regex pattern.
303
305
@@ -307,7 +309,7 @@ def find_by_role(self, pattern):
307
309
"""
308
310
return [c for c in self if c .window_role and re .search (pattern , c .window_role )]
309
311
310
- def find_named (self , pattern ) :
312
+ def find_named (self , pattern : str ) -> List [ 'Con' ] :
311
313
"""Finds all the containers under this node with a name that
312
314
matches the given regex pattern.
313
315
@@ -317,7 +319,7 @@ def find_named(self, pattern):
317
319
"""
318
320
return [c for c in self if c .name and re .search (pattern , c .name )]
319
321
320
- def find_titled (self , pattern ) :
322
+ def find_titled (self , pattern : str ) -> List [ 'Con' ] :
321
323
"""Finds all the containers under this node with a window title that
322
324
matches the given regex pattern.
323
325
@@ -327,7 +329,7 @@ def find_titled(self, pattern):
327
329
"""
328
330
return [c for c in self if c .window_title and re .search (pattern , c .window_title )]
329
331
330
- def find_classed (self , pattern ) :
332
+ def find_classed (self , pattern : str ) -> List [ 'Con' ] :
331
333
"""Finds all the containers under this node with a window class that
332
334
matches the given regex pattern.
333
335
@@ -337,7 +339,7 @@ def find_classed(self, pattern):
337
339
"""
338
340
return [c for c in self if c .window_class and re .search (pattern , c .window_class )]
339
341
340
- def find_instanced (self , pattern ) :
342
+ def find_instanced (self , pattern : str ) -> List [ 'Con' ] :
341
343
"""Finds all the containers under this node with a window instance that
342
344
matches the given regex pattern.
343
345
@@ -347,7 +349,7 @@ def find_instanced(self, pattern):
347
349
"""
348
350
return [c for c in self if c .window_instance and re .search (pattern , c .window_instance )]
349
351
350
- def find_marked (self , pattern = ".*" ):
352
+ def find_marked (self , pattern : str = ".*" ) -> List [ 'Con' ] :
351
353
"""Finds all the containers under this node with a mark that
352
354
matches the given regex pattern.
353
355
@@ -358,7 +360,7 @@ def find_marked(self, pattern=".*"):
358
360
pattern = re .compile (pattern )
359
361
return [c for c in self if any (pattern .search (mark ) for mark in c .marks )]
360
362
361
- def find_fullscreen (self ):
363
+ def find_fullscreen (self ) -> List [ 'Con' ] :
362
364
"""Finds all the containers under this node that are in fullscreen
363
365
mode.
364
366
@@ -367,7 +369,7 @@ def find_fullscreen(self):
367
369
"""
368
370
return [c for c in self if c .type == 'con' and c .fullscreen_mode ]
369
371
370
- def workspace (self ):
372
+ def workspace (self ) -> Optional [ 'Con' ] :
371
373
"""Finds the workspace container for this node if this container is at
372
374
or below the workspace level.
373
375
@@ -387,7 +389,7 @@ def workspace(self):
387
389
388
390
return ret
389
391
390
- def scratchpad (self ):
392
+ def scratchpad (self ) -> 'Con' :
391
393
"""Finds the scratchpad container.
392
394
393
395
:returns: The scratchpad container.
0 commit comments