pythonnative 0.3.0__py3-none-any.whl → 0.5.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 +45 -65
- pythonnative/cli/pn.py +16 -10
- pythonnative/components.py +241 -0
- pythonnative/element.py +47 -0
- pythonnative/native_views.py +800 -0
- pythonnative/page.py +321 -249
- pythonnative/reconciler.py +129 -0
- pythonnative/templates/android_template/app/build.gradle +2 -2
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PageFragment.kt +2 -1
- pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml +1 -1
- pythonnative/templates/android_template/build.gradle +3 -3
- pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +1 -1
- pythonnative/utils.py +21 -29
- pythonnative-0.5.0.dist-info/METADATA +161 -0
- {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/RECORD +19 -39
- {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/WHEEL +1 -1
- {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/licenses/LICENSE +1 -1
- pythonnative/activity_indicator_view.py +0 -71
- pythonnative/button.py +0 -109
- pythonnative/date_picker.py +0 -72
- pythonnative/image_view.py +0 -76
- pythonnative/label.py +0 -66
- pythonnative/list_view.py +0 -73
- pythonnative/material_activity_indicator_view.py +0 -69
- pythonnative/material_button.py +0 -65
- pythonnative/material_date_picker.py +0 -85
- pythonnative/material_progress_view.py +0 -66
- pythonnative/material_search_bar.py +0 -65
- pythonnative/material_switch.py +0 -65
- pythonnative/material_time_picker.py +0 -72
- pythonnative/picker_view.py +0 -65
- pythonnative/progress_view.py +0 -68
- pythonnative/scroll_view.py +0 -63
- pythonnative/search_bar.py +0 -65
- pythonnative/stack_view.py +0 -60
- pythonnative/switch.py +0 -66
- pythonnative/text_field.py +0 -67
- pythonnative/text_view.py +0 -70
- pythonnative/time_picker.py +0 -73
- pythonnative/view.py +0 -25
- pythonnative/web_view.py +0 -58
- pythonnative-0.3.0.dist-info/METADATA +0 -137
- {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/entry_points.txt +0 -0
- {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Virtual-tree reconciler.
|
|
2
|
+
|
|
3
|
+
Maintains a tree of :class:`VNode` objects (each wrapping a native view)
|
|
4
|
+
and diffs incoming :class:`Element` trees to apply the minimal set of
|
|
5
|
+
native mutations.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Any, List, Optional
|
|
9
|
+
|
|
10
|
+
from .element import Element
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class VNode:
|
|
14
|
+
"""A mounted element paired with its native view and child VNodes."""
|
|
15
|
+
|
|
16
|
+
__slots__ = ("element", "native_view", "children")
|
|
17
|
+
|
|
18
|
+
def __init__(self, element: Element, native_view: Any, children: List["VNode"]) -> None:
|
|
19
|
+
self.element = element
|
|
20
|
+
self.native_view = native_view
|
|
21
|
+
self.children = children
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Reconciler:
|
|
25
|
+
"""Create, diff, and patch native view trees from Element descriptors.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
backend:
|
|
30
|
+
An object implementing the :class:`NativeViewRegistry` protocol
|
|
31
|
+
(``create_view``, ``update_view``, ``add_child``, ``remove_child``,
|
|
32
|
+
``insert_child``).
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, backend: Any) -> None:
|
|
36
|
+
self.backend = backend
|
|
37
|
+
self._tree: Optional[VNode] = None
|
|
38
|
+
|
|
39
|
+
# ------------------------------------------------------------------
|
|
40
|
+
# Public API
|
|
41
|
+
# ------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
def mount(self, element: Element) -> Any:
|
|
44
|
+
"""Build native views from *element* and return the root native view."""
|
|
45
|
+
self._tree = self._create_tree(element)
|
|
46
|
+
return self._tree.native_view
|
|
47
|
+
|
|
48
|
+
def reconcile(self, new_element: Element) -> Any:
|
|
49
|
+
"""Diff *new_element* against the current tree and patch native views.
|
|
50
|
+
|
|
51
|
+
Returns the (possibly replaced) root native view.
|
|
52
|
+
"""
|
|
53
|
+
if self._tree is None:
|
|
54
|
+
self._tree = self._create_tree(new_element)
|
|
55
|
+
return self._tree.native_view
|
|
56
|
+
|
|
57
|
+
self._tree = self._reconcile_node(self._tree, new_element)
|
|
58
|
+
return self._tree.native_view
|
|
59
|
+
|
|
60
|
+
# ------------------------------------------------------------------
|
|
61
|
+
# Internal helpers
|
|
62
|
+
# ------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
def _create_tree(self, element: Element) -> VNode:
|
|
65
|
+
native_view = self.backend.create_view(element.type, element.props)
|
|
66
|
+
children: List[VNode] = []
|
|
67
|
+
for child_el in element.children:
|
|
68
|
+
child_node = self._create_tree(child_el)
|
|
69
|
+
self.backend.add_child(native_view, child_node.native_view, element.type)
|
|
70
|
+
children.append(child_node)
|
|
71
|
+
return VNode(element, native_view, children)
|
|
72
|
+
|
|
73
|
+
def _reconcile_node(self, old: VNode, new_el: Element) -> VNode:
|
|
74
|
+
if old.element.type != new_el.type:
|
|
75
|
+
new_node = self._create_tree(new_el)
|
|
76
|
+
self._destroy_tree(old)
|
|
77
|
+
return new_node
|
|
78
|
+
|
|
79
|
+
changed = self._diff_props(old.element.props, new_el.props)
|
|
80
|
+
if changed:
|
|
81
|
+
self.backend.update_view(old.native_view, old.element.type, changed)
|
|
82
|
+
|
|
83
|
+
self._reconcile_children(old, new_el.children)
|
|
84
|
+
old.element = new_el
|
|
85
|
+
return old
|
|
86
|
+
|
|
87
|
+
def _reconcile_children(self, parent: VNode, new_children: List[Element]) -> None:
|
|
88
|
+
old_children = parent.children
|
|
89
|
+
new_child_nodes: List[VNode] = []
|
|
90
|
+
max_len = max(len(old_children), len(new_children))
|
|
91
|
+
|
|
92
|
+
for i in range(max_len):
|
|
93
|
+
if i >= len(new_children):
|
|
94
|
+
self.backend.remove_child(parent.native_view, old_children[i].native_view, parent.element.type)
|
|
95
|
+
self._destroy_tree(old_children[i])
|
|
96
|
+
elif i >= len(old_children):
|
|
97
|
+
node = self._create_tree(new_children[i])
|
|
98
|
+
self.backend.add_child(parent.native_view, node.native_view, parent.element.type)
|
|
99
|
+
new_child_nodes.append(node)
|
|
100
|
+
else:
|
|
101
|
+
if old_children[i].element.type != new_children[i].type:
|
|
102
|
+
self.backend.remove_child(parent.native_view, old_children[i].native_view, parent.element.type)
|
|
103
|
+
self._destroy_tree(old_children[i])
|
|
104
|
+
node = self._create_tree(new_children[i])
|
|
105
|
+
self.backend.insert_child(parent.native_view, node.native_view, parent.element.type, i)
|
|
106
|
+
new_child_nodes.append(node)
|
|
107
|
+
else:
|
|
108
|
+
updated = self._reconcile_node(old_children[i], new_children[i])
|
|
109
|
+
new_child_nodes.append(updated)
|
|
110
|
+
|
|
111
|
+
parent.children = new_child_nodes
|
|
112
|
+
|
|
113
|
+
def _destroy_tree(self, node: VNode) -> None:
|
|
114
|
+
for child in node.children:
|
|
115
|
+
self._destroy_tree(child)
|
|
116
|
+
node.children = []
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def _diff_props(old: dict, new: dict) -> dict:
|
|
120
|
+
"""Return props that changed (callables always count as changed)."""
|
|
121
|
+
changed = {}
|
|
122
|
+
for key, new_val in new.items():
|
|
123
|
+
old_val = old.get(key)
|
|
124
|
+
if callable(new_val) or old_val != new_val:
|
|
125
|
+
changed[key] = new_val
|
|
126
|
+
for key in old:
|
|
127
|
+
if key not in new:
|
|
128
|
+
changed[key] = None
|
|
129
|
+
return changed
|
|
@@ -6,12 +6,12 @@ plugins {
|
|
|
6
6
|
|
|
7
7
|
android {
|
|
8
8
|
namespace 'com.pythonnative.android_template'
|
|
9
|
-
compileSdk
|
|
9
|
+
compileSdk 34
|
|
10
10
|
|
|
11
11
|
defaultConfig {
|
|
12
12
|
applicationId "com.pythonnative.android_template"
|
|
13
13
|
minSdk 24
|
|
14
|
-
targetSdk
|
|
14
|
+
targetSdk 34
|
|
15
15
|
versionCode 1
|
|
16
16
|
versionName "1.0"
|
|
17
17
|
|
|
@@ -65,7 +65,8 @@ class PageFragment : Fragment() {
|
|
|
65
65
|
utils.callAttr("set_android_fragment_container", view)
|
|
66
66
|
// Now that container exists, invoke on_create so Python can attach its root view
|
|
67
67
|
page?.callAttr("on_create")
|
|
68
|
-
} catch (
|
|
68
|
+
} catch (e: Exception) {
|
|
69
|
+
Log.e(TAG, "on_create failed", e)
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
2
2
|
plugins {
|
|
3
|
-
id 'com.android.application' version '8.
|
|
4
|
-
id 'com.android.library' version '8.
|
|
5
|
-
id 'org.jetbrains.kotlin.android' version '1.
|
|
3
|
+
id 'com.android.application' version '8.2.2' apply false
|
|
4
|
+
id 'com.android.library' version '8.2.2' apply false
|
|
5
|
+
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false
|
|
6
6
|
id 'com.chaquo.python' version '14.0.2' apply false
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#Mon Jun 19 11:09:16 PDT 2023
|
|
2
2
|
distributionBase=GRADLE_USER_HOME
|
|
3
3
|
distributionPath=wrapper/dists
|
|
4
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.
|
|
4
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
|
|
5
5
|
zipStoreBase=GRADLE_USER_HOME
|
|
6
6
|
zipStorePath=wrapper/dists
|
pythonnative/utils.py
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
+
"""Platform detection and shared helpers.
|
|
2
|
+
|
|
3
|
+
This module is imported early by most other modules, so it avoids
|
|
4
|
+
importing platform-specific packages at module level.
|
|
5
|
+
"""
|
|
6
|
+
|
|
1
7
|
import os
|
|
2
8
|
from typing import Any, Optional
|
|
3
9
|
|
|
4
|
-
#
|
|
10
|
+
# ======================================================================
|
|
11
|
+
# Platform detection
|
|
12
|
+
# ======================================================================
|
|
13
|
+
|
|
5
14
|
_is_android: Optional[bool] = None
|
|
6
15
|
|
|
7
16
|
|
|
8
17
|
def _detect_android() -> bool:
|
|
9
|
-
# 1) Direct environment hints commonly present on Android
|
|
10
18
|
env = os.environ
|
|
11
19
|
if "ANDROID_BOOTLOGO" in env or "ANDROID_ROOT" in env or "ANDROID_DATA" in env or "ANDROID_ARGUMENT" in env:
|
|
12
20
|
return True
|
|
13
|
-
|
|
14
|
-
# 2) Chaquopy-specific: the builtin 'java' package is available
|
|
15
21
|
try:
|
|
16
|
-
|
|
17
|
-
from java import jclass
|
|
22
|
+
from java import jclass # noqa: F401
|
|
18
23
|
|
|
19
|
-
_ = jclass # silence linter unused
|
|
20
24
|
return True
|
|
21
25
|
except Exception:
|
|
22
26
|
pass
|
|
23
|
-
|
|
24
|
-
# 3) Last resort: some Android Python dists set os.name/others, but avoid false positives
|
|
25
27
|
return False
|
|
26
28
|
|
|
27
29
|
|
|
@@ -39,53 +41,43 @@ def _get_is_android() -> bool:
|
|
|
39
41
|
|
|
40
42
|
IS_ANDROID: bool = _get_is_android()
|
|
41
43
|
|
|
42
|
-
#
|
|
44
|
+
# ======================================================================
|
|
45
|
+
# Android context management
|
|
46
|
+
# ======================================================================
|
|
47
|
+
|
|
43
48
|
_android_context: Any = None
|
|
44
49
|
_android_fragment_container: Any = None
|
|
45
50
|
|
|
46
51
|
|
|
47
52
|
def set_android_context(context: Any) -> None:
|
|
48
|
-
"""Record the current Android Activity/Context for
|
|
49
|
-
|
|
50
|
-
On Android, Python UI components require a Context to create native views.
|
|
51
|
-
We capture it when a Page is constructed from the host Activity so component
|
|
52
|
-
constructors can be platform-consistent and avoid explicit context params.
|
|
53
|
-
"""
|
|
54
|
-
|
|
53
|
+
"""Record the current Android Activity/Context for view construction."""
|
|
55
54
|
global _android_context
|
|
56
55
|
_android_context = context
|
|
57
56
|
|
|
58
57
|
|
|
59
58
|
def set_android_fragment_container(container_view: Any) -> None:
|
|
60
|
-
"""Record the current Fragment root container ViewGroup
|
|
61
|
-
|
|
62
|
-
The current Page's `set_root_view` will attach its native view to this container.
|
|
63
|
-
"""
|
|
59
|
+
"""Record the current Fragment root container ViewGroup."""
|
|
64
60
|
global _android_fragment_container
|
|
65
61
|
_android_fragment_container = container_view
|
|
66
62
|
|
|
67
63
|
|
|
68
64
|
def get_android_context() -> Any:
|
|
69
|
-
"""Return the
|
|
70
|
-
|
|
65
|
+
"""Return the current Android Activity/Context."""
|
|
71
66
|
if not IS_ANDROID:
|
|
72
67
|
raise RuntimeError("get_android_context() called on non-Android platform")
|
|
73
68
|
if _android_context is None:
|
|
74
69
|
raise RuntimeError(
|
|
75
|
-
"Android context
|
|
70
|
+
"Android context not set. Ensure Page is initialized from an Activity before constructing views."
|
|
76
71
|
)
|
|
77
72
|
return _android_context
|
|
78
73
|
|
|
79
74
|
|
|
80
75
|
def get_android_fragment_container() -> Any:
|
|
81
|
-
"""Return the
|
|
82
|
-
|
|
83
|
-
This is set by the host `PageFragment` when its view is created.
|
|
84
|
-
"""
|
|
76
|
+
"""Return the current Fragment container ViewGroup."""
|
|
85
77
|
if not IS_ANDROID:
|
|
86
78
|
raise RuntimeError("get_android_fragment_container() called on non-Android platform")
|
|
87
79
|
if _android_fragment_container is None:
|
|
88
80
|
raise RuntimeError(
|
|
89
|
-
"Android fragment container
|
|
81
|
+
"Android fragment container not set. Ensure PageFragment has been created before set_root_view."
|
|
90
82
|
)
|
|
91
83
|
return _android_fragment_container
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pythonnative
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Cross-platform native UI toolkit for Android and iOS
|
|
5
|
+
Author: Owen Carey
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Owen Carey
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/pythonnative/pythonnative
|
|
29
|
+
Project-URL: Repository, https://github.com/pythonnative/pythonnative
|
|
30
|
+
Project-URL: Issues, https://github.com/pythonnative/pythonnative/issues
|
|
31
|
+
Project-URL: Documentation, https://docs.pythonnative.com/
|
|
32
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
42
|
+
Requires-Python: >=3.9
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: requests>=2.31.0
|
|
46
|
+
Provides-Extra: ios
|
|
47
|
+
Requires-Dist: rubicon-objc<0.5.0,>=0.4.6; extra == "ios"
|
|
48
|
+
Provides-Extra: docs
|
|
49
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
50
|
+
Requires-Dist: mkdocs-material[imaging]>=9.5; extra == "docs"
|
|
51
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
52
|
+
Provides-Extra: dev
|
|
53
|
+
Requires-Dist: black>=24.0; extra == "dev"
|
|
54
|
+
Requires-Dist: ruff>=0.5; extra == "dev"
|
|
55
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
56
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
57
|
+
Provides-Extra: ci
|
|
58
|
+
Requires-Dist: black>=24.0; extra == "ci"
|
|
59
|
+
Requires-Dist: ruff>=0.5; extra == "ci"
|
|
60
|
+
Requires-Dist: mypy>=1.10; extra == "ci"
|
|
61
|
+
Requires-Dist: pytest>=8.0; extra == "ci"
|
|
62
|
+
Dynamic: license-file
|
|
63
|
+
|
|
64
|
+
<p align="center">
|
|
65
|
+
<img src="docs/assets/banner.jpg" alt="PythonNative" width="800" />
|
|
66
|
+
</p>
|
|
67
|
+
|
|
68
|
+
<p align="center">
|
|
69
|
+
<em>Build native Android and iOS apps in Python.</em>
|
|
70
|
+
</p>
|
|
71
|
+
|
|
72
|
+
<p align="center">
|
|
73
|
+
<a href="https://github.com/pythonnative/pythonnative/actions/workflows/ci.yml"><img src="https://github.com/pythonnative/pythonnative/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
74
|
+
<a href="https://github.com/pythonnative/pythonnative/actions/workflows/release.yml"><img src="https://github.com/pythonnative/pythonnative/actions/workflows/release.yml/badge.svg" alt="Release" /></a>
|
|
75
|
+
<a href="https://pypi.org/project/pythonnative/"><img src="https://img.shields.io/pypi/v/pythonnative" alt="PyPI Version" /></a>
|
|
76
|
+
<a href="https://pypi.org/project/pythonnative/"><img src="https://img.shields.io/pypi/pyversions/pythonnative" alt="Python Versions" /></a>
|
|
77
|
+
<a href="LICENSE"><img src="https://img.shields.io/pypi/l/pythonnative" alt="License: MIT" /></a>
|
|
78
|
+
<a href="https://docs.pythonnative.com/"><img src="https://img.shields.io/website?url=https%3A%2F%2Fdocs.pythonnative.com&label=docs" alt="Docs" /></a>
|
|
79
|
+
</p>
|
|
80
|
+
|
|
81
|
+
<p align="center">
|
|
82
|
+
<a href="https://docs.pythonnative.com/">Documentation</a> ·
|
|
83
|
+
<a href="https://docs.pythonnative.com/getting-started/">Getting Started</a> ·
|
|
84
|
+
<a href="https://docs.pythonnative.com/examples/">Examples</a> ·
|
|
85
|
+
<a href="CONTRIBUTING.md">Contributing</a>
|
|
86
|
+
</p>
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Overview
|
|
91
|
+
|
|
92
|
+
PythonNative is a cross-platform toolkit for building native Android and iOS apps in Python. It provides a **declarative, React-like component model** with automatic reconciliation, powered by Chaquopy on Android and rubicon-objc on iOS. Describe your UI as a tree of elements, manage state with `set_state()`, and let PythonNative handle creating and updating native views.
|
|
93
|
+
|
|
94
|
+
## Features
|
|
95
|
+
|
|
96
|
+
- **Declarative UI:** Describe *what* your UI should look like with element functions (`Text`, `Button`, `Column`, `Row`, etc.). PythonNative creates and updates native views automatically.
|
|
97
|
+
- **Reactive state:** Call `self.set_state(key=value)` and the framework re-renders only what changed — no manual view mutation.
|
|
98
|
+
- **Virtual view tree + reconciler:** Element trees are diffed and patched with minimal native mutations, similar to React's reconciliation.
|
|
99
|
+
- **Direct native bindings:** Python calls platform APIs directly through Chaquopy and rubicon-objc, with no JavaScript bridge.
|
|
100
|
+
- **CLI scaffolding:** `pn init` creates a ready-to-run project; `pn run android` and `pn run ios` build and launch your app.
|
|
101
|
+
- **Navigation:** Push and pop screens with argument passing for multi-page apps.
|
|
102
|
+
- **Bundled templates:** Android Gradle and iOS Xcode templates are included — scaffolding requires no network access.
|
|
103
|
+
|
|
104
|
+
## Quick Start
|
|
105
|
+
|
|
106
|
+
### Installation
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install pythonnative
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Usage
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
import pythonnative as pn
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class MainPage(pn.Page):
|
|
119
|
+
def __init__(self, native_instance):
|
|
120
|
+
super().__init__(native_instance)
|
|
121
|
+
self.state = {"count": 0}
|
|
122
|
+
|
|
123
|
+
def render(self):
|
|
124
|
+
return pn.Column(
|
|
125
|
+
pn.Text(f"Count: {self.state['count']}", font_size=24),
|
|
126
|
+
pn.Button(
|
|
127
|
+
"Tap me",
|
|
128
|
+
on_click=lambda: self.set_state(count=self.state["count"] + 1),
|
|
129
|
+
),
|
|
130
|
+
spacing=12,
|
|
131
|
+
padding=16,
|
|
132
|
+
)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Available Components
|
|
136
|
+
|
|
137
|
+
| Component | Description |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `Text` | Display text |
|
|
140
|
+
| `Button` | Tappable button with `on_click` callback |
|
|
141
|
+
| `Column` / `Row` | Vertical / horizontal layout containers |
|
|
142
|
+
| `ScrollView` | Scrollable wrapper |
|
|
143
|
+
| `TextInput` | Text entry field with `on_change` callback |
|
|
144
|
+
| `Image` | Display images |
|
|
145
|
+
| `Switch` | Toggle with `on_change` callback |
|
|
146
|
+
| `ProgressBar` | Determinate progress (0.0–1.0) |
|
|
147
|
+
| `ActivityIndicator` | Indeterminate loading spinner |
|
|
148
|
+
| `WebView` | Embedded web content |
|
|
149
|
+
| `Spacer` | Empty space |
|
|
150
|
+
|
|
151
|
+
## Documentation
|
|
152
|
+
|
|
153
|
+
Visit [docs.pythonnative.com](https://docs.pythonnative.com/) for the full documentation, including getting started guides, platform-specific instructions for Android and iOS, API reference, and working examples.
|
|
154
|
+
|
|
155
|
+
## Contributing
|
|
156
|
+
|
|
157
|
+
Contributions are welcome. Please see [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions, coding standards, and guidelines for submitting pull requests.
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
[MIT](LICENSE)
|
|
@@ -1,47 +1,27 @@
|
|
|
1
|
-
pythonnative/__init__.py,sha256=
|
|
2
|
-
pythonnative/activity_indicator_view.py,sha256=cYRiyGf5o4dlEy7v6v9yUt212E4cK6Hpn85P7uRIin0,2314
|
|
3
|
-
pythonnative/button.py,sha256=UMwgjb6EhxLQgf3OIXtnoydy5pVEg_1B3fsOp2dLISo,3766
|
|
1
|
+
pythonnative/__init__.py,sha256=E0OXTarwvCIL7DcnuAC8GhLe_EY-7MrQJzwaBH8yVYY,1040
|
|
4
2
|
pythonnative/collection_view.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
pythonnative/
|
|
6
|
-
pythonnative/
|
|
7
|
-
pythonnative/label.py,sha256=DGFspuVOJt1uhjklUzSY-FEN3jAz1ouzWxWib9NXtpg,1881
|
|
8
|
-
pythonnative/list_view.py,sha256=d6U-CTc8BFivLBKQamrdqe5tKZ1menN6u1Wg_JoPE5E,2354
|
|
9
|
-
pythonnative/material_activity_indicator_view.py,sha256=VEbS17GGJKs0jb4GET762XTERMrcbL-JX7IRW2zGNPs,2280
|
|
3
|
+
pythonnative/components.py,sha256=TASfQZS1u_tEF0QvK3E1Uj0Dzb26GA3kvGqOLOpbuxY,6756
|
|
4
|
+
pythonnative/element.py,sha256=7gfdjtCAcz4YBrWmUkve3zeyM_495yiPKAJZEXq2QZM,1453
|
|
10
5
|
pythonnative/material_bottom_navigation_view.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
pythonnative/material_button.py,sha256=_IZ73GOBNIU14Q3zqDEfzhO8pBACI1hRHW7Ouz2IP8Q,2027
|
|
12
|
-
pythonnative/material_date_picker.py,sha256=GoESAVJ0OQupUj4z3nmtjSc06GztnCMIbA-cSnGHJkc,2888
|
|
13
|
-
pythonnative/material_progress_view.py,sha256=TM3yQonjswiWEz_1pad2e5rNzU8wmxjYi5Z9nSyxVCk,2149
|
|
14
|
-
pythonnative/material_search_bar.py,sha256=j8a52smIUAem48AJ693g-aeNswNHpHp3N8M0qnyFjrE,1974
|
|
15
|
-
pythonnative/material_switch.py,sha256=b4K6pKX_RQbmlEiL9nNEZiyOhkvJd5t_m4Ak7RoD7FE,1944
|
|
16
|
-
pythonnative/material_time_picker.py,sha256=bCUcrqsIRbFnt4g-vXfiSuuJrbaJJJjLrSSV_nSdOe8,2319
|
|
17
6
|
pythonnative/material_toolbar.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
pythonnative/
|
|
19
|
-
pythonnative/
|
|
20
|
-
pythonnative/
|
|
21
|
-
pythonnative/
|
|
22
|
-
pythonnative/search_bar.py,sha256=XM6-8hd6NGV-3mvbjtpzjxQcciBWY63C9fK8OBXDAq8,1884
|
|
23
|
-
pythonnative/stack_view.py,sha256=tZielyMPs6yahRRKg_xm-CmXoHQ7LgtdtUQ_Poe7Cxw,1895
|
|
24
|
-
pythonnative/switch.py,sha256=Ca-XJnHMQdqJrLzDMRZGmm2d7J7GIZ_B0F1xxXF85Zs,1896
|
|
25
|
-
pythonnative/text_field.py,sha256=CaLH9erxY0hfKWYkkrF9rTkzgmt7Nax8qjqy-qW_Lmc,1962
|
|
26
|
-
pythonnative/text_view.py,sha256=ZO3Ff_vl4CX1evYYTHZqzgYhpxyvk0bSKI2oIMHW9bs,2140
|
|
27
|
-
pythonnative/time_picker.py,sha256=StGElEDNKnuw1j6iVPyIMwBAyZ5yxEwx2XTzfam2a0M,2258
|
|
28
|
-
pythonnative/utils.py,sha256=0Ub6DDg4uX4ToqoyioQzUJ-_ERzXlJ2r70pBSmeiaYY,3038
|
|
29
|
-
pythonnative/view.py,sha256=PJ0vNdRkyKKtiIxTYYDU0iDvR2r4WG8ZVUmMSeeJhmE,586
|
|
30
|
-
pythonnative/web_view.py,sha256=knBh-R1jP_JChADIo1SqwI5mCbonJuI81Q6vdWot7UU,1775
|
|
7
|
+
pythonnative/native_views.py,sha256=lQK7EMQhG2foBSjonH8iIQbCAkqwPj-QV6xg5e8l9HQ,36357
|
|
8
|
+
pythonnative/page.py,sha256=agVamXmMAbOlYB1MLp7GGosiH75p6C2CYvNPVTWg930,15150
|
|
9
|
+
pythonnative/reconciler.py,sha256=P7KM71BoQGpsU2wsvB-o2QxHAfOy9zXZwCx2lBBLyz8,4976
|
|
10
|
+
pythonnative/utils.py,sha256=IqR_GYknveM_NfAblcaizg9S66hCZfrfiH08HzpOc-4,2537
|
|
31
11
|
pythonnative/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
-
pythonnative/cli/pn.py,sha256=
|
|
33
|
-
pythonnative/templates/android_template/build.gradle,sha256=
|
|
12
|
+
pythonnative/cli/pn.py,sha256=m6mwfS2SAu9W53yhouzFHfnALXtrCQB_04uFXMev5dc,27239
|
|
13
|
+
pythonnative/templates/android_template/build.gradle,sha256=metF5S4LveW05kDE2e-nzVG5rtwe2HESYs-lGNl390A,352
|
|
34
14
|
pythonnative/templates/android_template/gradle.properties,sha256=REPaKLRfQiiVfIV8wYmgwzPWvF1f3bhh_kAMV9p4HME,1358
|
|
35
15
|
pythonnative/templates/android_template/gradlew,sha256=YxNShxF6Hm0SyEWA8fScYdG6AiGOzShmBgXpf5dufWU,5766
|
|
36
16
|
pythonnative/templates/android_template/gradlew.bat,sha256=xGonx5AHdG3lkisXq7YjDWStixujrRWF7lxlQ8KpsSk,2674
|
|
37
17
|
pythonnative/templates/android_template/settings.gradle,sha256=GKZiYUYWsaXxaiKOB65xnOs4jLmf0rhvI_3f8x0ic-o,333
|
|
38
|
-
pythonnative/templates/android_template/app/build.gradle,sha256=
|
|
18
|
+
pythonnative/templates/android_template/app/build.gradle,sha256=JPHjBIEJTzrO4mMXvOdWhlSiIKuwHJmROiQmjr_tPGs,1863
|
|
39
19
|
pythonnative/templates/android_template/app/proguard-rules.pro,sha256=Vv2WDPIl9spA-YKxOl27DYvD394T_3ZCKCXGBw0KGJA,750
|
|
40
20
|
pythonnative/templates/android_template/app/src/androidTest/java/com/pythonnative/android_template/ExampleInstrumentedTest.kt,sha256=Am8Yla3i1eR_ac5FVgPU_RsuMrCbyT79h1BcajGE-zI,693
|
|
41
21
|
pythonnative/templates/android_template/app/src/main/AndroidManifest.xml,sha256=MdWrXxOrwUjnqtDbV952NI4nVF2dTUX9xwSS8chhd9I,940
|
|
42
22
|
pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt,sha256=sqOQ4k--WVyfnrhfNkzqAEQ211uYNPxhmIUXDrIb0zY,1321
|
|
43
23
|
pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/Navigator.kt,sha256=dWOpdJFuGO2CWZZQjYPmSNxljjDyGUuys7-ehHhAqyM,931
|
|
44
|
-
pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PageFragment.kt,sha256=
|
|
24
|
+
pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PageFragment.kt,sha256=fMQUugt9WqUIA9CbE4BafrVdPAbBTR_K_LH6bLed7XQ,4047
|
|
45
25
|
pythonnative/templates/android_template/app/src/main/res/drawable/ic_launcher_background.xml,sha256=7UI8c6b0Ck0pCfCQHmBSezqAfNWeG1WTvKrhgIscYyE,5606
|
|
46
26
|
pythonnative/templates/android_template/app/src/main/res/drawable-v24/ic_launcher_foreground.xml,sha256=AdGmpsEjTrf-Jw0JfrKD1yucla5RGIhvG2VzqtKA8fc,1702
|
|
47
27
|
pythonnative/templates/android_template/app/src/main/res/layout/activity_main.xml,sha256=HIgdCNktb3YoJC8QOTIv-0qZRtMRoPdARK59nyYFO6g,461
|
|
@@ -57,7 +37,7 @@ pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launch
|
|
|
57
37
|
pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp,sha256=MAn60Hn1dy8w7Ndn-YkkNn--D4HDAEjWctT9otXKfRI,5914
|
|
58
38
|
pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp,sha256=-Y_vW8O_5bZWksQK0cuuK-xPr58bJJw5diZ0DbcbYtg,3844
|
|
59
39
|
pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp,sha256=X68DN0XIyILEO7GzctTkpYkMrsY9mJKi51bJVBCLhdw,7778
|
|
60
|
-
pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml,sha256=
|
|
40
|
+
pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml,sha256=vAO2Z45XOCs_O2IPxccPXNQO8gHegOQR4rimdnPG8TI,759
|
|
61
41
|
pythonnative/templates/android_template/app/src/main/res/values/colors.xml,sha256=77cNdJlUmlfOoysA55DvBjLLDJXNru_RaQPIzRLIieQ,147
|
|
62
42
|
pythonnative/templates/android_template/app/src/main/res/values/strings.xml,sha256=y212ihQZPuuegFVU54kyOMwU50J759yi6h1CNAo-RDc,78
|
|
63
43
|
pythonnative/templates/android_template/app/src/main/res/values/themes.xml,sha256=8Amp6l23WClwtnLrfXYI2UFvC1eS6JzMRivN57rQBzw,420
|
|
@@ -66,7 +46,7 @@ pythonnative/templates/android_template/app/src/main/res/xml/backup_rules.xml,sh
|
|
|
66
46
|
pythonnative/templates/android_template/app/src/main/res/xml/data_extraction_rules.xml,sha256=yx_EerSphFMO1g4ObuY4kpwwOCkOfn4LSwOjow--c4E,551
|
|
67
47
|
pythonnative/templates/android_template/app/src/test/java/com/pythonnative/android_template/ExampleUnitTest.kt,sha256=Z6lsNy__lyw7Nzj4GndWK1VLZkgAyX3czP8YX9to7r4,357
|
|
68
48
|
pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.jar,sha256=6ZbUUtJkXnDAHBEUPKLTdCc0oo2iv2HyXIK9wojJ5jc,59203
|
|
69
|
-
pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties,sha256=
|
|
49
|
+
pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties,sha256=nG5CWg_8OmJISSdiSxhYMPnob2ji-O7t0vYmSsW48vc,232
|
|
70
50
|
pythonnative/templates/ios_template/ios_template/AppDelegate.swift,sha256=_6G8GNcw4idXd75qKgQKTDCr45Ez73QB8WTvhBqqcMw,1349
|
|
71
51
|
pythonnative/templates/ios_template/ios_template/Info.plist,sha256=ZQIJGpo8Y2qP0j29xqOsIEGvPpEVICLTAw2NehC5CSo,704
|
|
72
52
|
pythonnative/templates/ios_template/ios_template/SceneDelegate.swift,sha256=lqtre92dc6d6s-f4ieh_M_4xmc_zMGW79j46tDu9cOY,2177
|
|
@@ -81,9 +61,9 @@ pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/x
|
|
|
81
61
|
pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift,sha256=YnwzZx7yXB13xKAXEGNgz17VuhWeqkHTRTtBJ2Vu3_E,1238
|
|
82
62
|
pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift,sha256=l2Pwa50F_rv-qPu2go6e4bQernM6PTQJeNPFl_c4ivY,1387
|
|
83
63
|
pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift,sha256=f5JrG0uVtLMeJQy26Yyz7Om-JUkT220osqcbeIVkj2g,815
|
|
84
|
-
pythonnative-0.
|
|
85
|
-
pythonnative-0.
|
|
86
|
-
pythonnative-0.
|
|
87
|
-
pythonnative-0.
|
|
88
|
-
pythonnative-0.
|
|
89
|
-
pythonnative-0.
|
|
64
|
+
pythonnative-0.5.0.dist-info/licenses/LICENSE,sha256=A69iG7TIAe6KkGQf6xoVHkc5JSZtOr5eRSvC5iuivnI,1067
|
|
65
|
+
pythonnative-0.5.0.dist-info/METADATA,sha256=TVhRDPT4qFBuijk8eEIgDTXugnxw6G-B_1_JBGpMCpM,7256
|
|
66
|
+
pythonnative-0.5.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
67
|
+
pythonnative-0.5.0.dist-info/entry_points.txt,sha256=iUtDawWSAJAEyWTycpZxDuYz73ol31butpzDIEAgPO0,48
|
|
68
|
+
pythonnative-0.5.0.dist-info/top_level.txt,sha256=kT4SEATY2ywzrZ2Pgea6_zxyym44Q_PbOsUoOYjJLFE,13
|
|
69
|
+
pythonnative-0.5.0.dist-info/RECORD,,
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
|
|
3
|
-
from .utils import IS_ANDROID, get_android_context
|
|
4
|
-
from .view import ViewBase
|
|
5
|
-
|
|
6
|
-
# ========================================
|
|
7
|
-
# Base class
|
|
8
|
-
# ========================================
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class ActivityIndicatorViewBase(ABC):
|
|
12
|
-
@abstractmethod
|
|
13
|
-
def __init__(self) -> None:
|
|
14
|
-
super().__init__()
|
|
15
|
-
|
|
16
|
-
@abstractmethod
|
|
17
|
-
def start_animating(self) -> None:
|
|
18
|
-
pass
|
|
19
|
-
|
|
20
|
-
@abstractmethod
|
|
21
|
-
def stop_animating(self) -> None:
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if IS_ANDROID:
|
|
26
|
-
# ========================================
|
|
27
|
-
# Android class
|
|
28
|
-
# https://developer.android.com/reference/android/widget/ProgressBar
|
|
29
|
-
# ========================================
|
|
30
|
-
|
|
31
|
-
from java import jclass
|
|
32
|
-
|
|
33
|
-
class ActivityIndicatorView(ActivityIndicatorViewBase, ViewBase):
|
|
34
|
-
def __init__(self) -> None:
|
|
35
|
-
super().__init__()
|
|
36
|
-
self.native_class = jclass("android.widget.ProgressBar")
|
|
37
|
-
# self.native_instance = self.native_class(context, None, android.R.attr.progressBarStyleLarge)
|
|
38
|
-
context = get_android_context()
|
|
39
|
-
self.native_instance = self.native_class(context)
|
|
40
|
-
self.native_instance.setIndeterminate(True)
|
|
41
|
-
|
|
42
|
-
def start_animating(self) -> None:
|
|
43
|
-
# self.native_instance.setVisibility(android.view.View.VISIBLE)
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
def stop_animating(self) -> None:
|
|
47
|
-
# self.native_instance.setVisibility(android.view.View.GONE)
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
else:
|
|
51
|
-
# ========================================
|
|
52
|
-
# iOS class
|
|
53
|
-
# https://developer.apple.com/documentation/uikit/uiactivityindicatorview
|
|
54
|
-
# ========================================
|
|
55
|
-
|
|
56
|
-
from rubicon.objc import ObjCClass
|
|
57
|
-
|
|
58
|
-
class ActivityIndicatorView(ActivityIndicatorViewBase, ViewBase):
|
|
59
|
-
def __init__(self) -> None:
|
|
60
|
-
super().__init__()
|
|
61
|
-
self.native_class = ObjCClass("UIActivityIndicatorView")
|
|
62
|
-
self.native_instance = self.native_class.alloc().initWithActivityIndicatorStyle_(
|
|
63
|
-
0
|
|
64
|
-
) # 0: UIActivityIndicatorViewStyleLarge
|
|
65
|
-
self.native_instance.hidesWhenStopped = True
|
|
66
|
-
|
|
67
|
-
def start_animating(self) -> None:
|
|
68
|
-
self.native_instance.startAnimating()
|
|
69
|
-
|
|
70
|
-
def stop_animating(self) -> None:
|
|
71
|
-
self.native_instance.stopAnimating()
|