pythonnative 0.4.0__tar.gz → 0.5.0__tar.gz

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 (107) hide show
  1. {pythonnative-0.4.0/src/pythonnative.egg-info → pythonnative-0.5.0}/PKG-INFO +35 -17
  2. {pythonnative-0.4.0 → pythonnative-0.5.0}/README.md +34 -16
  3. {pythonnative-0.4.0 → pythonnative-0.5.0}/pyproject.toml +1 -1
  4. pythonnative-0.5.0/src/pythonnative/__init__.py +54 -0
  5. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/cli/pn.py +15 -14
  6. pythonnative-0.5.0/src/pythonnative/components.py +241 -0
  7. pythonnative-0.5.0/src/pythonnative/element.py +47 -0
  8. pythonnative-0.5.0/src/pythonnative/native_views.py +800 -0
  9. pythonnative-0.5.0/src/pythonnative/page.py +468 -0
  10. pythonnative-0.5.0/src/pythonnative/reconciler.py +129 -0
  11. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PageFragment.kt +2 -1
  12. pythonnative-0.5.0/src/pythonnative/utils.py +83 -0
  13. {pythonnative-0.4.0 → pythonnative-0.5.0/src/pythonnative.egg-info}/PKG-INFO +35 -17
  14. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative.egg-info/SOURCES.txt +7 -24
  15. pythonnative-0.5.0/tests/test_components.py +194 -0
  16. pythonnative-0.5.0/tests/test_element.py +71 -0
  17. pythonnative-0.5.0/tests/test_reconciler.py +280 -0
  18. pythonnative-0.5.0/tests/test_smoke.py +32 -0
  19. pythonnative-0.4.0/src/pythonnative/__init__.py +0 -74
  20. pythonnative-0.4.0/src/pythonnative/activity_indicator_view.py +0 -71
  21. pythonnative-0.4.0/src/pythonnative/button.py +0 -113
  22. pythonnative-0.4.0/src/pythonnative/date_picker.py +0 -76
  23. pythonnative-0.4.0/src/pythonnative/image_view.py +0 -78
  24. pythonnative-0.4.0/src/pythonnative/label.py +0 -133
  25. pythonnative-0.4.0/src/pythonnative/list_view.py +0 -76
  26. pythonnative-0.4.0/src/pythonnative/material_activity_indicator_view.py +0 -71
  27. pythonnative-0.4.0/src/pythonnative/material_button.py +0 -69
  28. pythonnative-0.4.0/src/pythonnative/material_date_picker.py +0 -87
  29. pythonnative-0.4.0/src/pythonnative/material_progress_view.py +0 -70
  30. pythonnative-0.4.0/src/pythonnative/material_search_bar.py +0 -69
  31. pythonnative-0.4.0/src/pythonnative/material_switch.py +0 -69
  32. pythonnative-0.4.0/src/pythonnative/material_time_picker.py +0 -76
  33. pythonnative-0.4.0/src/pythonnative/page.py +0 -396
  34. pythonnative-0.4.0/src/pythonnative/picker_view.py +0 -69
  35. pythonnative-0.4.0/src/pythonnative/progress_view.py +0 -70
  36. pythonnative-0.4.0/src/pythonnative/scroll_view.py +0 -101
  37. pythonnative-0.4.0/src/pythonnative/search_bar.py +0 -69
  38. pythonnative-0.4.0/src/pythonnative/stack_view.py +0 -199
  39. pythonnative-0.4.0/src/pythonnative/switch.py +0 -68
  40. pythonnative-0.4.0/src/pythonnative/text_field.py +0 -132
  41. pythonnative-0.4.0/src/pythonnative/text_view.py +0 -135
  42. pythonnative-0.4.0/src/pythonnative/time_picker.py +0 -77
  43. pythonnative-0.4.0/src/pythonnative/utils.py +0 -91
  44. pythonnative-0.4.0/src/pythonnative/view.py +0 -173
  45. pythonnative-0.4.0/src/pythonnative/web_view.py +0 -60
  46. pythonnative-0.4.0/tests/test_smoke.py +0 -2
  47. {pythonnative-0.4.0 → pythonnative-0.5.0}/LICENSE +0 -0
  48. {pythonnative-0.4.0 → pythonnative-0.5.0}/setup.cfg +0 -0
  49. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/cli/__init__.py +0 -0
  50. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/collection_view.py +0 -0
  51. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/material_bottom_navigation_view.py +0 -0
  52. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/material_toolbar.py +0 -0
  53. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/build.gradle +0 -0
  54. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/proguard-rules.pro +0 -0
  55. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/androidTest/java/com/pythonnative/android_template/ExampleInstrumentedTest.kt +0 -0
  56. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +0 -0
  57. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +0 -0
  58. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/Navigator.kt +0 -0
  59. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/drawable/ic_launcher_background.xml +0 -0
  60. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +0 -0
  61. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/layout/activity_main.xml +0 -0
  62. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +0 -0
  63. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +0 -0
  64. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
  65. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
  66. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
  67. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
  68. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
  69. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
  70. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
  71. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
  72. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
  73. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
  74. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml +0 -0
  75. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/values/colors.xml +0 -0
  76. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/values/strings.xml +0 -0
  77. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/values/themes.xml +0 -0
  78. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/values-night/themes.xml +0 -0
  79. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/xml/backup_rules.xml +0 -0
  80. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/main/res/xml/data_extraction_rules.xml +0 -0
  81. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/app/src/test/java/com/pythonnative/android_template/ExampleUnitTest.kt +0 -0
  82. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/build.gradle +0 -0
  83. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.jar +0 -0
  84. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +0 -0
  85. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/gradle.properties +0 -0
  86. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/gradlew +0 -0
  87. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/gradlew.bat +0 -0
  88. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/android_template/settings.gradle +0 -0
  89. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/AppDelegate.swift +0 -0
  90. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/Assets.xcassets/AccentColor.colorset/Contents.json +0 -0
  91. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -0
  92. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/Assets.xcassets/Contents.json +0 -0
  93. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/Base.lproj/LaunchScreen.storyboard +0 -0
  94. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/Base.lproj/Main.storyboard +0 -0
  95. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/Info.plist +0 -0
  96. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/SceneDelegate.swift +0 -0
  97. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template/ViewController.swift +0 -0
  98. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +0 -0
  99. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  100. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift +0 -0
  101. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift +0 -0
  102. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift +0 -0
  103. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative.egg-info/dependency_links.txt +0 -0
  104. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative.egg-info/entry_points.txt +0 -0
  105. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative.egg-info/requires.txt +0 -0
  106. {pythonnative-0.4.0 → pythonnative-0.5.0}/src/pythonnative.egg-info/top_level.txt +0 -0
  107. {pythonnative-0.4.0 → pythonnative-0.5.0}/tests/test_cli.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonnative
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Cross-platform native UI toolkit for Android and iOS
5
5
  Author: Owen Carey
6
6
  License: MIT License
@@ -89,18 +89,17 @@ Dynamic: license-file
89
89
 
90
90
  ## Overview
91
91
 
92
- PythonNative is a cross-platform toolkit for building native Android and iOS apps in Python. It provides a Pythonic API for native UI components, lifecycle events, and device capabilities, powered by Chaquopy on Android and rubicon-objc on iOS. Write your app once in Python and run it on both platforms with genuinely native interfaces.
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
93
 
94
94
  ## Features
95
95
 
96
- - **Cross-platform native UI:** Build Android and iOS apps from a single Python codebase with truly native rendering.
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.
97
99
  - **Direct native bindings:** Python calls platform APIs directly through Chaquopy and rubicon-objc, with no JavaScript bridge.
98
- - **Unified component API:** Components like `Page`, `StackView`, `Label`, `Button`, and `WebView` share a consistent interface across platforms.
99
- - **CLI scaffolding:** `pn init` creates a ready-to-run project structure; `pn run android` and `pn run ios` build and launch your app.
100
- - **Page lifecycle:** Hooks for `on_create`, `on_start`, `on_resume`, `on_pause`, `on_stop`, and `on_destroy`, with state save and restore.
100
+ - **CLI scaffolding:** `pn init` creates a ready-to-run project; `pn run android` and `pn run ios` build and launch your app.
101
101
  - **Navigation:** Push and pop screens with argument passing for multi-page apps.
