omnipython-apps 0.1.4.dev8__py3-none-any.whl → 0.1.4.dev10__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.
apps/desktop.py ADDED
@@ -0,0 +1,211 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Start Home on a computer, or add it to the Windows Start menu.
5
+
6
+ pip installs two commands that run this: ``omnipython-apps``, which opens
7
+ Home with no terminal window on Windows, and ``omnipython-apps-terminal``,
8
+ which keeps the terminal so you can read what the apps print::
9
+
10
+ omnipython-apps # Home
11
+ omnipython-apps chess # one app on its own
12
+ omnipython-apps --add-shortcut # a Start menu entry for Home (Windows)
13
+ omnipython-apps --remove-shortcut # and take it away again
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import argparse
19
+ import os
20
+ import subprocess
21
+ import sys
22
+ import sysconfig
23
+ import traceback
24
+ from pathlib import Path
25
+
26
+ #: The command the shortcut starts: the one with no terminal window.
27
+ GUI_COMMAND = "omnipython-apps"
28
+ SHORTCUT_NAME = "OmniPython Apps.lnk"
29
+ ICON = Path(__file__).with_name("omnipython-apps.ico")
30
+ #: The taskbar identity appkit.run gives Home (appkit.WINDOWS_APP_ID). The
31
+ #: shortcut carries it too, so a pinned shortcut and the running Home share
32
+ #: one taskbar button.
33
+ APP_ID = "PyDevices.OmniPython.Apps"
34
+
35
+ # WScript.Shell writes the shortcut, then the shell's own property store gives
36
+ # it the AppUserModelID, which WScript.Shell can't set. The paths and the ID
37
+ # come in through the environment, so no quoting can break the script.
38
+ _WRITE_SHORTCUT = """
39
+ $s = (New-Object -ComObject WScript.Shell).CreateShortcut($env:SHORTCUT_PATH)
40
+ $s.TargetPath = $env:SHORTCUT_TARGET
41
+ $s.WorkingDirectory = $env:SHORTCUT_DIR
42
+ $s.IconLocation = $env:SHORTCUT_ICON + ',0'
43
+ $s.Description = 'Every app for Home'
44
+ $s.Save()
45
+ Add-Type -TypeDefinition @'
46
+ using System;
47
+ using System.Runtime.InteropServices;
48
+ using System.Runtime.InteropServices.ComTypes;
49
+
50
+ [StructLayout(LayoutKind.Sequential, Pack = 4)]
51
+ public struct PropertyKey { public Guid FormatId; public uint PropertyId; }
52
+
53
+ [StructLayout(LayoutKind.Explicit, Size = 24)]
54
+ public struct PropVariant { [FieldOffset(0)] public ushort Type; [FieldOffset(8)] public IntPtr Value; }
55
+
56
+ [ComImport, Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
57
+ public interface IPropertyStore {
58
+ void GetCount(out uint count);
59
+ void GetAt(uint index, out PropertyKey key);
60
+ void GetValue(ref PropertyKey key, out PropVariant value);
61
+ void SetValue(ref PropertyKey key, ref PropVariant value);
62
+ void Commit();
63
+ }
64
+
65
+ [ComImport, Guid("00021401-0000-0000-C000-000000000046")]
66
+ public class ShellLink { }
67
+
68
+ public static class ShortcutAppId {
69
+ public static void Set(string path, string id) {
70
+ var link = new ShellLink();
71
+ ((IPersistFile)link).Load(path, 2); // STGM_READWRITE
72
+ var key = new PropertyKey { FormatId = new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), PropertyId = 5 };
73
+ var value = new PropVariant { Type = 31, Value = Marshal.StringToCoTaskMemUni(id) }; // VT_LPWSTR
74
+ try {
75
+ var store = (IPropertyStore)link;
76
+ store.SetValue(ref key, ref value);
77
+ store.Commit();
78
+ ((IPersistFile)link).Save(path, true);
79
+ } finally {
80
+ Marshal.FreeCoTaskMem(value.Value);
81
+ }
82
+ }
83
+ }
84
+ '@
85
+ [ShortcutAppId]::Set($env:SHORTCUT_PATH, $env:SHORTCUT_APP_ID)
86
+ """
87
+
88
+
89
+ def start_menu() -> Path:
90
+ """The current user's Start menu Programs folder."""
91
+ appdata = os.environ.get("APPDATA")
92
+ if not appdata:
93
+ raise SystemExit("APPDATA isn't set, so there's no Start menu folder to put the shortcut in")
94
+ return Path(appdata) / "Microsoft" / "Windows" / "Start Menu" / "Programs"
95
+
96
+
97
+ def gui_launcher() -> Path:
98
+ """The ``omnipython-apps.exe`` that pip installed beside this command."""
99
+ folders = [Path(sys.argv[0]).resolve().parent, Path(sysconfig.get_path("scripts"))]
100
+ try:
101
+ folders.append(Path(sysconfig.get_path("scripts", f"{os.name}_user")))
102
+ except KeyError:
103
+ pass
104
+ for folder in folders:
105
+ exe = folder / f"{GUI_COMMAND}.exe"
106
+ if exe.is_file():
107
+ return exe
108
+ raise SystemExit(
109
+ f"can't find {GUI_COMMAND}.exe in {', '.join(str(f) for f in folders)}: "
110
+ "reinstall omnipython-apps with pip, then try again"
111
+ )
112
+
113
+
114
+ def _windows_only(option: str) -> None:
115
+ if sys.platform != "win32":
116
+ raise SystemExit(f"{option} makes a Windows Start menu shortcut; elsewhere, start Home with {GUI_COMMAND}")
117
+
118
+
119
+ def add_shortcut() -> Path:
120
+ """Write a Start menu shortcut that opens Home with its own icon.
121
+
122
+ pip's ``omnipython-apps.exe`` can't carry an icon of its own, so the
123
+ shortcut gives it one, and Home's AppUserModelID, so pinning it puts Home
124
+ on the taskbar as one button. Returns the shortcut's path.
125
+ """
126
+ _windows_only("--add-shortcut")
127
+ shortcut = start_menu() / SHORTCUT_NAME
128
+ env = dict(os.environ)
129
+ env.update(
130
+ SHORTCUT_PATH=str(shortcut),
131
+ SHORTCUT_TARGET=str(gui_launcher()),
132
+ SHORTCUT_DIR=str(Path.home()),
133
+ SHORTCUT_ICON=str(ICON),
134
+ SHORTCUT_APP_ID=APP_ID,
135
+ )
136
+ subprocess.run(
137
+ ["powershell.exe", "-NoProfile", "-NonInteractive", "-Command", _WRITE_SHORTCUT],
138
+ env=env,
139
+ check=True,
140
+ )
141
+ if not shortcut.is_file():
142
+ raise SystemExit(f"PowerShell ran but {shortcut} isn't there")
143
+ return shortcut
144
+
145
+
146
+ def remove_shortcut() -> Path:
147
+ """Remove the Start menu shortcut `add_shortcut` wrote. Returns its path."""
148
+ _windows_only("--remove-shortcut")
149
+ shortcut = start_menu() / SHORTCUT_NAME
150
+ shortcut.unlink(missing_ok=True)
151
+ return shortcut
152
+
153
+
154
+ def no_terminal() -> bool:
155
+ """True under Windows' ``omnipython-apps``, which runs with no terminal to print to."""
156
+ return sys.platform == "win32" and sys.stderr is None
157
+
158
+
159
+ def show_error(text: str) -> None:
160
+ """Show *text* in a Windows message box, the one place a run with no terminal can report."""
161
+ import ctypes
162
+
163
+ mb_iconerror = 0x10
164
+ mb_setforeground = 0x10000
165
+ ctypes.windll.user32.MessageBoxW(None, text, "OmniPython Apps", mb_iconerror | mb_setforeground)
166
+
167
+
168
+ def main(argv: list[str] | None = None) -> int:
169
+ """Run Home, or one app, or add or remove the Start menu shortcut.
170
+
171
+ With no terminal to print to, an error that stops it is shown in a message
172
+ box, rather than lost with the window that never opened.
173
+ """
174
+ if not no_terminal():
175
+ return _main(argv)
176
+ try:
177
+ return _main(argv)
178
+ except SystemExit as exc:
179
+ if exc.code is None or isinstance(exc.code, int):
180
+ raise
181
+ show_error(str(exc.code))
182
+ return 1
183
+ except Exception as exc:
184
+ # The error itself first: the traceback under it can run long.
185
+ error = "".join(traceback.format_exception_only(type(exc), exc)).strip()
186
+ show_error(f"Home couldn't start:\n\n{error}\n\n{traceback.format_exc()}")
187
+ return 1
188
+
189
+
190
+ def _main(argv: list[str] | None) -> int:
191
+ parser = argparse.ArgumentParser(prog=GUI_COMMAND, description="Start Home, with every app installed.")
192
+ parser.add_argument("app", nargs="?", help="run this app on its own, without Home")
193
+ shortcut = parser.add_mutually_exclusive_group()
194
+ shortcut.add_argument("--add-shortcut", action="store_true", help="add Home to the Windows Start menu")
195
+ shortcut.add_argument("--remove-shortcut", action="store_true", help="remove it from the Start menu")
196
+ args = parser.parse_args(argv)
197
+ if args.add_shortcut:
198
+ print(f"added {add_shortcut()}")
199
+ return 0
200
+ if args.remove_shortcut:
201
+ print(f"removed {remove_shortcut()}")
202
+ return 0
203
+
204
+ import appkit
205
+
206
+ appkit.run(args.app)
207
+ return 0
208
+
209
+
210
+ if __name__ == "__main__":
211
+ sys.exit(main())
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omnipython-apps
3
- Version: 0.1.4.dev8
3
+ Version: 0.1.4.dev10
4
4
  Summary: Every app for Home, with everything the apps need
