pythonnative 0.37.0__py3-none-any.whl → 0.39.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.
Files changed (96) hide show
  1. pythonnative/__init__.py +9 -1
  2. pythonnative/alerts.py +7 -15
  3. pythonnative/animated.py +1 -1
  4. pythonnative/bootstrap.py +15 -6
  5. pythonnative/bridge/__init__.py +16 -9
  6. pythonnative/bridge/codec.py +1 -1
  7. pythonnative/bridge/web.py +530 -0
  8. pythonnative/cli/pn.py +424 -339
  9. pythonnative/components/_base.py +31 -0
  10. pythonnative/components/controls.py +19 -16
  11. pythonnative/components/layout.py +5 -8
  12. pythonnative/components/lists.py +8 -8
  13. pythonnative/devclient.py +824 -0
  14. pythonnative/devserver/__init__.py +34 -0
  15. pythonnative/devserver/server.py +712 -0
  16. pythonnative/devserver/static/bridge.js +155 -0
  17. pythonnative/devserver/static/colors.js +70 -0
  18. pythonnative/devserver/static/host.js +577 -0
  19. pythonnative/devserver/static/index.html +60 -0
  20. pythonnative/devserver/static/preview.css +415 -0
  21. pythonnative/devserver/static/renderer.js +2037 -0
  22. pythonnative/devserver/static/shell.js +343 -0
  23. pythonnative/devserver/watcher.py +267 -0
  24. pythonnative/devserver/ws.py +421 -0
  25. pythonnative/gestures.py +31 -10
  26. pythonnative/hooks.py +2 -2
  27. pythonnative/hosts/__init__.py +20 -19
  28. pythonnative/hosts/base.py +35 -44
  29. pythonnative/hosts/native.py +4 -14
  30. pythonnative/hot_reload.py +205 -280
  31. pythonnative/images.py +2 -1
  32. pythonnative/native_modules/__init__.py +25 -4
  33. pythonnative/native_modules/battery.py +13 -14
  34. pythonnative/native_modules/biometrics.py +12 -14
  35. pythonnative/native_modules/camera.py +10 -6
  36. pythonnative/native_modules/clipboard.py +9 -11
  37. pythonnative/native_modules/{desktop.py → fallback.py} +42 -40
  38. pythonnative/native_modules/file_system.py +81 -172
  39. pythonnative/native_modules/haptics.py +14 -10
  40. pythonnative/native_modules/linking.py +9 -8
  41. pythonnative/native_modules/location.py +10 -12
  42. pythonnative/native_modules/net_info.py +1 -4
  43. pythonnative/native_modules/notifications.py +26 -33
  44. pythonnative/native_modules/permissions.py +70 -22
  45. pythonnative/native_modules/registry.py +6 -6
  46. pythonnative/native_modules/secure_store.py +16 -20
  47. pythonnative/native_modules/share.py +5 -5
  48. pythonnative/native_views/__init__.py +18 -23
  49. pythonnative/native_views/base.py +1 -1
  50. pythonnative/native_views/bridge_backend.py +3 -2
  51. pythonnative/navigation/__init__.py +2 -1
  52. pythonnative/navigation/handle.py +1 -1
  53. pythonnative/navigation/hooks.py +46 -7
  54. pythonnative/navigation/screen.py +1 -1
  55. pythonnative/navigation/state.py +30 -9
  56. pythonnative/platform.py +21 -20
  57. pythonnative/platform_metrics.py +1 -1
  58. pythonnative/preview.py +261 -499
  59. pythonnative/project/android.py +36 -3
  60. pythonnative/project/builder.py +93 -39
  61. pythonnative/project/config.py +84 -24
  62. pythonnative/project/deps.py +703 -0
  63. pythonnative/project/doctor.py +51 -22
  64. pythonnative/project/fingerprint.py +170 -0
  65. pythonnative/project/ios.py +6 -0
  66. pythonnative/project/runtime_assets.py +13 -14
  67. pythonnative/reconciler/core.py +1 -1
  68. pythonnative/runtime.py +18 -42
  69. pythonnative/sdk/__init__.py +6 -6
  70. pythonnative/sdk/_components.py +12 -12
  71. pythonnative/storage.py +2 -2
  72. pythonnative/style.py +94 -44
  73. pythonnative/templates/android_template/app/build.gradle +11 -2
  74. pythonnative/templates/android_template/app/src/debug/AndroidManifest.xml +7 -0
  75. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +5 -2
  76. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/ScreenFragment.kt +0 -3
  77. pythonnative/templates/android_template/build.gradle +7 -4
  78. pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +1 -1
  79. pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/PermissionsModule.kt +15 -4
  80. pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/screens/PNScreenFragment.kt +6 -41
  81. pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/HostModule.swift +0 -1
  82. pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/PermissionModules.swift +25 -10
  83. pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Screens/PNViewController.swift +6 -22
  84. pythonnative/templates/ios_template/ios_template/PythonRuntime.swift +3 -2
  85. pythonnative/templates/ios_template/ios_template/ViewController.swift +1 -7
  86. pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +35 -9
  87. pythonnative/utils.py +61 -58
  88. pythonnative/virtual_rows.py +10 -20
  89. {pythonnative-0.37.0.dist-info → pythonnative-0.39.0.dist-info}/METADATA +23 -13
  90. {pythonnative-0.37.0.dist-info → pythonnative-0.39.0.dist-info}/RECORD +94 -80
  91. pythonnative/hosts/desktop.py +0 -107
  92. pythonnative/native_views/desktop.py +0 -2356
  93. {pythonnative-0.37.0.dist-info → pythonnative-0.39.0.dist-info}/WHEEL +0 -0
  94. {pythonnative-0.37.0.dist-info → pythonnative-0.39.0.dist-info}/entry_points.txt +0 -0
  95. {pythonnative-0.37.0.dist-info → pythonnative-0.39.0.dist-info}/licenses/LICENSE +0 -0
  96. {pythonnative-0.37.0.dist-info → pythonnative-0.39.0.dist-info}/top_level.txt +0 -0