102
- - **Rich component set:** Core views (Label, Button, TextField, ImageView, WebView, Switch, DatePicker, and more) plus Material Design variants.
103
- - **Bundled templates:** Android Gradle and iOS Xcode templates are included, so scaffolding requires no network access.
102
+ - **Bundled templates:** Android Gradle and iOS Xcode templates are included scaffolding requires no network access.
104
103
 
105
104
  ## Quick Start
106
105
 
@@ -119,17 +118,36 @@ import pythonnative as pn
119
118
  class MainPage(pn.Page):
120
119
  def __init__(self, native_instance):
121
120
  super().__init__(native_instance)
122
-
123
- def on_create(self):
124
- super().on_create()
125
- stack = pn.StackView()
126
- stack.add_view(pn.Label("Hello from PythonNative!"))
127
- button = pn.Button("Tap me")
128
- button.set_on_click(lambda: print("Button tapped"))
129
- stack.add_view(button)
130
- self.set_root_view(stack)
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
+ )
131
133
  ```
132
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
+
133
151
  ## Documentation
134
152
 
135
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.
@@ -26,18 +26,17 @@
26
26
 
27
27
  ## Overview
28
28
 
29
- PythonNative is a cross-platform toolkit for building native Android and iOS apps in Python. It provides a Pythonic API for native UI components, lifecycle events, and device capabilities, powered by Chaquopy on Android and rubicon-objc on iOS. Write your app once in Python and run it on both platforms with genuinely native interfaces.
29
+ 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.
30
30
 
31
31
  ## Features
32
32
 
33
- - **Cross-platform native UI:** Build Android and iOS apps from a single Python codebase with truly native rendering.
33
+ - **Declarative UI:** Describe *what* your UI should look like with element functions (`Text`, `Button`, `Column`, `Row`, etc.). PythonNative creates and updates native views automatically.
34
+ - **Reactive state:** Call `self.set_state(key=value)` and the framework re-renders only what changed — no manual view mutation.
35
+ - **Virtual view tree + reconciler:** Element trees are diffed and patched with minimal native mutations, similar to React's reconciliation.
34
36
  - **Direct native bindings:** Python calls platform APIs directly through Chaquopy and rubicon-objc, with no JavaScript bridge.
35
- - **Unified component API:** Components like `Page`, `StackView`, `Label`, `Button`, and `WebView` share a consistent interface across platforms.
36
- - **CLI scaffolding:** `pn init` creates a ready-to-run project structure; `pn run android` and `pn run ios` build and launch your app.
37
- - **Page lifecycle:** Hooks for `on_create`, `on_start`, `on_resume`, `on_pause`, `on_stop`, and `on_destroy`, with state save and restore.
37
+ - **CLI scaffolding:** `pn init` creates a ready-to-run project; `pn run android` and `pn run ios` build and launch your app.
38
38
  - **Navigation:** Push and pop screens with argument passing for multi-page apps.
39
- - **Rich component set:** Core views (Label, Button, TextField, ImageView, WebView, Switch, DatePicker, and more) plus Material Design variants.
40
- - **Bundled templates:** Android Gradle and iOS Xcode templates are included, so scaffolding requires no network access.
39
+ - **Bundled templates:** Android Gradle and iOS Xcode templates are included scaffolding requires no network access.
41
40
 
42
41
  ## Quick Start
43
42
 
@@ -56,17 +55,36 @@ import pythonnative as pn
56
55
  class MainPage(pn.Page):
57
56
  def __init__(self, native_instance):
58
57
  super().__init__(native_instance)
59
-
60
- def on_create(self):
61
- super().on_create()
62
- stack = pn.StackView()
63
- stack.add_view(pn.Label("Hello from PythonNative!"))
64
- button = pn.Button("Tap me")
65
- button.set_on_click(lambda: print("Button tapped"))
66
- stack.add_view(button)
67
- self.set_root_view(stack)
58
+ self.state = {"count": 0}
59
+
60
+ def render(self):
61
+ return pn.Column(
62
+ pn.Text(f"Count: {self.state['count']}", font_size=24),
63
+ pn.Button(
64
+ "Tap me",
65
+ on_click=lambda: self.set_state(count=self.state["count"] + 1),
66
+ ),
67
+ spacing=12,
68
+ padding=16,
69
+ )
68
70
  ```