5
5
  Author: Brad Barnett
6
6
  License: MIT
@@ -8,14 +8,14 @@ Description-Content-Type: text/markdown
8
8
  Requires-Dist: numpy
9
9
  Requires-Dist: omnipython-audioeffects
10
10
  Requires-Dist: omnipython-audioinstruments
11
- Requires-Dist: omnipython-desktop>=0.8.2.dev11
11
+ Requires-Dist: omnipython-desktop>=0.8.2.dev13
12
12
  Requires-Dist: omnipython-lvgl
13
13
  Requires-Dist: omnipython-palettes
14
14
  Requires-Dist: omnipython-pygraphics
15
15
  Requires-Dist: omnipython>=0.8.1.dev10
16
16
  Requires-Dist: requests
17
17
  Requires-Dist: scipy
18
- Requires-Dist: omnipython-applibs==0.1.4.dev8
18
+ Requires-Dist: omnipython-applibs==0.1.4.dev10
19
19
 
20
20
  # omnipython-apps
21
21
 
@@ -26,8 +26,14 @@ computer:
26
26
 
27
27
  ```bash
28
28
  pip install omnipython-apps
29
+ omnipython-apps
29
30
  ```
30
31
 
32
+ `omnipython-apps` opens Home, and `omnipython-apps chess` one app on its own.
33
+ On Windows it opens no terminal window; `omnipython-apps-terminal` keeps one,
34
+ for what the apps print. `omnipython-apps --add-shortcut` puts Home in the
35
+ Windows Start menu, with its icon.
36
+
31
37
  On a board, `omip.install("apps")` installs the same apps from the OmniPython
