omnipython-apps 0.1.4.dev8__py3-none-any.whl → 0.1.4.dev9__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,175 @@
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
+ from pathlib import Path
24
+
25
+ #: The command the shortcut starts: the one with no terminal window.
26
+ GUI_COMMAND = "omnipython-apps"
27
+ SHORTCUT_NAME = "OmniPython Apps.lnk"
28
+ ICON = Path(__file__).with_name("omnipython-apps.ico")
29
+ #: The taskbar identity appkit.run gives Home (appkit.WINDOWS_APP_ID). The
30
+ #: shortcut carries it too, so a pinned shortcut and the running Home share
31
+ #: one taskbar button.
32
+ APP_ID = "PyDevices.OmniPython.Apps"
33
+
34
+ # WScript.Shell writes the shortcut, then the shell's own property store gives
35
+ # it the AppUserModelID, which WScript.Shell can't set. The paths and the ID
36
+ # come in through the environment, so no quoting can break the script.
37
+ _WRITE_SHORTCUT = """
38
+ $s = (New-Object -ComObject WScript.Shell).CreateShortcut($env:SHORTCUT_PATH)
39
+ $s.TargetPath = $env:SHORTCUT_TARGET
40
+ $s.WorkingDirectory = $env:SHORTCUT_DIR
41
+ $s.IconLocation = $env:SHORTCUT_ICON + ',0'
42
+ $s.Description = 'Every app for Home'
43
+ $s.Save()
44
+ Add-Type -TypeDefinition @'
45
+ using System;
46
+ using System.Runtime.InteropServices;
47
+ using System.Runtime.InteropServices.ComTypes;
48
+
49
+ [StructLayout(LayoutKind.Sequential, Pack = 4)]
50
+ public struct PropertyKey { public Guid FormatId; public uint PropertyId; }
51
+
52
+ [StructLayout(LayoutKind.Explicit, Size = 24)]
53
+ public struct PropVariant { [FieldOffset(0)] public ushort Type; [FieldOffset(8)] public IntPtr Value; }
54
+
55
+ [ComImport, Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
56
+ public interface IPropertyStore {
57
+ void GetCount(out uint count);
58
+ void GetAt(uint index, out PropertyKey key);
59
+ void GetValue(ref PropertyKey key, out PropVariant value);
60
+ void SetValue(ref PropertyKey key, ref PropVariant value);
61
+ void Commit();
62
+ }
63
+
64
+ [ComImport, Guid("00021401-0000-0000-C000-000000000046")]
65
+ public class ShellLink { }
66
+
67
+ public static class ShortcutAppId {
68
+ public static void Set(string path, string id) {
69
+ var link = new ShellLink();
70
+ ((IPersistFile)link).Load(path, 2); // STGM_READWRITE
71
+ var key = new PropertyKey { FormatId = new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), PropertyId = 5 };
72
+ var value = new PropVariant { Type = 31, Value = Marshal.StringToCoTaskMemUni(id) }; // VT_LPWSTR
73
+ try {
74
+ var store = (IPropertyStore)link;
75
+ store.SetValue(ref key, ref value);
76
+ store.Commit();
77
+ ((IPersistFile)link).Save(path, true);
78
+ } finally {
79
+ Marshal.FreeCoTaskMem(value.Value);
80
+ }
81
+ }
82
+ }
83
+ '@
84
+ [ShortcutAppId]::Set($env:SHORTCUT_PATH, $env:SHORTCUT_APP_ID)
85
+ """
86
+
87
+
88
+ def start_menu() -> Path:
89
+ """The current user's Start menu Programs folder."""
90
+ appdata = os.environ.get("APPDATA")
91
+ if not appdata:
92
+ raise SystemExit("APPDATA isn't set, so there's no Start menu folder to put the shortcut in")
93
+ return Path(appdata) / "Microsoft" / "Windows" / "Start Menu" / "Programs"
94
+
95
+
96
+ def gui_launcher() -> Path:
97
+ """The ``omnipython-apps.exe`` that pip installed beside this command."""
98
+ folders = [Path(sys.argv[0]).resolve().parent, Path(sysconfig.get_path("scripts"))]
99
+ try:
100
+ folders.append(Path(sysconfig.get_path("scripts", f"{os.name}_user")))
101
+ except KeyError:
102
+ pass
103
+ for folder in folders:
104
+ exe = folder / f"{GUI_COMMAND}.exe"
105
+ if exe.is_file():
106
+ return exe
107
+ raise SystemExit(
108
+ f"can't find {GUI_COMMAND}.exe in {', '.join(str(f) for f in folders)}: "
109
+ "reinstall omnipython-apps with pip, then try again"
110
+ )
111
+
112
+
113
+ def _windows_only(option: str) -> None:
114
+ if sys.platform != "win32":
115
+ raise SystemExit(f"{option} makes a Windows Start menu shortcut; elsewhere, start Home with {GUI_COMMAND}")
116
+
117
+
118
+ def add_shortcut() -> Path:
119
+ """Write a Start menu shortcut that opens Home with its own icon.
120
+
121
+ pip's ``omnipython-apps.exe`` can't carry an icon of its own, so the
122
+ shortcut gives it one, and Home's AppUserModelID, so pinning it puts Home
123
+ on the taskbar as one button. Returns the shortcut's path.
124
+ """
125
+ _windows_only("--add-shortcut")
126
+ shortcut = start_menu() / SHORTCUT_NAME
127
+ env = dict(os.environ)
128
+ env.update(
129
+ SHORTCUT_PATH=str(shortcut),
130
+ SHORTCUT_TARGET=str(gui_launcher()),
131
+ SHORTCUT_DIR=str(Path.home()),
132
+ SHORTCUT_ICON=str(ICON),
133
+ SHORTCUT_APP_ID=APP_ID,
134
+ )
135
+ subprocess.run(
136
+ ["powershell.exe", "-NoProfile", "-NonInteractive", "-Command", _WRITE_SHORTCUT],
137
+ env=env,
138
+ check=True,
139
+ )
140
+ if not shortcut.is_file():
141
+ raise SystemExit(f"PowerShell ran but {shortcut} isn't there")
142
+ return shortcut
143
+
144
+
145
+ def remove_shortcut() -> Path:
146
+ """Remove the Start menu shortcut `add_shortcut` wrote. Returns its path."""
147
+ _windows_only("--remove-shortcut")
148
+ shortcut = start_menu() / SHORTCUT_NAME
149
+ shortcut.unlink(missing_ok=True)
150
+ return shortcut
151
+
152
+
153
+ def main(argv: list[str] | None = None) -> int:
154
+ """Run Home, or one app, or add or remove the Start menu shortcut."""
155
+ parser = argparse.ArgumentParser(prog=GUI_COMMAND, description="Start Home, with every app installed.")
156
+ parser.add_argument("app", nargs="?", help="run this app on its own, without Home")
157
+ shortcut = parser.add_mutually_exclusive_group()
158
+ shortcut.add_argument("--add-shortcut", action="store_true", help="add Home to the Windows Start menu")
159
+ shortcut.add_argument("--remove-shortcut", action="store_true", help="remove it from the Start menu")
160
+ args = parser.parse_args(argv)
161
+ if args.add_shortcut:
162
+ print(f"added {add_shortcut()}")
163
+ return 0
164
+ if args.remove_shortcut:
165
+ print(f"removed {remove_shortcut()}")
166
+ return 0
167
+
168
+ import appkit
169
+
170
+ appkit.run(args.app)
171
+ return 0
172
+
173
+
174
+ if __name__ == "__main__":
175
+ 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.dev9
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.dev12
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.dev9
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=b34yGBIgVWgBJie__lDmZkSNWBUXHc186PPfoGnZhDI,6471
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.dev9.dist-info/METADATA,sha256=yHioJbH_jqWTHloiq-KzJWvrmuPhttB8BTuUZVLvcXA,1370
218
+ omnipython_apps-0.1.4.dev9.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
219
+ omnipython_apps-0.1.4.dev9.dist-info/entry_points.txt,sha256=_FyMC9xyAlIOsHMa6OHFSUiEkrJy2kDTtxrZzs-78hw,114
220
+ omnipython_apps-0.1.4.dev9.dist-info/top_level.txt,sha256=tDgFUeDjw0_X74xMPXr2TmKPB7BjXkoRZOavLez_SgE,5
221
+ omnipython_apps-0.1.4.dev9.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