pythonnative 0.22.1__py3-none-any.whl → 0.24.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.
- pythonnative/__init__.py +43 -50
- pythonnative/animated.py +1 -1
- pythonnative/appearance.py +124 -0
- pythonnative/cli/pn.py +3 -3
- pythonnative/components.py +873 -466
- pythonnative/diagnostics.py +214 -0
- pythonnative/element.py +5 -2
- pythonnative/events.py +13 -8
- pythonnative/hooks.py +454 -49
- pythonnative/hot_reload.py +9 -1
- pythonnative/images.py +196 -0
- pythonnative/mutations.py +3 -12
- pythonnative/native_views/__init__.py +1 -7
- pythonnative/native_views/android.py +651 -46
- pythonnative/native_views/desktop.py +116 -20
- pythonnative/native_views/ios.py +974 -52
- pythonnative/navigation.py +41 -17
- pythonnative/preview.py +74 -7
- pythonnative/project/config.py +1 -9
- pythonnative/reconciler.py +863 -441
- pythonnative/screen.py +409 -27
- pythonnative/storage.py +3 -3
- pythonnative/style.py +148 -6
- pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +2 -1
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNAccessibilityDelegate.kt +47 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNBorderDrawable.kt +67 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNVirtualListView.java +172 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/ScreenFragment.kt +22 -0
- pythonnative/virtual_rows.py +137 -0
- {pythonnative-0.22.1.dist-info → pythonnative-0.24.0.dist-info}/METADATA +5 -4
- {pythonnative-0.22.1.dist-info → pythonnative-0.24.0.dist-info}/RECORD +35 -28
- {pythonnative-0.22.1.dist-info → pythonnative-0.24.0.dist-info}/WHEEL +1 -1
- {pythonnative-0.22.1.dist-info → pythonnative-0.24.0.dist-info}/entry_points.txt +0 -0
- {pythonnative-0.22.1.dist-info → pythonnative-0.24.0.dist-info}/licenses/LICENSE +0 -0
- {pythonnative-0.22.1.dist-info → pythonnative-0.24.0.dist-info}/top_level.txt +0 -0
pythonnative/__init__.py
CHANGED
|
@@ -54,87 +54,72 @@ Example:
|
|
|
54
54
|
count, set_count = pn.use_state(0)
|
|
55
55
|
return pn.Column(
|
|
56
56
|
pn.Text(f"Count: {count}", style=pn.style(font_size=24)),
|
|
57
|
-
pn.Button("+",
|
|
57
|
+
pn.Button("+", on_press=lambda: set_count(count + 1)),
|
|
58
58
|
style=pn.style(spacing=12),
|
|
59
59
|
)
|
|
60
60
|
```
|
|
61
61
|
"""
|
|
62
62
|
|
|
63
|
-
__version__ = "0.
|
|
63
|
+
__version__ = "0.24.0"
|
|
64
64
|
|
|
65
|
-
from . import gestures, runtime, sdk
|
|
65
|
+
from . import appearance, diagnostics, gestures, images, runtime, sdk
|
|
66
66
|
from .alerts import Alert
|
|
67
67
|
from .animated import Animated, AnimatedValue, use_animated_value
|
|
68
68
|
from .components import (
|
|
69
69
|
ActivityIndicator,
|
|
70
|
-
ActivityIndicatorProps,
|
|
71
70
|
Button,
|
|
72
|
-
ButtonProps,
|
|
73
71
|
Checkbox,
|
|
74
|
-
CheckboxProps,
|
|
75
72
|
Column,
|
|
76
73
|
DatePicker,
|
|
77
|
-
DatePickerProps,
|
|
78
74
|
ErrorBoundary,
|
|
79
75
|
FlatList,
|
|
80
76
|
Fragment,
|
|
81
77
|
Image,
|
|
82
78
|
ImageBackground,
|
|
83
|
-
ImageBackgroundProps,
|
|
84
|
-
ImageProps,
|
|
85
79
|
KeyboardAvoidingView,
|
|
86
|
-
|
|
80
|
+
ListController,
|
|
87
81
|
Modal,
|
|
88
|
-
ModalProps,
|
|
89
82
|
Picker,
|
|
90
|
-
|
|
83
|
+
Portal,
|
|
91
84
|
Pressable,
|
|
92
|
-
PressableProps,
|
|
93
85
|
ProgressBar,
|
|
94
|
-
ProgressBarProps,
|
|
95
86
|
RefreshControl,
|
|
96
87
|
Row,
|
|
97
88
|
SafeAreaView,
|
|
98
|
-
SafeAreaViewProps,
|
|
99
89
|
ScrollView,
|
|
100
|
-
ScrollViewProps,
|
|
101
90
|
SectionList,
|
|
102
91
|
SegmentedControl,
|
|
103
|
-
SegmentedControlProps,
|
|
104
92
|
Slider,
|
|
105
|
-
SliderProps,
|
|
106
93
|
Spacer,
|
|
107
|
-
SpacerProps,
|
|
108
94
|
StatusBar,
|
|
109
|
-
StatusBarProps,
|
|
110
95
|
Switch,
|
|
111
|
-
SwitchProps,
|
|
112
96
|
Text,
|
|
113
97
|
TextInput,
|
|
114
|
-
TextInputProps,
|
|
115
|
-
TextProps,
|
|
116
98
|
TouchableOpacity,
|
|
117
|
-
TouchableOpacityProps,
|
|
118
99
|
View,
|
|
119
|
-
ViewProps,
|
|
120
100
|
WebView,
|
|
121
|
-
WebViewProps,
|
|
122
101
|
)
|
|
102
|
+
from .diagnostics import HookOrderError
|
|
123
103
|
from .element import Element
|
|
124
104
|
from .hooks import (
|
|
125
105
|
MutationCall,
|
|
126
106
|
MutationState,
|
|
127
107
|
Provider,
|
|
128
108
|
QueryResult,
|
|
109
|
+
Ref,
|
|
129
110
|
batch_updates,
|
|
130
111
|
component,
|
|
131
112
|
create_context,
|
|
132
113
|
memo,
|
|
133
114
|
use_async_effect,
|
|
115
|
+
use_back_handler,
|
|
134
116
|
use_callback,
|
|
117
|
+
use_color_scheme,
|
|
135
118
|
use_context,
|
|
136
119
|
use_effect,
|
|
120
|
+
use_imperative_handle,
|
|
137
121
|
use_keyboard_height,
|
|
122
|
+
use_layout_effect,
|
|
138
123
|
use_memo,
|
|
139
124
|
use_mutation,
|
|
140
125
|
use_navigation,
|
|
@@ -166,6 +151,7 @@ from .native_modules import (
|
|
|
166
151
|
)
|
|
167
152
|
from .navigation import (
|
|
168
153
|
NavigationContainer,
|
|
154
|
+
ScreenOptions,
|
|
169
155
|
create_drawer_navigator,
|
|
170
156
|
create_stack_navigator,
|
|
171
157
|
create_tab_navigator,
|
|
@@ -185,6 +171,10 @@ from .sdk import (
|
|
|
185
171
|
)
|
|
186
172
|
from .storage import AsyncStorage, use_persisted_state
|
|
187
173
|
from .style import (
|
|
174
|
+
DEFAULT_DARK_THEME,
|
|
175
|
+
DEFAULT_LIGHT_THEME,
|
|
176
|
+
AccessibilityState,
|
|
177
|
+
AlignContent,
|
|
188
178
|
AlignItems,
|
|
189
179
|
AlignSelf,
|
|
190
180
|
AutoCapitalize,
|
|
@@ -192,9 +182,11 @@ from .style import (
|
|
|
192
182
|
Dimension,
|
|
193
183
|
EdgeInsets,
|
|
194
184
|
FlexDirection,
|
|
185
|
+
FlexWrap,
|
|
195
186
|
FontWeight,
|
|
196
187
|
JustifyContent,
|
|
197
188
|
KeyboardType,
|
|
189
|
+
LayoutDirection,
|
|
198
190
|
Overflow,
|
|
199
191
|
Position,
|
|
200
192
|
ReturnKeyType,
|
|
@@ -207,8 +199,10 @@ from .style import (
|
|
|
207
199
|
TextDecoration,
|
|
208
200
|
ThemeContext,
|
|
209
201
|
TransformSpec,
|
|
202
|
+
default_theme,
|
|
210
203
|
resolve_style,
|
|
211
204
|
style,
|
|
205
|
+
use_theme,
|
|
212
206
|
)
|
|
213
207
|
|
|
214
208
|
__all__ = [
|
|
@@ -224,8 +218,10 @@ __all__ = [
|
|
|
224
218
|
"Image",
|
|
225
219
|
"ImageBackground",
|
|
226
220
|
"KeyboardAvoidingView",
|
|
221
|
+
"ListController",
|
|
227
222
|
"Modal",
|
|
228
223
|
"Picker",
|
|
224
|
+
"Portal",
|
|
229
225
|
"Pressable",
|
|
230
226
|
"ProgressBar",
|
|
231
227
|
"RefreshControl",
|
|
@@ -243,30 +239,6 @@ __all__ = [
|
|
|
243
239
|
"TouchableOpacity",
|
|
244
240
|
"View",
|
|
245
241
|
"WebView",
|
|
246
|
-
# Built-in Props dataclasses
|
|
247
|
-
"ActivityIndicatorProps",
|
|
248
|
-
"ButtonProps",
|
|
249
|
-
"CheckboxProps",
|
|
250
|
-
"DatePickerProps",
|
|
251
|
-
"ImageBackgroundProps",
|
|
252
|
-
"ImageProps",
|
|
253
|
-
"KeyboardAvoidingViewProps",
|
|
254
|
-
"ModalProps",
|
|
255
|
-
"PickerProps",
|
|
256
|
-
"PressableProps",
|
|
257
|
-
"ProgressBarProps",
|
|
258
|
-
"SafeAreaViewProps",
|
|
259
|
-
"ScrollViewProps",
|
|
260
|
-
"SegmentedControlProps",
|
|
261
|
-
"SliderProps",
|
|
262
|
-
"SpacerProps",
|
|
263
|
-
"StatusBarProps",
|
|
264
|
-
"SwitchProps",
|
|
265
|
-
"TextInputProps",
|
|
266
|
-
"TextProps",
|
|
267
|
-
"TouchableOpacityProps",
|
|
268
|
-
"ViewProps",
|
|
269
|
-
"WebViewProps",
|
|
270
242
|
# Core
|
|
271
243
|
"Element",
|
|
272
244
|
"create_screen",
|
|
@@ -278,12 +250,17 @@ __all__ = [
|
|
|
278
250
|
"MutationCall",
|
|
279
251
|
"MutationState",
|
|
280
252
|
"QueryResult",
|
|
253
|
+
"Ref",
|
|
281
254
|
"use_async_effect",
|
|
255
|
+
"use_back_handler",
|
|
282
256
|
"use_callback",
|
|
257
|
+
"use_color_scheme",
|
|
283
258
|
"use_context",
|
|
284
259
|
"use_effect",
|
|
285
260
|
"use_focus_effect",
|
|
261
|
+
"use_imperative_handle",
|
|
286
262
|
"use_keyboard_height",
|
|
263
|
+
"use_layout_effect",
|
|
287
264
|
"use_memo",
|
|
288
265
|
"use_mutation",
|
|
289
266
|
"use_navigation",
|
|
@@ -298,20 +275,27 @@ __all__ = [
|
|
|
298
275
|
"Provider",
|
|
299
276
|
# Navigation
|
|
300
277
|
"NavigationContainer",
|
|
278
|
+
"ScreenOptions",
|
|
301
279
|
"create_drawer_navigator",
|
|
302
280
|
"create_stack_navigator",
|
|
303
281
|
"create_tab_navigator",
|
|
304
282
|
# Styling - typed primitives
|
|
283
|
+
"AccessibilityState",
|
|
284
|
+
"AlignContent",
|
|
305
285
|
"AlignItems",
|
|
306
286
|
"AlignSelf",
|
|
307
287
|
"AutoCapitalize",
|
|
308
288
|
"Color",
|
|
289
|
+
"DEFAULT_DARK_THEME",
|
|
290
|
+
"DEFAULT_LIGHT_THEME",
|
|
309
291
|
"Dimension",
|
|
310
292
|
"EdgeInsets",
|
|
311
293
|
"FlexDirection",
|
|
294
|
+
"FlexWrap",
|
|
312
295
|
"FontWeight",
|
|
313
296
|
"JustifyContent",
|
|
314
297
|
"KeyboardType",
|
|
298
|
+
"LayoutDirection",
|
|
315
299
|
"Overflow",
|
|
316
300
|
"Position",
|
|
317
301
|
"ReturnKeyType",
|
|
@@ -324,8 +308,14 @@ __all__ = [
|
|
|
324
308
|
"TextDecoration",
|
|
325
309
|
"ThemeContext",
|
|
326
310
|
"TransformSpec",
|
|
311
|
+
"default_theme",
|
|
327
312
|
"resolve_style",
|
|
328
313
|
"style",
|
|
314
|
+
"use_theme",
|
|
315
|
+
# Appearance
|
|
316
|
+
"appearance",
|
|
317
|
+
# Image pipeline
|
|
318
|
+
"images",
|
|
329
319
|
# Animation
|
|
330
320
|
"Animated",
|
|
331
321
|
"AnimatedValue",
|
|
@@ -360,6 +350,9 @@ __all__ = [
|
|
|
360
350
|
# Runtime
|
|
361
351
|
"run_async",
|
|
362
352
|
"runtime",
|
|
353
|
+
# Diagnostics
|
|
354
|
+
"HookOrderError",
|
|
355
|
+
"diagnostics",
|
|
363
356
|
# Platform
|
|
364
357
|
"Platform",
|
|
365
358
|
# Custom-component SDK
|
pythonnative/animated.py
CHANGED
|
@@ -834,7 +834,7 @@ def _make_animated_factory(
|
|
|
834
834
|
ref = use_ref(None)
|
|
835
835
|
|
|
836
836
|
def _attach_bindings() -> Callable[[], None]:
|
|
837
|
-
tag = ref.
|
|
837
|
+
tag = ref._pn_tag
|
|
838
838
|
if tag is None:
|
|
839
839
|
return lambda: None
|
|
840
840
|
detachers = [value.attach(tag, _animated_prop_name(prop)) for prop, value in bindings.items()]
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""System color-scheme (light / dark mode) tracking.
|
|
2
|
+
|
|
3
|
+
The platform screen host publishes the operating system's current
|
|
4
|
+
appearance here (Android: ``Configuration.uiMode``; iOS:
|
|
5
|
+
``UITraitCollection.userInterfaceStyle``), and components read it back
|
|
6
|
+
through [`use_color_scheme`][pythonnative.use_color_scheme] or
|
|
7
|
+
[`use_theme`][pythonnative.use_theme], both of which re-render when
|
|
8
|
+
the scheme changes.
|
|
9
|
+
|
|
10
|
+
Apps can also *override* the scheme (e.g. an in-app appearance
|
|
11
|
+
setting) with [`set_color_scheme`][pythonnative.appearance.set_color_scheme];
|
|
12
|
+
the override wins over the system value until cleared with ``None``.
|
|
13
|
+
|
|
14
|
+
Example:
|
|
15
|
+
>>> from pythonnative import appearance
|
|
16
|
+
>>> appearance.get_color_scheme()
|
|
17
|
+
'light'
|
|
18
|
+
>>> appearance.set_color_scheme("dark") # app-level override
|
|
19
|
+
>>> appearance.get_color_scheme()
|
|
20
|
+
'dark'
|
|
21
|
+
>>> appearance.set_color_scheme(None) # follow the system again
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import threading
|
|
27
|
+
from typing import Callable, List, Literal, Optional
|
|
28
|
+
|
|
29
|
+
ColorScheme = Literal["light", "dark"]
|
|
30
|
+
"""The two supported appearance values."""
|
|
31
|
+
|
|
32
|
+
_system_scheme: str = "light"
|
|
33
|
+
_override_scheme: Optional[str] = None
|
|
34
|
+
|
|
35
|
+
_subscribers: List[Callable[[], None]] = []
|
|
36
|
+
_subscribers_lock = threading.Lock()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _notify_subscribers() -> None:
|
|
40
|
+
"""Invoke every registered subscriber, swallowing exceptions."""
|
|
41
|
+
with _subscribers_lock:
|
|
42
|
+
callbacks = list(_subscribers)
|
|
43
|
+
for cb in callbacks:
|
|
44
|
+
try:
|
|
45
|
+
cb()
|
|
46
|
+
except Exception:
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def subscribe(callback: Callable[[], None]) -> Callable[[], None]:
|
|
51
|
+
"""Register ``callback`` to fire whenever the effective scheme changes.
|
|
52
|
+
|
|
53
|
+
Returns an unsubscribe function. Threadsafe.
|
|
54
|
+
"""
|
|
55
|
+
with _subscribers_lock:
|
|
56
|
+
_subscribers.append(callback)
|
|
57
|
+
|
|
58
|
+
def _unsub() -> None:
|
|
59
|
+
with _subscribers_lock:
|
|
60
|
+
try:
|
|
61
|
+
_subscribers.remove(callback)
|
|
62
|
+
except ValueError:
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
return _unsub
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _coerce(scheme: object) -> Optional[str]:
|
|
69
|
+
if scheme in ("light", "dark"):
|
|
70
|
+
return str(scheme)
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def set_system_color_scheme(scheme: str) -> None:
|
|
75
|
+
"""Publish the operating system's current scheme.
|
|
76
|
+
|
|
77
|
+
Called by the platform screen host on create/resume and whenever
|
|
78
|
+
the system reports an appearance change. Invalid values are
|
|
79
|
+
ignored. Subscribers are only notified when the *effective* scheme
|
|
80
|
+
(after any app override) actually changes.
|
|
81
|
+
"""
|
|
82
|
+
global _system_scheme
|
|
83
|
+
coerced = _coerce(scheme)
|
|
84
|
+
if coerced is None or coerced == _system_scheme:
|
|
85
|
+
return
|
|
86
|
+
effective_before = get_color_scheme()
|
|
87
|
+
_system_scheme = coerced
|
|
88
|
+
if get_color_scheme() != effective_before:
|
|
89
|
+
_notify_subscribers()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def set_color_scheme(scheme: Optional[str]) -> None:
|
|
93
|
+
"""Set (or clear) the app-level scheme override.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
scheme: ``"light"`` or ``"dark"`` to force that appearance
|
|
97
|
+
regardless of the system setting, or ``None`` to follow
|
|
98
|
+
the system again.
|
|
99
|
+
"""
|
|
100
|
+
global _override_scheme
|
|
101
|
+
coerced = _coerce(scheme) if scheme is not None else None
|
|
102
|
+
if scheme is not None and coerced is None:
|
|
103
|
+
return
|
|
104
|
+
effective_before = get_color_scheme()
|
|
105
|
+
_override_scheme = coerced
|
|
106
|
+
if get_color_scheme() != effective_before:
|
|
107
|
+
_notify_subscribers()
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def get_color_scheme() -> str:
|
|
111
|
+
"""Return the effective scheme: the app override if set, else the system value."""
|
|
112
|
+
return _override_scheme if _override_scheme is not None else _system_scheme
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def get_system_color_scheme() -> str:
|
|
116
|
+
"""Return the system-reported scheme, ignoring any app override."""
|
|
117
|
+
return _system_scheme
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def reset_color_scheme() -> None:
|
|
121
|
+
"""Reset to system ``"light"`` with no override. Intended for tests."""
|
|
122
|
+
global _system_scheme, _override_scheme
|
|
123
|
+
_system_scheme = "light"
|
|
124
|
+
_override_scheme = None
|
pythonnative/cli/pn.py
CHANGED
|
@@ -59,8 +59,8 @@ def HomeScreen():
|
|
|
59
59
|
pn.Column(
|
|
60
60
|
pn.Text("Hello from PythonNative!", style={"font_size": 24, "bold": True}),
|
|
61
61
|
pn.Text(f"Tapped {count} times"),
|
|
62
|
-
pn.Button("Tap me",
|
|
63
|
-
pn.Button("Open detail",
|
|
62
|
+
pn.Button("Tap me", on_press=lambda: set_count(count + 1)),
|
|
63
|
+
pn.Button("Open detail", on_press=lambda: nav.navigate("Detail", {"count": count})),
|
|
64
64
|
style={"spacing": 12, "padding": 16, "align_items": "stretch"},
|
|
65
65
|
)
|
|
66
66
|
)
|
|
@@ -72,7 +72,7 @@ def DetailScreen():
|
|
|
72
72
|
params = pn.use_route()
|
|
73
73
|
return pn.Column(
|
|
74
74
|
pn.Text(f"Detail: count was {params.get('count', 0)}", style={"font_size": 20}),
|
|
75
|
-
pn.Button("Back",
|
|
75
|
+
pn.Button("Back", on_press=nav.go_back),
|
|
76
76
|
style={"spacing": 12, "padding": 16},
|
|
77
77
|
)
|
|
78
78
|
|