neutralino-python 0.1.0rc1__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.
- neutralino/__init__.py +88 -0
- neutralino/_catalog.py +297 -0
- neutralino/_data/LICENSE.neutralino-js-client +21 -0
- neutralino/_data/LICENSE.neutralinojs +1066 -0
- neutralino/_data/docs/cli.md +315 -0
- neutralino/_data/docs/custom-components.md +107 -0
- neutralino/_data/docs/custom-frontends.md +80 -0
- neutralino/_data/docs/desktop-helpers.md +296 -0
- neutralino/_data/docs/guide.md +131 -0
- neutralino/_data/docs/llms-full.txt +3921 -0
- neutralino/_data/docs/llms.txt +43 -0
- neutralino/_data/docs/manifests/components.json +20128 -0
- neutralino/_data/docs/manifests/examples.json +52 -0
- neutralino/_data/docs/manifests/native.json +3024 -0
- neutralino/_data/docs/manifests/schema.json +43 -0
- neutralino/_data/docs/manual-checklist.md +189 -0
- neutralino/_data/docs/packaging.md +252 -0
- neutralino/_data/docs/performance.md +15 -0
- neutralino/_data/docs/platforms.md +15 -0
- neutralino/_data/docs/reference/components.md +1685 -0
- neutralino/_data/docs/reference/native.md +148 -0
- neutralino/_data/docs/security.md +60 -0
- neutralino/_data/docs/ui.md +249 -0
- neutralino/_data/docs/updates.md +366 -0
- neutralino/_data/examples/README.md +6 -0
- neutralino/_data/examples/crud/README.md +36 -0
- neutralino/_data/examples/crud/app.py +243 -0
- neutralino/_data/examples/dashboard/README.md +36 -0
- neutralino/_data/examples/dashboard/app.py +367 -0
- neutralino/_data/examples/editor/README.md +35 -0
- neutralino/_data/examples/editor/app.py +190 -0
- neutralino/_data/examples/file-manager/README.md +40 -0
- neutralino/_data/examples/file-manager/app.py +120 -0
- neutralino/_data/examples/file-manager/frontend/index.html +20 -0
- neutralino/_data/examples/file-manager/frontend/main.js +55 -0
- neutralino/_data/examples/file-manager/frontend/neutralino.js +1 -0
- neutralino/_data/examples/file-manager/frontend/python-bridge.d.ts +207 -0
- neutralino/_data/examples/file-manager/frontend/python-bridge.mjs +854 -0
- neutralino/_data/examples/file-manager/frontend/style.css +4 -0
- neutralino/_data/examples/hybrid/README.md +48 -0
- neutralino/_data/examples/hybrid/app.py +80 -0
- neutralino/_data/examples/hybrid/components/counter.mjs +37 -0
- neutralino/_data/examples/hybrid/components/widget.mjs +23 -0
- neutralino/_data/examples/hybrid/styles.css +21 -0
- neutralino/_data/examples/hybrid/widget/package.json +20 -0
- neutralino/_data/examples/hybrid/widget/src/Widget.jsx +25 -0
- neutralino/_data/examples/hybrid/widget/vite.config.mjs +19 -0
- neutralino/_data/examples/monitor/README.md +36 -0
- neutralino/_data/examples/monitor/app.py +375 -0
- neutralino/_data/examples/react/README.md +90 -0
- neutralino/_data/examples/react/app.py +68 -0
- neutralino/_data/examples/react/frontend/.gitignore +5 -0
- neutralino/_data/examples/react/frontend/index.html +17 -0
- neutralino/_data/examples/react/frontend/package-lock.json +1232 -0
- neutralino/_data/examples/react/frontend/package.json +25 -0
- neutralino/_data/examples/react/frontend/scripts/prepare-bridge.mjs +49 -0
- neutralino/_data/examples/react/frontend/src/App.tsx +157 -0
- neutralino/_data/examples/react/frontend/src/backend.ts +21 -0
- neutralino/_data/examples/react/frontend/src/calls.test.ts +206 -0
- neutralino/_data/examples/react/frontend/src/calls.ts +306 -0
- neutralino/_data/examples/react/frontend/src/globals.d.ts +14 -0
- neutralino/_data/examples/react/frontend/src/hooks.ts +45 -0
- neutralino/_data/examples/react/frontend/src/main.tsx +13 -0
- neutralino/_data/examples/react/frontend/src/styles.css +11 -0
- neutralino/_data/examples/react/frontend/tsconfig.json +18 -0
- neutralino/_data/examples/react/frontend/vite.config.ts +9 -0
- neutralino/_data/examples/settings/README.md +38 -0
- neutralino/_data/examples/settings/app.py +440 -0
- neutralino/_data/examples/updater/.gitignore +2 -0
- neutralino/_data/examples/updater/README.md +82 -0
- neutralino/_data/examples/updater/app.py +160 -0
- neutralino/_data/examples/updater/app.toml +21 -0
- neutralino/_data/examples/updater/demo.py +107 -0
- neutralino/_data/examples/updater/requirements.txt +2 -0
- neutralino/_data/examples/updater/sources/github-private.toml +21 -0
- neutralino/_data/examples/updater/sources/github-public.toml +21 -0
- neutralino/_data/examples/vanilla/README.md +35 -0
- neutralino/_data/examples/vanilla/app.py +46 -0
- neutralino/_data/examples/vanilla/frontend/index.html +17 -0
- neutralino/_data/examples/vanilla/frontend/main.js +29 -0
- neutralino/_data/examples/vanilla/frontend/neutralino.js +1 -0
- neutralino/_data/examples/vanilla/frontend/python-bridge.d.ts +207 -0
- neutralino/_data/examples/vanilla/frontend/python-bridge.mjs +854 -0
- neutralino/_data/examples/vanilla/frontend/style.css +4 -0
- neutralino/_data/explorer/app.py +1328 -0
- neutralino/_data/explorer/catalogue.json +48179 -0
- neutralino/_data/explorer/explorer_previews.py +247 -0
- neutralino/_data/explorer/sources/native/always_on_top.py +55 -0
- neutralino/_data/explorer/sources/native/binary.py +125 -0
- neutralino/_data/explorer/sources/native/borderless.py +99 -0
- neutralino/_data/explorer/sources/native/broadcast.py +90 -0
- neutralino/_data/explorer/sources/native/config.py +78 -0
- neutralino/_data/explorer/sources/native/controls.py +140 -0
- neutralino/_data/explorer/sources/native/directory.py +163 -0
- neutralino/_data/explorer/sources/native/displays.py +75 -0
- neutralino/_data/explorer/sources/native/env.py +98 -0
- neutralino/_data/explorer/sources/native/events.py +124 -0
- neutralino/_data/explorer/sources/native/exec_command.py +79 -0
- neutralino/_data/explorer/sources/native/folder.py +70 -0
- neutralino/_data/explorer/sources/native/icon_badge.py +101 -0
- neutralino/_data/explorer/sources/native/image.py +119 -0
- neutralino/_data/explorer/sources/native/lifecycle.py +99 -0
- neutralino/_data/explorer/sources/native/locale.py +70 -0
- neutralino/_data/explorer/sources/native/main_menu.py +103 -0
- neutralino/_data/explorer/sources/native/message_box.py +101 -0
- neutralino/_data/explorer/sources/native/mouse.py +70 -0
- neutralino/_data/explorer/sources/native/multi_window.py +134 -0
- neutralino/_data/explorer/sources/native/notification.py +74 -0
- neutralino/_data/explorer/sources/native/open_external.py +81 -0
- neutralino/_data/explorer/sources/native/open_file.py +102 -0
- neutralino/_data/explorer/sources/native/paths.py +77 -0
- neutralino/_data/explorer/sources/native/print_snapshot.py +84 -0
- neutralino/_data/explorer/sources/native/read_write.py +192 -0
- neutralino/_data/explorer/sources/native/resources.py +110 -0
- neutralino/_data/explorer/sources/native/save_file.py +101 -0
- neutralino/_data/explorer/sources/native/server_mount.py +106 -0
- neutralino/_data/explorer/sources/native/sound.py +84 -0
- neutralino/_data/explorer/sources/native/spawn_process.py +128 -0
- neutralino/_data/explorer/sources/native/states.py +122 -0
- neutralino/_data/explorer/sources/native/stats_permissions.py +147 -0
- neutralino/_data/explorer/sources/native/storage.py +108 -0
- neutralino/_data/explorer/sources/native/system_info.py +115 -0
- neutralino/_data/explorer/sources/native/text.py +133 -0
- neutralino/_data/explorer/sources/native/trash.py +98 -0
- neutralino/_data/explorer/sources/native/tray.py +109 -0
- neutralino/_data/explorer/sources/native/watcher.py +167 -0
- neutralino/_data/explorer/sources/patterns/content_blocks.py +119 -0
- neutralino/_data/explorer/sources/patterns/dynamic_dashboard.py +121 -0
- neutralino/_data/explorer/sources/patterns/dynamic_form.py +120 -0
- neutralino/_data/explorer/sources/patterns/dynamic_table.py +109 -0
- neutralino/_data/explorer/sources/patterns/error_reporting.mjs +24 -0
- neutralino/_data/explorer/sources/patterns/error_reporting.py +124 -0
- neutralino/_data/explorer/sources/patterns/errors_timeouts.py +108 -0
- neutralino/_data/explorer/sources/patterns/feature_flags.py +99 -0
- neutralino/_data/explorer/sources/patterns/file_drop.py +126 -0
- neutralino/_data/explorer/sources/patterns/http_from_python.py +152 -0
- neutralino/_data/explorer/sources/patterns/keyboard_shortcuts.py +153 -0
- neutralino/_data/explorer/sources/patterns/live_config_reload.py +160 -0
- neutralino/_data/explorer/sources/patterns/logging.py +184 -0
- neutralino/_data/explorer/sources/patterns/long_tasks.py +121 -0
- neutralino/_data/explorer/sources/patterns/multi_window_sync.py +68 -0
- neutralino/_data/explorer/sources/patterns/navigation_from_backend.py +109 -0
- neutralino/_data/explorer/sources/patterns/onboarding.py +123 -0
- neutralino/_data/explorer/sources/patterns/optimistic_updates.py +89 -0
- neutralino/_data/explorer/sources/patterns/persistence.py +114 -0
- neutralino/_data/explorer/sources/patterns/python_calls_page.mjs +10 -0
- neutralino/_data/explorer/sources/patterns/python_calls_page.py +64 -0
- neutralino/_data/explorer/sources/patterns/python_push.py +84 -0
- neutralino/_data/explorer/sources/patterns/recurring_events.py +114 -0
- neutralino/_data/explorer/sources/patterns/roles_permissions.py +104 -0
- neutralino/_data/explorer/sources/patterns/scheduled_jobs.py +194 -0
- neutralino/_data/explorer/sources/patterns/settings_page.py +165 -0
- neutralino/_data/explorer/sources/patterns/sqlite.py +181 -0
- neutralino/_data/explorer/sources/patterns/streaming.py +102 -0
- neutralino/_data/explorer/sources/patterns/texts_i18n.py +81 -0
- neutralino/_data/explorer/sources/patterns/theme_from_backend.py +86 -0
- neutralino/_data/explorer/sources/patterns/updater.py +232 -0
- neutralino/_data/explorer/sources/workspace/calendar/app.py +547 -0
- neutralino/_data/explorer/sources/workspace/customers/app.py +467 -0
- neutralino/_data/explorer/sources/workspace/dashboard/README.md +36 -0
- neutralino/_data/explorer/sources/workspace/dashboard/app.py +367 -0
- neutralino/_data/explorer/sources/workspace/documents/app.py +511 -0
- neutralino/_data/explorer/sources/workspace/inbox/app.py +439 -0
- neutralino/_data/explorer/sources/workspace/orders/app.py +491 -0
- neutralino/_data/explorer/sources/workspace/reports/app.py +386 -0
- neutralino/_data/explorer/sources/workspace/settings/README.md +38 -0
- neutralino/_data/explorer/sources/workspace/settings/app.py +440 -0
- neutralino/_data/explorer/sources/workspace/system/README.md +36 -0
- neutralino/_data/explorer/sources/workspace/system/app.py +375 -0
- neutralino/_data/explorer/sources/workspace/tasks/app.py +462 -0
- neutralino/_data/renderer/LICENSES/@babel__runtime@7.29.17/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/@codemirror__autocomplete@6.20.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__commands@6.11.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-css@6.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-html@6.4.12/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-javascript@6.2.5/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-json@6.0.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-markdown@6.5.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-python@6.2.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-sql@6.10.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-yaml@6.1.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__language@6.13.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__search@6.7.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__state@6.7.6/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__view@6.44.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__accessibility@3.1.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__core@6.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__sortable@10.0.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__utilities@3.2.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@emoji-mart__data@1.2.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__core@1.8.0/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__dom@1.8.0/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__react-dom@2.1.9/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__react@0.27.20/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__utils@0.2.12/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@lezer__common@1.5.7/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__css@1.3.9/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__highlight@1.2.5/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__html@1.3.13/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__javascript@1.5.7/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__json@1.0.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__lr@1.4.13/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__markdown@1.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__python@1.1.21/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__yaml@1.0.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__carousel@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__charts@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__code-highlight@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__core@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__dates@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__dropzone@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__emoji@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__hooks@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__lightbox@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__notifications@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__nprogress@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__schedule@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__spotlight@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__store@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__tiptap@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@marijn__find-cluster-break@1.0.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@reduxjs__toolkit@2.16.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tabler__icons-react@3.55.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tanstack__react-virtual@3.14.32/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tanstack__virtual-core@3.19.17/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__core@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-blockquote@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-bold@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-code-block@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-code@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-document@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-hard-break@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-heading@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-horizontal-rule@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-italic@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-link@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-list@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-paragraph@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-strike@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-text@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-underline@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extensions@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__react@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__starter-kit@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/attr-accept@4.0.1/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/clsx@2.1.1/license +9 -0
- neutralino/_data/renderer/LICENSES/crelt@1.0.7/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/d3-array@3.2.5/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-color@3.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-format@3.1.3/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-interpolate@3.0.2/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-path@3.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-scale@4.0.3/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-shape@3.2.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-time-format@4.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-time@3.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/dayjs@1.11.23/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/decimal.js-light@2.5.1/LICENCE.md +23 -0
- neutralino/_data/renderer/LICENSES/diff@9.0.0/LICENSE +29 -0
- neutralino/_data/renderer/LICENSES/dompurify@3.5.1/LICENSE +202 -0
- neutralino/_data/renderer/LICENSES/dompurify@3.5.1/LICENSE-MPL +373 -0
- neutralino/_data/renderer/LICENSES/embla-carousel-react@8.6.0/MIT-embla-carousel.txt +21 -0
- neutralino/_data/renderer/LICENSES/embla-carousel-reactive-utils@8.6.0/MIT-embla-carousel.txt +21 -0
- neutralino/_data/renderer/LICENSES/embla-carousel@8.6.0/MIT-embla-carousel.txt +21 -0
- neutralino/_data/renderer/LICENSES/es-toolkit@1.53.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/es-toolkit@1.53.2/NOTICE +39 -0
- neutralino/_data/renderer/LICENSES/eventemitter3@5.0.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/fast-equals@5.4.7/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/file-selector@5.0.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/get-nonce@1.0.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/immer@11.2.14/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/linkifyjs@4.4.0/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/marked@18.4.0/LICENSE +44 -0
- neutralino/_data/renderer/LICENSES/neutralino.js@6.11.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/orderedmap@2.1.1/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/packages.json +1838 -0
- neutralino/_data/renderer/LICENSES/prosemirror-commands@1.7.2/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-dropcursor@1.8.4/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-gapcursor@1.4.1/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-history@1.5.2/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-keymap@1.2.3/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-model@1.25.13/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-schema-list@1.6.1/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-state@1.4.4/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-transform@1.12.7/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-view@1.44.0/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/react-dom@19.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-dropzone@20.1.4/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/react-is@19.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-number-format@5.4.5/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-redux@9.3.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/react-remove-scroll-bar@2.3.8/MIT-react-remove-scroll-bar.txt +21 -0
- neutralino/_data/renderer/LICENSES/react-remove-scroll@2.7.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-style-singleton@2.2.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-transition-group@4.4.5/LICENSE +30 -0
- neutralino/_data/renderer/LICENSES/react@19.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/recharts@3.11.3/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/redux-thunk@3.1.0/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/redux@5.0.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/reselect@5.2.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/rolldown@1.3.4/LICENSE +25 -0
- neutralino/_data/renderer/LICENSES/rope-sequence@1.3.4/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/rrule@2.8.1/LICENCE +65 -0
- neutralino/_data/renderer/LICENSES/scheduler@0.28.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/style-mod@4.1.5/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/tiny-invariant@1.3.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/tslib@2.9.1/LICENSE.txt +12 -0
- neutralino/_data/renderer/LICENSES/use-callback-ref@1.3.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/use-sidecar@1.1.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/use-sync-external-store@1.7.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/victory-vendor@38.1.1/LICENSE.txt +150 -0
- neutralino/_data/renderer/LICENSES/vite@8.4.1/LICENSE.md +2320 -0
- neutralino/_data/renderer/LICENSES/w3c-keyname@2.2.8/LICENSE +19 -0
- neutralino/_data/renderer/assets/IconGripVertical-C2NUKJAE.js +1 -0
- neutralino/_data/renderer/assets/carousel-D1j1SkWR.css +1 -0
- neutralino/_data/renderer/assets/carousel-DHnOKa8c.js +1 -0
- neutralino/_data/renderer/assets/chunk-CCkLOSkX.css +1 -0
- neutralino/_data/renderer/assets/chunk-CLVygP7p.js +9 -0
- neutralino/_data/renderer/assets/codehighlight-CXJaU0yv.js +10 -0
- neutralino/_data/renderer/assets/codehighlight-THJMNDh8.css +1 -0
- neutralino/_data/renderer/assets/codemirror-DX0MbxKq.js +2 -0
- neutralino/_data/renderer/assets/css-BotC7byr.js +1 -0
- neutralino/_data/renderer/assets/dist-3kB5bJpS.js +23 -0
- neutralino/_data/renderer/assets/dist-6zrr4MrK.js +1 -0
- neutralino/_data/renderer/assets/dist-Beotrn8G.js +1 -0
- neutralino/_data/renderer/assets/dist-CCJHv8n0.js +11 -0
- neutralino/_data/renderer/assets/dist-CdYA9or5.js +1 -0
- neutralino/_data/renderer/assets/dist-D2p_6o_g.js +1 -0
- neutralino/_data/renderer/assets/dnd-DkNumIKC.js +5 -0
- neutralino/_data/renderer/assets/dropzone-aPCBPjDN.css +1 -0
- neutralino/_data/renderer/assets/dropzone-agrigkXv.js +1 -0
- neutralino/_data/renderer/assets/embla-carousel-react.esm-_ztrE73N.js +1 -0
- neutralino/_data/renderer/assets/emoji-Cj3VQHg8.js +1 -0
- neutralino/_data/renderer/assets/emoji-DV8OzU1E.css +1 -0
- neutralino/_data/renderer/assets/esm-DbOmMyz5.js +82 -0
- neutralino/_data/renderer/assets/highlight-Dlb5DJwL.css +1 -0
- neutralino/_data/renderer/assets/highlight-LH6Cyuz6.js +3 -0
- neutralino/_data/renderer/assets/html-CpATC083.js +1 -0
- neutralino/_data/renderer/assets/icon-chunk-C-4QDF6w.js +1 -0
- neutralino/_data/renderer/assets/index-CqHW60Dy.js +69 -0
- neutralino/_data/renderer/assets/index-TWpF4Lef.css +1 -0
- neutralino/_data/renderer/assets/javascript-D2QSKlDI.js +1 -0
- neutralino/_data/renderer/assets/json-D8zfYii3.js +1 -0
- neutralino/_data/renderer/assets/lightbox-BijRfmPy.js +1 -0
- neutralino/_data/renderer/assets/lightbox-BzKDpkAD.css +1 -0
- neutralino/_data/renderer/assets/markdown-Cpthnhzg.js +77 -0
- neutralino/_data/renderer/assets/markdown-CsS2tf5C.js +5 -0
- neutralino/_data/renderer/assets/python-B477ud9A.js +9 -0
- neutralino/_data/renderer/assets/richtext-BwtgvH7-.js +137 -0
- neutralino/_data/renderer/assets/richtext-DIAsHMuK.css +1 -0
- neutralino/_data/renderer/assets/spotlight-Ccstaz1-.css +1 -0
- neutralino/_data/renderer/assets/spotlight-Db1pwUWd.js +1 -0
- neutralino/_data/renderer/assets/sql-DbpHRl6F.js +2 -0
- neutralino/_data/renderer/assets/with-selector-CUfuSYau.js +1 -0
- neutralino/_data/renderer/assets/yaml-BPsr1O3S.js +1 -0
- neutralino/_data/renderer/index.html +22 -0
- neutralino/_data/renderer/manifest.json +202 -0
- neutralino/_data/renderer/neutralino.js +1 -0
- neutralino/_data/renderer/shared/mantine-core.mjs +5 -0
- neutralino/_data/renderer/shared/mantine-hooks.mjs +5 -0
- neutralino/_data/renderer/shared/react-dom-client.mjs +5 -0
- neutralino/_data/renderer/shared/react-dom.mjs +6 -0
- neutralino/_data/renderer/shared/react-jsx-runtime.mjs +5 -0
- neutralino/_data/renderer/shared/react.mjs +6 -0
- neutralino/_data/skills/README.md +6 -0
- neutralino/_data/skills/neutralino-app-patterns/SKILL.md +101 -0
- neutralino/_data/skills/neutralino-app-patterns/references/dashboards-and-background-work.md +55 -0
- neutralino/_data/skills/neutralino-app-patterns/references/storage-and-settings.md +57 -0
- neutralino/_data/skills/neutralino-app-patterns/references/tables-and-crud.md +81 -0
- neutralino/_data/skills/neutralino-frontend/SKILL.md +121 -0
- neutralino/_data/skills/neutralino-frontend/references/bridge.md +63 -0
- neutralino/_data/skills/neutralino-frontend/references/custom-components.md +84 -0
- neutralino/_data/skills/neutralino-frontend/references/frameworks.md +61 -0
- neutralino/_data/skills/neutralino-maintenance/SKILL.md +85 -0
- neutralino/_data/skills/neutralino-maintenance/references/platforms-and-gates.md +35 -0
- neutralino/_data/skills/neutralino-maintenance/references/records.md +38 -0
- neutralino/_data/skills/neutralino-maintenance/references/review-process.md +36 -0
- neutralino/_data/skills/neutralino-native/SKILL.md +107 -0
- neutralino/_data/skills/neutralino-native/references/api-conventions.md +72 -0
- neutralino/_data/skills/neutralino-native/references/desktop-helpers.md +53 -0
- neutralino/_data/skills/neutralino-native/references/permissions-windows.md +53 -0
- neutralino/_data/skills/neutralino-packaging/SKILL.md +99 -0
- neutralino/_data/skills/neutralino-packaging/references/build-layout.md +51 -0
- neutralino/_data/skills/neutralino-packaging/references/managed-install.md +59 -0
- neutralino/_data/skills/neutralino-packaging/references/templates-and-config.md +63 -0
- neutralino/_data/skills/neutralino-python/SKILL.md +109 -0
- neutralino/_data/skills/neutralino-python/references/architecture.md +53 -0
- neutralino/_data/skills/neutralino-python/references/cli.md +60 -0
- neutralino/_data/skills/neutralino-python/references/platforms-security.md +44 -0
- neutralino/_data/skills/neutralino-rpc/SKILL.md +114 -0
- neutralino/_data/skills/neutralino-rpc/references/errors-and-limits.md +44 -0
- neutralino/_data/skills/neutralino-rpc/references/expose-and-context.md +74 -0
- neutralino/_data/skills/neutralino-rpc/references/streams-and-cancellation.md +53 -0
- neutralino/_data/skills/neutralino-ui/SKILL.md +115 -0
- neutralino/_data/skills/neutralino-ui/references/components-and-tree.md +74 -0
- neutralino/_data/skills/neutralino-ui/references/state-forms-events.md +85 -0
- neutralino/_data/skills/neutralino-ui/references/themes-profiles-assets.md +105 -0
- neutralino/_data/skills/neutralino-updates/SKILL.md +94 -0
- neutralino/_data/skills/neutralino-updates/references/config-and-api.md +80 -0
- neutralino/_data/skills/neutralino-updates/references/releases-and-install.md +77 -0
- neutralino/_data/skills/neutralino-updates/references/security-rollback.md +48 -0
- neutralino/_data/ui/contracts.json +32927 -0
- neutralino/_data/ui/emoji.json +1 -0
- neutralino/_data/upstream-lock.json +97 -0
- neutralino/_managed.py +1099 -0
- neutralino/_paths.py +220 -0
- neutralino/_platform.py +150 -0
- neutralino/_scaffold.py +344 -0
- neutralino/api/_base.py +99 -0
- neutralino/api/_custom.py +1350 -0
- neutralino/api/_dec.py +21 -0
- neutralino/api/_enc.py +80 -0
- neutralino/api/app.py +119 -0
- neutralino/api/clipboard.py +101 -0
- neutralino/api/computer.py +261 -0
- neutralino/api/custom.py +36 -0
- neutralino/api/debug.py +41 -0
- neutralino/api/extensions.py +57 -0
- neutralino/api/filesystem.py +633 -0
- neutralino/api/net.py +22 -0
- neutralino/api/os.py +508 -0
- neutralino/api/resources.py +124 -0
- neutralino/api/server.py +66 -0
- neutralino/api/storage.py +98 -0
- neutralino/api/types.py +342 -0
- neutralino/api/updater.py +22 -0
- neutralino/api/window.py +397 -0
- neutralino/application.py +1261 -0
- neutralino/bundle.py +187 -0
- neutralino/cli.py +629 -0
- neutralino/client.py +496 -0
- neutralino/config.py +671 -0
- neutralino/devtools.py +1973 -0
- neutralino/errors.py +142 -0
- neutralino/events.py +579 -0
- neutralino/execution.py +293 -0
- neutralino/extension.py +134 -0
- neutralino/frontend/python-bridge.d.ts +207 -0
- neutralino/frontend/python-bridge.mjs +854 -0
- neutralino/protocol.py +456 -0
- neutralino/py.typed +0 -0
- neutralino/rpc.py +1625 -0
- neutralino/runtime.py +591 -0
- neutralino/supervisor.py +866 -0
- neutralino/sync_client.py +376 -0
- neutralino/templates/default/app.py +32 -0
- neutralino/templates/default/frontend/app.js +28 -0
- neutralino/templates/default/frontend/index.html +26 -0
- neutralino/templates/default/frontend/neutralino.js +1 -0
- neutralino/templates/default/frontend/styles.css +8 -0
- neutralino/templates/default/gitignore.txt +3 -0
- neutralino/templates/default/neutralino.config.json +25 -0
- neutralino/templates/hybrid/README.md +17 -0
- neutralino/templates/hybrid/app.py +49 -0
- neutralino/templates/hybrid/components/counter.mjs +37 -0
- neutralino/templates/hybrid/styles.css +21 -0
- neutralino/templates/python-ui/README.md +15 -0
- neutralino/templates/python-ui/app.py +44 -0
- neutralino/templates/python-ui/gitignore.txt +3 -0
- neutralino/templates/python-ui/requirements.txt +4 -0
- neutralino/templates/react/README.md +28 -0
- neutralino/templates/react/app.py +52 -0
- neutralino/templates/react/components/widget.mjs +23 -0
- neutralino/templates/react/widget/package.json +20 -0
- neutralino/templates/react/widget/src/Widget.jsx +25 -0
- neutralino/templates/react/widget/vite.config.mjs +19 -0
- neutralino/transport.py +661 -0
- neutralino/types.py +93 -0
- neutralino/ui/__init__.py +139 -0
- neutralino/ui/_app.py +1529 -0
- neutralino/ui/_assets.py +407 -0
- neutralino/ui/_bases.py +1210 -0
- neutralino/ui/_behaviours.py +1066 -0
- neutralino/ui/_charts.py +732 -0
- neutralino/ui/_component.py +882 -0
- neutralino/ui/_dates.py +168 -0
- neutralino/ui/_desktop.py +879 -0
- neutralino/ui/_events.py +192 -0
- neutralino/ui/_filters.py +427 -0
- neutralino/ui/_forms.py +282 -0
- neutralino/ui/_protocol.py +201 -0
- neutralino/ui/_schedule.py +543 -0
- neutralino/ui/_security.py +106 -0
- neutralino/ui/_session.py +969 -0
- neutralino/ui/_state.py +199 -0
- neutralino/ui/_tables.py +256 -0
- neutralino/ui/_theme.py +154 -0
- neutralino/ui/blocks/__init__.py +19 -0
- neutralino/ui/blocks/_data.py +2239 -0
- neutralino/ui/blocks/_interactive.py +622 -0
- neutralino/ui/blocks/_layout.py +2967 -0
- neutralino/ui/components/__init__.py +81 -0
- neutralino/ui/components/_dates.py +879 -0
- neutralino/ui/components/_editors.py +217 -0
- neutralino/ui/components/_extensions.py +790 -0
- neutralino/ui/components/_extras.py +303 -0
- neutralino/ui/components/_generated.py +30565 -0
- neutralino/ui/components/_types.py +17 -0
- neutralino/ui/schema.py +824 -0
- neutralino/ui/validators.py +362 -0
- neutralino/updates/__init__.py +96 -0
- neutralino/updates/_http.py +320 -0
- neutralino/updates/_layout.py +762 -0
- neutralino/updates/archive.py +216 -0
- neutralino/updates/config.py +256 -0
- neutralino/updates/errors.py +97 -0
- neutralino/updates/install.sh.in +201 -0
- neutralino/updates/launcher.py +18 -0
- neutralino/updates/manager.py +808 -0
- neutralino/updates/manifest.py +196 -0
- neutralino/updates/release.py +314 -0
- neutralino/updates/semver.py +84 -0
- neutralino/updates/sources.py +392 -0
- neutralino/windows.py +316 -0
- neutralino_python-0.1.0rc1.dist-info/METADATA +117 -0
- neutralino_python-0.1.0rc1.dist-info/RECORD +521 -0
- neutralino_python-0.1.0rc1.dist-info/WHEEL +4 -0
- neutralino_python-0.1.0rc1.dist-info/entry_points.txt +3 -0
- neutralino_python-0.1.0rc1.dist-info/licenses/LICENSE +21 -0
- neutralino_python-0.1.0rc1.dist-info/licenses/THIRD_PARTY_NOTICES.md +16 -0
- neutralino_python-0.1.0rc1.dist-info/licenses/src/neutralino/_data/renderer/LICENSES/packages.json +1838 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""Recurring jobs on one asyncio scheduler: no drift, per-job outcome, clean shutdown.
|
|
2
|
+
|
|
3
|
+
Run: uv run python examples/patterns/scheduled_jobs.py
|
|
4
|
+
|
|
5
|
+
``Scheduler`` decides what is due from a single task and runs each job as its own task
|
|
6
|
+
(a slow job never delays the others, and never overlaps itself). The next due time of a
|
|
7
|
+
job is computed *before* it runs, from the previous due time and not from "now",
|
|
8
|
+
so a slow run or a late wake-up never shifts the schedule (``due`` times are
|
|
9
|
+
exactly ``first + n * interval``); if a run overruns whole intervals the missed
|
|
10
|
+
ones are skipped and counted, never queued up. An action that raises is recorded
|
|
11
|
+
as that job's outcome and the others keep running. Disabling a job stops it;
|
|
12
|
+
enabling re-anchors it one interval from now. ``stop()`` cancels the loop and a
|
|
13
|
+
job that is running right now, and returns only when both are gone.
|
|
14
|
+
|
|
15
|
+
The page shows a ``ui.Table`` of the jobs and a ``ui.Switch`` for each one.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import asyncio
|
|
21
|
+
import contextlib
|
|
22
|
+
import time
|
|
23
|
+
from collections.abc import Awaitable, Callable
|
|
24
|
+
from dataclasses import dataclass, field
|
|
25
|
+
from typing import Any
|
|
26
|
+
|
|
27
|
+
from neutralino import ui
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class Job:
|
|
32
|
+
name: str
|
|
33
|
+
interval: float
|
|
34
|
+
action: Callable[[], Awaitable[object]]
|
|
35
|
+
enabled: bool = True
|
|
36
|
+
next_due: float = 0.0
|
|
37
|
+
runs: int = 0
|
|
38
|
+
skipped: int = 0
|
|
39
|
+
last: str = "not run yet"
|
|
40
|
+
due_log: list[float] = field(default_factory=list[float])
|
|
41
|
+
started_log: list[float] = field(default_factory=list[float])
|
|
42
|
+
task: asyncio.Task[None] | None = None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Scheduler:
|
|
46
|
+
def __init__(
|
|
47
|
+
self, on_change: Callable[[], None] | None = None, clock: Callable[[], float] | None = None
|
|
48
|
+
) -> None:
|
|
49
|
+
self.jobs: dict[str, Job] = {}
|
|
50
|
+
self.on_change = on_change
|
|
51
|
+
self._clock = clock
|
|
52
|
+
self._task: asyncio.Task[None] | None = None
|
|
53
|
+
self._wake = asyncio.Event()
|
|
54
|
+
|
|
55
|
+
def now(self) -> float:
|
|
56
|
+
return self._clock() if self._clock else time.monotonic() # the loop's own clock
|
|
57
|
+
|
|
58
|
+
def add(self, job: Job) -> Job:
|
|
59
|
+
job.next_due = self.now() + job.interval
|
|
60
|
+
self.jobs[job.name] = job
|
|
61
|
+
self._wake.set()
|
|
62
|
+
return job
|
|
63
|
+
|
|
64
|
+
def set_enabled(self, name: str, enabled: bool) -> None:
|
|
65
|
+
job = self.jobs[name]
|
|
66
|
+
if enabled and not job.enabled:
|
|
67
|
+
job.next_due = self.now() + job.interval # re-anchor, no burst of missed runs
|
|
68
|
+
job.enabled = enabled
|
|
69
|
+
self._wake.set()
|
|
70
|
+
self._changed()
|
|
71
|
+
|
|
72
|
+
def _changed(self) -> None:
|
|
73
|
+
if self.on_change is not None:
|
|
74
|
+
self.on_change()
|
|
75
|
+
|
|
76
|
+
async def start(self) -> None:
|
|
77
|
+
if self._task is None or self._task.done():
|
|
78
|
+
for job in self.jobs.values(): # the schedule starts now, not when the job was added
|
|
79
|
+
job.next_due = self.now() + job.interval
|
|
80
|
+
self._task = asyncio.ensure_future(self._loop())
|
|
81
|
+
|
|
82
|
+
async def stop(self) -> None:
|
|
83
|
+
"""Cancel the loop and every running job; returns when all of them are gone."""
|
|
84
|
+
task, self._task = self._task, None
|
|
85
|
+
running = [j.task for j in self.jobs.values() if j.task is not None]
|
|
86
|
+
for t in [*([task] if task else []), *running]:
|
|
87
|
+
t.cancel()
|
|
88
|
+
await asyncio.gather(
|
|
89
|
+
*(t for t in [task, *running] if t is not None), return_exceptions=True
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
async def _loop(self) -> None:
|
|
93
|
+
while True:
|
|
94
|
+
self._wake.clear()
|
|
95
|
+
now = self.now()
|
|
96
|
+
due = sorted((j for j in self.jobs.values() if j.enabled and j.next_due <= now),
|
|
97
|
+
key=lambda j: j.next_due) # fmt: skip
|
|
98
|
+
for job in due:
|
|
99
|
+
self._run(job)
|
|
100
|
+
enabled = [j.next_due for j in self.jobs.values() if j.enabled]
|
|
101
|
+
wait = max(0.0, min(enabled) - self.now()) if enabled else None
|
|
102
|
+
with contextlib.suppress(TimeoutError):
|
|
103
|
+
await asyncio.wait_for(self._wake.wait(), wait)
|
|
104
|
+
|
|
105
|
+
def _run(self, job: Job) -> None:
|
|
106
|
+
scheduled = job.next_due
|
|
107
|
+
job.next_due = scheduled + job.interval # computed before the run: no drift
|
|
108
|
+
while job.next_due <= self.now(): # overran whole intervals: skip, do not catch up
|
|
109
|
+
job.next_due += job.interval
|
|
110
|
+
job.skipped += 1
|
|
111
|
+
if job.task is not None and not job.task.done():
|
|
112
|
+
job.skipped += 1 # still running from the last time: never two at once
|
|
113
|
+
return
|
|
114
|
+
job.due_log.append(scheduled)
|
|
115
|
+
job.started_log.append(self.now())
|
|
116
|
+
job.task = asyncio.ensure_future(self._execute(job))
|
|
117
|
+
|
|
118
|
+
async def _execute(self, job: Job) -> None:
|
|
119
|
+
try:
|
|
120
|
+
result = await job.action()
|
|
121
|
+
job.last = f"ok: {result}" if result is not None else "ok"
|
|
122
|
+
except Exception as err: # one failing job never stops the scheduler
|
|
123
|
+
job.last = f"failed: {type(err).__name__}"
|
|
124
|
+
job.runs += 1
|
|
125
|
+
self._changed()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def demo_jobs() -> list[Job]:
|
|
129
|
+
counter = {"n": 0}
|
|
130
|
+
|
|
131
|
+
async def heartbeat() -> str:
|
|
132
|
+
return "alive"
|
|
133
|
+
|
|
134
|
+
async def cleanup() -> None:
|
|
135
|
+
counter["n"] += 1
|
|
136
|
+
if counter["n"] % 3 == 0:
|
|
137
|
+
raise RuntimeError("disk is busy")
|
|
138
|
+
|
|
139
|
+
return [Job("heartbeat", 2.0, heartbeat), Job("cleanup", 5.0, cleanup)]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def build(
|
|
143
|
+
app: ui.Application | ui.AsyncApplication, jobs: list[Job] | None = None
|
|
144
|
+
) -> dict[str, Any]:
|
|
145
|
+
sched = Scheduler()
|
|
146
|
+
for job in jobs if jobs is not None else demo_jobs():
|
|
147
|
+
sched.add(job)
|
|
148
|
+
switches: dict[str, ui.Switch] = {}
|
|
149
|
+
|
|
150
|
+
def rows() -> dict[str, Any]:
|
|
151
|
+
now = sched.now()
|
|
152
|
+
return {
|
|
153
|
+
"head": ["Job", "Every", "Next in", "Runs", "Last result"],
|
|
154
|
+
"body": [
|
|
155
|
+
[
|
|
156
|
+
j.name, f"{j.interval:g} s",
|
|
157
|
+
f"{max(0.0, j.next_due - now):.1f} s" if j.enabled else "off",
|
|
158
|
+
j.runs, j.last,
|
|
159
|
+
]
|
|
160
|
+
for j in sched.jobs.values()
|
|
161
|
+
],
|
|
162
|
+
} # fmt: skip
|
|
163
|
+
|
|
164
|
+
with app.page("/"), ui.Stack(gap="sm"):
|
|
165
|
+
ui.Title("Scheduled jobs", order=3)
|
|
166
|
+
table = ui.Table(data=rows(), striped=True, with_table_border=True)
|
|
167
|
+
|
|
168
|
+
def toggler(name: str) -> Callable[[ui.ChangeEvent[bool]], Awaitable[None]]:
|
|
169
|
+
async def toggle(ev: ui.ChangeEvent[bool]) -> None: # async: runs on the event loop
|
|
170
|
+
sched.set_enabled(name, bool(ev.value))
|
|
171
|
+
|
|
172
|
+
return toggle
|
|
173
|
+
|
|
174
|
+
for job in sched.jobs.values():
|
|
175
|
+
switches[job.name] = ui.Switch(
|
|
176
|
+
label=f"{job.name} enabled", checked=job.enabled, on_change=toggler(job.name)
|
|
177
|
+
)
|
|
178
|
+
sched.on_change = lambda: table.update(data=rows())
|
|
179
|
+
return {"scheduler": sched, "table": table, "switches": switches}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
async def main() -> None:
|
|
183
|
+
app = ui.AsyncApplication(title="Scheduled jobs", width=560, height=400)
|
|
184
|
+
c = build(app)
|
|
185
|
+
await app.start()
|
|
186
|
+
await c["scheduler"].start()
|
|
187
|
+
try:
|
|
188
|
+
await app.run()
|
|
189
|
+
finally:
|
|
190
|
+
await c["scheduler"].stop()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
if __name__ == "__main__":
|
|
194
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""A settings page generated from a schema: validated in Python, saved atomically, applied live.
|
|
2
|
+
|
|
3
|
+
Run: uv run python examples/patterns/settings_page.py
|
|
4
|
+
|
|
5
|
+
``SCHEMA`` is plain data. Switches and selects become a ``ui.blocks.SettingsPanel``
|
|
6
|
+
that applies every change at once; text and number fields become a ``ui.Form``
|
|
7
|
+
whose fields carry validators built from the same schema (``ui.validators``), so
|
|
8
|
+
an invalid value is refused with its message before anything is saved. The values
|
|
9
|
+
live in one ``ui.State`` that ``State.persist`` writes to the application's
|
|
10
|
+
settings file (an atomic JSON replace) on every change, and the "preview" line
|
|
11
|
+
follows the state, which is what "applied live" means for a real application.
|
|
12
|
+
"Reset to defaults" puts the schema defaults back in the state, the panel and the
|
|
13
|
+
form. ``validate`` is the authoritative check (used again on submit); a stored
|
|
14
|
+
value that does not validate is ignored on load.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import Any, cast
|
|
20
|
+
|
|
21
|
+
from neutralino import ui
|
|
22
|
+
|
|
23
|
+
KEY = "preferences"
|
|
24
|
+
SCHEMA: list[dict[str, Any]] = [
|
|
25
|
+
{"key": "autosave", "kind": "switch", "label": "Autosave", "default": True},
|
|
26
|
+
{"key": "notify", "kind": "switch", "label": "Notifications", "default": False},
|
|
27
|
+
{"key": "language", "kind": "select", "label": "Language", "options": ["en", "de"],
|
|
28
|
+
"default": "en"},
|
|
29
|
+
{"key": "display_name", "kind": "text", "label": "Display name", "default": "",
|
|
30
|
+
"min": 2, "max": 30},
|
|
31
|
+
{"key": "interval", "kind": "number", "label": "Autosave every (minutes)", "default": 5,
|
|
32
|
+
"min": 1, "max": 60},
|
|
33
|
+
] # fmt: skip
|
|
34
|
+
BY_KEY = {f["key"]: f for f in SCHEMA}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def defaults() -> dict[str, Any]:
|
|
38
|
+
return {f["key"]: f["default"] for f in SCHEMA}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def rule(spec: dict[str, Any]) -> Any:
|
|
42
|
+
"""The ``ui.validators`` rule of one field (``None`` for switches and selects)."""
|
|
43
|
+
v = ui.validators
|
|
44
|
+
if spec["kind"] == "text":
|
|
45
|
+
return v.all_of(v.required(), v.length(min=spec["min"], max=spec["max"]))
|
|
46
|
+
if spec["kind"] == "number":
|
|
47
|
+
return v.all_of(v.required(), v.integer(), v.range(min=spec["min"], max=spec["max"]))
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def validate(values: dict[str, Any]) -> dict[str, str]:
|
|
52
|
+
"""Errors by key (empty when everything is valid): the authoritative check."""
|
|
53
|
+
errors: dict[str, str] = {}
|
|
54
|
+
for spec in SCHEMA:
|
|
55
|
+
key, value = spec["key"], values.get(spec["key"])
|
|
56
|
+
if spec["kind"] == "switch":
|
|
57
|
+
ok = isinstance(value, bool)
|
|
58
|
+
elif spec["kind"] == "select":
|
|
59
|
+
ok = value in spec["options"]
|
|
60
|
+
else:
|
|
61
|
+
err = rule(spec)(value)
|
|
62
|
+
ok = err is None and (spec["kind"] != "number" or not isinstance(value, bool))
|
|
63
|
+
if err is not None:
|
|
64
|
+
errors[key] = str(err)
|
|
65
|
+
if not ok and key not in errors:
|
|
66
|
+
errors[key] = "Invalid value"
|
|
67
|
+
return errors
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def decode(raw: Any) -> dict[str, Any]:
|
|
71
|
+
"""A stored value, or ``ValueError`` (the stored value is then ignored)."""
|
|
72
|
+
if not isinstance(raw, dict):
|
|
73
|
+
raise ValueError("preferences must be an object")
|
|
74
|
+
stored = cast("dict[str, Any]", raw)
|
|
75
|
+
values = {**defaults(), **{k: v for k, v in stored.items() if k in BY_KEY}}
|
|
76
|
+
if validate(values):
|
|
77
|
+
raise ValueError("stored preferences are invalid")
|
|
78
|
+
return values
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def build(app: ui.Application | ui.AsyncApplication) -> dict[str, Any]:
|
|
82
|
+
prefs: ui.State[dict[str, Any]] = ui.State(defaults())
|
|
83
|
+
prefs.persist(app.settings, KEY, decode=decode)
|
|
84
|
+
inputs: dict[str, Any] = {}
|
|
85
|
+
|
|
86
|
+
def merge(**changes: Any) -> None:
|
|
87
|
+
prefs.set({**prefs.value, **changes})
|
|
88
|
+
|
|
89
|
+
with app.page("/"), ui.Stack(gap="md"):
|
|
90
|
+
ui.Title("Settings", order=3)
|
|
91
|
+
panel = ui.blocks.SettingsPanel(
|
|
92
|
+
[
|
|
93
|
+
ui.blocks.SettingSpec(
|
|
94
|
+
key=f["key"], label=f["label"], kind=f["kind"],
|
|
95
|
+
options=f.get("options", ()), default=prefs.value[f["key"]],
|
|
96
|
+
)
|
|
97
|
+
for f in SCHEMA
|
|
98
|
+
if f["kind"] in ("switch", "select")
|
|
99
|
+
],
|
|
100
|
+
title="Behaviour",
|
|
101
|
+
on_change=lambda ev: merge(**ev.values),
|
|
102
|
+
) # fmt: skip
|
|
103
|
+
with ui.Form(on_submit=lambda ev: save(getattr(ev, "values", None))) as form:
|
|
104
|
+
with ui.Stack(gap="xs"):
|
|
105
|
+
for f in SCHEMA:
|
|
106
|
+
if f["kind"] == "text":
|
|
107
|
+
inputs[f["key"]] = ui.TextInput(
|
|
108
|
+
name=f["key"], label=f["label"], value=prefs.value[f["key"]],
|
|
109
|
+
validator=rule(f),
|
|
110
|
+
) # fmt: skip
|
|
111
|
+
elif f["kind"] == "number":
|
|
112
|
+
inputs[f["key"]] = ui.NumberInput(
|
|
113
|
+
name=f["key"], label=f["label"], value=prefs.value[f["key"]],
|
|
114
|
+
validator=rule(f),
|
|
115
|
+
) # fmt: skip
|
|
116
|
+
with ui.Group():
|
|
117
|
+
save_button = ui.Button("Save", type="submit")
|
|
118
|
+
reset_button = ui.Button("Reset to defaults", variant="default")
|
|
119
|
+
preview = ui.Text()
|
|
120
|
+
|
|
121
|
+
def save(values: dict[str, Any] | None) -> None:
|
|
122
|
+
if not isinstance(values, dict): # not a real form submission
|
|
123
|
+
status.update(text="not saved: no form values")
|
|
124
|
+
return
|
|
125
|
+
errors = validate({**prefs.value, **values}) # the page's checks are not trusted
|
|
126
|
+
if errors:
|
|
127
|
+
status.update(
|
|
128
|
+
text="not saved: " + "; ".join(f"{k}: {m}" for k, m in errors.items())
|
|
129
|
+
)
|
|
130
|
+
return
|
|
131
|
+
merge(**{k: values[k] for k in inputs})
|
|
132
|
+
status.update(text="saved")
|
|
133
|
+
|
|
134
|
+
def reset(ev: ui.Event) -> None:
|
|
135
|
+
prefs.set(defaults())
|
|
136
|
+
panel.set_values({k: v for k, v in defaults().items() if k not in inputs}, notify=False)
|
|
137
|
+
for key, comp in inputs.items():
|
|
138
|
+
comp.update(value=defaults()[key])
|
|
139
|
+
status.update(text="defaults restored")
|
|
140
|
+
|
|
141
|
+
status = ui.Text("", size="xs", dimmed=True)
|
|
142
|
+
reset_button.on("click", reset)
|
|
143
|
+
prefs.bind(
|
|
144
|
+
preview,
|
|
145
|
+
"text",
|
|
146
|
+
lambda p: (
|
|
147
|
+
f"Hello {p['display_name'] or 'stranger'}: {p['language']}, "
|
|
148
|
+
f"autosave {'every ' + str(p['interval']) + ' min' if p['autosave'] else 'off'}, "
|
|
149
|
+
f"notifications {'on' if p['notify'] else 'off'}"
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
return {
|
|
153
|
+
"prefs": prefs, "save_values": save, "panel": panel, "form": form, "inputs": inputs,
|
|
154
|
+
"save": save_button, "reset": reset_button, "preview": preview, "status": status,
|
|
155
|
+
} # fmt: skip
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def main() -> None:
|
|
159
|
+
app = ui.Application(title="Settings", width=520, height=640, app_id="neutralino_settings_page")
|
|
160
|
+
build(app)
|
|
161
|
+
app.run()
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
if __name__ == "__main__":
|
|
165
|
+
main()
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"""SQLite CRUD behind a server-paged table: 100 000 rows, a few on the page.
|
|
2
|
+
|
|
3
|
+
Run: uv run python examples/patterns/sqlite.py
|
|
4
|
+
|
|
5
|
+
The database is a ``sqlite3`` file that only Python opens: the page never sees a
|
|
6
|
+
path, SQL or the connection. ``ui.DataTable(provider=...)`` asks ``Store.page``
|
|
7
|
+
for one window of rows at a time (``offset``/``limit``, sort on a whitelisted
|
|
8
|
+
column, search text as a bound parameter), so only the visible page travels, and
|
|
9
|
+
``Store.fetched`` counts every row ever returned to prove it. A ``ui.Form`` adds a
|
|
10
|
+
row (validated), inline cell edits and a confirmed "delete" row action update or
|
|
11
|
+
remove it, and the table asks for its page again. All SQL uses parameters; column
|
|
12
|
+
names for sorting come from a fixed set.
|
|
13
|
+
|
|
14
|
+
The default database is a temporary file; pass ``path`` for a real one.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import sqlite3
|
|
20
|
+
import tempfile
|
|
21
|
+
import threading
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
from neutralino import ui
|
|
26
|
+
|
|
27
|
+
SORTABLE = {"id", "name", "qty"}
|
|
28
|
+
MAX_PAGE = 200
|
|
29
|
+
SEED_ROWS = 100_000
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Store:
|
|
33
|
+
"""One sqlite file, one connection, one lock."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, path: Path, seed: int = SEED_ROWS) -> None:
|
|
36
|
+
self.path = path
|
|
37
|
+
self.fetched = 0 # rows returned by ``page`` since the start
|
|
38
|
+
self._lock = threading.Lock()
|
|
39
|
+
self._db = sqlite3.connect(path, check_same_thread=False)
|
|
40
|
+
self._db.row_factory = sqlite3.Row
|
|
41
|
+
with self._lock, self._db:
|
|
42
|
+
self._db.execute(
|
|
43
|
+
"CREATE TABLE IF NOT EXISTS items ("
|
|
44
|
+
"id INTEGER PRIMARY KEY, name TEXT NOT NULL, qty INTEGER NOT NULL)"
|
|
45
|
+
)
|
|
46
|
+
if self._db.execute("SELECT COUNT(*) FROM items").fetchone()[0] == 0 and seed:
|
|
47
|
+
self._db.executemany(
|
|
48
|
+
"INSERT INTO items (name, qty) VALUES (?, ?)",
|
|
49
|
+
((f"item {i:06d}", i % 97) for i in range(seed)),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def count(self, search: str | None = None) -> int:
|
|
53
|
+
sql, args = "SELECT COUNT(*) FROM items", []
|
|
54
|
+
if search:
|
|
55
|
+
sql, args = sql + " WHERE name LIKE ? ESCAPE '\\'", [_like(search)]
|
|
56
|
+
with self._lock:
|
|
57
|
+
return int(self._db.execute(sql, args).fetchone()[0])
|
|
58
|
+
|
|
59
|
+
def page(self, q: ui.TableQuery) -> ui.TablePage:
|
|
60
|
+
"""One window of rows. ``limit`` is capped, ``sort`` is checked against ``SORTABLE``."""
|
|
61
|
+
order = (
|
|
62
|
+
f" ORDER BY {q.sort} {'DESC' if q.direction == 'desc' else 'ASC'}"
|
|
63
|
+
if (q.sort in SORTABLE)
|
|
64
|
+
else " ORDER BY id"
|
|
65
|
+
)
|
|
66
|
+
where, args = "", []
|
|
67
|
+
if q.search:
|
|
68
|
+
where, args = " WHERE name LIKE ? ESCAPE '\\'", [_like(q.search)]
|
|
69
|
+
limit = max(1, min(int(q.limit), MAX_PAGE))
|
|
70
|
+
with self._lock:
|
|
71
|
+
rows = self._db.execute(
|
|
72
|
+
f"SELECT id, name, qty FROM items{where}{order} LIMIT ? OFFSET ?",
|
|
73
|
+
[*args, limit, max(0, int(q.offset))],
|
|
74
|
+
).fetchall()
|
|
75
|
+
total = int(self._db.execute(f"SELECT COUNT(*) FROM items{where}", args).fetchone()[0])
|
|
76
|
+
self.fetched += len(rows)
|
|
77
|
+
return ui.TablePage(rows=[dict(r) for r in rows], total=total)
|
|
78
|
+
|
|
79
|
+
def add(self, name: str, qty: int) -> int:
|
|
80
|
+
with self._lock, self._db:
|
|
81
|
+
return int(
|
|
82
|
+
self._db.execute(
|
|
83
|
+
"INSERT INTO items (name, qty) VALUES (?, ?)", (name, qty)
|
|
84
|
+
).lastrowid
|
|
85
|
+
or 0
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def update(self, item_id: int, column: str, value: Any) -> bool:
|
|
89
|
+
if column not in ("name", "qty"):
|
|
90
|
+
return False
|
|
91
|
+
with self._lock, self._db:
|
|
92
|
+
cur = self._db.execute(f"UPDATE items SET {column} = ? WHERE id = ?", (value, item_id))
|
|
93
|
+
return cur.rowcount == 1
|
|
94
|
+
|
|
95
|
+
def delete(self, item_id: int) -> bool:
|
|
96
|
+
with self._lock, self._db:
|
|
97
|
+
return self._db.execute("DELETE FROM items WHERE id = ?", (item_id,)).rowcount == 1
|
|
98
|
+
|
|
99
|
+
def get(self, item_id: int) -> dict[str, Any] | None:
|
|
100
|
+
with self._lock:
|
|
101
|
+
row = self._db.execute(
|
|
102
|
+
"SELECT id, name, qty FROM items WHERE id = ?", (item_id,)
|
|
103
|
+
).fetchone()
|
|
104
|
+
return dict(row) if row else None
|
|
105
|
+
|
|
106
|
+
def close(self) -> None:
|
|
107
|
+
with self._lock:
|
|
108
|
+
self._db.close()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _like(text: str) -> str:
|
|
112
|
+
return "%" + text.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") + "%"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def build(
|
|
116
|
+
app: ui.Application | ui.AsyncApplication, path: Path | None = None, seed: int = SEED_ROWS
|
|
117
|
+
) -> dict[str, Any]:
|
|
118
|
+
store = Store(path or Path(tempfile.mkdtemp(prefix="neutralino-sqlite-")) / "items.db", seed)
|
|
119
|
+
columns = [
|
|
120
|
+
ui.Column("id", "ID", kind="number", sortable=True),
|
|
121
|
+
ui.Column("name", "Name", sortable=True, editable=True),
|
|
122
|
+
ui.Column("qty", "Qty", kind="number", sortable=True, editable=True),
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
def added(ev: ui.SubmitEvent) -> None:
|
|
126
|
+
name, qty = str(ev.values.get("name", "")).strip(), ev.values.get("qty")
|
|
127
|
+
if not name or not isinstance(qty, (int, float)) or isinstance(qty, bool) or qty < 0:
|
|
128
|
+
status.update(text="not added: a name and a quantity of 0 or more")
|
|
129
|
+
return
|
|
130
|
+
new_id = store.add(name, int(qty))
|
|
131
|
+
table.refresh()
|
|
132
|
+
total.update(text=f"{store.count():,} rows")
|
|
133
|
+
status.update(text=f"added #{new_id}")
|
|
134
|
+
|
|
135
|
+
def edited(ev: ui.TableEvent) -> None:
|
|
136
|
+
item_id, column, value = ev.keys[0], str(ev.column), ev.value
|
|
137
|
+
if column == "name" and not str(value).strip():
|
|
138
|
+
status.update(text="not saved: the name is empty")
|
|
139
|
+
elif store.update(int(item_id), column, value.strip() if isinstance(value, str) else value):
|
|
140
|
+
status.update(text=f"saved #{item_id} {column}")
|
|
141
|
+
table.refresh()
|
|
142
|
+
|
|
143
|
+
def acted(ev: ui.RowActionEvent) -> None:
|
|
144
|
+
if ev.action == "delete" and store.delete(int(ev.key)):
|
|
145
|
+
total.update(text=f"{store.count():,} rows")
|
|
146
|
+
status.update(text=f"deleted #{ev.key}")
|
|
147
|
+
table.refresh()
|
|
148
|
+
|
|
149
|
+
with app.page("/"), ui.Stack(gap="sm"):
|
|
150
|
+
ui.Title("Items", order=3)
|
|
151
|
+
with ui.Form(on_submit=added) as form, ui.Group(align="flex-end"):
|
|
152
|
+
name = ui.TextInput(name="name", label="Name", required=True)
|
|
153
|
+
qty = ui.NumberInput(name="qty", label="Qty", value=1, min=0)
|
|
154
|
+
add = ui.Button("Add item", type="submit")
|
|
155
|
+
total = ui.Text(f"{store.count():,} rows", size="sm", dimmed=True)
|
|
156
|
+
status = ui.Text("", size="xs", dimmed=True)
|
|
157
|
+
table = ui.DataTable(
|
|
158
|
+
columns=[c.to_json() for c in columns],
|
|
159
|
+
provider=store.page,
|
|
160
|
+
page_size=25,
|
|
161
|
+
searchable=True,
|
|
162
|
+
row_actions=[
|
|
163
|
+
ui.RowAction("delete", "Delete", color="red", confirm="Delete {name}?").to_json()
|
|
164
|
+
],
|
|
165
|
+
on_cell_edit=edited,
|
|
166
|
+
on_row_action=acted,
|
|
167
|
+
)
|
|
168
|
+
return {
|
|
169
|
+
"store": store, "table": table, "form": form, "name": name, "qty": qty, "add": add,
|
|
170
|
+
"total": total, "status": status,
|
|
171
|
+
} # fmt: skip
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def main() -> None:
|
|
175
|
+
app = ui.Application(title="SQLite", width=760, height=720)
|
|
176
|
+
build(app)
|
|
177
|
+
app.run()
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
if __name__ == "__main__":
|
|
181
|
+
main()
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Streaming: one call, many items, backpressure and cancel.
|
|
2
|
+
|
|
3
|
+
Run: uv run python examples/patterns/streaming.py
|
|
4
|
+
|
|
5
|
+
A generator (sync or async) exposed with ``stream=True`` sends each ``yield`` as
|
|
6
|
+
a chunk over the same call. The page consumes it with ``backend.stream(...)``
|
|
7
|
+
and grants credit as it reads (a window of at most 64 items), so a slow page
|
|
8
|
+
holds the producer back instead of growing a queue. Cancelling (the page's
|
|
9
|
+
``AbortSignal``, a timeout, a disconnect) stops the generator at its next
|
|
10
|
+
``yield``; its ``finally`` block runs. ``ctx.progress`` can report where the
|
|
11
|
+
producer is along the way (coalesced and rate limited).
|
|
12
|
+
|
|
13
|
+
The same generator also feeds a ``ui.Text`` from Python: "Stream here" iterates
|
|
14
|
+
it and updates the text for every item, "Stop" cancels that task.
|
|
15
|
+
|
|
16
|
+
Page side::
|
|
17
|
+
|
|
18
|
+
for await (const item of backend.stream('numbers', {count: 100})) { ... }
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import asyncio
|
|
24
|
+
from collections.abc import AsyncIterator
|
|
25
|
+
from dataclasses import dataclass
|
|
26
|
+
|
|
27
|
+
from neutralino import RpcContext, RpcError, ui
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class Stats:
|
|
32
|
+
"""What the producers did, for tests and for the page's curiosity."""
|
|
33
|
+
|
|
34
|
+
produced: int = 0
|
|
35
|
+
closed: int = 0
|
|
36
|
+
cancelled_seen: int = 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def counter(count: int, delay: float, stats: Stats) -> AsyncIterator[dict[str, int]]:
|
|
40
|
+
"""The producer: ``count`` items, ``delay`` seconds apart (``count=0``: endless)."""
|
|
41
|
+
i = 0
|
|
42
|
+
try:
|
|
43
|
+
while count == 0 or i < count:
|
|
44
|
+
yield {"n": i}
|
|
45
|
+
i += 1
|
|
46
|
+
stats.produced += 1
|
|
47
|
+
if delay:
|
|
48
|
+
await asyncio.sleep(delay)
|
|
49
|
+
finally:
|
|
50
|
+
stats.closed += 1 # runs on completion and on cancel
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def build(app: ui.Application | ui.AsyncApplication) -> tuple[Stats, ui.Text]:
|
|
54
|
+
stats = Stats()
|
|
55
|
+
|
|
56
|
+
@app.expose(stream=True)
|
|
57
|
+
async def numbers(
|
|
58
|
+
count: int, ctx: RpcContext, delay: float = 0.0
|
|
59
|
+
) -> AsyncIterator[dict[str, int]]:
|
|
60
|
+
"""Page-callable stream: ``backend.stream('numbers', {count, delay})``."""
|
|
61
|
+
if not (0 <= count <= 1_000_000) or not (0 <= delay <= 10):
|
|
62
|
+
raise RpcError("INVALID_PARAMS", "count in [0, 1e6], delay in [0, 10]")
|
|
63
|
+
async for item in counter(count, delay, stats):
|
|
64
|
+
if ctx.cancelled: # also observable here, e.g. to skip cleanup work
|
|
65
|
+
stats.cancelled_seen += 1
|
|
66
|
+
ctx.progress(current=item["n"], total=count or None, message="producing")
|
|
67
|
+
yield item
|
|
68
|
+
|
|
69
|
+
job: list[asyncio.Task[None]] = []
|
|
70
|
+
with app.page("/"), ui.Stack(gap="sm"):
|
|
71
|
+
ui.Title("Streaming", order=3)
|
|
72
|
+
latest = ui.Text("idle")
|
|
73
|
+
|
|
74
|
+
async def run_here(ev: ui.Event) -> None:
|
|
75
|
+
async def consume() -> None:
|
|
76
|
+
async for item in counter(30, 0.05, stats):
|
|
77
|
+
latest.update(text=f"item {item['n']}")
|
|
78
|
+
latest.update(text="finished")
|
|
79
|
+
|
|
80
|
+
if not job or job[0].done():
|
|
81
|
+
job[:] = [asyncio.ensure_future(consume())]
|
|
82
|
+
|
|
83
|
+
async def stop(ev: ui.Event) -> None:
|
|
84
|
+
if job and not job[0].done():
|
|
85
|
+
job[0].cancel()
|
|
86
|
+
await asyncio.gather(job[0], return_exceptions=True)
|
|
87
|
+
latest.update(text="stopped")
|
|
88
|
+
|
|
89
|
+
with ui.Group():
|
|
90
|
+
ui.Button("Stream here", on_click=run_here)
|
|
91
|
+
ui.Button("Stop", on_click=stop, variant="light")
|
|
92
|
+
return stats, latest
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def main() -> None:
|
|
96
|
+
app = ui.Application(title="Streaming", width=480, height=320)
|
|
97
|
+
build(app)
|
|
98
|
+
app.run()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
main()
|