raedir 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- raedir/__init__.py +3 -0
- raedir/__main__.py +83 -0
- raedir/accessibility.py +131 -0
- raedir/app.py +583 -0
- raedir/config.py +90 -0
- raedir/downloader.py +144 -0
- raedir/kicad_paths.py +223 -0
- raedir/kicad_session.py +720 -0
- raedir/lib_tables.py +95 -0
- raedir/library.py +190 -0
- raedir/place_schematic.py +387 -0
- raedir/setup_wizard.py +64 -0
- raedir/theme.py +140 -0
- raedir/util.py +25 -0
- raedir-0.1.0.dist-info/METADATA +73 -0
- raedir-0.1.0.dist-info/RECORD +19 -0
- raedir-0.1.0.dist-info/WHEEL +4 -0
- raedir-0.1.0.dist-info/entry_points.txt +2 -0
- raedir-0.1.0.dist-info/licenses/LICENSE +21 -0
raedir/__init__.py
ADDED
raedir/__main__.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""CLI entry: `python -m raedir` / `raedir`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main(argv: list[str] | None = None) -> int:
|
|
10
|
+
parser = argparse.ArgumentParser(
|
|
11
|
+
prog="raedir",
|
|
12
|
+
description="Terminal GUI for downloading JLCPCB/LCSC parts into KiCad",
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
"--setup",
|
|
16
|
+
action="store_true",
|
|
17
|
+
help="Run path discovery / easyeda2kicad install and exit",
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--add",
|
|
21
|
+
metavar="LCSC_ID",
|
|
22
|
+
help="Download a part without opening the TUI",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"--no-reload",
|
|
26
|
+
action="store_true",
|
|
27
|
+
help="Skip KiCad reload after --add",
|
|
28
|
+
)
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--version",
|
|
31
|
+
action="store_true",
|
|
32
|
+
help="Print version and exit",
|
|
33
|
+
)
|
|
34
|
+
args = parser.parse_args(argv)
|
|
35
|
+
|
|
36
|
+
if args.version:
|
|
37
|
+
from raedir import __version__
|
|
38
|
+
|
|
39
|
+
print(__version__)
|
|
40
|
+
return 0
|
|
41
|
+
|
|
42
|
+
from raedir.config import load_config, save_config
|
|
43
|
+
from raedir.setup_wizard import ensure_ready
|
|
44
|
+
|
|
45
|
+
config = load_config()
|
|
46
|
+
status = ensure_ready(
|
|
47
|
+
config,
|
|
48
|
+
interactive=sys.stdin.isatty(),
|
|
49
|
+
verbose=bool(args.setup),
|
|
50
|
+
)
|
|
51
|
+
save_config(config)
|
|
52
|
+
|
|
53
|
+
if not status.ok:
|
|
54
|
+
print(status.message, file=sys.stderr)
|
|
55
|
+
return 1
|
|
56
|
+
|
|
57
|
+
if args.setup:
|
|
58
|
+
print(status.message or "Ready.")
|
|
59
|
+
return 0
|
|
60
|
+
|
|
61
|
+
if args.add:
|
|
62
|
+
from raedir.downloader import download_part
|
|
63
|
+
from raedir.kicad_session import reload_kicad
|
|
64
|
+
|
|
65
|
+
result = download_part(args.add, config)
|
|
66
|
+
print(result.message)
|
|
67
|
+
if not result.ok:
|
|
68
|
+
return 1
|
|
69
|
+
if not args.no_reload and config.auto_reload_kicad:
|
|
70
|
+
reload = reload_kicad()
|
|
71
|
+
print(reload.message)
|
|
72
|
+
return 0 if reload.ok else 2
|
|
73
|
+
return 0
|
|
74
|
+
|
|
75
|
+
from raedir.app import run_app
|
|
76
|
+
|
|
77
|
+
run_app(config)
|
|
78
|
+
save_config(config)
|
|
79
|
+
return 0
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
raise SystemExit(main())
|
raedir/accessibility.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""macOS Accessibility (assistive access) checks and prompts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import platform
|
|
6
|
+
import subprocess
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
ACCESSIBILITY_ERROR_MARKERS = (
|
|
11
|
+
"not allowed assistive access",
|
|
12
|
+
"not authorized to send keystrokes",
|
|
13
|
+
"osascript is not allowed",
|
|
14
|
+
"assistive access",
|
|
15
|
+
"1002", # error code often seen for AX denial
|
|
16
|
+
"-1719",
|
|
17
|
+
"-25211",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class AccessibilityStatus:
|
|
23
|
+
trusted: bool
|
|
24
|
+
detail: str = ""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def is_accessibility_error(message: str) -> bool:
|
|
28
|
+
lower = message.lower()
|
|
29
|
+
return any(marker in lower for marker in ACCESSIBILITY_ERROR_MARKERS)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def check_accessibility() -> AccessibilityStatus:
|
|
33
|
+
"""Return whether this process can control other apps via System Events."""
|
|
34
|
+
if platform.system() != "Darwin":
|
|
35
|
+
return AccessibilityStatus(True, "not macOS")
|
|
36
|
+
|
|
37
|
+
# Prefer the official AX API when available
|
|
38
|
+
try:
|
|
39
|
+
from ApplicationServices import AXIsProcessTrusted # type: ignore
|
|
40
|
+
|
|
41
|
+
trusted = bool(AXIsProcessTrusted())
|
|
42
|
+
return AccessibilityStatus(trusted, "AXIsProcessTrusted")
|
|
43
|
+
except Exception:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
import ctypes
|
|
48
|
+
import ctypes.util
|
|
49
|
+
|
|
50
|
+
path = ctypes.util.find_library("ApplicationServices") or ctypes.util.find_library(
|
|
51
|
+
"CoreFoundation"
|
|
52
|
+
)
|
|
53
|
+
if path:
|
|
54
|
+
lib = ctypes.cdll.LoadLibrary(path)
|
|
55
|
+
if hasattr(lib, "AXIsProcessTrusted"):
|
|
56
|
+
lib.AXIsProcessTrusted.restype = ctypes.c_bool
|
|
57
|
+
trusted = bool(lib.AXIsProcessTrusted())
|
|
58
|
+
return AccessibilityStatus(trusted, "ctypes AXIsProcessTrusted")
|
|
59
|
+
except Exception:
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
# Probe System Events — fails loudly without Accessibility
|
|
63
|
+
proc = subprocess.run(
|
|
64
|
+
[
|
|
65
|
+
"osascript",
|
|
66
|
+
"-e",
|
|
67
|
+
'tell application "System Events" to get name of first process',
|
|
68
|
+
],
|
|
69
|
+
capture_output=True,
|
|
70
|
+
text=True,
|
|
71
|
+
check=False,
|
|
72
|
+
)
|
|
73
|
+
if proc.returncode == 0 and proc.stdout.strip():
|
|
74
|
+
return AccessibilityStatus(True, "System Events probe ok")
|
|
75
|
+
|
|
76
|
+
err = (proc.stderr or proc.stdout or "System Events probe failed").strip()
|
|
77
|
+
if is_accessibility_error(err) or proc.returncode != 0:
|
|
78
|
+
return AccessibilityStatus(False, err)
|
|
79
|
+
return AccessibilityStatus(False, err)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def open_accessibility_settings() -> bool:
|
|
83
|
+
"""Open System Settings to the Accessibility privacy pane."""
|
|
84
|
+
if platform.system() != "Darwin":
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
urls = [
|
|
88
|
+
# Sequoia / Sonoma style
|
|
89
|
+
"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_Accessibility",
|
|
90
|
+
# Older macOS
|
|
91
|
+
"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility",
|
|
92
|
+
]
|
|
93
|
+
for url in urls:
|
|
94
|
+
proc = subprocess.run(["open", url], capture_output=True, check=False)
|
|
95
|
+
if proc.returncode == 0:
|
|
96
|
+
return True
|
|
97
|
+
|
|
98
|
+
# Last resort: open Privacy & Security root
|
|
99
|
+
subprocess.run(
|
|
100
|
+
["open", "/System/Library/PreferencePanes/Security.prefPane"],
|
|
101
|
+
check=False,
|
|
102
|
+
)
|
|
103
|
+
return True
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def terminal_app_hint() -> str:
|
|
107
|
+
"""Best-effort name of the host terminal for the permission prompt."""
|
|
108
|
+
import os
|
|
109
|
+
|
|
110
|
+
term_program = os.environ.get("TERM_PROGRAM", "")
|
|
111
|
+
mapping = {
|
|
112
|
+
"Apple_Terminal": "Terminal",
|
|
113
|
+
"iTerm.app": "iTerm",
|
|
114
|
+
"WarpTerminal": "Warp",
|
|
115
|
+
"ghostty": "Ghostty",
|
|
116
|
+
"WezTerm": "WezTerm",
|
|
117
|
+
"alacritty": "Alacritty",
|
|
118
|
+
"vscode": "Cursor",
|
|
119
|
+
"Cursor": "Cursor",
|
|
120
|
+
}
|
|
121
|
+
if term_program in mapping:
|
|
122
|
+
return mapping[term_program]
|
|
123
|
+
# Cursor / VS Code embedded terminals often omit TERM_PROGRAM
|
|
124
|
+
env_blob = " ".join(
|
|
125
|
+
f"{k}={v}" for k, v in os.environ.items() if "CURSOR" in k.upper() or k.startswith("VSCODE")
|
|
126
|
+
)
|
|
127
|
+
if "CURSOR" in env_blob.upper() or os.environ.get("CURSOR_TRACE_ID"):
|
|
128
|
+
return "Cursor"
|
|
129
|
+
if os.environ.get("VSCODE_INJECTION") or os.environ.get("TERM_PROGRAM_VERSION"):
|
|
130
|
+
return "Cursor"
|
|
131
|
+
return "Terminal (or Cursor, if you launch Raedir from there)"
|