From 2ee4032e0161576e7ab96c3df9c9617eb6b9ed7a Mon Sep 17 00:00:00 2001 From: TheAbider <51920546+TheAbider@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:05:19 -0700 Subject: [PATCH 1/3] Build a console EXE for the command line QuickPRS.exe is a windowed program: a console that starts it does not wait for it or show its output, so `QuickPRS.exe validate radio.PRS` typed in cmd or PowerShell printed nothing. build.py now also builds QuickPRS-cli.exe, a console build with the same modules, and passes extra options (e.g. --workpath) to PyInstaller. Also: the version text and the GUI said 50+ commands (there are 63), and the 1.1.0 changelog takes the release date. --- CHANGELOG.md | 3 +- README.md | 2 +- build.py | 67 +++++++++++++++++++++++++------------ quickprs/cli.py | 2 +- quickprs/gui/app.py | 2 +- tests/test_build_script.py | 68 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 25 deletions(-) create mode 100644 tests/test_build_script.py diff --git a/CHANGELOG.md b/CHANGELOG.md index fe92088..adea3f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to QuickPRS will be documented in this file. -## [1.1.0] - 2026-10-27 +## [1.1.0] - 2026-10-28 ### Fixed - **Edits broke the file structure RPM reads.** A .PRS file is an MFC archive: every class and object is numbered as it is written, and every list starts with its count. Adding or removing a talkgroup, channel, set or system left every later class tag and the list counts stale, and MFC's loader, which RPM uses, rejects tags that name the wrong class. QuickPRS now reads a personality into a tree that keeps every byte and writes it back with tags and counts recomputed. All 36 RPM-saved test files re-serialize byte for byte. See [docs/prs-format.md](docs/prs-format.md). @@ -27,6 +27,7 @@ All notable changes to QuickPRS will be documented in this file. - `set-option` accepted misspelt attributes and values a field does not allow, and wrote nested settings on the parent element; the default options XML is now RPM's own; presets and profiles no longer set attributes the XG-100P does not have - GUI: crashed on start; the Import Wizard failed every non-talkgroup import; the System Wizard reported failure on success and could add a system twice; undo history carried over to the next file; opening a recent file did not ask about unsaved changes; Delete, F2 and undo acted on the tree while typing; multi-select edits touched talkgroups that were not selected; Health Check crashed; dropped paths were not read as Unicode - `search` skipped unreadable files without saying so; listings print 6.25 kHz channels with 5 decimals +- The standalone EXE is a windowed program, so its commands printed nothing in a console; releases now include `QuickPRS-cli.exe`, a console build for the command line ### Added - `quickprs radio`: groundwork for reading the radio over Bluetooth. The XG-100P uses Bluetooth Classic (serial port profile), which RPM programs over like the USB cable. `scan` finds paired radios and their COM ports, `probe` listens, `relay` sits between RPM and the radio and logs both directions, and `analyze` summarises a capture and extracts any personality in it. None of them sends bytes of its own to the radio. See [docs/bluetooth.md](docs/bluetooth.md). diff --git a/README.md b/README.md index 328f103..4312772 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ python -m quickprs # Launch GUI python -m quickprs --help # CLI help ``` -Or use the standalone EXE from [Releases](../../releases) (no Python required). +Or use the standalone EXEs from [Releases](../../releases) (no Python required): `QuickPRS.exe` is the GUI, and `QuickPRS-cli.exe` runs the commands below from a console, for example `QuickPRS-cli.exe validate radio.PRS`. ### Optional dependencies: diff --git a/build.py b/build.py index 2a114f1..5a6f8eb 100644 --- a/build.py +++ b/build.py @@ -1,13 +1,14 @@ -"""Build QuickPRS standalone executable using PyInstaller. +"""Build QuickPRS standalone executables using PyInstaller. Usage: - python build.py + python build.py [extra PyInstaller options, e.g. --workpath DIR] Requires: pip install pyinstaller Output: - dist/QuickPRS.exe (single-file executable) + dist/QuickPRS.exe GUI (windowed, no console) + dist/QuickPRS-cli.exe command line (console) """ import os @@ -17,6 +18,13 @@ ROOT = Path(__file__).parent +# (name, windowed). A console does not wait for a windowed program or show +# its output, so the command line needs its own console build. +EXECUTABLES = ( + ("QuickPRS", True), + ("QuickPRS-cli", False), +) + def get_version(): """Read version from quickprs/__init__.py.""" @@ -27,17 +35,16 @@ def get_version(): return "0.0.0" -def build(): - version = get_version() - +def pyinstaller_cmd(name, windowed, extra=()): + """The PyInstaller command line for one executable.""" # Windows uses ';' as path separator for --add-data, Unix uses ':' sep = ';' if os.name == 'nt' else ':' - cmd = [ + return [ sys.executable, "-m", "PyInstaller", "--onefile", - "--windowed", - "--name", "QuickPRS", + "--windowed" if windowed else "--console", + "--name", name, "--add-data", f"{ROOT / 'quickprs'}{sep}quickprs", # Every quickprs module, so new ones need no list to keep "--collect-submodules", "quickprs", @@ -52,26 +59,44 @@ def build(): "--hidden-import", "windnd", "--hidden-import", "sv_ttk", "--hidden-import", "darkdetect", + *extra, str(ROOT / "run.py"), ] + +def _dist_dir(extra): + """Where PyInstaller puts the executables (--distpath or dist/).""" + extra = list(extra) + for i, arg in enumerate(extra): + if arg == "--distpath" and i + 1 < len(extra): + return Path(extra[i + 1]) + if arg.startswith("--distpath="): + return Path(arg.split("=", 1)[1]) + return ROOT / "dist" + + +def build(extra=()): + version = get_version() print(f"Building QuickPRS v{version}...") - print(f"Command: {' '.join(cmd)}") - result = subprocess.run(cmd, cwd=str(ROOT)) - if result.returncode == 0: - exe = ROOT / "dist" / "QuickPRS.exe" + for name, windowed in EXECUTABLES: + cmd = pyinstaller_cmd(name, windowed, extra) + print(f"Command: {' '.join(cmd)}") + result = subprocess.run(cmd, cwd=str(ROOT)) + if result.returncode != 0: + print(f"\nBuild of {name} failed with return code " + f"{result.returncode}") + sys.exit(1) + + print(f"\nVersion: {version}") + for name, _ in EXECUTABLES: + exe = _dist_dir(extra) / f"{name}.exe" if exe.exists(): size_mb = exe.stat().st_size / 1024 / 1024 - print(f"\nBuild successful: {exe}") - print(f"Version: {version}") - print(f"Size: {size_mb:.1f} MB") + print(f"Built: {exe} ({size_mb:.1f} MB)") else: - print("\nBuild completed but exe not found at expected path.") - else: - print(f"\nBuild failed with return code {result.returncode}") - sys.exit(1) + print(f"Build completed but {exe} was not found.") if __name__ == "__main__": - build() + build(sys.argv[1:]) diff --git a/quickprs/cli.py b/quickprs/cli.py index b91d864..a9915ab 100644 --- a/quickprs/cli.py +++ b/quickprs/cli.py @@ -4286,7 +4286,7 @@ def run_cli(args=None): version_str = ( f"QuickPRS v{__version__}\n" f"Python {py_ver} on {os_label}\n" - f"50+ CLI commands | quickprs cheat-sheet for reference" + f"60+ CLI commands | quickprs cheat-sheet for reference" ) parser = argparse.ArgumentParser( diff --git a/quickprs/gui/app.py b/quickprs/gui/app.py index 11215d5..3f1c2db 100644 --- a/quickprs/gui/app.py +++ b/quickprs/gui/app.py @@ -443,7 +443,7 @@ def _build_welcome(self): # Version info ttk.Label(self._welcome_frame, - text=f"v{__version__} \u2022 50+ CLI commands \u2022 quickprs --help", + text=f"v{__version__} \u2022 60+ CLI commands \u2022 quickprs --help", foreground="gray").pack(side=tk.BOTTOM, pady=10) # Show the welcome screen initially diff --git a/tests/test_build_script.py b/tests/test_build_script.py new file mode 100644 index 0000000..fcebd0c --- /dev/null +++ b/tests/test_build_script.py @@ -0,0 +1,68 @@ +"""Tests for build.py: which executables a release build makes.""" + +import importlib.util +import subprocess +from pathlib import Path + +ROOT = Path(__file__).parent.parent + +_spec = importlib.util.spec_from_file_location("quickprs_build_script", + ROOT / "build.py") +build = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(build) + + +def _commands(monkeypatch, extra): + """The PyInstaller command lines build() runs, without running them.""" + calls = [] + + def fake_run(cmd, cwd=None, **kwargs): + calls.append(cmd) + return subprocess.CompletedProcess(cmd, 0) + + monkeypatch.setattr(build.subprocess, "run", fake_run) + build.build(extra) + return calls + + +def _by_name(cmds): + return {cmd[cmd.index("--name") + 1]: cmd for cmd in cmds} + + +class TestExecutables: + + def test_gui_and_console_builds(self, monkeypatch, tmp_path): + """A console neither waits for the windowed GUI build nor shows its + output, so the command line gets a console build of its own.""" + builds = _by_name(_commands(monkeypatch, ["--distpath", str(tmp_path)])) + assert set(builds) == {"QuickPRS", "QuickPRS-cli"} + assert "--windowed" in builds["QuickPRS"] + assert "--console" not in builds["QuickPRS"] + assert "--console" in builds["QuickPRS-cli"] + assert "--windowed" not in builds["QuickPRS-cli"] + + def test_builds_bundle_the_same_modules(self, monkeypatch, tmp_path): + builds = _by_name(_commands(monkeypatch, ["--distpath", str(tmp_path)])) + + def options(cmd): + cmd = [a for a in cmd if a not in ("--windowed", "--console")] + i = cmd.index("--name") + return cmd[:i] + cmd[i + 2:] + + assert options(builds["QuickPRS"]) == options(builds["QuickPRS-cli"]) + + def test_extra_options_reach_every_build(self, monkeypatch, tmp_path): + work = str(tmp_path / "work") + cmds = _commands(monkeypatch, ["--workpath", work, + "--distpath", str(tmp_path)]) + for cmd in cmds: + assert cmd[-1] == str(ROOT / "run.py") + assert cmd[cmd.index("--workpath") + 1] == work + + def test_reports_where_the_executables_are(self, monkeypatch, tmp_path, + capsys): + (tmp_path / "QuickPRS.exe").write_bytes(b"x" * 2048) + _commands(monkeypatch, [f"--distpath={tmp_path}"]) + out = capsys.readouterr().out + assert f"Built: {tmp_path / 'QuickPRS.exe'}" in out + assert f"{tmp_path / 'QuickPRS-cli.exe'} was not found" in out From e8de5feed99b1732276aca7d19d7970be312fbfd Mon Sep 17 00:00:00 2001 From: TheAbider <51920546+TheAbider@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:10:43 -0700 Subject: [PATCH 2/3] Show colors in Windows consoles, or none A Windows console prints ANSI codes as text unless the program turns their handling on, so validate and friends showed a left arrow and [1m around every heading in a classic console window. Turn it on for the console (Windows 10 and later) and leave colors out where that fails. NO_COLOR is honored. --- quickprs/colors.py | 49 ++++++++++++++++-- tests/test_favorites.py | 112 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 4 deletions(-) diff --git a/quickprs/colors.py b/quickprs/colors.py index 42e6e39..1f2bdfb 100644 --- a/quickprs/colors.py +++ b/quickprs/colors.py @@ -1,15 +1,22 @@ """ANSI color support for terminal output. Provides colored text helpers that auto-detect TTY capability. -Colors are disabled when output is piped or redirected, or when -the --no-color flag is active. +Colors are disabled when output is piped or redirected, when the +--no-color flag is active or NO_COLOR is set, and in a Windows console +that cannot show them. """ +import os import sys # Global flag — set True by --no-color CLI flag _no_color = False +# Whether this Windows console shows ANSI codes (None until checked) +_windows_vt = None + +ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004 + def disable_color(): """Disable all color output (called by --no-color flag).""" @@ -17,11 +24,45 @@ def disable_color(): _no_color = True +def _kernel32(): + import ctypes + return ctypes.WinDLL("kernel32", use_last_error=True) + + +def _enable_windows_vt(): + """Turn on ANSI code handling in this Windows console. + + A Windows console prints escape codes as text unless the program + turns this on (Windows 10 and later). Returns False when it cannot. + """ + global _windows_vt + if _windows_vt is None: + _windows_vt = False + try: + import ctypes + from ctypes import wintypes + k32 = _kernel32() + k32.GetStdHandle.restype = wintypes.HANDLE + handle = k32.GetStdHandle(-11) # STD_OUTPUT_HANDLE + mode = wintypes.DWORD() + if k32.GetConsoleMode(handle, ctypes.pointer(mode)): + vt = ENABLE_VIRTUAL_TERMINAL_PROCESSING + _windows_vt = bool(mode.value & vt) or bool( + k32.SetConsoleMode(handle, mode.value | vt)) + except (AttributeError, OSError): + pass + return _windows_vt + + def supports_color(): """Check if stdout supports ANSI color codes.""" - if _no_color: + if _no_color or os.environ.get("NO_COLOR"): + return False + if not (hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()): return False - return hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() + if sys.platform == "win32": + return _enable_windows_vt() + return True def _code(ansi): diff --git a/tests/test_favorites.py b/tests/test_favorites.py index 059b8eb..cb9901d 100644 --- a/tests/test_favorites.py +++ b/tests/test_favorites.py @@ -561,6 +561,8 @@ def test_supports_color_tty(self, monkeypatch): """supports_color returns True when stdout is a TTY.""" import quickprs.colors as colors_mod monkeypatch.setattr(colors_mod, '_no_color', False) + monkeypatch.setattr(colors_mod, '_windows_vt', True) + monkeypatch.delenv('NO_COLOR', raising=False) mock_stdout = MagicMock() mock_stdout.isatty.return_value = True @@ -579,6 +581,116 @@ def test_disable_color_function(self): colors_mod._no_color = old_val +class _FakeKernel32: + """Stands in for kernel32's console mode calls.""" + + class _Call: + def __init__(self, fn): + self.fn = fn + self.restype = None + + def __call__(self, *args): + return self.fn(*args) + + def __init__(self, mode, is_console=True, set_ok=True): + self.mode = mode + self.set_calls = [] + self.GetStdHandle = self._Call(lambda n: 7) + self.GetConsoleMode = self._Call(self._get) + self.SetConsoleMode = self._Call(self._set) + self._is_console = is_console + self._set_ok = set_ok + + def _get(self, handle, mode_ptr): + if not self._is_console: + return 0 + mode_ptr.contents.value = self.mode + return 1 + + def _set(self, handle, mode): + self.set_calls.append(mode) + return 1 if self._set_ok else 0 + + +class TestColorsInWindowsConsoles: + """A Windows console shows ANSI codes as text (a left arrow and + "[1m") unless the program turns on their handling.""" + + def _tty(self, monkeypatch): + import quickprs.colors as colors_mod + monkeypatch.setattr(colors_mod, '_no_color', False) + monkeypatch.delenv('NO_COLOR', raising=False) + mock_stdout = MagicMock() + mock_stdout.isatty.return_value = True + monkeypatch.setattr(sys, 'stdout', mock_stdout) + return colors_mod + + def test_no_color_when_the_console_cannot_show_it(self, monkeypatch): + colors_mod = self._tty(monkeypatch) + monkeypatch.setattr(sys, 'platform', 'win32') + monkeypatch.setattr(colors_mod, '_windows_vt', False) + assert colors_mod.supports_color() is False + assert colors_mod.red("x") == "x" + + def test_color_once_handling_is_on(self, monkeypatch): + colors_mod = self._tty(monkeypatch) + monkeypatch.setattr(sys, 'platform', 'win32') + monkeypatch.setattr(colors_mod, '_windows_vt', True) + assert colors_mod.supports_color() is True + + def test_turns_on_ansi_handling(self, monkeypatch): + import quickprs.colors as colors_mod + k32 = _FakeKernel32(mode=0x0003) + monkeypatch.setattr(colors_mod, '_kernel32', lambda: k32) + monkeypatch.setattr(colors_mod, '_windows_vt', None) + assert colors_mod._enable_windows_vt() is True + assert k32.set_calls == [0x0003 | 0x0004] + + def test_already_on_is_left_alone(self, monkeypatch): + import quickprs.colors as colors_mod + k32 = _FakeKernel32(mode=0x0007) + monkeypatch.setattr(colors_mod, '_kernel32', lambda: k32) + monkeypatch.setattr(colors_mod, '_windows_vt', None) + assert colors_mod._enable_windows_vt() is True + assert k32.set_calls == [] + + def test_older_windows_without_ansi_handling(self, monkeypatch): + import quickprs.colors as colors_mod + k32 = _FakeKernel32(mode=0x0003, set_ok=False) + monkeypatch.setattr(colors_mod, '_kernel32', lambda: k32) + monkeypatch.setattr(colors_mod, '_windows_vt', None) + assert colors_mod._enable_windows_vt() is False + + def test_not_a_console(self, monkeypatch): + import quickprs.colors as colors_mod + k32 = _FakeKernel32(mode=0, is_console=False) + monkeypatch.setattr(colors_mod, '_kernel32', lambda: k32) + monkeypatch.setattr(colors_mod, '_windows_vt', None) + assert colors_mod._enable_windows_vt() is False + assert k32.set_calls == [] + + def test_checked_once(self, monkeypatch): + import quickprs.colors as colors_mod + k32 = _FakeKernel32(mode=0x0003) + monkeypatch.setattr(colors_mod, '_kernel32', lambda: k32) + monkeypatch.setattr(colors_mod, '_windows_vt', None) + colors_mod._enable_windows_vt() + colors_mod._enable_windows_vt() + assert len(k32.set_calls) == 1 + + def test_no_color_environment_variable(self, monkeypatch): + colors_mod = self._tty(monkeypatch) + monkeypatch.setattr(colors_mod, '_windows_vt', True) + monkeypatch.setenv('NO_COLOR', '1') + assert colors_mod.supports_color() is False + + def test_empty_no_color_is_ignored(self, monkeypatch): + colors_mod = self._tty(monkeypatch) + monkeypatch.setattr(colors_mod, '_windows_vt', True) + monkeypatch.setenv('NO_COLOR', '') + assert colors_mod.supports_color() is True + + class TestColorsNotPiped: """Test color behavior when output is piped (StringIO).""" From 2e150910b5f1dd4441e1d3006c0bb0039be97c88 Mon Sep 17 00:00:00 2001 From: TheAbider <51920546+TheAbider@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:11:12 -0700 Subject: [PATCH 3/3] Changelog: console colors --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index adea3f3..5389ce4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable changes to QuickPRS will be documented in this file. - GUI: crashed on start; the Import Wizard failed every non-talkgroup import; the System Wizard reported failure on success and could add a system twice; undo history carried over to the next file; opening a recent file did not ask about unsaved changes; Delete, F2 and undo acted on the tree while typing; multi-select edits touched talkgroups that were not selected; Health Check crashed; dropped paths were not read as Unicode - `search` skipped unreadable files without saying so; listings print 6.25 kHz channels with 5 decimals - The standalone EXE is a windowed program, so its commands printed nothing in a console; releases now include `QuickPRS-cli.exe`, a console build for the command line +- Classic Windows console windows showed color codes as text (`←[1m`); QuickPRS now turns on their handling, leaves colors out where it cannot, and honors `NO_COLOR` ### Added - `quickprs radio`: groundwork for reading the radio over Bluetooth. The XG-100P uses Bluetooth Classic (serial port profile), which RPM programs over like the USB cable. `scan` finds paired radios and their COM ports, `probe` listens, `relay` sits between RPM and the radio and logs both directions, and `analyze` summarises a capture and extracts any personality in it. None of them sends bytes of its own to the radio. See [docs/bluetooth.md](docs/bluetooth.md).