pythonnative/__init__.py CHANGED
@@ -62,7 +62,7 @@ Example:
62
62
  ```
63
63
  """
64
64
 
65
- __version__ = "0.37.0"
65
+ __version__ = "0.39.0"
66
66
 
67
67
  from . import appearance, diagnostics, gestures, images, runtime, sdk
68
68
  from .alerts import Alert
@@ -190,6 +190,7 @@ from .style import (
190
190
  AutoCapitalize,
191
191
  Color,
192
192
  Dimension,
193
+ Display,
193
194
  EdgeInsets,
194
195
  FlexDirection,
195
196
  FlexWrap,
@@ -198,6 +199,7 @@ from .style import (
198
199
  KeyboardType,
199
200
  LayoutDirection,
200
201
  Overflow,
202
+ PointerEvents,
201
203
  Position,
202
204
  ReturnKeyType,
203
205
  ScaleType,
@@ -207,6 +209,8 @@ from .style import (
207
209
  StyleSheet,
208
210
  TextAlign,
209
211
  TextDecoration,
212
+ TextTransform,
213
+ Theme,
210
214
  ThemeContext,
211
215
  TransformSpec,
212
216
  default_theme,
@@ -314,6 +318,7 @@ __all__ = [
314
318
  "DEFAULT_DARK_THEME",
315
319
  "DEFAULT_LIGHT_THEME",
316
320
  "Dimension",
321
+ "Display",
317
322
  "EdgeInsets",
318
323
  "FlexDirection",
319
324
  "FlexWrap",
@@ -322,6 +327,7 @@ __all__ = [
322
327
  "KeyboardType",
323
328
  "LayoutDirection",
324
329
  "Overflow",
330
+ "PointerEvents",
325
331
  "Position",
326
332
  "ReturnKeyType",
327
333
  "ScaleType",
@@ -331,6 +337,8 @@ __all__ = [
331
337
  "StyleSheet",
332
338
  "TextAlign",
333
339
  "TextDecoration",
340
+ "TextTransform",
341
+ "Theme",
334
342
  "ThemeContext",
335
343
  "TransformSpec",
336
344
  "default_theme",
pythonnative/alerts.py CHANGED
@@ -52,16 +52,13 @@ async def _present(
52
52
  "default"|"cancel"|"destructive"}`` dicts. The module resolves with
53
53
  the index the user picked, or ``-1`` if the dialog was dismissed
54
54
  without a selection. Off device the
55
- [`DesktopAlert`][pythonnative.native_modules.desktop.DesktopAlert]
55
+ [`FallbackAlert`][pythonnative.native_modules.fallback.FallbackAlert]
56
56
  implementation records the call and answers from the queue set by
57
57
  [`Alert.set_test_response`][pythonnative.alerts.Alert.set_test_response].
58
58
  """
59
- try:
60
- result = await native_module("Alert").call_async(
61
- "present", title=title, message=message, buttons=buttons, style=style
62
- )
63
- except Exception:
64
- return -1
59
+ result = await native_module("Alert").call_async(
60
+ "present", title=title, message=message, buttons=buttons, style=style
61
+ )
65
62
  try:
66
63
  return int(result)
67
64
  except (TypeError, ValueError):
@@ -135,14 +132,9 @@ class Alert:
135
132
  [`choose`][pythonnative.alerts.Alert.choose] and ``await``
136
133
  the result.
137
134
  """
138
- try:
139
- native_module("Alert").call(
140
- "show", title=title, message=message, buttons=[{"label": button, "style": "default"}], style="alert"
141
- )
142
- except Exception:
143
- from . import diagnostics
144
-
145
- diagnostics.swallowed("alerts.Alert.show")
135
+ native_module("Alert").call(
136
+ "show", title=title, message=message, buttons=[{"label": button, "style": "default"}], style="alert"
137
+ )
146
138
 
147
139
  @staticmethod
148
140
  async def confirm(
pythonnative/animated.py CHANGED
@@ -40,7 +40,7 @@ native view the value is attached to
40
40
  callback when the animation settles, updates the
41
41
  [`AnimatedValue`][pythonnative.animated.AnimatedValue], and resolves
42
42
  any awaiting tasks.
43
- - **Declined** (desktop preview, unattached values, callable easings,
43
+ - **Declined** (unattached values, callable easings,
44
44
  values feeding Python-side listeners or derived nodes): a single
45
45
  background thread ticks the animation at ~60 Hz from Python, pushing
46
46
  each frame through ``set_animated_property``. Semantics are
pythonnative/bootstrap.py CHANGED
@@ -8,9 +8,10 @@ import pythonnative.bootstrap; pythonnative.bootstrap.start()
8
8
 
9
9
  [`start`][pythonnative.bootstrap.start] connects the two halves of the
10
10
  bridge (installing the native -> Python callback on iOS), verifies the
11
- protocol version, routes ``print()`` to the console on iOS, and warms
12
- the asyncio runtime. From then on the native runtime drives everything
13
- through ``callback("host", ...)``; see ``docs/concepts/bridge.md``.
11
+ protocol version, routes ``print()`` to the console on iOS, warms the
12
+ asyncio runtime, and, in debug builds, starts the dev client that syncs
13
+ sources from ``pn start``. From then on the native runtime drives
14
+ everything through ``callback("host", ...)``; see ``docs/concepts/bridge.md``.
14
15
  """
15
16
 
16
17
  from __future__ import annotations
@@ -29,8 +30,8 @@ def start(dev: bool = False, strict: bool = False) -> Dict[str, Any]:
29
30
  """Connect the bridge and prepare the runtime.
30
31
 
31
32
  Args:
32
- dev: Enable dev mode (RedBox, validation warnings). Debug
33
- templates pass ``True``; hot reload turns it on as well.
33
+ dev: Enable dev mode (RedBox, validation warnings, the dev
34
+ client). Debug templates pass ``True``.
34
35
  strict: Re-raise the failure after recording it. The templates
35
36
  pass ``True`` so a broken bridge surfaces as a bootstrap
36
37
  error screen with the full traceback.
@@ -59,7 +60,8 @@ def start(dev: bool = False, strict: bool = False) -> Dict[str, Any]:
59
60
  from . import bridge
60
61
 
61
62
  status_["protocol"] = bridge.handshake()
62
- if dev or os.environ.get("PN_DEV") in ("1", "true"):
63
+ dev_mode = bool(dev or os.environ.get("PN_DEV") in ("1", "true"))
64
+ if dev_mode:
63
65
  from . import diagnostics
64
66
 
65
67
  diagnostics.set_dev_mode(True)
@@ -73,6 +75,13 @@ def start(dev: bool = False, strict: bool = False) -> Dict[str, Any]:
73
75
  from .native_views import get_registry
74
76
 
75
77
  get_registry()
78
+ if dev_mode:
79
+ # Debug builds are dev clients: connect to `pn start` when
80
+ # the build (or a remembered connection) names a server.
81
+ from . import devclient
82
+
83
+ client = devclient.start_if_configured()
84
+ status_["dev_server"] = client.url if client is not None else None
76
85
  except Exception as exc:
77
86
  status_["error"] = f"{type(exc).__name__}: {exc}"
78
87
  print(f"[pn.bootstrap] start failed: {exc!r}", file=sys.stderr)
@@ -7,11 +7,13 @@ Everything that crosses into native code goes through a
7
7
  [`native_callback`][pythonnative.bridge.native_callback]. The protocol
8
8
  is documented in ``docs/concepts/bridge.md``.
9
9
 
10
- Off-device (tests, ``pn preview``) there is no transport; the desktop
11
- registry renders with Tkinter and native modules fall back to their
12
- Python implementations. Tests that want to exercise the bridge itself
13
- install a [`FakeTransport`][pythonnative.bridge.fake.FakeTransport]
14
- with [`set_transport`][pythonnative.bridge.set_transport].
10
+ Under ``pn preview`` the native side is a browser page, reached through
11
+ [`WebTransport`][pythonnative.bridge.web.WebTransport]; the preview
12
+ installs it with [`set_transport`][pythonnative.bridge.set_transport]
13
+ before any screen mounts. In headless tests there is no transport at
14
+ all: native modules fall back to their Python implementations, and
15
+ tests that want to exercise the bridge itself install a
16
+ [`FakeTransport`][pythonnative.bridge.fake.FakeTransport].
15
17
  """
16
18
 
17
19
  from __future__ import annotations
@@ -74,7 +76,7 @@ _explicit = False
74
76
 
75
77
 
76
78
  def _create_platform_transport() -> Optional[Transport]:
77
- from ..utils import IS_ANDROID, IS_IOS
79
+ from ..utils import IS_ANDROID, IS_IOS, IS_WEB
78
80
 
79
81
  if IS_IOS:
80
82
  from .ios import IOSTransport
@@ -86,6 +88,11 @@ def _create_platform_transport() -> Optional[Transport]:
86
88
  from .android import AndroidTransport
87
89
 
88
90
  return AndroidTransport()
91
+ if IS_WEB:
92
+ raise RuntimeError(
93
+ "PN_PLATFORM=web is set but no browser preview transport is installed. "
94
+ "Start the app with `pn preview` (or `pn start`), which installs the WebTransport."
95
+ )
89
96
  return None
90
97
 
91
98
 
@@ -104,7 +111,7 @@ def get_transport() -> Transport:
104
111
  if created is None:
105
112
  raise RuntimeError(
106
113
  "No native bridge is available on this platform (running off-device). "
107
- "Use `pn preview` for the desktop renderer or install a FakeTransport in tests."
114
+ "Use `pn preview` for the browser renderer or install a FakeTransport in tests."
108
115
  )
109
116
  _transport = created
110
117
  return _transport
@@ -116,9 +123,9 @@ def has_transport() -> bool:
116
123
  return True
117
124
  if _explicit:
118
125
  return False
119
- from ..utils import IS_ANDROID, IS_IOS
126
+ from ..utils import IS_ANDROID, IS_IOS, IS_WEB
120
127
 
121
- return bool(IS_IOS or IS_ANDROID)
128
+ return bool(IS_IOS or IS_ANDROID or IS_WEB)
122
129
 
123
130
 
124
131
  def set_transport(transport: Optional[Transport]) -> None:
@@ -104,7 +104,7 @@ def encode_transaction(
104
104
 
105
105
  Args:
106
106
  ops: Ordered mutations from the reconciler.
107
- prop_filter: Unused hook kept for symmetry with the desktop
107
+ prop_filter: Unused hook kept for symmetry with the test
108
108
  registry; reserved for per-type prop rewriting.
109
109
 
110
110
  Returns: