pyjs-examples 0.3.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 (171) hide show
  1. pyjs_examples-0.5.0/LICENSE +28 -0
  2. pyjs_examples-0.5.0/PKG-INFO +113 -0
  3. pyjs_examples-0.5.0/README.md +78 -0
  4. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/calculator/README.md +37 -7
  5. pyjs_examples-0.5.0/calculator/__init__.py +1 -0
  6. pyjs_examples-0.5.0/calculator/__main__.py +24 -0
  7. pyjs_examples-0.5.0/calculator/android.py +163 -0
  8. pyjs_examples-0.5.0/calculator/android_build.py +27 -0
  9. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/calculator/calculator.py +31 -102
  10. pyjs_examples-0.5.0/calculator/model.py +124 -0
  11. pyjs_examples-0.5.0/calculator/tests/test_android_calculator.py +53 -0
  12. pyjs_examples-0.5.0/calculator/tests/test_android_calculator_model.py +26 -0
  13. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/calculator/tests/test_browser_calculator.py +24 -3
  14. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/calculator/tests/test_calculator.py +2 -1
  15. pyjs_examples-0.5.0/calculator/tests/test_model.py +72 -0
  16. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/calculator/tests/test_pwa.py +24 -7
  17. pyjs_examples-0.5.0/chat/README.md +79 -0
  18. {pyjs_examples-0.3.0/chatroom → pyjs_examples-0.5.0/chat}/__main__.py +3 -3
  19. pyjs_examples-0.5.0/chat/chat.py +1165 -0
  20. {pyjs_examples-0.3.0/chatroom → pyjs_examples-0.5.0/chat}/chat_server.py +79 -36
  21. pyjs_examples-0.5.0/chat/protocol.py +28 -0
  22. pyjs_examples-0.5.0/chat/tests/test_browser_chat.py +165 -0
  23. {pyjs_examples-0.3.0/chatroom → pyjs_examples-0.5.0/chat}/tests/test_chat_server.py +50 -2
  24. {pyjs_examples-0.3.0/chatroom → pyjs_examples-0.5.0/chat}/visual_test.py +68 -13
  25. pyjs_examples-0.5.0/components/README.md +169 -0
  26. pyjs_examples-0.5.0/components/__init__.py +1 -0
  27. pyjs_examples-0.5.0/components/__main__.py +29 -0
  28. pyjs_examples-0.5.0/components/app.py +118 -0
  29. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0/components}/catalog.py +531 -64
  30. pyjs_examples-0.5.0/components/catalog_sources.py +318 -0
  31. pyjs_examples-0.5.0/components/diagram_viewer.py +69 -0
  32. pyjs_examples-0.5.0/components/diagrams.py +102 -0
  33. pyjs_examples-0.5.0/components/images.py +49 -0
  34. pyjs_examples-0.5.0/components/tests/test_browser_diagram_viewer.py +139 -0
  35. pyjs_examples-0.5.0/components/tests/test_browser_diagrams.py +116 -0
  36. pyjs_examples-0.5.0/components/tests/test_browser_navigation.py +435 -0
  37. {pyjs_examples-0.3.0/workspace → pyjs_examples-0.5.0/components}/tests/test_browser_workspace.py +33 -4
  38. pyjs_examples-0.5.0/components/tests/test_components.py +90 -0
  39. {pyjs_examples-0.3.0/workspace → pyjs_examples-0.5.0/components}/tests/test_workspace.py +3 -1
  40. {pyjs_examples-0.3.0/workspace → pyjs_examples-0.5.0/components}/workspace.py +35 -15
  41. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/counter.py +1 -1
  42. pyjs_examples-0.5.0/homescreen_widget/README.md +20 -0
  43. pyjs_examples-0.5.0/homescreen_widget/__init__.py +1 -0
  44. pyjs_examples-0.5.0/homescreen_widget/android.py +142 -0
  45. pyjs_examples-0.5.0/homescreen_widget/android_build.py +42 -0
  46. pyjs_examples-0.5.0/homescreen_widget/res/layout/note_widget_item.xml +13 -0
  47. pyjs_examples-0.5.0/homescreen_widget/res/layout/notes_widget.xml +36 -0
  48. pyjs_examples-0.5.0/homescreen_widget/res/values/strings.xml +6 -0
  49. pyjs_examples-0.5.0/homescreen_widget/res/xml/notes_widget_info.xml +11 -0
  50. pyjs_examples-0.5.0/notes/README.md +152 -0
  51. pyjs_examples-0.5.0/notes/__init__.py +1 -0
  52. pyjs_examples-0.5.0/notes/__main__.py +21 -0
  53. pyjs_examples-0.5.0/notes/android.py +401 -0
  54. pyjs_examples-0.5.0/notes/android_build.py +39 -0
  55. pyjs_examples-0.5.0/notes/android_datetime.py +81 -0
  56. pyjs_examples-0.5.0/notes/android_saves.py +52 -0
  57. pyjs_examples-0.5.0/notes/android_storage.py +222 -0
  58. pyjs_examples-0.5.0/notes/share.xml +12 -0
  59. pyjs_examples-0.5.0/notes/tests/test_android_model.py +20 -0
  60. pyjs_examples-0.5.0/notes/tests/test_android_save_queue.py +232 -0
  61. pyjs_examples-0.5.0/notes/tests/test_android_saves.py +113 -0
  62. pyjs_examples-0.5.0/notes/tests/test_android_storage.py +335 -0
  63. pyjs_examples-0.5.0/notes/tests/test_android_ui.py +700 -0
  64. pyjs_examples-0.5.0/notes/tests/test_browser_web_notes.py +149 -0
  65. pyjs_examples-0.5.0/notes/tests/test_web_notes.py +56 -0
  66. {pyjs_examples-0.3.0/kanban → pyjs_examples-0.5.0/notes}/visual_test.py +29 -25
  67. pyjs_examples-0.3.0/kanban/kanban.py → pyjs_examples-0.5.0/notes/web.py +159 -89
  68. pyjs_examples-0.5.0/pyjs_examples.egg-info/PKG-INFO +113 -0
  69. pyjs_examples-0.5.0/pyjs_examples.egg-info/SOURCES.txt +193 -0
  70. pyjs_examples-0.5.0/pyjs_examples.egg-info/entry_points.txt +7 -0
  71. pyjs_examples-0.5.0/pyjs_examples.egg-info/requires.txt +14 -0
  72. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/pyproject.toml +38 -43
  73. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/README.md +8 -7
  74. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/__main__.py +1 -1
  75. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/space_invaders.py +67 -15
  76. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/tests/test_browser_game.py +27 -2
  77. pyjs_examples-0.5.0/store/README.md +144 -0
  78. pyjs_examples-0.5.0/store/__init__.py +1 -0
  79. pyjs_examples-0.5.0/store/__main__.py +67 -0
  80. pyjs_examples-0.5.0/store/api.py +641 -0
  81. pyjs_examples-0.5.0/store/apps.py +7 -0
  82. pyjs_examples-0.5.0/store/core.py +145 -0
  83. pyjs_examples-0.5.0/store/fixtures/store.json +258 -0
  84. pyjs_examples-0.5.0/store/models.py +93 -0
  85. pyjs_examples-0.5.0/store/server.py +192 -0
  86. pyjs_examples-0.5.0/store/settings.py +23 -0
  87. pyjs_examples-0.5.0/store/store.py +1879 -0
  88. pyjs_examples-0.5.0/store/tests/conftest.py +33 -0
  89. pyjs_examples-0.5.0/store/tests/test_browser_store.py +564 -0
  90. pyjs_examples-0.5.0/store/tests/test_store.py +1048 -0
  91. pyjs_examples-0.5.0/store/urls.py +28 -0
  92. pyjs_examples-0.5.0/store/visual_test.py +129 -0
  93. pyjs_examples-0.3.0/PKG-INFO +0 -82
  94. pyjs_examples-0.3.0/README.md +0 -54
  95. pyjs_examples-0.3.0/calculator/__init__.py +0 -1
  96. pyjs_examples-0.3.0/calculator/__main__.py +0 -15
  97. pyjs_examples-0.3.0/chatroom/README.md +0 -50
  98. pyjs_examples-0.3.0/chatroom/chatroom.py +0 -726
  99. pyjs_examples-0.3.0/chatroom/tests/test_browser_chatroom.py +0 -63
  100. pyjs_examples-0.3.0/issue_tracker/README.md +0 -45
  101. pyjs_examples-0.3.0/issue_tracker/__init__.py +0 -1
  102. pyjs_examples-0.3.0/issue_tracker/__main__.py +0 -46
  103. pyjs_examples-0.3.0/issue_tracker/api.py +0 -353
  104. pyjs_examples-0.3.0/issue_tracker/apps.py +0 -7
  105. pyjs_examples-0.3.0/issue_tracker/core.py +0 -130
  106. pyjs_examples-0.3.0/issue_tracker/fixtures/issue_tracker.json +0 -218
  107. pyjs_examples-0.3.0/issue_tracker/migrations/0001_initial.py +0 -103
  108. pyjs_examples-0.3.0/issue_tracker/models.py +0 -140
  109. pyjs_examples-0.3.0/issue_tracker/server.py +0 -37
  110. pyjs_examples-0.3.0/issue_tracker/settings.py +0 -22
  111. pyjs_examples-0.3.0/issue_tracker/tests/conftest.py +0 -27
  112. pyjs_examples-0.3.0/issue_tracker/tests/test_browser_issue_tracker.py +0 -204
  113. pyjs_examples-0.3.0/issue_tracker/tests/test_issue_tracker.py +0 -295
  114. pyjs_examples-0.3.0/issue_tracker/ui.py +0 -742
  115. pyjs_examples-0.3.0/issue_tracker/urls.py +0 -10
  116. pyjs_examples-0.3.0/kanban/README.md +0 -31
  117. pyjs_examples-0.3.0/kanban/__init__.py +0 -1
  118. pyjs_examples-0.3.0/kanban/__main__.py +0 -8
  119. pyjs_examples-0.3.0/kanban/tests/test_browser_kanban.py +0 -155
  120. pyjs_examples-0.3.0/kanban/tests/test_kanban.py +0 -38
  121. pyjs_examples-0.3.0/nativescript_counter/README.md +0 -31
  122. pyjs_examples-0.3.0/nativescript_counter/__init__.py +0 -5
  123. pyjs_examples-0.3.0/nativescript_counter/__main__.py +0 -17
  124. pyjs_examples-0.3.0/nativescript_counter/counter.py +0 -54
  125. pyjs_examples-0.3.0/nativescript_counter/tests/test_android_counter.py +0 -31
  126. pyjs_examples-0.3.0/nativescript_counter/tests/test_counter.py +0 -11
  127. pyjs_examples-0.3.0/navigation/README.md +0 -20
  128. pyjs_examples-0.3.0/navigation/__init__.py +0 -1
  129. pyjs_examples-0.3.0/navigation/__main__.py +0 -49
  130. pyjs_examples-0.3.0/navigation/navigation.py +0 -800
  131. pyjs_examples-0.3.0/navigation/tests/test_browser_navigation.py +0 -83
  132. pyjs_examples-0.3.0/navigation/tests/test_navigation.py +0 -59
  133. pyjs_examples-0.3.0/pyjs_examples.egg-info/PKG-INFO +0 -82
  134. pyjs_examples-0.3.0/pyjs_examples.egg-info/SOURCES.txt +0 -188
  135. pyjs_examples-0.3.0/pyjs_examples.egg-info/entry_points.txt +0 -12
  136. pyjs_examples-0.3.0/pyjs_examples.egg-info/requires.txt +0 -9
  137. pyjs_examples-0.3.0/samples/__init__.py +0 -1
  138. pyjs_examples-0.3.0/samples/state_counter/README.md +0 -19
  139. pyjs_examples-0.3.0/samples/state_counter/__init__.py +0 -1
  140. pyjs_examples-0.3.0/samples/state_counter/__main__.py +0 -3
  141. pyjs_examples-0.3.0/samples/state_counter/state_counter.py +0 -60
  142. pyjs_examples-0.3.0/samples/state_counter/tests/test_browser_state_counter.py +0 -18
  143. pyjs_examples-0.3.0/samples/state_counter/tests/test_state_counter.py +0 -17
  144. pyjs_examples-0.3.0/samples/ui_dialog/README.md +0 -19
  145. pyjs_examples-0.3.0/samples/ui_dialog/__init__.py +0 -1
  146. pyjs_examples-0.3.0/samples/ui_dialog/__main__.py +0 -3
  147. pyjs_examples-0.3.0/samples/ui_dialog/tests/test_browser_ui_dialog.py +0 -21
  148. pyjs_examples-0.3.0/samples/ui_dialog/tests/test_ui_dialog.py +0 -10
  149. pyjs_examples-0.3.0/samples/ui_dialog/ui_dialog.py +0 -65
  150. pyjs_examples-0.3.0/todomvc/README.md +0 -50
  151. pyjs_examples-0.3.0/todomvc/__init__.py +0 -1
  152. pyjs_examples-0.3.0/todomvc/__main__.py +0 -12
  153. pyjs_examples-0.3.0/todomvc/base.css +0 -141
  154. pyjs_examples-0.3.0/todomvc/index.css +0 -393
  155. pyjs_examples-0.3.0/todomvc/tests/test_browser_todomvc.py +0 -153
  156. pyjs_examples-0.3.0/todomvc/tests/test_todomvc.py +0 -84
  157. pyjs_examples-0.3.0/todomvc/todomvc.py +0 -426
  158. pyjs_examples-0.3.0/workspace/README.md +0 -25
  159. pyjs_examples-0.3.0/workspace/__init__.py +0 -1
  160. pyjs_examples-0.3.0/workspace/__main__.py +0 -3
  161. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/__init__.py +0 -0
  162. {pyjs_examples-0.3.0/issue_tracker/migrations → pyjs_examples-0.5.0/calculator/tests}/__init__.py +0 -0
  163. {pyjs_examples-0.3.0/chatroom → pyjs_examples-0.5.0/chat}/__init__.py +0 -0
  164. /pyjs_examples-0.3.0/kanban/tests/renders/kanban-board.png → /pyjs_examples-0.5.0/notes/tests/renders/notes-board.png +0 -0
  165. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/pyjs_examples.egg-info/dependency_links.txt +0 -0
  166. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/pyjs_examples.egg-info/top_level.txt +0 -0
  167. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/setup.cfg +0 -0
  168. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/__init__.py +0 -0
  169. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/tests/renders/action_scene.png +0 -0
  170. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/tests/renders/initial_wave.png +0 -0
  171. {pyjs_examples-0.3.0 → pyjs_examples-0.5.0}/space_invaders/tests/test_game.py +0 -0
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Lex Berezhny
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyjs-examples
3
+ Version: 0.5.0
4
+ Summary: Official example applications for PyJS.
5
+ Author-email: Lex Berezhny <lex@damoti.com>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/pyjs/pyjs
8
+ Project-URL: Source, https://github.com/pyjs/pyjs
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.14
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pyjs==0.5.0
23
+ Provides-Extra: store
24
+ Requires-Dist: django<6.2,>=6.0; extra == "store"
25
+ Requires-Dist: pydantic<3,>=2; extra == "store"
26
+ Requires-Dist: pyjs-extras==0.5.0; extra == "store"
27
+ Requires-Dist: uvicorn<1,>=0.52; extra == "store"
28
+ Provides-Extra: test
29
+ Requires-Dist: django<6.2,>=6.0; extra == "test"
30
+ Requires-Dist: pydantic<3,>=2; extra == "test"
31
+ Requires-Dist: pyjs-extras==0.5.0; extra == "test"
32
+ Requires-Dist: pytest>=9.0; extra == "test"
33
+ Requires-Dist: uvicorn<1,>=0.52; extra == "test"
34
+ Dynamic: license-file
35
+
36
+ # PyJS Examples
37
+
38
+ This directory is the source tree for the separately installable
39
+ `pyjs-examples` distribution. Setuptools maps it to the `pyjs_examples` import
40
+ package while keeping each application easy to browse in the repository.
41
+
42
+ Install the core and examples from a source checkout:
43
+
44
+ ```bash
45
+ uv sync
46
+ ```
47
+
48
+ An installed release provides the examples through an extra:
49
+
50
+ ```bash
51
+ python -m pip install "pyjs[examples]"
52
+ ```
53
+
54
+ ## Application responsibilities
55
+
56
+ The examples progress from small programs to composed, full-stack systems.
57
+ Features may overlap when that makes an application more realistic.
58
+
59
+ | Example | Role | Principal PyJS coverage |
60
+ | --- | --- | --- |
61
+ | [Counter](counter.py) | Smallest app | DOM, events, one-file tests |
62
+ | [Calculator](calculator/) | Universal app | Web, PWA, Android, SSR, state |
63
+ | [Components](components/) | UI reference | Widgets, forms, navigation |
64
+ | [Notes](notes/) | Personal app | Web, Android, drag/drop, restore |
65
+ | [Home screen widget](homescreen_widget/) | Android sample | RemoteViews |
66
+ | [Chat](chat/) | Real-time starter | WebSockets, multi-window, plans |
67
+ | [Store](store/) | Business app | Django, JSON:API, streams, cursor feeds |
68
+ | [Space Invaders](space_invaders/) | GPU game | WebGPU, input, render tests |
69
+
70
+ Run an application with its module name, for example:
71
+
72
+ ```bash
73
+ python -m pyjs_examples.calculator
74
+ python -m pyjs_examples.components
75
+ python -m pyjs_examples.notes
76
+ python -m pyjs_examples.chat
77
+ python -m pyjs_examples.store
78
+ ```
79
+
80
+ Install `pyjs-examples[store]` before running Store from a release package.
81
+
82
+ Calculator and Notes accept `--android` to build and launch their direct-JVM
83
+ Android versions. Their default command serves the web version.
84
+
85
+ Home screen widget is a direct-JVM example rather than a template application.
86
+ Its local README shows the small build command for its signed APK.
87
+
88
+ Components is also the source and test surface for the planned website
89
+ component reference. It combines the former catalog, workspace, navigation,
90
+ and focused dialog sample in one application.
91
+
92
+ Notes combines the former Kanban board with the mobile notes application. It
93
+ uses DOM-owned ordering, drag/drop, server restoration, and visual tests.
94
+
95
+ Store is the canonical Django and typed client/server example. It also owns the
96
+ themability story, signed cursor feeds, infinite scrolling, and data-driven
97
+ charts. Its visitor page demonstrates snapshot-backed typed streams and a
98
+ bounded plain-text log viewer.
99
+
100
+ ## Templates
101
+
102
+ List, inspect, or copy examples using the core scaffolding command:
103
+
104
+ ```bash
105
+ pyjs template
106
+ pyjs template pyjs_examples.calculator
107
+ pyjs create my-calculator --template pyjs_examples.calculator
108
+ pyjs create --single-file my_counter.py --template pyjs_examples.counter
109
+ ```
110
+
111
+ The distribution registers modules and packages through the `pyjs.templates`
112
+ entry-point group. PyJS infers file and directory templates from normal Python
113
+ module structure instead of hardcoding a catalog.
@@ -0,0 +1,78 @@
1
+ # PyJS Examples
2
+
3
+ This directory is the source tree for the separately installable
4
+ `pyjs-examples` distribution. Setuptools maps it to the `pyjs_examples` import
5
+ package while keeping each application easy to browse in the repository.
6
+
7
+ Install the core and examples from a source checkout:
8
+
9
+ ```bash
10
+ uv sync
11
+ ```
12
+
13
+ An installed release provides the examples through an extra:
14
+
15
+ ```bash
16
+ python -m pip install "pyjs[examples]"
17
+ ```
18
+
19
+ ## Application responsibilities
20
+
21
+ The examples progress from small programs to composed, full-stack systems.
22
+ Features may overlap when that makes an application more realistic.
23
+
24
+ | Example | Role | Principal PyJS coverage |
25
+ | --- | --- | --- |
26
+ | [Counter](counter.py) | Smallest app | DOM, events, one-file tests |
27
+ | [Calculator](calculator/) | Universal app | Web, PWA, Android, SSR, state |
28
+ | [Components](components/) | UI reference | Widgets, forms, navigation |
29
+ | [Notes](notes/) | Personal app | Web, Android, drag/drop, restore |
30
+ | [Home screen widget](homescreen_widget/) | Android sample | RemoteViews |
31
+ | [Chat](chat/) | Real-time starter | WebSockets, multi-window, plans |
32
+ | [Store](store/) | Business app | Django, JSON:API, streams, cursor feeds |
33
+ | [Space Invaders](space_invaders/) | GPU game | WebGPU, input, render tests |
34
+
35
+ Run an application with its module name, for example:
36
+
37
+ ```bash
38
+ python -m pyjs_examples.calculator
39
+ python -m pyjs_examples.components
40
+ python -m pyjs_examples.notes
41
+ python -m pyjs_examples.chat
42
+ python -m pyjs_examples.store
43
+ ```
44
+
45
+ Install `pyjs-examples[store]` before running Store from a release package.
46
+
47
+ Calculator and Notes accept `--android` to build and launch their direct-JVM
48
+ Android versions. Their default command serves the web version.
49
+
50
+ Home screen widget is a direct-JVM example rather than a template application.
51
+ Its local README shows the small build command for its signed APK.
52
+
53
+ Components is also the source and test surface for the planned website
54
+ component reference. It combines the former catalog, workspace, navigation,
55
+ and focused dialog sample in one application.
56
+
57
+ Notes combines the former Kanban board with the mobile notes application. It
58
+ uses DOM-owned ordering, drag/drop, server restoration, and visual tests.
59
+
60
+ Store is the canonical Django and typed client/server example. It also owns the
61
+ themability story, signed cursor feeds, infinite scrolling, and data-driven
62
+ charts. Its visitor page demonstrates snapshot-backed typed streams and a
63
+ bounded plain-text log viewer.
64
+
65
+ ## Templates
66
+
67
+ List, inspect, or copy examples using the core scaffolding command:
68
+
69
+ ```bash
70
+ pyjs template
71
+ pyjs template pyjs_examples.calculator
72
+ pyjs create my-calculator --template pyjs_examples.calculator
73
+ pyjs create --single-file my_counter.py --template pyjs_examples.counter
74
+ ```
75
+
76
+ The distribution registers modules and packages through the `pyjs.templates`
77
+ entry-point group. PyJS infers file and directory templates from normal Python
78
+ module structure instead of hardcoding a catalog.
@@ -5,8 +5,9 @@ example for pyjs browser-target testing.
5
5
 
