9
9
from functools import partial
10
10
from gettext import gettext as _
11
11
from typing import (
12
- Any , Callable , Dict , Generator , Iterable , List , Optional , Tuple , Union ,
13
- cast
12
+ Any , Callable , Dict , Iterable , Iterator , List , Optional , Tuple ,
13
+ Union , cast
14
14
)
15
15
from weakref import WeakValueDictionary
16
16
27
27
)
28
28
from .fast_data_types import (
29
29
CLOSE_BEING_CONFIRMED , GLFW_MOD_ALT , GLFW_MOD_CONTROL , GLFW_MOD_SHIFT ,
30
- GLFW_MOD_SUPER , IMPERATIVE_CLOSE_REQUESTED , NO_CLOSE_REQUESTED ,
31
- ChildMonitor , KeyEvent , add_timer , apply_options_update ,
32
- background_opacity_of , change_background_opacity , change_os_window_state ,
33
- cocoa_set_menubar_title , create_os_window , GLFW_PRESS , GLFW_MOUSE_BUTTON_LEFT ,
34
- current_application_quit_request , current_os_window , destroy_global_data ,
35
- focus_os_window , get_clipboard_string , get_options , get_os_window_size ,
36
- global_font_size , mark_os_window_for_close , os_window_font_size ,
37
- patch_global_colors , redirect_mouse_handling , ring_bell , safe_pipe ,
38
- set_application_quit_request , set_background_image , set_boss ,
39
- set_clipboard_string , set_in_sequence_mode , set_options ,
30
+ GLFW_MOD_SUPER , GLFW_MOUSE_BUTTON_LEFT , GLFW_PRESS ,
31
+ IMPERATIVE_CLOSE_REQUESTED , NO_CLOSE_REQUESTED , ChildMonitor , KeyEvent ,
32
+ add_timer , apply_options_update , background_opacity_of ,
33
+ change_background_opacity , change_os_window_state , cocoa_set_menubar_title ,
34
+ create_os_window , current_application_quit_request , current_os_window ,
35
+ destroy_global_data , focus_os_window , get_clipboard_string , get_options ,
36
+ get_os_window_size , global_font_size , mark_os_window_for_close ,
37
+ os_window_font_size , patch_global_colors , redirect_mouse_handling ,
38
+ ring_bell , safe_pipe , set_application_quit_request , set_background_image ,
39
+ set_boss , set_clipboard_string , set_in_sequence_mode , set_options ,
40
40
set_os_window_size , thread_write , toggle_fullscreen , toggle_maximized
41
41
)
42
42
from .key_encoding import get_name_to_functional_number_map
@@ -234,7 +234,7 @@ def add_os_window(
234
234
self .os_window_map [os_window_id ] = tm
235
235
return os_window_id
236
236
237
- def list_os_windows (self , self_window : Optional [Window ] = None ) -> Generator [OSWindowDict , None , None ]:
237
+ def list_os_windows (self , self_window : Optional [Window ] = None ) -> Iterator [OSWindowDict ]:
238
238
with cached_process_data ():
239
239
active_tab , active_window = self .active_tab , self .active_window
240
240
active_tab_manager = self .active_tab_manager
@@ -249,20 +249,20 @@ def list_os_windows(self, self_window: Optional[Window] = None) -> Generator[OSW
249
249
}
250
250
251
251
@property
252
- def all_tab_managers (self ) -> Generator [TabManager , None , None ]:
252
+ def all_tab_managers (self ) -> Iterator [TabManager ]:
253
253
yield from self .os_window_map .values ()
254
254
255
255
@property
256
- def all_tabs (self ) -> Generator [Tab , None , None ]:
256
+ def all_tabs (self ) -> Iterator [Tab ]:
257
257
for tm in self .all_tab_managers :
258
258
yield from tm
259
259
260
260
@property
261
- def all_windows (self ) -> Generator [Window , None , None ]:
261
+ def all_windows (self ) -> Iterator [Window ]:
262
262
for tab in self .all_tabs :
263
263
yield from tab
264
264
265
- def match_windows (self , match : str ) -> Generator [Window , None , None ]:
265
+ def match_windows (self , match : str ) -> Iterator [Window ]:
266
266
try :
267
267
field , exp = match .split (':' , 1 )
268
268
except ValueError :
@@ -305,8 +305,9 @@ def tab_for_window(self, window: Window) -> Optional[Tab]:
305
305
for w in tab :
306
306
if w .id == window .id :
307
307
return tab
308
+ return None
308
309
309
- def match_tabs (self , match : str ) -> Generator [Tab , None , None ]:
310
+ def match_tabs (self , match : str ) -> Iterator [Tab ]:
310
311
try :
311
312
field , exp = match .split (':' , 1 )
312
313
except ValueError :
@@ -359,6 +360,7 @@ def set_active_window(self, window: Window, switch_os_window_if_needed: bool = F
359
360
if switch_os_window_if_needed and current_os_window () != os_window_id :
360
361
focus_os_window (os_window_id , True )
361
362
return os_window_id
363
+ return None
362
364
363
365
def _new_os_window (self , args : Union [SpecialWindowInstance , Iterable [str ]], cwd_from : Optional [int ] = None ) -> int :
364
366
if isinstance (args , SpecialWindowInstance ):
@@ -377,6 +379,7 @@ def active_window_for_cwd(self) -> Optional[Window]:
377
379
t = self .active_tab
378
380
if t is not None :
379
381
return t .active_window_for_cwd
382
+ return None
380
383
381
384
@ac ('win' , 'New OS Window with the same working directory as the currently active window' )
382
385
def new_os_window_with_cwd (self , * args : str ) -> None :
@@ -595,7 +598,7 @@ def start(self, first_os_window_id: int) -> None:
595
598
run_update_check (get_options ().update_check_interval * 60 * 60 )
596
599
self .update_check_started = True
597
600
598
- def handle_click_on_tab (self , os_window_id : int , x : int , button : int , modifiers : int , action : int ) -> int :
601
+ def handle_click_on_tab (self , os_window_id : int , x : int , button : int , modifiers : int , action : int ) -> None :
599
602
tm = self .os_window_map .get (os_window_id )
600
603
if tm is not None :
601
604
tm .handle_click_on_tab (x , button , modifiers , action )
@@ -751,20 +754,17 @@ def set_background_opacity(self, opacity: str) -> None:
751
754
@property
752
755
def active_tab_manager (self ) -> Optional [TabManager ]:
753
756
os_window_id = current_os_window ()
754
- if os_window_id is not None :
755
- return self .os_window_map .get (os_window_id )
757
+ return None if os_window_id is None else self .os_window_map .get (os_window_id )
756
758
757
759
@property
758
760
def active_tab (self ) -> Optional [Tab ]:
759
761
tm = self .active_tab_manager
760
- if tm is not None :
761
- return tm .active_tab
762
+ return None if tm is None else tm .active_tab
762
763
763
764
@property
764
765
def active_window (self ) -> Optional [Window ]:
765
766
t = self .active_tab
766
- if t is not None :
767
- return t .active_window
767
+ return None if t is None else t .active_window
768
768
769
769
def set_pending_sequences (self , sequences : SubSequenceMap , default_pending_action : Optional [KeyAction ] = None ) -> None :
770
770
self .pending_sequences = sequences
@@ -783,6 +783,7 @@ def dispatch_possible_special_key(self, ev: KeyEvent) -> bool:
783
783
return True
784
784
elif isinstance (key_action , KeyAction ):
785
785
return self .dispatch_action (key_action )
786
+ return False
786
787
787
788
def clear_pending_sequences (self ) -> None :
788
789
self .pending_sequences = self .default_pending_action = None
@@ -1530,7 +1531,7 @@ def run_background_process(
1530
1531
else :
1531
1532
subprocess .Popen (cmd , env = env , cwd = cwd )
1532
1533
1533
- def pipe (self , source : str , dest : str , exe : str , * args : str ) -> Window :
1534
+ def pipe (self , source : str , dest : str , exe : str , * args : str ) -> Optional [ Window ] :
1534
1535
cmd = [exe ] + list (args )
1535
1536
window = self .active_window
1536
1537
cwd_from = window .child .pid_for_cwd if window else None
@@ -1559,6 +1560,7 @@ def create_window() -> SpecialWindowInstance:
1559
1560
else :
1560
1561
env , stdin = self .process_stdin_source (stdin = source , window = window )
1561
1562
self .run_background_process (cmd , cwd_from = cwd_from , stdin = stdin , env = env )
1563
+ return None
1562
1564
1563
1565
def args_to_special_window (self , args : Iterable [str ], cwd_from : Optional [int ] = None ) -> SpecialWindowInstance :
1564
1566
args = list (args )
@@ -1591,6 +1593,7 @@ def _new_tab(self, args: Union[SpecialWindowInstance, Iterable[str]], cwd_from:
1591
1593
tm = self .active_tab_manager
1592
1594
if tm is not None :
1593
1595
return tm .new_tab (special_window = special_window , cwd_from = cwd_from , as_neighbor = as_neighbor )
1596
+ return None
1594
1597
1595
1598
def _create_tab (self , args : List [str ], cwd_from : Optional [int ] = None ) -> None :
1596
1599
as_neighbor = False
@@ -1615,21 +1618,22 @@ def new_tab_with_wd(self, wd: str) -> None:
1615
1618
1616
1619
def _new_window (self , args : List [str ], cwd_from : Optional [int ] = None ) -> Optional [Window ]:
1617
1620
tab = self .active_tab
1618
- if tab is not None :
1619
- allow_remote_control = False
1620
- location = None
1621
- if args and args [0 ].startswith ('!' ):
1622
- location = args [0 ][1 :].lower ()
1623
- args = args [1 :]
1624
- if args and args [0 ] == '@' :
1625
- args = args [1 :]
1626
- allow_remote_control = True
1627
- if args :
1628
- return tab .new_special_window (
1629
- self .args_to_special_window (args , cwd_from = cwd_from ),
1630
- location = location , allow_remote_control = allow_remote_control )
1631
- else :
1632
- return tab .new_window (cwd_from = cwd_from , location = location , allow_remote_control = allow_remote_control )
1621
+ if tab is None :
1622
+ return None
1623
+ allow_remote_control = False
1624
+ location = None
1625
+ if args and args [0 ].startswith ('!' ):
1626
+ location = args [0 ][1 :].lower ()
1627
+ args = args [1 :]
1628
+ if args and args [0 ] == '@' :
1629
+ args = args [1 :]
1630
+ allow_remote_control = True
1631
+ if args :
1632
+ return tab .new_special_window (
1633
+ self .args_to_special_window (args , cwd_from = cwd_from ),
1634
+ location = location , allow_remote_control = allow_remote_control )
1635
+ else :
1636
+ return tab .new_window (cwd_from = cwd_from , location = location , allow_remote_control = allow_remote_control )
1633
1637
1634
1638
@ac ('win' , 'Create a new window' )
1635
1639
def new_window (self , * args : str ) -> None :
0 commit comments