69
71
 
72
+ ### Available Components
73
+
74
+ | Component | Description |
75
+ |---|---|
76
+ | `Text` | Display text |
77
+ | `Button` | Tappable button with `on_click` callback |
78
+ | `Column` / `Row` | Vertical / horizontal layout containers |
79
+ | `ScrollView` | Scrollable wrapper |
80
+ | `TextInput` | Text entry field with `on_change` callback |
81
+ | `Image` | Display images |
82
+ | `Switch` | Toggle with `on_change` callback |
83
+ | `ProgressBar` | Determinate progress (0.0–1.0) |
84
+ | `ActivityIndicator` | Indeterminate loading spinner |
85
+ | `WebView` | Embedded web content |
86
+ | `Spacer` | Empty space |
87
+
70
88
  ## Documentation
71
89
 
72
90
  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.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pythonnative"
7
- version = "0.4.0"
7
+ version = "0.5.0"
8
8
  description = "Cross-platform native UI toolkit for Android and iOS"
9
9
  authors = [
10
10
  { name = "Owen Carey" }
@@ -0,0 +1,54 @@
1
+ """PythonNative — declarative native UI for Android and iOS.
2
+
3
+ Public API::
4
+
5
+ import pythonnative as pn
6
+
7
+ class MainPage(pn.Page):
8
+ def __init__(self, native_instance):
9
+ super().__init__(native_instance)
10
+ self.state = {"count": 0}
11
+
12
+ def render(self):
13
+ return pn.Column(
14
+ pn.Text(f"Count: {self.state['count']}", font_size=24),
15
+ pn.Button("Increment", on_click=lambda: self.set_state(count=self.state["count"] + 1)),
16
+ spacing=12,
17
+ )
18
+ """
19
+
20
+ __version__ = "0.5.0"
21
+
22
+ from .components import (
23
+ ActivityIndicator,
24
+ Button,
25
+ Column,
26
+ Image,
27
+ ProgressBar,
28
+ Row,
29
+ ScrollView,
30
+ Spacer,
31
+ Switch,
32
+ Text,
33
+ TextInput,
34
+ WebView,
35
+ )
36
+ from .element import Element
37
+ from .page import Page
38
+
39
+ __all__ = [
40
+ "ActivityIndicator",
41
+ "Button",
42
+ "Column",
43
+ "Element",
44
+ "Image",
45
+ "Page",
46
+ "ProgressBar",
47
+ "Row",
48
+ "ScrollView",
49
+ "Spacer",
50
+ "Switch",
51
+ "Text",
52
+ "TextInput",
53
+ "WebView",
54
+ ]
@@ -41,7 +41,6 @@ def init_project(args: argparse.Namespace) -> None:
41
41
 
42
42
  os.makedirs(app_dir, exist_ok=True)
43
43
 
44
- # Minimal hello world app scaffold (no bootstrap function; host instantiates Page directly)
45
44
  main_page_py = os.path.join(app_dir, "main_page.py")
46
45
  if not os.path.exists(main_page_py) or args.force:
47
46
  with open(main_page_py, "w", encoding="utf-8") as f:
@@ -52,20 +51,22 @@ def init_project(args: argparse.Namespace) -> None:
52
51
  class MainPage(pn.Page):
53
52
  def __init__(self, native_instance):
54
53
  super().__init__(native_instance)
55
-
56
- def on_create(self):
57
- super().on_create()
58
- stack = (
59
- pn.StackView()
60
- .set_axis("vertical")
61
- .set_spacing(12)
62
- .set_alignment("fill")
63
- .set_padding(all=16)
54
+ self.state = {"count": 0}
55
+
56
+ def increment(self):
57
+ self.set_state(count=self.state["count"] + 1)
58
+
59
+ def render(self):
60
+ return pn.ScrollView(
61
+ pn.Column(
62
+ pn.Text("Hello from PythonNative!", font_size=24, bold=True),
63
+ pn.Text(f"Tapped {self.state['count']} times"),
64
+ pn.Button("Tap me", on_click=self.increment),
65
+ spacing=12,
66
+ padding=16,
67
+ alignment="fill",
68
+ )
64
69
  )
65
- stack.add_view(pn.Label("Hello from PythonNative!").set_text_size(18))
66
- button = pn.Button("Tap me").set_on_click(lambda: print("Button clicked"))
67
- stack.add_view(button)
68
- self.set_root_view(stack.wrap_in_scroll())
69
70
  """
70
71
  )
71
72
 
@@ -0,0 +1,241 @@
1
+ """Built-in element-creating functions for declarative UI composition.
2
+
3
+ Each function returns an :class:`Element` describing a native UI widget.
4
+ These are pure data — no native views are created until the reconciler
5
+ mounts the element tree.
6
+
7
+ Naming follows React Native conventions:
8
+
9
+ - ``Text`` (was *Label*)
10
+ - ``Button``
11
+ - ``Column`` / ``Row`` (was *StackView* vertical/horizontal)
12
+ - ``ScrollView``
13
+ - ``TextInput`` (was *TextField*)
14
+ - ``Image`` (was *ImageView*)
15
+ - ``Switch``
16
+ - ``ProgressBar`` (was *ProgressView*)
17
+ - ``ActivityIndicator`` (was *ActivityIndicatorView*)
18
+ - ``WebView``
19
+ - ``Spacer`` (new)
20
+ """
21
+
22
+ from typing import Any, Callable, Dict, Optional, Union
23
+
24
+ from .element import Element
25
+
26
+
27
+ def _filter_none(**kwargs: Any) -> Dict[str, Any]:
28
+ """Return *kwargs* with ``None``-valued entries removed."""
29
+ return {k: v for k, v in kwargs.items() if v is not None}
30
+
31
+
32
+ # ---------------------------------------------------------------------------
33
+ # Leaf components
34
+ # ---------------------------------------------------------------------------
35
+
36
+
37
+ def Text(
38
+ text: str = "",
39
+ *,
40
+ font_size: Optional[float] = None,
41
+ color: Optional[str] = None,
42
+ bold: bool = False,
43
+ text_align: Optional[str] = None,
44
+ background_color: Optional[str] = None,
45
+ max_lines: Optional[int] = None,
46
+ key: Optional[str] = None,
47
+ ) -> Element:
48
+ """Display text."""
49
+ props = _filter_none(
50
+ text=text,
51
+ font_size=font_size,
52
+ color=color,
53
+ bold=bold or None,
54
+ text_align=text_align,
55
+ background_color=background_color,
56
+ max_lines=max_lines,
57
+ )
58
+ return Element("Text", props, [], key=key)
59
+
60
+
61
+ def Button(
62
+ title: str = "",
63
+ *,
64
+ on_click: Optional[Callable[[], None]] = None,
65
+ color: Optional[str] = None,
66
+ background_color: Optional[str] = None,
67
+ font_size: Optional[float] = None,
68
+ enabled: bool = True,
69
+ key: Optional[str] = None,
70
+ ) -> Element:
71
+ """Create a tappable button."""
72
+ props: Dict[str, Any] = {"title": title}
73
+ if on_click is not None:
74
+ props["on_click"] = on_click
75
+ if color is not None:
76
+ props["color"] = color
77
+ if background_color is not None:
78
+ props["background_color"] = background_color
79
+ if font_size is not None:
80
+ props["font_size"] = font_size
81
+ if not enabled:
82
+ props["enabled"] = False
83
+ return Element("Button", props, [], key=key)
84
+
85
+
86
+ def TextInput(
87
+ *,
88
+ value: str = "",
89
+ placeholder: str = "",
90
+ on_change: Optional[Callable[[str], None]] = None,
91
+ secure: bool = False,
92
+ font_size: Optional[float] = None,
93
+ color: Optional[str] = None,
94
+ background_color: Optional[str] = None,
95
+ key: Optional[str] = None,
96
+ ) -> Element:
97
+ """Create a single-line text entry field."""
98
+ props: Dict[str, Any] = {"value": value}
99
+ if placeholder:
100
+ props["placeholder"] = placeholder
101
+ if on_change is not None:
102
+ props["on_change"] = on_change
103
+ if secure:
104
+ props["secure"] = True
105
+ if font_size is not None:
106
+ props["font_size"] = font_size
107
+ if color is not None:
108
+ props["color"] = color
109
+ if background_color is not None:
110
+ props["background_color"] = background_color
111
+ return Element("TextInput", props, [], key=key)
112
+
113
+
114
+ def Image(
115
+ source: str = "",
116
+ *,
117
+ width: Optional[float] = None,
118
+ height: Optional[float] = None,
119
+ scale_type: Optional[str] = None,
120
+ background_color: Optional[str] = None,
121
+ key: Optional[str] = None,
122
+ ) -> Element:
123
+ """Display an image from a resource path or URL."""
124
+ props = _filter_none(
125
+ source=source or None,
126
+ width=width,
127
+ height=height,
128
+ scale_type=scale_type,
129
+ background_color=background_color,
130
+ )
131
+ return Element("Image", props, [], key=key)
132
+
133
+
134
+ def Switch(
135
+ *,
136
+ value: bool = False,
137
+ on_change: Optional[Callable[[bool], None]] = None,
138
+ key: Optional[str] = None,
139
+ ) -> Element:
140
+ """Create a toggle switch."""
141
+ props: Dict[str, Any] = {"value": value}
142
+ if on_change is not None:
143
+ props["on_change"] = on_change
144
+ return Element("Switch", props, [], key=key)
145
+
146
+
147
+ def ProgressBar(
148
+ *,
149
+ value: float = 0.0,
150
+ background_color: Optional[str] = None,
151
+ key: Optional[str] = None,
152
+ ) -> Element:
153
+ """Show determinate progress (0.0 – 1.0)."""
154
+ props = _filter_none(value=value, background_color=background_color)
155
+ return Element("ProgressBar", props, [], key=key)
156
+
157
+
158
+ def ActivityIndicator(
159
+ *,
160
+ animating: bool = True,
161
+ key: Optional[str] = None,
162
+ ) -> Element:
163
+ """Show an indeterminate loading spinner."""
164
+ return Element("ActivityIndicator", {"animating": animating}, [], key=key)
165
+
166
+
167
+ def WebView(
168
+ *,
169
+ url: str = "",
170
+ key: Optional[str] = None,
171
+ ) -> Element:
172
+ """Embed web content."""
173
+ props: Dict[str, Any] = {}
174
+ if url:
175
+ props["url"] = url
176
+ return Element("WebView", props, [], key=key)
177
+
178
+
179
+ def Spacer(
180
+ *,
181
+ size: Optional[float] = None,
182
+ key: Optional[str] = None,
183
+ ) -> Element:
184
+ """Insert empty space with an optional fixed size."""
185
+ props = _filter_none(size=size)
186
+ return Element("Spacer", props, [], key=key)
187
+
188
+
189
+ # ---------------------------------------------------------------------------
190
+ # Container components
191
+ # ---------------------------------------------------------------------------
192
+
193
+ PaddingValue = Union[int, float, Dict[str, Union[int, float]]]
194
+
195
+
196
+ def Column(
197
+ *children: Element,
198
+ spacing: float = 0,
199
+ padding: Optional[PaddingValue] = None,
200
+ alignment: Optional[str] = None,
201
+ background_color: Optional[str] = None,
202
+ key: Optional[str] = None,
203
+ ) -> Element:
204
+ """Arrange children vertically."""
205
+ props = _filter_none(
206
+ spacing=spacing or None,
207
+ padding=padding,
208
+ alignment=alignment,
209
+ background_color=background_color,
210
+ )
211
+ return Element("Column", props, list(children), key=key)
212
+
213
+
214
+ def Row(
215
+ *children: Element,
216
+ spacing: float = 0,
217
+ padding: Optional[PaddingValue] = None,
218
+ alignment: Optional[str] = None,
219
+ background_color: Optional[str] = None,
220
+ key: Optional[str] = None,
221
+ ) -> Element:
222
+ """Arrange children horizontally."""
223
+ props = _filter_none(
224
+ spacing=spacing or None,
225
+ padding=padding,
226
+ alignment=alignment,
227
+ background_color=background_color,
228
+ )
229
+ return Element("Row", props, list(children), key=key)
230
+
231
+
232
+ def ScrollView(
233
+ child: Optional[Element] = None,
234
+ *,
235
+ background_color: Optional[str] = None,
236
+ key: Optional[str] = None,
237
+ ) -> Element:
238
+ """Wrap a single child in a scrollable container."""
239
+ children = [child] if child is not None else []
240
+ props = _filter_none(background_color=background_color)
241
+ return Element("ScrollView", props, children, key=key)
@@ -0,0 +1,47 @@
1
+ """Lightweight element descriptors for the virtual view tree.
2
+
3
+ An Element is an immutable description of a UI node — analogous to a React
4
+ element. It captures a type name, a props dictionary, and an ordered list
5
+ of children without creating any native platform objects. The reconciler
6
+ consumes these trees to determine what native views must be created,
7
+ updated, or removed.
8
+ """
9
+
10
+ from typing import Any, Dict, List, Optional
11
+
12
+
13
+ class Element:
14
+ """Immutable description of a single UI node."""
15
+
16
+ __slots__ = ("type", "props", "children", "key")
17
+
18
+ def __init__(
19
+ self,
20
+ type_name: str,
21
+ props: Dict[str, Any],
22
+ children: List["Element"],
23
+ key: Optional[str] = None,
24
+ ) -> None:
25
+ self.type = type_name
26
+ self.props = props
27
+ self.children = children
28
+ self.key = key
29
+
30
+ def __repr__(self) -> str:
31
+ return f"Element({self.type!r}, props={set(self.props)}, children={len(self.children)})"
32
+
33
+ def __eq__(self, other: object) -> bool:
34
+ if not isinstance(other, Element):
35
+ return NotImplemented
36
+ return (
37
+ self.type == other.type
38
+ and self.props == other.props
39
+ and self.children == other.children
40
+ and self.key == other.key
41
+ )
42
+
43
+ def __ne__(self, other: object) -> bool:
44
+ result = self.__eq__(other)
45
+ if result is NotImplemented:
46
+ return result
47
+ return not result