6
6
  It demonstrates:
7
7
 
8
- - calculator state and behavior owned by a custom element
9
- - typed `state()` fields serialized to DOM attributes and rendered with `@effect`
8
+ - a shared calculator model with browser and native Android views
9
+ - typed `state()` fields serialized to DOM attributes and rendered with
10
+ `@effect`
10
11
  - a centered responsive custom-element UI
11
12
  - digit and decimal entry
12
13
  - addition, subtraction, multiplication, and division
@@ -14,6 +15,7 @@ It demonstrates:
14
15
  - asynchronous result persistence through an HTTP POST route
15
16
  - per-browser in-memory sessions that restore the last result after refresh
16
17
  - a Python-authored service worker with cache-first offline application loading
18
+ - a native Android implementation using the same state machine
17
19
  - browser tests that interact with the real DOM through button events
18
20
 
19
21
  The example intentionally stays focused on calculator behavior. Reusable widget
@@ -25,7 +27,7 @@ coverage, including the dropdown menu and floating positioning, lives under
25
27
  From the repository root:
26
28
 
27
29
  ```bash
28
- .venv/bin/python -m pyjs_examples.calculator
30
+ python -m pyjs_examples.calculator
29
31
  ```
30
32
 
31
33
  Open `http://127.0.0.1:8000/`. Completing a calculation with `=` saves its
@@ -35,24 +37,52 @@ the server clears them. The app also registers `/calculator-serviceworker.js`.
35
37
  After its first controlled reload, the calculator can load and calculate while
36
38
  the browser is offline.
37
39
 
40
+ Run the native Android version with an Android SDK and JDK installed. PyJS
41
+ builds a signed debug APK and uses a running or configured emulator:
42
+
43
+ ```console
44
+ python -m pyjs_examples.calculator --android
45
+ ```
46
+
47
+ `model.py` owns number entry, arithmetic, operator selection, and error
48
+ recovery. Both views dispatch key actions to its `Calculator` class. The web
49
+ view copies its DOM-backed state into the model for each action and writes the
50
+ result back, preserving server rendering and hydration. Android keeps a model
51
+ instance and updates its native display after each action. The two numeric
52
+ conversion helpers use Python/JavaScript conversion with explicit JVM bindings.
53
+
54
+ `android.py` implements the native controls and `android_build.py`
55
+ packages them through D8 and AAPT2. This is the only Android implementation;
56
+ there is no JavaScript runtime or Gradle project in the app.
57
+
38
58
  ## Run the tests
39
59
 
40
60
  From the repository root, run the Python target:
41
61
 
42
62
  ```bash
43
- .venv/bin/python -m pytest -q examples/calculator/tests
63
+ pytest -q examples/calculator/tests
44
64
  ```
45
65
 
46
- Run the same model tests plus the browser-only UI tests in the browser:
66
+ Run the browser UI tests and shared model scenarios in the browser:
47
67
 
48
68
  ```bash
49
- .venv/bin/python -m pytest -q examples/calculator/tests --pyjs-target=web
69
+ pytest -q examples/calculator/tests --pyjs-target=web
50
70
  ```
51
71
 
52
72
  The pytest plugin starts or reconnects to the browser-test daemon on
53
73
  `127.0.0.1:8765`. To keep the daemon alive while iterating:
54
74
 
55
75
  ```bash
56
- .venv/bin/python -m pytest -q examples/calculator/tests --pyjs-target=web \
76
+ pytest -q examples/calculator/tests --pyjs-target=web \
57
77
  --pyjs-daemon-idle-seconds=0
58
78
  ```
79
+
80
+ Run the Android interaction test with:
81
+
82
+ ```console
83
+ pytest -q examples/calculator/tests/test_android_calculator.py \
84
+ --pyjs-target=android --pyjs-android-runtime=robolectric
85
+ ```
86
+
87
+ Use `--pyjs-android-runtime=device --pyjs-android-avd=YOUR_AVD` instead
88
+ for the emulator tier.
@@ -0,0 +1 @@
1
+ """A tested universal calculator for the Web, PWA, and Android targets."""
@@ -0,0 +1,24 @@
1
+ import argparse
2
+ import os
3
+
4
+ parser = argparse.ArgumentParser(description="Run the Calculator example.")
5
+ parser.add_argument("--android", action="store_true", help="Build and run the Android APK")
6
+
7
+ if parser.parse_args().android:
8
+ from .android_build import run_android
9
+
10
+ run_android()
11
+ else:
12
+ from pyjs.server.dev import serve
13
+
14
+ from .calculator import render, save_result, service_worker_javascript
15
+
16
+ serve(
17
+ "pyjs_examples.calculator.calculator",
18
+ render=render,
19
+ routes={
20
+ ("POST", "/api/calculator/result"): save_result,
21
+ ("GET", "/calculator-serviceworker.js"): service_worker_javascript,
22
+ },
23
+ port=int(os.environ.get("PYJS_PORT", "8000")),
24
+ )
@@ -0,0 +1,163 @@
1
+ """Native Android Calculator implementation."""
2
+
3
+ from pyjs.android import (
4
+ Activity,
5
+ Bundle,
6
+ Button,
7
+ Context,
8
+ Gravity,
9
+ LayoutParams,
10
+ LinearLayout,
11
+ LinearLayoutParams,
12
+ OnClickListener,
13
+ TextView,
14
+ View,
15
+ parse_color,
16
+ )
17
+ from pyjs.android.controls import ScrollView
18
+ from pyjs.java import f32, i32
19
+
20
+ from .model import Calculator
21
+
22
+
23
+ class CalculatorClickListener(OnClickListener):
24
+ def __init__(
25
+ self,
26
+ calculator: AndroidCalculator,
27
+ kind: str,
28
+ value: str,
29
+ ) -> None:
30
+ self.calculator = calculator
31
+ self.kind = kind
32
+ self.value = value
33
+
34
+ def onClick(self, view: View) -> None:
35
+ self.calculator.press(self.kind, self.value)
36
+
37
+
38
+ class AndroidCalculator:
39
+ def __init__(self, context: Context) -> None:
40
+ self.context = context
41
+ self.calculator = Calculator()
42
+
43
+ self.display = TextView(context)
44
+ self.display.setText(self.calculator.display_value)
45
+ self.display.setTextSize(f32(40.0))
46
+ self.display.setGravity(Gravity.END)
47
+ self.display.setPadding(i32(24), i32(32), i32(24), i32(32))
48
+ self.display.setBackgroundColor(parse_color("#020617"))
49
+
50
+ def press(self, kind: str, value: str) -> None:
51
+ self.calculator.press(kind, value)
52
+ self.display.setText(self.calculator.display_value)
53
+
54
+ def key(self, label: str, value: str, kind: str) -> Button:
55
+ key = Button(self.context)
56
+ key.setText(label)
57
+ key.setTextSize(f32(22.0))
58
+ key.setContentDescription(label)
59
+ key.setPadding(i32(12), i32(16), i32(12), i32(16))
60
+ key.setOnClickListener(CalculatorClickListener(self, kind, value))
61
+ return key
62
+
63
+ def page(self) -> ScrollView:
64
+ root = LinearLayout(self.context)
65
+ root.setOrientation(LinearLayout.VERTICAL)
66
+ root.setGravity(Gravity.CENTER)
67
+ root.setPadding(i32(20), i32(20), i32(20), i32(20))
68
+ root.setBackgroundColor(parse_color("#0f172a"))
69
+ root.setLayoutParams(
70
+ LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
71
+ )
72
+
73
+ title = TextView(self.context)
74
+ title.setText("PyJS Calculator")
75
+ title.setTextSize(f32(24.0))
76
+ title.setGravity(Gravity.CENTER_HORIZONTAL)
77
+ root.addView(title)
78
+ root.addView(self.display)
79
+
80
+ keypad = LinearLayout(self.context)
81
+ keypad.setOrientation(LinearLayout.VERTICAL)
82
+ keypad.setLayoutParams(
83
+ LinearLayoutParams(
84
+ LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, f32(0.0)
85
+ )
86
+ )
87
+ labels = [
88
+ ("AC", "clear", "action"),
89
+ ("±", "sign", "action"),
90
+ ("%", "percent", "action"),
91
+ ("÷", "/", "operator"),
92
+ ("7", "7", "digit"),
93
+ ("8", "8", "digit"),
94
+ ("9", "9", "digit"),
95
+ ("×", "*", "operator"),
96
+ ("4", "4", "digit"),
97
+ ("5", "5", "digit"),
98
+ ("6", "6", "digit"),
99
+ ("−", "-", "operator"),
100
+ ("1", "1", "digit"),
101
+ ("2", "2", "digit"),
102
+ ("3", "3", "digit"),
103
+ ("+", "+", "operator"),
104
+ ("0", "0", "digit"),
105
+ (".", ".", "decimal"),
106
+ ("=", "=", "equals"),
107
+ ]
108
+ row = LinearLayout(self.context)
109
+ index = 0
110
+ for label, value, kind in labels:
111
+ if index % 4 == 0:
112
+ row = LinearLayout(self.context)
113
+ row.setOrientation(LinearLayout.HORIZONTAL)
114
+ row.setLayoutParams(
115
+ LinearLayoutParams(
116
+ LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, f32(0.0)
117
+ )
118
+ )
119
+ keypad.addView(row)
120
+ key = self.key(label, value, kind)
121
+ key.setId(i32(100 + index))
122
+ key.setLayoutParams(
123
+ LinearLayoutParams(i32(0), LayoutParams.WRAP_CONTENT, f32(1.0))
124
+ )
125
+ row.addView(key)
126
+ index += 1
127
+ root.addView(keypad)
128
+ scroll = ScrollView(self.context)
129
+ scroll.setFitsSystemWindows(True)
130
+ scroll.set_fill_viewport(True)
131
+ scroll.addView(root)
132
+ return scroll
133
+
134
+
135
+ class CalculatorActivity(Activity):
136
+ def onCreate(self, state: Bundle | None) -> None:
137
+ super().onCreate(state)
138
+ self.setTitle("PyJS Calculator")
139
+ self.view = AndroidCalculator(self)
140
+ calculator = self.view.calculator
141
+ if state is not None:
142
+ calculator.display_value = state.get_string("display") or "0"
143
+ calculator.stored_value = state.get_double("stored", 0.0)
144
+ calculator.pending_operator = state.get_string("operator") or ""
145
+ calculator.replace_display = state.get_boolean("replace", True)
146
+ calculator.error = state.get_boolean("error", False)
147
+ self.view.display.setText(calculator.display_value)
148
+ self.setContentView(self.view.page())
149
+
150
+ def onSaveInstanceState(self, state: Bundle) -> None:
151
+ calculator = self.view.calculator
152
+ state.put_string("display", calculator.display_value)
153
+ state.put_double("stored", calculator.stored_value)
154
+ state.put_string("operator", calculator.pending_operator)
155
+ state.put_boolean("replace", calculator.replace_display)
156
+ state.put_boolean("error", calculator.error)
157
+ super().onSaveInstanceState(state)
158
+
159
+
160
+ def main() -> int:
161
+ activity = CalculatorActivity()
162
+ activity.onCreate(Bundle())
163
+ return 0
@@ -0,0 +1,27 @@
1
+ from pathlib import Path
2
+
3
+ from pyjs.tooling.android import AndroidSDK
4
+ from pyjs.tooling.android_jvm import AndroidJVMApplication, AndroidJVMBuilder
5
+
6
+
7
+ def application() -> AndroidJVMApplication:
8
+ return AndroidJVMApplication(
9
+ Path(__file__).with_name("android.py"),
10
+ "pyjs_examples.calculator.android",
11
+ "org.pyjs.calculator",
12
+ "CalculatorActivity",
13
+ "PyJS Calculator",
14
+ compile_sdk=35,
15
+ )
16
+
17
+
18
+ def run_android(output: Path | None = None) -> Path:
19
+ sdk = AndroidSDK()
20
+ app = application()
21
+ package = AndroidJVMBuilder(sdk).build(
22
+ app, output or Path("build/android-calculator"),
23
+ )
24
+ device = sdk.ensure_emulator()
25
+ sdk.install(device, package)
26
+ sdk.launch(device, app.app_id, app.android_activity)
27
+ return package