32
38
  index. [The install page](https://github.com/PyDevices/apps/blob/main/docs/get-started/install.md)
33
39
  says how to start Home once they're in.
@@ -1,5 +1,7 @@
1
1
  apps/__init__.py,sha256=lrxXBVt0CEmuZeZFyxrNRZaK-4iR9ZhOZainQ43e9mQ,155
2
+ apps/desktop.py,sha256=Mtxu44ylu3v-cV20Fl3TP9AsMq1RJoWGhQxhQ-Qb90I,7693
2
3
  apps/manifest.py,sha256=ExufWnlxnY6jpYOHexOVUKLbmp5BwtlcI2nJFPwCY8w,2560
4
+ apps/omnipython-apps.ico,sha256=__o2-2FUq3x2_IRhqg42i7FueZDuY0JcUyDtZTLxEx4,32211
3
5
  apps/about/__init__.py,sha256=DWxumTyHXrDP4ot1ElwIYx3X7nW8QXM-lXtXnArA7i4,9049
4
6
  apps/about/app.json,sha256=bKoiQGxiqitB9H18cZpqY6HaFdGKC9U-rXMq5wezrOo,95
5
7
  apps/about/credits.py,sha256=6EFJ53fjFrBdxwrhBmOLy5D0BJoDALLhfT6wIFmKyEc,4650
@@ -212,7 +214,8 @@ apps/weather/app.json,sha256=r46LeVRGD2bWNzL52P3b_NUD2ZlEcHfl98RJYpbvFus,115
212
214
  apps/weather/icons.py,sha256=DSGtZ9GtsnFDGqvxjy_ONkEet7nsbARh79OU0nZTJxE,4842
213
215
  apps/weather/sizing.py,sha256=V5a7cavJOuhBc7is47BapmbD4_TiNUvS1xLDjHAlp2k,2658
214
216
  apps/weather/zippad.py,sha256=Zaw-DfWGXkHs0pu8wF_JPfsbnQakZemKSYzGF6z_Q2Y,6750
215
- omnipython_apps-0.1.4.dev8.dist-info/METADATA,sha256=yuEtaf4UArjbJHbn4nXHBagl2Sp-6QiHgRSslx7WthU,1087
216
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
217
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt,sha256=tDgFUeDjw0_X74xMPXr2TmKPB7BjXkoRZOavLez_SgE,5
218
- omnipython_apps-0.1.4.dev8.dist-info/RECORD,,
217
+ omnipython_apps-0.1.4.dev10.dist-info/METADATA,sha256=WT81qXSJSOmGJvMBeyFiHGe6a_wtNoQj-jPDENKkHlU,1372
218
+ omnipython_apps-0.1.4.dev10.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
219
+ omnipython_apps-0.1.4.dev10.dist-info/entry_points.txt,sha256=_FyMC9xyAlIOsHMa6OHFSUiEkrJy2kDTtxrZzs-78hw,114
220
+ omnipython_apps-0.1.4.dev10.dist-info/top_level.txt,sha256=tDgFUeDjw0_X74xMPXr2TmKPB7BjXkoRZOavLez_SgE,5
221
+ omnipython_apps-0.1.4.dev10.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ omnipython-apps-terminal = apps.desktop:main
3
+
4
+ [gui_scripts]
5
+ omnipython-apps = apps.desktop:main