This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nav.py
85 lines (69 loc) 路 2.53 KB
/
nav.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (C) 2019
# Authors: Cesar Roman, Kyle Chase.
# Contact: thecesrom@gmail.com
"""Navigation module."""
__all__ = [
'swap_to',
'swap_windows'
]
import system.nav
# Constants.
CURRENT_DIRECTORY = '.'
PARENT_DIRECTORY = '..'
PATH_SEPARATOR = '/'
def _get_full_path(from_path, to_path):
"""Returns the full path of the window to swap to relative to the
path of the window to swap from.
Args:
from_path: The full path of the window to swap from.
to_path: The full path or relative path of the window to swap
to.
Returns:
str: The full path of the window to swap to.
"""
_from = from_path.split(PATH_SEPARATOR)
_to = to_path.split(PATH_SEPARATOR)
path_parts = []
if _to[0] not in (PARENT_DIRECTORY, CURRENT_DIRECTORY):
path_parts = _to
elif _to[0] == PARENT_DIRECTORY:
path_parts = _from[:-2] + _to[1:]
elif _to[0] == CURRENT_DIRECTORY:
path_parts = _from[:-1] + _to[1:]
full_path = []
for path_part in path_parts:
if path_part == PARENT_DIRECTORY and len(full_path):
full_path = full_path[:-1]
elif path_part == CURRENT_DIRECTORY:
pass
else:
full_path.append(path_part)
return '/'.join(full_path)
def swap_to(path, params=None):
"""Performs a window swap from the current main screen window to
the window specified.
Args:
path (str): The full path or relative path of the window to
swap to.
params (dict): A dictionary of parameters to pass into the
window. The keys in the dictionary must match dynamic
property names on the target window's root container. The
values for each key will be used to set those properties.
Optional.
"""
swap_windows(system.nav.getCurrentWindow(), path, params)
def swap_windows(from_path, to_path, params=None):
"""Performs a window swap.
Args:
from_path (str): The full path of the window to swap from.
to_path (str): The full path or relative path of the window to
swap to.
params (dict): A dictionary of parameters to pass into the
window. The keys in the dictionary must match dynamic
property names on the target window's root container. The
values for each key will be used to set those properties.
Optional.
"""
_to_path = _get_full_path(from_path, to_path)
if _to_path != from_path:
system.nav.swapWindow(from_path, _to_path, params)