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
neutralino/ui/_app.py
ADDED
|
@@ -0,0 +1,1529 @@
|
|
|
1
|
+
"""``ui.Application`` / ``ui.AsyncApplication``: thin facades over the core apps.
|
|
2
|
+
|
|
3
|
+
The facade owns one core application (``native``) and one UI core. It
|
|
4
|
+
registers the ``ui_internal.*`` RPC methods on the core registry, composes
|
|
5
|
+
the renderer resources, and maps every page (peer) to its logical window
|
|
6
|
+
through the verified RPC context (session endpoint + peer id), never through
|
|
7
|
+
an id in the payload.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import contextlib
|
|
14
|
+
import json
|
|
15
|
+
import logging
|
|
16
|
+
import math
|
|
17
|
+
import os
|
|
18
|
+
import threading
|
|
19
|
+
from collections.abc import Callable, Coroutine, Generator, Mapping, Sequence
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, cast, overload
|
|
22
|
+
|
|
23
|
+
from .. import application as core_app
|
|
24
|
+
from .. import config as config_mod
|
|
25
|
+
from ..api.storage import StorageApi, SyncStorageApi
|
|
26
|
+
from ..errors import RpcError, StartupError, ValidationError
|
|
27
|
+
from ..events import EventBus
|
|
28
|
+
from ..rpc import RpcContext
|
|
29
|
+
from ..sync_client import SyncEvents
|
|
30
|
+
from ..types import UNSET, Unset
|
|
31
|
+
from ._assets import AppAssets, renderer_manifest, stage
|
|
32
|
+
from ._bases import FormComponent, TableComponent
|
|
33
|
+
from ._behaviours import (
|
|
34
|
+
Environment,
|
|
35
|
+
ModalHandle,
|
|
36
|
+
NavigationProgress,
|
|
37
|
+
NotificationHandle,
|
|
38
|
+
Pending,
|
|
39
|
+
app_loop,
|
|
40
|
+
call_native,
|
|
41
|
+
check_title,
|
|
42
|
+
confirm,
|
|
43
|
+
notification_id,
|
|
44
|
+
open_modal,
|
|
45
|
+
read_icon,
|
|
46
|
+
run_on_window,
|
|
47
|
+
stage_icon,
|
|
48
|
+
)
|
|
49
|
+
from ._component import (
|
|
50
|
+
TREE_LOCK,
|
|
51
|
+
Component,
|
|
52
|
+
Subscription,
|
|
53
|
+
_build_stack, # pyright: ignore[reportPrivateUsage]
|
|
54
|
+
)
|
|
55
|
+
from ._desktop import (
|
|
56
|
+
GEOMETRY_FILE,
|
|
57
|
+
GEOMETRY_ROUTES,
|
|
58
|
+
AppPaths,
|
|
59
|
+
DesktopHelpers,
|
|
60
|
+
FilterSpec,
|
|
61
|
+
GeometryTracker,
|
|
62
|
+
MessageChoice,
|
|
63
|
+
MessageIcon,
|
|
64
|
+
Settings,
|
|
65
|
+
config_mapping,
|
|
66
|
+
geometry_window_options,
|
|
67
|
+
is_wayland,
|
|
68
|
+
resolve_app_id,
|
|
69
|
+
)
|
|
70
|
+
from ._events import EnvironmentEvent, Handler, IdleEvent
|
|
71
|
+
from ._protocol import (
|
|
72
|
+
M_DISPOSE,
|
|
73
|
+
M_EVENTS,
|
|
74
|
+
M_HELLO,
|
|
75
|
+
M_QUERY,
|
|
76
|
+
M_RESYNC,
|
|
77
|
+
M_SUBMIT,
|
|
78
|
+
PROTOCOL_VERSION,
|
|
79
|
+
ROUTE_RE,
|
|
80
|
+
UiLimits,
|
|
81
|
+
)
|
|
82
|
+
from ._security import NativeProfile, resolve_native_profile
|
|
83
|
+
from ._session import BatchScope, Page, WindowSession, _current_window # pyright: ignore[reportPrivateUsage]
|
|
84
|
+
from ._theme import normalize_theme
|
|
85
|
+
|
|
86
|
+
if TYPE_CHECKING:
|
|
87
|
+
from ..execution import ExecutionEngine
|
|
88
|
+
from ..rpc import RpcEndpoint
|
|
89
|
+
|
|
90
|
+
log = logging.getLogger("neutralino.ui")
|
|
91
|
+
|
|
92
|
+
__all__ = ["Application", "AsyncApplication", "PageHandle", "UiCore", "Window"]
|
|
93
|
+
|
|
94
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
95
|
+
T = TypeVar("T")
|
|
96
|
+
|
|
97
|
+
# Native routes the renderer itself needs (on top of the SDK minimum): none.
|
|
98
|
+
# Applications that use native helpers add their own routes explicitly.
|
|
99
|
+
UI_NATIVE_ALLOW_LIST: tuple[str, ...] = ()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _caller_dir(depth: int = 3) -> Path | None:
|
|
103
|
+
import inspect
|
|
104
|
+
|
|
105
|
+
frame = inspect.stack()[depth]
|
|
106
|
+
f = frame.filename
|
|
107
|
+
if f.startswith("<"):
|
|
108
|
+
return None
|
|
109
|
+
return Path(f).resolve().parent
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class UiCore:
|
|
113
|
+
"""State shared by the sync and async facades (one per application)."""
|
|
114
|
+
|
|
115
|
+
def __init__(
|
|
116
|
+
self,
|
|
117
|
+
native: core_app.AsyncApplication,
|
|
118
|
+
*,
|
|
119
|
+
theme: Mapping[str, Any] | str | None,
|
|
120
|
+
limits: UiLimits | None,
|
|
121
|
+
origin: Path | None,
|
|
122
|
+
asset_roots: Sequence[str | os.PathLike[str]] = (),
|
|
123
|
+
) -> None:
|
|
124
|
+
self.native = native
|
|
125
|
+
self.limits = limits or UiLimits()
|
|
126
|
+
self.theme = normalize_theme(theme)
|
|
127
|
+
self.origin = origin
|
|
128
|
+
# The application's own directory (the file that created the app; the
|
|
129
|
+
# working directory only in an interactive session) is the base of
|
|
130
|
+
# relative asset paths; asset_roots adds other trusted directories.
|
|
131
|
+
base = origin if origin is not None else Path.cwd()
|
|
132
|
+
extra: list[Path] = []
|
|
133
|
+
if isinstance(asset_roots, (str, os.PathLike)):
|
|
134
|
+
raise ValidationError("asset_roots must be a sequence of directories")
|
|
135
|
+
for r in asset_roots:
|
|
136
|
+
rp = Path(r)
|
|
137
|
+
rp = rp if rp.is_absolute() else base / rp
|
|
138
|
+
if not rp.is_dir():
|
|
139
|
+
raise ValidationError(f"asset root {str(r)!r} is not a directory")
|
|
140
|
+
extra.append(rp.resolve())
|
|
141
|
+
self.asset_roots: tuple[Path, ...] = (base.resolve(), *extra)
|
|
142
|
+
self.builders: dict[str, Callable[[], Any]] = {}
|
|
143
|
+
self.assets = AppAssets(roots=self.asset_roots)
|
|
144
|
+
self.batches = BatchScope() # app.batch() state of this application only
|
|
145
|
+
self.main = WindowSession(self, main=True)
|
|
146
|
+
self.windows: dict[str, WindowSession] = {} # token -> secondary window
|
|
147
|
+
self.on_error: Callable[[WindowSession | None, BaseException], Any] | None = None
|
|
148
|
+
self.error_count = 0
|
|
149
|
+
self._unregister: list[Callable[[], None]] = []
|
|
150
|
+
self._register_methods()
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def engine(self) -> ExecutionEngine:
|
|
154
|
+
return self.native.engine
|
|
155
|
+
|
|
156
|
+
# ---------------------------------------------------------- resources
|
|
157
|
+
def resolve(self, path: str | os.PathLike[str]) -> Path:
|
|
158
|
+
"""Window icon paths (not page assets): as given, else from the app directory."""
|
|
159
|
+
p = Path(path)
|
|
160
|
+
if not p.is_absolute() and self.origin is not None and not p.exists():
|
|
161
|
+
p = self.origin / p
|
|
162
|
+
return p
|
|
163
|
+
|
|
164
|
+
def stage_resources(self) -> Path:
|
|
165
|
+
cfg = {
|
|
166
|
+
"protocol": PROTOCOL_VERSION,
|
|
167
|
+
"custom": self.assets.manifest(),
|
|
168
|
+
}
|
|
169
|
+
extra = {"ui-app.json": json.dumps(cfg, sort_keys=True).encode()}
|
|
170
|
+
return stage(self.assets, extra)
|
|
171
|
+
|
|
172
|
+
# ------------------------------------------------------- RPC methods
|
|
173
|
+
def _register_methods(self) -> None:
|
|
174
|
+
reg = self.native.registry
|
|
175
|
+
for name, fn in (
|
|
176
|
+
(M_HELLO, self._hello),
|
|
177
|
+
(M_EVENTS, self._events),
|
|
178
|
+
(M_SUBMIT, self._submit),
|
|
179
|
+
(M_QUERY, self._query),
|
|
180
|
+
(M_RESYNC, self._resync),
|
|
181
|
+
(M_DISPOSE, self._dispose),
|
|
182
|
+
):
|
|
183
|
+
self._unregister.append(reg.register(name, fn))
|
|
184
|
+
|
|
185
|
+
def _session_for(self, ctx: RpcContext, generation: Any) -> WindowSession:
|
|
186
|
+
endpoint = ctx._endpoint # pyright: ignore[reportPrivateUsage]
|
|
187
|
+
for w in (self.main, *self.windows.values()):
|
|
188
|
+
if w.accepts(endpoint, ctx.peer, generation):
|
|
189
|
+
return w
|
|
190
|
+
raise RpcError("UNSUPPORTED", "stale or unknown UI session", {"stale": True})
|
|
191
|
+
|
|
192
|
+
async def _hello(
|
|
193
|
+
self,
|
|
194
|
+
ctx: RpcContext,
|
|
195
|
+
protocol: int,
|
|
196
|
+
renderer: str,
|
|
197
|
+
token: str | None = None,
|
|
198
|
+
capabilities: list[str] | None = None,
|
|
199
|
+
) -> dict[str, Any]:
|
|
200
|
+
if protocol != PROTOCOL_VERSION:
|
|
201
|
+
raise RpcError(
|
|
202
|
+
"UNSUPPORTED",
|
|
203
|
+
f"renderer speaks UI protocol {protocol}, this backend {PROTOCOL_VERSION}: "
|
|
204
|
+
"reinstall neutralino-python so the renderer matches",
|
|
205
|
+
)
|
|
206
|
+
endpoint: RpcEndpoint = ctx._endpoint # pyright: ignore[reportPrivateUsage]
|
|
207
|
+
session: WindowSession | None = None
|
|
208
|
+
if token:
|
|
209
|
+
session = self.windows.get(token)
|
|
210
|
+
if (
|
|
211
|
+
session is not None
|
|
212
|
+
and session.endpoint is not None
|
|
213
|
+
and session.endpoint is not endpoint
|
|
214
|
+
):
|
|
215
|
+
session = None # a token is bound to its own runtime session only
|
|
216
|
+
elif endpoint is self.native.endpoint:
|
|
217
|
+
session = self.main
|
|
218
|
+
if session is None or session.closed:
|
|
219
|
+
raise RpcError("UNSUPPORTED", "unknown UI window")
|
|
220
|
+
loop = asyncio.get_running_loop()
|
|
221
|
+
snap = session.mount(endpoint, ctx.peer, loop)
|
|
222
|
+
expected = renderer_manifest().get("build")
|
|
223
|
+
if expected and renderer != expected:
|
|
224
|
+
log.warning(
|
|
225
|
+
"renderer build %s differs from the packaged build %s",
|
|
226
|
+
renderer[:16],
|
|
227
|
+
str(expected)[:16],
|
|
228
|
+
)
|
|
229
|
+
snap.update(
|
|
230
|
+
protocol=PROTOCOL_VERSION,
|
|
231
|
+
limits=self.limits.to_json(),
|
|
232
|
+
custom=self.assets.manifest(),
|
|
233
|
+
)
|
|
234
|
+
return snap
|
|
235
|
+
|
|
236
|
+
async def _events(
|
|
237
|
+
self, ctx: RpcContext, generation: int, events: Any, revision: int | None = None
|
|
238
|
+
) -> dict[str, Any]:
|
|
239
|
+
try:
|
|
240
|
+
session = self._session_for(ctx, generation)
|
|
241
|
+
except RpcError:
|
|
242
|
+
return {
|
|
243
|
+
"accepted": 0,
|
|
244
|
+
"rejected": len(cast("list[Any]", events)) if isinstance(events, list) else 0,
|
|
245
|
+
"stale": True,
|
|
246
|
+
}
|
|
247
|
+
try:
|
|
248
|
+
return session.handle_events(events)
|
|
249
|
+
except ValidationError as err:
|
|
250
|
+
raise RpcError("INVALID_PARAMS", str(err)) from None
|
|
251
|
+
|
|
252
|
+
async def _submit(
|
|
253
|
+
self,
|
|
254
|
+
ctx: RpcContext,
|
|
255
|
+
generation: int,
|
|
256
|
+
form: str,
|
|
257
|
+
values: dict[str, Any],
|
|
258
|
+
submission: str | None = None,
|
|
259
|
+
revision: int | None = None,
|
|
260
|
+
) -> dict[str, Any]:
|
|
261
|
+
session = self._session_for(ctx, generation)
|
|
262
|
+
with TREE_LOCK:
|
|
263
|
+
comp = session.nodes.get(form)
|
|
264
|
+
if not isinstance(comp, FormComponent):
|
|
265
|
+
raise RpcError("INVALID_PARAMS", "unknown form")
|
|
266
|
+
try:
|
|
267
|
+
return await comp.handle_submit(values, session)
|
|
268
|
+
except ValidationError as err:
|
|
269
|
+
raise RpcError("INVALID_PARAMS", str(err)) from None
|
|
270
|
+
|
|
271
|
+
async def _query(
|
|
272
|
+
self, ctx: RpcContext, generation: int, id: str, query: dict[str, Any]
|
|
273
|
+
) -> dict[str, Any]:
|
|
274
|
+
session = self._session_for(ctx, generation)
|
|
275
|
+
with TREE_LOCK:
|
|
276
|
+
comp = session.nodes.get(id)
|
|
277
|
+
if not isinstance(comp, TableComponent):
|
|
278
|
+
raise RpcError("INVALID_PARAMS", "unknown table")
|
|
279
|
+
try:
|
|
280
|
+
return await comp.handle_query(query, session)
|
|
281
|
+
except ValidationError as err:
|
|
282
|
+
raise RpcError("INVALID_PARAMS", str(err)) from None
|
|
283
|
+
except Exception as err:
|
|
284
|
+
self.report_error(session, err, "ui:query", notify=False)
|
|
285
|
+
raise RpcError("INTERNAL_ERROR", "data provider failed") from None
|
|
286
|
+
|
|
287
|
+
async def _resync(self, ctx: RpcContext, generation: int, reason: str = "") -> dict[str, Any]:
|
|
288
|
+
session = self._session_for(ctx, generation)
|
|
289
|
+
return session.resync(str(reason))
|
|
290
|
+
|
|
291
|
+
async def _dispose(self, ctx: RpcContext, generation: int, reason: str = "") -> None:
|
|
292
|
+
with contextlib.suppress(RpcError):
|
|
293
|
+
self._session_for(ctx, generation).unmount()
|
|
294
|
+
|
|
295
|
+
# ------------------------------------------------------------- errors
|
|
296
|
+
def report_error(
|
|
297
|
+
self, window: WindowSession | None, err: BaseException, where: str, *, notify: bool = True
|
|
298
|
+
) -> None:
|
|
299
|
+
"""Isolate a callback failure: log it with traceback, show the page a sanitized notice."""
|
|
300
|
+
self.error_count += 1
|
|
301
|
+
log.error("UI callback %s failed", where, exc_info=err)
|
|
302
|
+
if self.on_error is not None:
|
|
303
|
+
try:
|
|
304
|
+
self.on_error(window, err)
|
|
305
|
+
except Exception:
|
|
306
|
+
log.exception("on_error handler failed")
|
|
307
|
+
return
|
|
308
|
+
if notify and window is not None:
|
|
309
|
+
window.notify(
|
|
310
|
+
f"{type(err).__name__} in {where.removeprefix('ui:')} handler",
|
|
311
|
+
title="Error",
|
|
312
|
+
color="red",
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
# ------------------------------------------------------------ windows
|
|
316
|
+
def page_handle(self, route: str, session: WindowSession | None = None) -> PageHandle:
|
|
317
|
+
if not ROUTE_RE.fullmatch(route):
|
|
318
|
+
raise ValidationError(f"invalid route {route!r}")
|
|
319
|
+
return PageHandle(self, route, session)
|
|
320
|
+
|
|
321
|
+
def new_window(self, route: str) -> WindowSession:
|
|
322
|
+
w = WindowSession(self, main=False, route=route)
|
|
323
|
+
self.windows[w.token] = w
|
|
324
|
+
return w
|
|
325
|
+
|
|
326
|
+
def window_url(self, w: WindowSession) -> str:
|
|
327
|
+
return f"/index.html?w={w.token}"
|
|
328
|
+
|
|
329
|
+
async def close_windows(self) -> None:
|
|
330
|
+
for w in [self.main, *self.windows.values()]:
|
|
331
|
+
await w.close_session()
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class PageHandle:
|
|
335
|
+
"""``with app.page("/"):`` builds the main window's page now;
|
|
336
|
+
``@app.page("/x")`` registers a builder called once per window that shows it."""
|
|
337
|
+
|
|
338
|
+
def __init__(self, core: UiCore, route: str, session: WindowSession | None) -> None:
|
|
339
|
+
self._core, self.route, self._session = core, route, session
|
|
340
|
+
self._tokens: list[Any] = []
|
|
341
|
+
|
|
342
|
+
def __enter__(self) -> Page:
|
|
343
|
+
session = self._session or self._core.main
|
|
344
|
+
with TREE_LOCK:
|
|
345
|
+
page = session.pages.get(self.route)
|
|
346
|
+
if page is None:
|
|
347
|
+
page = Page(self.route)
|
|
348
|
+
session._own_root(page) # pyright: ignore[reportPrivateUsage]
|
|
349
|
+
self._tokens.append((_build_stack.set((page,)), _current_window.set(session)))
|
|
350
|
+
return page
|
|
351
|
+
|
|
352
|
+
def __exit__(self, *exc: object) -> None:
|
|
353
|
+
tb, tw = self._tokens.pop()
|
|
354
|
+
_current_window.reset(tw)
|
|
355
|
+
_build_stack.reset(tb)
|
|
356
|
+
|
|
357
|
+
def __call__(self, fn: F) -> F:
|
|
358
|
+
if self.route in self._core.builders:
|
|
359
|
+
raise ValidationError(f"a page builder for {self.route!r} is already registered")
|
|
360
|
+
self._core.builders[self.route] = fn
|
|
361
|
+
return fn
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
class Window:
|
|
365
|
+
"""Public handle of one logical window (main or secondary)."""
|
|
366
|
+
|
|
367
|
+
def __init__(self, session: WindowSession) -> None:
|
|
368
|
+
self._s = session
|
|
369
|
+
|
|
370
|
+
@property
|
|
371
|
+
def id(self) -> str:
|
|
372
|
+
return self._s.id
|
|
373
|
+
|
|
374
|
+
@property
|
|
375
|
+
def session(self) -> WindowSession:
|
|
376
|
+
return self._s
|
|
377
|
+
|
|
378
|
+
@property
|
|
379
|
+
def route(self) -> str:
|
|
380
|
+
return self._s.route
|
|
381
|
+
|
|
382
|
+
@property
|
|
383
|
+
def state(self) -> dict[str, Any]:
|
|
384
|
+
"""Free per-window storage for application data."""
|
|
385
|
+
return self._s.state
|
|
386
|
+
|
|
387
|
+
@property
|
|
388
|
+
def closed(self) -> bool:
|
|
389
|
+
return self._s.closed
|
|
390
|
+
|
|
391
|
+
@property
|
|
392
|
+
def native(self) -> Any:
|
|
393
|
+
"""The core :class:`~neutralino.ManagedWindow` (secondary windows) or None."""
|
|
394
|
+
return self._s.native
|
|
395
|
+
|
|
396
|
+
def close(self) -> Pending[None]:
|
|
397
|
+
"""Close this window. A secondary window's runtime stops and its pages
|
|
398
|
+
are disposed; closing the main window stops the application, as if the
|
|
399
|
+
user closed it. Idempotent: closing a closed window does nothing.
|
|
400
|
+
``await`` it (async callbacks) or call ``.result()`` (sync callbacks)
|
|
401
|
+
to wait until the window is gone."""
|
|
402
|
+
s = self._s
|
|
403
|
+
if s.closed:
|
|
404
|
+
return Pending[None].completed(None)
|
|
405
|
+
if s.main:
|
|
406
|
+
s.core.native.request_stop()
|
|
407
|
+
return Pending[None].completed(None)
|
|
408
|
+
native = s.native
|
|
409
|
+
loop = app_loop(s)
|
|
410
|
+
if native is None or loop is None or loop.is_closed():
|
|
411
|
+
raise ValidationError("the window is not open")
|
|
412
|
+
|
|
413
|
+
async def stop() -> None:
|
|
414
|
+
await native.close()
|
|
415
|
+
await native.wait_closed()
|
|
416
|
+
|
|
417
|
+
# Not a task of this window: closing the window cancels its own tasks.
|
|
418
|
+
return Pending(asyncio.run_coroutine_threadsafe(stop(), loop), loop)
|
|
419
|
+
|
|
420
|
+
def page(self, route: str) -> PageHandle:
|
|
421
|
+
return self._s.core.page_handle(route, self._s)
|
|
422
|
+
|
|
423
|
+
def navigate(self, route: str) -> None:
|
|
424
|
+
self._s.navigate(route)
|
|
425
|
+
|
|
426
|
+
def set_theme(self, **theme: Any) -> None:
|
|
427
|
+
self._s.set_theme(**theme)
|
|
428
|
+
|
|
429
|
+
async def drain(self, timeout: float = 10.0) -> None:
|
|
430
|
+
await self._s.drain(timeout)
|
|
431
|
+
|
|
432
|
+
# ------------------------------------------------- environment / idle
|
|
433
|
+
@property
|
|
434
|
+
def environment(self) -> Environment | None:
|
|
435
|
+
"""What the page last reported (None until the page has loaded)."""
|
|
436
|
+
return self._s.environment
|
|
437
|
+
|
|
438
|
+
def on_environment_change(self, handler: Handler[EnvironmentEvent]) -> Subscription:
|
|
439
|
+
"""Call ``handler`` on each environment report (colour scheme, reduced
|
|
440
|
+
motion, visibility, online state, languages, viewport, orientation).
|
|
441
|
+
The page reports when it loads and when something changes (resize is
|
|
442
|
+
debounced ~150 ms)."""
|
|
443
|
+
return self._s.add_window_handler("environment_change", handler)
|
|
444
|
+
|
|
445
|
+
@property
|
|
446
|
+
def idle(self) -> bool | None:
|
|
447
|
+
"""Last idle state reported by the page (None before any report)."""
|
|
448
|
+
return self._s.idle
|
|
449
|
+
|
|
450
|
+
@property
|
|
451
|
+
def idle_timeout(self) -> int | None:
|
|
452
|
+
return self._s.idle_timeout_ms
|
|
453
|
+
|
|
454
|
+
def set_idle_timeout(self, ms: int | None) -> None:
|
|
455
|
+
"""Report ``idle_change`` (True) after ``ms`` milliseconds without user
|
|
456
|
+
input in this window, and False on the next input; None turns it off.
|
|
457
|
+
Only the idle state is sent, never what the user typed or where."""
|
|
458
|
+
v: Any = ms
|
|
459
|
+
if v is not None and (
|
|
460
|
+
isinstance(v, bool) or not isinstance(v, int) or not 1000 <= v <= 86_400_000
|
|
461
|
+
):
|
|
462
|
+
raise ValidationError("idle timeout: None or 1000..86400000 milliseconds")
|
|
463
|
+
self._s.idle_timeout_ms = ms
|
|
464
|
+
if ms is None:
|
|
465
|
+
self._s.idle = None
|
|
466
|
+
self._s.command_nowait(None, "idle_timeout", {"ms": ms})
|
|
467
|
+
|
|
468
|
+
def on_idle_change(self, handler: Handler[IdleEvent]) -> Subscription:
|
|
469
|
+
return self._s.add_window_handler("idle_change", handler)
|
|
470
|
+
|
|
471
|
+
# ------------------------------------------------------ native window
|
|
472
|
+
def _native_window(self) -> Any:
|
|
473
|
+
s = self._s
|
|
474
|
+
if s.main:
|
|
475
|
+
native = s.core.native
|
|
476
|
+
if native.state is not core_app.AppState.RUNNING:
|
|
477
|
+
raise ValidationError("the application is not running")
|
|
478
|
+
return native.window
|
|
479
|
+
if s.native is None:
|
|
480
|
+
raise ValidationError("the window is not open")
|
|
481
|
+
return s.native.window
|
|
482
|
+
|
|
483
|
+
def _instance_root(self) -> Path:
|
|
484
|
+
s = self._s
|
|
485
|
+
proc = s.core.native.process if s.main else getattr(s.native, "process", None)
|
|
486
|
+
root = getattr(proc, "root", None)
|
|
487
|
+
if root is None:
|
|
488
|
+
raise ValidationError("the window's runtime is not running")
|
|
489
|
+
return Path(root)
|
|
490
|
+
|
|
491
|
+
def set_title(self, title: str) -> Pending[None]:
|
|
492
|
+
"""Set the window title: the native title (``window.setTitle``) and
|
|
493
|
+
``document.title``. Needs ``ui.desktop_routes("set_title")`` in the
|
|
494
|
+
native allow list. Before the application runs only the title is kept."""
|
|
495
|
+
text = check_title(title)
|
|
496
|
+
s = self._s
|
|
497
|
+
with TREE_LOCK:
|
|
498
|
+
s.title = text
|
|
499
|
+
if s.live:
|
|
500
|
+
s._struct.append({"op": "title", "title": text}) # pyright: ignore[reportPrivateUsage]
|
|
501
|
+
s._kick() # pyright: ignore[reportPrivateUsage]
|
|
502
|
+
if app_loop(s) is None:
|
|
503
|
+
return Pending[None].completed(None)
|
|
504
|
+
api = self._native_window()
|
|
505
|
+
return run_on_window(
|
|
506
|
+
s,
|
|
507
|
+
"set_title",
|
|
508
|
+
lambda: call_native("window.setTitle", "set_title", api.set_title(text)),
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
def set_fullscreen(self, fullscreen: bool = True) -> Pending[None]:
|
|
512
|
+
"""Enter or leave native full screen (``window.setFullScreen`` /
|
|
513
|
+
``window.exitFullScreen``; ``ui.desktop_routes("set_fullscreen")``)."""
|
|
514
|
+
flag: Any = fullscreen
|
|
515
|
+
if not isinstance(flag, bool):
|
|
516
|
+
raise ValidationError("fullscreen must be a bool")
|
|
517
|
+
api = self._native_window()
|
|
518
|
+
if fullscreen:
|
|
519
|
+
return run_on_window(
|
|
520
|
+
self._s,
|
|
521
|
+
"set_fullscreen",
|
|
522
|
+
lambda: call_native(
|
|
523
|
+
"window.setFullScreen", "set_fullscreen", api.set_full_screen()
|
|
524
|
+
),
|
|
525
|
+
)
|
|
526
|
+
return run_on_window(
|
|
527
|
+
self._s,
|
|
528
|
+
"set_fullscreen",
|
|
529
|
+
lambda: call_native("window.exitFullScreen", "set_fullscreen", api.exit_full_screen()),
|
|
530
|
+
)
|
|
531
|
+
|
|
532
|
+
def set_icon(self, path: str | os.PathLike[str]) -> Pending[None]:
|
|
533
|
+
"""Set the native window icon from a local PNG/JPEG/ICO/BMP/GIF file
|
|
534
|
+
(at most 4 MiB, content checked). The file is copied into the
|
|
535
|
+
runtime's private instance directory and passed to ``window.setIcon``
|
|
536
|
+
(``ui.desktop_routes("set_icon")``)."""
|
|
537
|
+
data, ext = read_icon(self._s.core.resolve(path))
|
|
538
|
+
api = self._native_window()
|
|
539
|
+
name = stage_icon(self._instance_root(), data, ext)
|
|
540
|
+
return run_on_window(
|
|
541
|
+
self._s,
|
|
542
|
+
"set_icon",
|
|
543
|
+
lambda: call_native("window.setIcon", "set_icon", api.set_icon(name)),
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
def scroll_to(self, x: float = 0, y: float = 0, *, smooth: bool = False) -> None:
|
|
547
|
+
"""Scroll the page to ``(x, y)`` CSS pixels."""
|
|
548
|
+
for name, v in (("x", x), ("y", y)):
|
|
549
|
+
val: Any = v
|
|
550
|
+
if isinstance(val, bool) or not isinstance(val, (int, float)):
|
|
551
|
+
raise ValidationError(f"{name} must be a number")
|
|
552
|
+
if not math.isfinite(val) or not 0 <= val <= 10_000_000:
|
|
553
|
+
raise ValidationError(f"{name} must be in 0..10000000")
|
|
554
|
+
sm: Any = smooth
|
|
555
|
+
if not isinstance(sm, bool):
|
|
556
|
+
raise ValidationError("smooth must be a bool")
|
|
557
|
+
self._s.command_nowait(None, "scroll_to", {"x": x, "y": y, "smooth": smooth})
|
|
558
|
+
|
|
559
|
+
# ------------------------------------------------------------ overlays
|
|
560
|
+
@property
|
|
561
|
+
def modals(self) -> tuple[ModalHandle, ...]:
|
|
562
|
+
"""Open modals of this window (oldest first)."""
|
|
563
|
+
with TREE_LOCK:
|
|
564
|
+
return tuple(self._s.modals.values())
|
|
565
|
+
|
|
566
|
+
def open_modal(
|
|
567
|
+
self,
|
|
568
|
+
title: str | None,
|
|
569
|
+
content: Component,
|
|
570
|
+
on_close: Callable[..., Any] | None = None,
|
|
571
|
+
*,
|
|
572
|
+
size: str | float | Unset = UNSET,
|
|
573
|
+
centered: bool | Unset = UNSET,
|
|
574
|
+
full_screen: bool | Unset = UNSET,
|
|
575
|
+
close_on_escape: bool | Unset = UNSET,
|
|
576
|
+
close_on_click_outside: bool | Unset = UNSET,
|
|
577
|
+
with_close_button: bool | Unset = UNSET,
|
|
578
|
+
) -> ModalHandle:
|
|
579
|
+
"""Open a modal over the current page showing ``content`` (a ui
|
|
580
|
+
component tree that the modal owns). It stays open across routes until
|
|
581
|
+
the user closes it (Escape, close button, outside click) or
|
|
582
|
+
:meth:`close_modal`; ``on_close`` then runs once."""
|
|
583
|
+
return open_modal(
|
|
584
|
+
self._s,
|
|
585
|
+
title,
|
|
586
|
+
content,
|
|
587
|
+
on_close,
|
|
588
|
+
{
|
|
589
|
+
"size": size,
|
|
590
|
+
"centered": centered,
|
|
591
|
+
"full_screen": full_screen,
|
|
592
|
+
"close_on_escape": close_on_escape,
|
|
593
|
+
"close_on_click_outside": close_on_click_outside,
|
|
594
|
+
"with_close_button": with_close_button,
|
|
595
|
+
},
|
|
596
|
+
)
|
|
597
|
+
|
|
598
|
+
def update_modal(
|
|
599
|
+
self,
|
|
600
|
+
handle: ModalHandle,
|
|
601
|
+
*,
|
|
602
|
+
title: str | Unset = UNSET,
|
|
603
|
+
content: Component | None = None,
|
|
604
|
+
size: str | float | Unset = UNSET,
|
|
605
|
+
centered: bool | Unset = UNSET,
|
|
606
|
+
full_screen: bool | Unset = UNSET,
|
|
607
|
+
) -> None:
|
|
608
|
+
"""Change an open modal's title, options or content (the old content
|
|
609
|
+
is disposed)."""
|
|
610
|
+
self._own(handle).update(
|
|
611
|
+
title=title, content=content, size=size, centered=centered, full_screen=full_screen
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
def close_modal(self, handle: ModalHandle) -> None:
|
|
615
|
+
self._own(handle).close()
|
|
616
|
+
|
|
617
|
+
def close_all_modals(self) -> None:
|
|
618
|
+
for h in self.modals:
|
|
619
|
+
h.close()
|
|
620
|
+
|
|
621
|
+
def _own(self, handle: ModalHandle) -> ModalHandle:
|
|
622
|
+
if not isinstance(handle, ModalHandle) or handle.window is not self._s: # pyright: ignore[reportUnnecessaryIsInstance]
|
|
623
|
+
raise ValidationError("not a modal of this window")
|
|
624
|
+
return handle
|
|
625
|
+
|
|
626
|
+
def confirm(
|
|
627
|
+
self,
|
|
628
|
+
title: str,
|
|
629
|
+
message: str,
|
|
630
|
+
*,
|
|
631
|
+
confirm_label: str = "OK",
|
|
632
|
+
cancel_label: str = "Cancel",
|
|
633
|
+
confirm_color: str | None = None,
|
|
634
|
+
) -> Pending[bool]:
|
|
635
|
+
"""In-window confirmation modal: True for the confirm button, False for
|
|
636
|
+
cancel or closing it. ``await window.confirm(...)`` in async callbacks,
|
|
637
|
+
``window.confirm(...).result()`` in sync ones. (The native dialog is
|
|
638
|
+
``app.confirm``.)"""
|
|
639
|
+
return confirm(self._s, title, message, confirm_label, cancel_label, confirm_color)
|
|
640
|
+
|
|
641
|
+
# ------------------------------------------------------- notifications
|
|
642
|
+
def notify(
|
|
643
|
+
self,
|
|
644
|
+
message: str,
|
|
645
|
+
*,
|
|
646
|
+
title: str | None = None,
|
|
647
|
+
color: str | None = None,
|
|
648
|
+
id: str | None = None,
|
|
649
|
+
auto_close: int | bool | None = None,
|
|
650
|
+
loading: bool | None = None,
|
|
651
|
+
with_close_button: bool | None = None,
|
|
652
|
+
) -> NotificationHandle:
|
|
653
|
+
"""Show an in-window notification (toast). ``auto_close``: milliseconds,
|
|
654
|
+
False to keep it, None for the default; ``loading`` shows a spinner.
|
|
655
|
+
Returns a handle to update or hide it (``id`` picks the id)."""
|
|
656
|
+
return self._s.notify(
|
|
657
|
+
message,
|
|
658
|
+
title=title,
|
|
659
|
+
color=color,
|
|
660
|
+
id=id,
|
|
661
|
+
auto_close=auto_close,
|
|
662
|
+
loading=loading,
|
|
663
|
+
with_close_button=with_close_button,
|
|
664
|
+
)
|
|
665
|
+
|
|
666
|
+
def update_notification(
|
|
667
|
+
self,
|
|
668
|
+
notification: NotificationHandle | str,
|
|
669
|
+
*,
|
|
670
|
+
message: str | Unset = UNSET,
|
|
671
|
+
title: str | Unset | None = UNSET,
|
|
672
|
+
color: str | Unset | None = UNSET,
|
|
673
|
+
auto_close: int | bool | Unset | None = UNSET,
|
|
674
|
+
loading: bool | Unset = UNSET,
|
|
675
|
+
with_close_button: bool | Unset = UNSET,
|
|
676
|
+
) -> None:
|
|
677
|
+
self._notification(notification).update(
|
|
678
|
+
message=message,
|
|
679
|
+
title=title,
|
|
680
|
+
color=color,
|
|
681
|
+
auto_close=auto_close,
|
|
682
|
+
loading=loading,
|
|
683
|
+
with_close_button=with_close_button,
|
|
684
|
+
)
|
|
685
|
+
|
|
686
|
+
def hide_notification(self, notification: NotificationHandle | str) -> None:
|
|
687
|
+
self._notification(notification).hide()
|
|
688
|
+
|
|
689
|
+
def clean_notifications(self) -> None:
|
|
690
|
+
"""Hide every notification of this window (and drop queued ones)."""
|
|
691
|
+
self._s.command_nowait(None, "clean_notifications", {})
|
|
692
|
+
|
|
693
|
+
def _notification(self, n: NotificationHandle | str) -> NotificationHandle:
|
|
694
|
+
if isinstance(n, NotificationHandle):
|
|
695
|
+
return NotificationHandle(self._s, n.id)
|
|
696
|
+
return NotificationHandle(self._s, notification_id(n))
|
|
697
|
+
|
|
698
|
+
@property
|
|
699
|
+
def navigation_progress(self) -> NavigationProgress:
|
|
700
|
+
"""The window's top progress bar: start/stop/set/increment/decrement/complete/reset."""
|
|
701
|
+
return NavigationProgress(self._s)
|
|
702
|
+
|
|
703
|
+
def __repr__(self) -> str:
|
|
704
|
+
return f"<ui.Window {self._s.id}>"
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
@contextlib.contextmanager
|
|
708
|
+
def _batch(core: UiCore) -> Generator[None]:
|
|
709
|
+
from ._session import batch
|
|
710
|
+
|
|
711
|
+
with batch(core.batches):
|
|
712
|
+
yield
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
N = TypeVar("N")
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
class _Native(Generic[N]):
|
|
719
|
+
"""Read-only view of an attribute of the core application (``app.native``).
|
|
720
|
+
|
|
721
|
+
``app.storage`` is ``app.native.storage`` and so on, so facade code reads
|
|
722
|
+
like the core API. On the class it is the API class (documentation and
|
|
723
|
+
introspection); on an instance it is the live core object.
|
|
724
|
+
"""
|
|
725
|
+
|
|
726
|
+
def __init__(self, cls: type[N]) -> None:
|
|
727
|
+
self._cls = cls
|
|
728
|
+
self._name = ""
|
|
729
|
+
|
|
730
|
+
def __set_name__(self, owner: type, name: str) -> None:
|
|
731
|
+
self._name = name
|
|
732
|
+
|
|
733
|
+
@overload
|
|
734
|
+
def __get__(self, obj: None, owner: type) -> type[N]: ...
|
|
735
|
+
@overload
|
|
736
|
+
def __get__(self, obj: object, owner: type) -> N: ...
|
|
737
|
+
def __get__(self, obj: object | None, owner: type) -> type[N] | N:
|
|
738
|
+
if obj is None:
|
|
739
|
+
return self._cls
|
|
740
|
+
native: Any = getattr(obj, "native") # noqa: B009
|
|
741
|
+
return cast("N", getattr(native, self._name))
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
class _FacadeMixin:
|
|
745
|
+
_core: UiCore
|
|
746
|
+
app_id: str
|
|
747
|
+
"""Application id used for :attr:`paths` (see ``docs/desktop-helpers.md``)."""
|
|
748
|
+
paths: AppPaths
|
|
749
|
+
"""Per-application data/config/cache/log/state directories (created on first use)."""
|
|
750
|
+
_desktop: DesktopHelpers
|
|
751
|
+
_geometry: GeometryTracker | None
|
|
752
|
+
_settings: Settings | None
|
|
753
|
+
_settings_lock: threading.Lock
|
|
754
|
+
native_profile: NativeProfile | None
|
|
755
|
+
"""The native permission profile (``None``: the core SDK's allow-list rules)."""
|
|
756
|
+
|
|
757
|
+
def _init_desktop(
|
|
758
|
+
self,
|
|
759
|
+
*,
|
|
760
|
+
app_id: str | None,
|
|
761
|
+
title: str | None,
|
|
762
|
+
width: int | None,
|
|
763
|
+
height: int | None,
|
|
764
|
+
native_allow_list: Sequence[str] | str | None,
|
|
765
|
+
remember_geometry: bool,
|
|
766
|
+
core_options: dict[str, Any],
|
|
767
|
+
origin: Path | None,
|
|
768
|
+
profile: NativeProfile | None = None,
|
|
769
|
+
) -> tuple[int | None, int | None, Sequence[str] | str | None]:
|
|
770
|
+
"""Resolve the application id, paths and geometry restore before the
|
|
771
|
+
core application is built; returns the (possibly restored) width,
|
|
772
|
+
height and the native allow list."""
|
|
773
|
+
cfg_arg = core_options.get("config")
|
|
774
|
+
try:
|
|
775
|
+
cfg = config_mapping(cfg_arg, origin)
|
|
776
|
+
except ValidationError:
|
|
777
|
+
if app_id is not None:
|
|
778
|
+
raise
|
|
779
|
+
cfg = None # the core reports the broken config at start(), as before
|
|
780
|
+
native_allow_list = resolve_native_profile(profile, native_allow_list, cfg)
|
|
781
|
+
self.native_profile = profile
|
|
782
|
+
self.app_id = resolve_app_id(app_id, title, cfg, origin)
|
|
783
|
+
if app_id is not None and (cfg is None or "applicationId" not in cfg):
|
|
784
|
+
# One id for app.paths and the runtime's applicationId.
|
|
785
|
+
core_options["config"] = {**(cfg or {}), "applicationId": app_id}
|
|
786
|
+
env = core_options.get("env")
|
|
787
|
+
runtime_env: dict[str, str] = dict(os.environ if env is None else env)
|
|
788
|
+
self.paths = AppPaths(self.app_id, env=runtime_env)
|
|
789
|
+
self._settings = None
|
|
790
|
+
self._settings_lock = threading.Lock()
|
|
791
|
+
self._geometry = None
|
|
792
|
+
if not remember_geometry:
|
|
793
|
+
return width, height, native_allow_list
|
|
794
|
+
tracker = GeometryTracker(
|
|
795
|
+
Settings(self.paths.location("state") / GEOMETRY_FILE),
|
|
796
|
+
position=not is_wayland(runtime_env),
|
|
797
|
+
)
|
|
798
|
+
self._geometry = tracker
|
|
799
|
+
opts = dict(cast("Mapping[str, Any]", core_options.get("window_options") or {}))
|
|
800
|
+
# The runtime's own saved state would fight the restored geometry.
|
|
801
|
+
opts.setdefault("useSavedState", False)
|
|
802
|
+
restore = geometry_window_options(tracker.saved)
|
|
803
|
+
width = restore.pop("width", width)
|
|
804
|
+
height = restore.pop("height", height)
|
|
805
|
+
opts.update(restore)
|
|
806
|
+
core_options["window_options"] = opts
|
|
807
|
+
return width, height, _with_geometry_routes(native_allow_list, cfg)
|
|
808
|
+
|
|
809
|
+
def expose(self, *args: Any, **kwargs: Any) -> Any:
|
|
810
|
+
"""Expose a Python function to the page's ``backend.invoke`` (see
|
|
811
|
+
``neutralino.Application.expose``): ``@app.expose()``,
|
|
812
|
+
``@app.expose("name", stream=True, timeout=30)``."""
|
|
813
|
+
native: Any = getattr(self, "native") # noqa: B009
|
|
814
|
+
return native.expose(*args, **kwargs)
|
|
815
|
+
|
|
816
|
+
@property
|
|
817
|
+
def desktop(self) -> DesktopHelpers:
|
|
818
|
+
"""Async native helpers (also usable from async callbacks of ``ui.Application``)."""
|
|
819
|
+
return self._desktop
|
|
820
|
+
|
|
821
|
+
@property
|
|
822
|
+
def settings(self) -> Settings:
|
|
823
|
+
"""Atomic JSON settings in ``paths.config_dir / "settings.json"``."""
|
|
824
|
+
with self._settings_lock:
|
|
825
|
+
if self._settings is None:
|
|
826
|
+
self._settings = Settings(self.paths.config_dir / "settings.json")
|
|
827
|
+
return self._settings
|
|
828
|
+
|
|
829
|
+
@property
|
|
830
|
+
def remember_geometry(self) -> bool:
|
|
831
|
+
return self._geometry is not None
|
|
832
|
+
|
|
833
|
+
@overload
|
|
834
|
+
def page(self, route: str) -> PageHandle: ...
|
|
835
|
+
@overload
|
|
836
|
+
def page(self, route: Callable[[], Any]) -> Callable[[], Any]: ...
|
|
837
|
+
def page(self, route: str | Callable[[], Any] = "/") -> PageHandle | Callable[[], Any]:
|
|
838
|
+
"""``with app.page("/"):`` or ``@app.page("/route")`` (builder per window)."""
|
|
839
|
+
if callable(route):
|
|
840
|
+
return self._core.page_handle("/")(route)
|
|
841
|
+
return self._core.page_handle(route)
|
|
842
|
+
|
|
843
|
+
@property
|
|
844
|
+
def main_window(self) -> Window:
|
|
845
|
+
return Window(self._core.main)
|
|
846
|
+
|
|
847
|
+
@property
|
|
848
|
+
def windows(self) -> list[Window]:
|
|
849
|
+
return [
|
|
850
|
+
Window(self._core.main),
|
|
851
|
+
*(Window(w) for w in self._core.windows.values() if not w.closed),
|
|
852
|
+
]
|
|
853
|
+
|
|
854
|
+
def batch(self) -> contextlib.AbstractContextManager[None]:
|
|
855
|
+
"""Apply several component changes as one patch: no window of this
|
|
856
|
+
application is sent changes until its outermost batch ends (other
|
|
857
|
+
applications in the process are not held back). The tree lock is not
|
|
858
|
+
held across the body, so blocking calls inside it still work."""
|
|
859
|
+
return _batch(self._core)
|
|
860
|
+
|
|
861
|
+
def add_css_file(self, path: str | os.PathLike[str]) -> str:
|
|
862
|
+
"""Load a trusted local stylesheet in every window (copied at start).
|
|
863
|
+
|
|
864
|
+
Paths are the application's own files: relative paths start at the
|
|
865
|
+
directory of the file that created the application (no ``..``); the
|
|
866
|
+
real path (symlinks followed) must be inside that directory or one of
|
|
867
|
+
``asset_roots`` and not inside the installed neutralino package.
|
|
868
|
+
Raises ``ValidationError`` otherwise.
|
|
869
|
+
"""
|
|
870
|
+
return self._core.assets.add_css(path)
|
|
871
|
+
|
|
872
|
+
def add_js_module(self, path: str | os.PathLike[str]) -> str:
|
|
873
|
+
"""Load a trusted local ES module (custom components / adapters).
|
|
874
|
+
|
|
875
|
+
Same path rules as :meth:`add_css_file`; ``.js``/``.mjs`` only.
|
|
876
|
+
"""
|
|
877
|
+
return self._core.assets.add_js(path)
|
|
878
|
+
|
|
879
|
+
def add_asset(self, path: str | os.PathLike[str], name: str | None = None) -> str:
|
|
880
|
+
"""Ship a local file (image, font, data); returns its page-relative URL.
|
|
881
|
+
|
|
882
|
+
Same path rules as :meth:`add_css_file`.
|
|
883
|
+
"""
|
|
884
|
+
return self._core.assets.add_file(path, name)
|
|
885
|
+
|
|
886
|
+
def add_asset_dir(self, path: str | os.PathLike[str], prefix: str = "") -> list[str]:
|
|
887
|
+
"""Ship a directory of the application (hidden files and symlinks skipped)."""
|
|
888
|
+
return self._core.assets.add_dir(path, prefix)
|
|
889
|
+
|
|
890
|
+
@property
|
|
891
|
+
def theme(self) -> dict[str, Any]:
|
|
892
|
+
return dict(self._core.theme)
|
|
893
|
+
|
|
894
|
+
def set_theme(self, theme: Mapping[str, Any] | str | None = None, **tokens: Any) -> None:
|
|
895
|
+
"""Change the application theme (windows without their own override update live)."""
|
|
896
|
+
base = normalize_theme(theme) if theme is not None else self._core.theme
|
|
897
|
+
with TREE_LOCK:
|
|
898
|
+
self._core.theme = normalize_theme({**base, **tokens})
|
|
899
|
+
for w in [self._core.main, *self._core.windows.values()]:
|
|
900
|
+
if w.theme is None and w.live:
|
|
901
|
+
w._struct.append({"op": "theme", "theme": w.theme_json()}) # pyright: ignore[reportPrivateUsage]
|
|
902
|
+
w._kick() # pyright: ignore[reportPrivateUsage]
|
|
903
|
+
|
|
904
|
+
def on_error(
|
|
905
|
+
self, fn: Callable[[WindowSession | None, BaseException], Any]
|
|
906
|
+
) -> Callable[[WindowSession | None, BaseException], Any]:
|
|
907
|
+
"""Replace the default error notice for failed callbacks."""
|
|
908
|
+
self._core.on_error = fn
|
|
909
|
+
return fn
|
|
910
|
+
|
|
911
|
+
@property
|
|
912
|
+
def limits(self) -> UiLimits:
|
|
913
|
+
return self._core.limits
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
def _with_geometry_routes(
|
|
917
|
+
allow: Sequence[str] | str | None, cfg: Mapping[str, Any] | None
|
|
918
|
+
) -> Sequence[str] | str | None:
|
|
919
|
+
"""Add the window routes remember_geometry needs (an explicit opt-in)."""
|
|
920
|
+
if allow == "*" or isinstance(allow, str):
|
|
921
|
+
return allow # "*" allows them; another string is rejected by the core
|
|
922
|
+
if allow is None:
|
|
923
|
+
if cfg is not None and config_mod._has_user_lists(cfg): # pyright: ignore[reportPrivateUsage]
|
|
924
|
+
log.info(
|
|
925
|
+
"remember_geometry: the config sets its own native allow/block list; it must "
|
|
926
|
+
"allow %s",
|
|
927
|
+
", ".join(GEOMETRY_ROUTES),
|
|
928
|
+
)
|
|
929
|
+
return None
|
|
930
|
+
return list(GEOMETRY_ROUTES)
|
|
931
|
+
return [*allow, *(r for r in GEOMETRY_ROUTES if r not in allow)]
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
def _core_kwargs(kw: dict[str, Any]) -> dict[str, Any]:
|
|
935
|
+
if "resources" in kw:
|
|
936
|
+
raise ValidationError(
|
|
937
|
+
"ui.Application composes its own resources; use add_css_file/add_js_module"
|
|
938
|
+
)
|
|
939
|
+
return kw
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
class AsyncApplication(_FacadeMixin):
|
|
943
|
+
"""Async facade: mirrors :class:`neutralino.AsyncApplication` lifecycle.
|
|
944
|
+
|
|
945
|
+
``profile`` selects the native permission profile: ``"restricted"`` (what
|
|
946
|
+
the UI engine needs, the template default), ``"trusted"`` (plus every typed
|
|
947
|
+
desktop helper) or ``"custom"`` (``native_allow_list=``). ``None`` keeps the
|
|
948
|
+
core SDK's rules. The same list applies to the page and to Python's own
|
|
949
|
+
native calls (ADR-006); it is not a sandbox. See ``docs/security.md``.
|
|
950
|
+
"""
|
|
951
|
+
|
|
952
|
+
def __init__(
|
|
953
|
+
self,
|
|
954
|
+
*,
|
|
955
|
+
title: str | None = None,
|
|
956
|
+
width: int | None = None,
|
|
957
|
+
height: int | None = None,
|
|
958
|
+
theme: Mapping[str, Any] | str | None = "system",
|
|
959
|
+
ui_limits: UiLimits | None = None,
|
|
960
|
+
native_allow_list: Sequence[str] | str | None = None,
|
|
961
|
+
app_id: str | None = None,
|
|
962
|
+
remember_geometry: bool = False,
|
|
963
|
+
profile: NativeProfile | None = None,
|
|
964
|
+
asset_roots: Sequence[str | os.PathLike[str]] = (),
|
|
965
|
+
**core_options: Any,
|
|
966
|
+
) -> None:
|
|
967
|
+
origin = _caller_dir(2)
|
|
968
|
+
core_options = _core_kwargs(core_options)
|
|
969
|
+
width, height, native_allow_list = self._init_desktop(
|
|
970
|
+
app_id=app_id,
|
|
971
|
+
title=title,
|
|
972
|
+
width=width,
|
|
973
|
+
height=height,
|
|
974
|
+
native_allow_list=native_allow_list,
|
|
975
|
+
remember_geometry=remember_geometry,
|
|
976
|
+
core_options=core_options,
|
|
977
|
+
origin=origin,
|
|
978
|
+
profile=profile,
|
|
979
|
+
)
|
|
980
|
+
self.native = core_app.AsyncApplication(
|
|
981
|
+
None,
|
|
982
|
+
title=title,
|
|
983
|
+
width=width,
|
|
984
|
+
height=height,
|
|
985
|
+
native_allow_list=native_allow_list,
|
|
986
|
+
**core_options,
|
|
987
|
+
)
|
|
988
|
+
self._core = UiCore(
|
|
989
|
+
self.native,
|
|
990
|
+
theme=theme,
|
|
991
|
+
limits=ui_limits,
|
|
992
|
+
origin=origin,
|
|
993
|
+
asset_roots=asset_roots,
|
|
994
|
+
)
|
|
995
|
+
self._core.main.title = title
|
|
996
|
+
self._desktop = DesktopHelpers(lambda: self.native)
|
|
997
|
+
|
|
998
|
+
storage = _Native(StorageApi)
|
|
999
|
+
"""Native ``storage`` API (``await app.storage.set_data(key, text)``)."""
|
|
1000
|
+
events = _Native(EventBus)
|
|
1001
|
+
"""Native event bus (``await app.events.broadcast(name, data)``)."""
|
|
1002
|
+
|
|
1003
|
+
async def start(self) -> AsyncApplication:
|
|
1004
|
+
self.native._resources_arg = self._core.stage_resources() # pyright: ignore[reportPrivateUsage]
|
|
1005
|
+
await self.native.start()
|
|
1006
|
+
if self._geometry is not None:
|
|
1007
|
+
self._geometry.start(lambda: self.native.window)
|
|
1008
|
+
return self
|
|
1009
|
+
|
|
1010
|
+
async def run(self) -> int | None:
|
|
1011
|
+
if self.native.state is core_app.AppState.CREATED:
|
|
1012
|
+
await self.start()
|
|
1013
|
+
if self._geometry is not None:
|
|
1014
|
+
try:
|
|
1015
|
+
stop = self.native._stop_requested # pyright: ignore[reportPrivateUsage]
|
|
1016
|
+
if stop is not None:
|
|
1017
|
+
await stop.wait()
|
|
1018
|
+
# Save once more while the runtime may still answer (orderly stop).
|
|
1019
|
+
await self._geometry.stop(lambda: self.native.window)
|
|
1020
|
+
except BaseException:
|
|
1021
|
+
await self.shutdown()
|
|
1022
|
+
raise
|
|
1023
|
+
try:
|
|
1024
|
+
return await self.native.run()
|
|
1025
|
+
finally:
|
|
1026
|
+
await self._core.close_windows()
|
|
1027
|
+
|
|
1028
|
+
async def shutdown(self) -> int | None:
|
|
1029
|
+
if self._geometry is not None:
|
|
1030
|
+
await self._geometry.stop(lambda: self.native.window)
|
|
1031
|
+
code = await self.native.shutdown()
|
|
1032
|
+
await self._core.close_windows()
|
|
1033
|
+
return code
|
|
1034
|
+
|
|
1035
|
+
# ------------------------------------------------------ desktop helpers
|
|
1036
|
+
@overload
|
|
1037
|
+
async def open_file(
|
|
1038
|
+
self,
|
|
1039
|
+
title: str | None = None,
|
|
1040
|
+
*,
|
|
1041
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1042
|
+
multiple: Literal[False] = False,
|
|
1043
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1044
|
+
) -> str | None: ...
|
|
1045
|
+
@overload
|
|
1046
|
+
async def open_file(
|
|
1047
|
+
self,
|
|
1048
|
+
title: str | None = None,
|
|
1049
|
+
*,
|
|
1050
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1051
|
+
multiple: Literal[True],
|
|
1052
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1053
|
+
) -> list[str]: ...
|
|
1054
|
+
async def open_file(
|
|
1055
|
+
self,
|
|
1056
|
+
title: str | None = None,
|
|
1057
|
+
*,
|
|
1058
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1059
|
+
multiple: bool = False,
|
|
1060
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1061
|
+
) -> str | list[str] | None:
|
|
1062
|
+
"""Native open dialog (``os.showOpenDialog``): a path or None (cancelled);
|
|
1063
|
+
with ``multiple=True`` a list. ``filters=[("Images", ["png", "jpg"])]``."""
|
|
1064
|
+
if multiple:
|
|
1065
|
+
return await self._desktop.open_file(
|
|
1066
|
+
title, filters=filters, multiple=True, default_path=default_path
|
|
1067
|
+
)
|
|
1068
|
+
return await self._desktop.open_file(title, filters=filters, default_path=default_path)
|
|
1069
|
+
|
|
1070
|
+
async def save_file(
|
|
1071
|
+
self,
|
|
1072
|
+
title: str | None = None,
|
|
1073
|
+
*,
|
|
1074
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1075
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1076
|
+
force_overwrite: bool = False,
|
|
1077
|
+
) -> str | None:
|
|
1078
|
+
"""Native save dialog (``os.showSaveDialog``): a path or None."""
|
|
1079
|
+
return await self._desktop.save_file(
|
|
1080
|
+
title, filters=filters, default_path=default_path, force_overwrite=force_overwrite
|
|
1081
|
+
)
|
|
1082
|
+
|
|
1083
|
+
async def select_folder(
|
|
1084
|
+
self, title: str | None = None, *, default_path: str | os.PathLike[str] | None = None
|
|
1085
|
+
) -> str | None:
|
|
1086
|
+
"""Native folder dialog (``os.showFolderDialog``): a path or None."""
|
|
1087
|
+
return await self._desktop.select_folder(title, default_path=default_path)
|
|
1088
|
+
|
|
1089
|
+
async def message_box(
|
|
1090
|
+
self,
|
|
1091
|
+
title: str,
|
|
1092
|
+
message: str,
|
|
1093
|
+
*,
|
|
1094
|
+
buttons: MessageChoice = "OK",
|
|
1095
|
+
icon: MessageIcon = "INFO",
|
|
1096
|
+
) -> str:
|
|
1097
|
+
"""Native message box (``os.showMessageBox``); returns the pressed button."""
|
|
1098
|
+
return await self._desktop.message_box(title, message, buttons=buttons, icon=icon)
|
|
1099
|
+
|
|
1100
|
+
async def confirm(self, title: str, message: str, *, icon: MessageIcon = "QUESTION") -> bool:
|
|
1101
|
+
"""Native Yes/No question; True for Yes."""
|
|
1102
|
+
return await self._desktop.confirm(title, message, icon=icon)
|
|
1103
|
+
|
|
1104
|
+
async def notify_native(self, title: str, body: str, *, icon: MessageIcon = "INFO") -> None:
|
|
1105
|
+
"""Desktop notification (``os.showNotification``)."""
|
|
1106
|
+
await self._desktop.notify_native(title, body, icon=icon)
|
|
1107
|
+
|
|
1108
|
+
async def clipboard_text(self) -> str:
|
|
1109
|
+
"""Clipboard text (``clipboard.readText``; '' when it holds no text)."""
|
|
1110
|
+
return await self._desktop.clipboard_text()
|
|
1111
|
+
|
|
1112
|
+
async def set_clipboard_text(self, text: str) -> None:
|
|
1113
|
+
"""Put ``text`` on the clipboard (``clipboard.writeText``)."""
|
|
1114
|
+
await self._desktop.set_clipboard_text(text)
|
|
1115
|
+
|
|
1116
|
+
async def open_url(self, url: str) -> None:
|
|
1117
|
+
"""Open an http/https/mailto URL with the user's default handler (``os.open``)."""
|
|
1118
|
+
await self._desktop.open_url(url)
|
|
1119
|
+
|
|
1120
|
+
def request_stop(self) -> None:
|
|
1121
|
+
self.native.request_stop()
|
|
1122
|
+
|
|
1123
|
+
async def __aenter__(self) -> AsyncApplication:
|
|
1124
|
+
return await self.start()
|
|
1125
|
+
|
|
1126
|
+
async def __aexit__(self, *exc: object) -> None:
|
|
1127
|
+
await self.shutdown()
|
|
1128
|
+
|
|
1129
|
+
async def window(
|
|
1130
|
+
self,
|
|
1131
|
+
route: str = "/",
|
|
1132
|
+
*,
|
|
1133
|
+
title: str | None = None,
|
|
1134
|
+
width: int | None = None,
|
|
1135
|
+
height: int | None = None,
|
|
1136
|
+
options: Mapping[str, Any] | None = None,
|
|
1137
|
+
state: Mapping[str, Any] | None = None,
|
|
1138
|
+
) -> Window:
|
|
1139
|
+
"""Open another native window showing ``route`` (its own session and tree).
|
|
1140
|
+
|
|
1141
|
+
``state`` is copied into the new window's ``Window.state`` before its
|
|
1142
|
+
page is built, so the page builder can read it with
|
|
1143
|
+
``ui.current_window().state`` (routes carry no parameters).
|
|
1144
|
+
"""
|
|
1145
|
+
w = self._core.new_window(route)
|
|
1146
|
+
w.title = title
|
|
1147
|
+
w.state.update(state or {})
|
|
1148
|
+
try:
|
|
1149
|
+
mw = await self.native.windows.create(
|
|
1150
|
+
self._core.window_url(w), title=title, width=width, height=height, options=options
|
|
1151
|
+
)
|
|
1152
|
+
except BaseException:
|
|
1153
|
+
self._core.windows.pop(w.token, None)
|
|
1154
|
+
await w.close_session()
|
|
1155
|
+
raise
|
|
1156
|
+
w.native = mw
|
|
1157
|
+
|
|
1158
|
+
async def watch() -> None:
|
|
1159
|
+
await mw.wait_closed()
|
|
1160
|
+
await w.close_session()
|
|
1161
|
+
self._core.windows.pop(w.token, None)
|
|
1162
|
+
|
|
1163
|
+
task = asyncio.ensure_future(watch())
|
|
1164
|
+
w._track(task) # pyright: ignore[reportPrivateUsage]
|
|
1165
|
+
return Window(w)
|
|
1166
|
+
|
|
1167
|
+
async def wait_for_window(self, window: Window | None = None, timeout: float = 30.0) -> Window:
|
|
1168
|
+
"""Wait until the window's page has applied its first tree.
|
|
1169
|
+
|
|
1170
|
+
Returns once the page has connected, committed the first tree to the
|
|
1171
|
+
DOM, rendered a frame and then reported its environment back, so it is
|
|
1172
|
+
past the loading spinner (WebKitGTK may put that frame on screen up to
|
|
1173
|
+
about 0.3 s later; screenshot code should wait for the screen): the point an
|
|
1174
|
+
updated app can call ``confirm_healthy()``. Raises ``StartupError`` if
|
|
1175
|
+
the window closes first and ``TimeoutError`` after ``timeout`` seconds.
|
|
1176
|
+
"""
|
|
1177
|
+
s = (window or self.main_window).session
|
|
1178
|
+
deadline = asyncio.get_running_loop().time() + timeout
|
|
1179
|
+
while not (s.live and s.environment is not None):
|
|
1180
|
+
if s.closed:
|
|
1181
|
+
raise StartupError("window closed")
|
|
1182
|
+
if asyncio.get_running_loop().time() > deadline:
|
|
1183
|
+
raise TimeoutError("window did not mount")
|
|
1184
|
+
await asyncio.sleep(0.01)
|
|
1185
|
+
return Window(s)
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
class Application(_FacadeMixin):
|
|
1189
|
+
"""Blocking facade over :class:`neutralino.Application`.
|
|
1190
|
+
|
|
1191
|
+
``app.run()`` blocks; callbacks run on worker threads (sync) or the
|
|
1192
|
+
application's event loop (async). ``native`` is the core application.
|
|
1193
|
+
|
|
1194
|
+
``profile`` selects the native permission profile: ``"restricted"`` (what
|
|
1195
|
+
the UI engine needs, the template default), ``"trusted"`` (plus every typed
|
|
1196
|
+
desktop helper) or ``"custom"`` (``native_allow_list=``). ``None`` keeps the
|
|
1197
|
+
core SDK's rules. The same list applies to the page and to Python's own
|
|
1198
|
+
native calls (ADR-006); it is not a sandbox. See ``docs/security.md``.
|
|
1199
|
+
"""
|
|
1200
|
+
|
|
1201
|
+
def __init__(
|
|
1202
|
+
self,
|
|
1203
|
+
*,
|
|
1204
|
+
title: str | None = None,
|
|
1205
|
+
width: int | None = None,
|
|
1206
|
+
height: int | None = None,
|
|
1207
|
+
theme: Mapping[str, Any] | str | None = "system",
|
|
1208
|
+
ui_limits: UiLimits | None = None,
|
|
1209
|
+
native_allow_list: Sequence[str] | str | None = None,
|
|
1210
|
+
app_id: str | None = None,
|
|
1211
|
+
remember_geometry: bool = False,
|
|
1212
|
+
profile: NativeProfile | None = None,
|
|
1213
|
+
asset_roots: Sequence[str | os.PathLike[str]] = (),
|
|
1214
|
+
**core_options: Any,
|
|
1215
|
+
) -> None:
|
|
1216
|
+
origin = _caller_dir(2)
|
|
1217
|
+
core_options = _core_kwargs(core_options)
|
|
1218
|
+
width, height, native_allow_list = self._init_desktop(
|
|
1219
|
+
app_id=app_id,
|
|
1220
|
+
title=title,
|
|
1221
|
+
width=width,
|
|
1222
|
+
height=height,
|
|
1223
|
+
native_allow_list=native_allow_list,
|
|
1224
|
+
remember_geometry=remember_geometry,
|
|
1225
|
+
core_options=core_options,
|
|
1226
|
+
origin=origin,
|
|
1227
|
+
profile=profile,
|
|
1228
|
+
)
|
|
1229
|
+
self.native = core_app.Application(
|
|
1230
|
+
None,
|
|
1231
|
+
title=title,
|
|
1232
|
+
width=width,
|
|
1233
|
+
height=height,
|
|
1234
|
+
native_allow_list=native_allow_list,
|
|
1235
|
+
**core_options,
|
|
1236
|
+
)
|
|
1237
|
+
self._core = UiCore(
|
|
1238
|
+
self.native.async_app,
|
|
1239
|
+
theme=theme,
|
|
1240
|
+
limits=ui_limits,
|
|
1241
|
+
origin=origin,
|
|
1242
|
+
asset_roots=asset_roots,
|
|
1243
|
+
)
|
|
1244
|
+
self._core.main.title = title
|
|
1245
|
+
self._desktop = DesktopHelpers(lambda: self.native.async_app)
|
|
1246
|
+
self._pending_windows: list[tuple[str, dict[str, Any]]] = []
|
|
1247
|
+
self._lock = threading.Lock()
|
|
1248
|
+
|
|
1249
|
+
storage = _Native(SyncStorageApi)
|
|
1250
|
+
"""Native ``storage`` API (``app.storage.set_data(key, text)``)."""
|
|
1251
|
+
events = _Native(SyncEvents)
|
|
1252
|
+
"""Native event bus (``app.events.broadcast(name, data)``)."""
|
|
1253
|
+
|
|
1254
|
+
def start(self) -> Application:
|
|
1255
|
+
self.native.async_app._resources_arg = self._core.stage_resources() # pyright: ignore[reportPrivateUsage]
|
|
1256
|
+
self.native.start()
|
|
1257
|
+
geometry = self._geometry
|
|
1258
|
+
runner = self.native._runner # pyright: ignore[reportPrivateUsage]
|
|
1259
|
+
if geometry is not None and runner is not None:
|
|
1260
|
+
|
|
1261
|
+
async def start_geometry() -> None:
|
|
1262
|
+
geometry.start(self._main_window_api)
|
|
1263
|
+
|
|
1264
|
+
runner.run(start_geometry(), 10)
|
|
1265
|
+
for route, kw in self._pending_windows:
|
|
1266
|
+
self.window(route, **kw)
|
|
1267
|
+
self._pending_windows.clear()
|
|
1268
|
+
return self
|
|
1269
|
+
|
|
1270
|
+
def _main_window_api(self) -> Any:
|
|
1271
|
+
return self.native.async_app.window
|
|
1272
|
+
|
|
1273
|
+
def run(self) -> int | None:
|
|
1274
|
+
if self.native.state is core_app.AppState.CREATED:
|
|
1275
|
+
try:
|
|
1276
|
+
self.start()
|
|
1277
|
+
except KeyboardInterrupt:
|
|
1278
|
+
return self.native.exit_code
|
|
1279
|
+
if self._geometry is not None:
|
|
1280
|
+
try:
|
|
1281
|
+
self._save_geometry_on_stop()
|
|
1282
|
+
except KeyboardInterrupt:
|
|
1283
|
+
log.info("interrupted; shutting down")
|
|
1284
|
+
self.shutdown()
|
|
1285
|
+
return self.native.exit_code
|
|
1286
|
+
try:
|
|
1287
|
+
return self.native.run()
|
|
1288
|
+
finally:
|
|
1289
|
+
self._close_windows()
|
|
1290
|
+
|
|
1291
|
+
def _save_geometry_on_stop(self) -> None:
|
|
1292
|
+
"""Wait (Ctrl-C responsive) for the stop request, then save the
|
|
1293
|
+
geometry once more while the runtime may still answer."""
|
|
1294
|
+
runner = self.native._runner # pyright: ignore[reportPrivateUsage]
|
|
1295
|
+
geometry = self._geometry
|
|
1296
|
+
if runner is None or geometry is None:
|
|
1297
|
+
return
|
|
1298
|
+
|
|
1299
|
+
async def wait() -> None:
|
|
1300
|
+
stop = self.native.async_app._stop_requested # pyright: ignore[reportPrivateUsage]
|
|
1301
|
+
if stop is not None:
|
|
1302
|
+
await stop.wait()
|
|
1303
|
+
await geometry.stop(self._main_window_api)
|
|
1304
|
+
|
|
1305
|
+
fut = asyncio.run_coroutine_threadsafe(wait(), runner.loop)
|
|
1306
|
+
try:
|
|
1307
|
+
while True:
|
|
1308
|
+
try:
|
|
1309
|
+
fut.result(0.2)
|
|
1310
|
+
return
|
|
1311
|
+
except TimeoutError:
|
|
1312
|
+
continue
|
|
1313
|
+
except BaseException:
|
|
1314
|
+
fut.cancel()
|
|
1315
|
+
raise
|
|
1316
|
+
|
|
1317
|
+
def _close_windows(self) -> None:
|
|
1318
|
+
runner = self.native._runner # pyright: ignore[reportPrivateUsage]
|
|
1319
|
+
if runner is not None:
|
|
1320
|
+
with contextlib.suppress(Exception):
|
|
1321
|
+
runner.run(self._core.close_windows(), 10)
|
|
1322
|
+
else:
|
|
1323
|
+
asyncio.run(self._core.close_windows())
|
|
1324
|
+
|
|
1325
|
+
def shutdown(self) -> int | None:
|
|
1326
|
+
runner = self.native._runner # pyright: ignore[reportPrivateUsage]
|
|
1327
|
+
if runner is not None:
|
|
1328
|
+
if self._geometry is not None:
|
|
1329
|
+
with contextlib.suppress(Exception):
|
|
1330
|
+
runner.run(self._geometry.stop(self._main_window_api), 10)
|
|
1331
|
+
with contextlib.suppress(Exception):
|
|
1332
|
+
runner.run(self._core.close_windows(), 10)
|
|
1333
|
+
return self.native.shutdown()
|
|
1334
|
+
|
|
1335
|
+
# ------------------------------------------------------ desktop helpers
|
|
1336
|
+
def _blocking(self, name: str, coro: Coroutine[Any, Any, T]) -> T:
|
|
1337
|
+
runner = self.native._runner # pyright: ignore[reportPrivateUsage]
|
|
1338
|
+
try:
|
|
1339
|
+
running: asyncio.AbstractEventLoop | None = asyncio.get_running_loop()
|
|
1340
|
+
except RuntimeError:
|
|
1341
|
+
running = None
|
|
1342
|
+
if running is not None:
|
|
1343
|
+
coro.close()
|
|
1344
|
+
raise RuntimeError(
|
|
1345
|
+
f"{name}() blocks: call it from a sync callback, or use "
|
|
1346
|
+
f"'await app.desktop.{name}(...)' in async code"
|
|
1347
|
+
)
|
|
1348
|
+
if runner is None:
|
|
1349
|
+
coro.close()
|
|
1350
|
+
raise StartupError("application is not running")
|
|
1351
|
+
return runner.run(coro, None)
|
|
1352
|
+
|
|
1353
|
+
@overload
|
|
1354
|
+
def open_file(
|
|
1355
|
+
self,
|
|
1356
|
+
title: str | None = None,
|
|
1357
|
+
*,
|
|
1358
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1359
|
+
multiple: Literal[False] = False,
|
|
1360
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1361
|
+
) -> str | None: ...
|
|
1362
|
+
@overload
|
|
1363
|
+
def open_file(
|
|
1364
|
+
self,
|
|
1365
|
+
title: str | None = None,
|
|
1366
|
+
*,
|
|
1367
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1368
|
+
multiple: Literal[True],
|
|
1369
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1370
|
+
) -> list[str]: ...
|
|
1371
|
+
def open_file(
|
|
1372
|
+
self,
|
|
1373
|
+
title: str | None = None,
|
|
1374
|
+
*,
|
|
1375
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1376
|
+
multiple: bool = False,
|
|
1377
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1378
|
+
) -> str | list[str] | None:
|
|
1379
|
+
"""Blocking native open dialog (refuses the event-loop thread); see
|
|
1380
|
+
:meth:`AsyncApplication.open_file`."""
|
|
1381
|
+
if multiple:
|
|
1382
|
+
return self._blocking(
|
|
1383
|
+
"open_file",
|
|
1384
|
+
self._desktop.open_file(
|
|
1385
|
+
title, filters=filters, multiple=True, default_path=default_path
|
|
1386
|
+
),
|
|
1387
|
+
)
|
|
1388
|
+
return self._blocking(
|
|
1389
|
+
"open_file",
|
|
1390
|
+
self._desktop.open_file(title, filters=filters, default_path=default_path),
|
|
1391
|
+
)
|
|
1392
|
+
|
|
1393
|
+
def save_file(
|
|
1394
|
+
self,
|
|
1395
|
+
title: str | None = None,
|
|
1396
|
+
*,
|
|
1397
|
+
filters: Sequence[FilterSpec] | None = None,
|
|
1398
|
+
default_path: str | os.PathLike[str] | None = None,
|
|
1399
|
+
force_overwrite: bool = False,
|
|
1400
|
+
) -> str | None:
|
|
1401
|
+
return self._blocking(
|
|
1402
|
+
"save_file",
|
|
1403
|
+
self._desktop.save_file(
|
|
1404
|
+
title, filters=filters, default_path=default_path, force_overwrite=force_overwrite
|
|
1405
|
+
),
|
|
1406
|
+
)
|
|
1407
|
+
|
|
1408
|
+
def select_folder(
|
|
1409
|
+
self, title: str | None = None, *, default_path: str | os.PathLike[str] | None = None
|
|
1410
|
+
) -> str | None:
|
|
1411
|
+
return self._blocking(
|
|
1412
|
+
"select_folder", self._desktop.select_folder(title, default_path=default_path)
|
|
1413
|
+
)
|
|
1414
|
+
|
|
1415
|
+
def message_box(
|
|
1416
|
+
self,
|
|
1417
|
+
title: str,
|
|
1418
|
+
message: str,
|
|
1419
|
+
*,
|
|
1420
|
+
buttons: MessageChoice = "OK",
|
|
1421
|
+
icon: MessageIcon = "INFO",
|
|
1422
|
+
) -> str:
|
|
1423
|
+
return self._blocking(
|
|
1424
|
+
"message_box",
|
|
1425
|
+
self._desktop.message_box(title, message, buttons=buttons, icon=icon),
|
|
1426
|
+
)
|
|
1427
|
+
|
|
1428
|
+
def confirm(self, title: str, message: str, *, icon: MessageIcon = "QUESTION") -> bool:
|
|
1429
|
+
return self._blocking("confirm", self._desktop.confirm(title, message, icon=icon))
|
|
1430
|
+
|
|
1431
|
+
def notify_native(self, title: str, body: str, *, icon: MessageIcon = "INFO") -> None:
|
|
1432
|
+
self._blocking("notify_native", self._desktop.notify_native(title, body, icon=icon))
|
|
1433
|
+
|
|
1434
|
+
def clipboard_text(self) -> str:
|
|
1435
|
+
return self._blocking("clipboard_text", self._desktop.clipboard_text())
|
|
1436
|
+
|
|
1437
|
+
def set_clipboard_text(self, text: str) -> None:
|
|
1438
|
+
self._blocking("set_clipboard_text", self._desktop.set_clipboard_text(text))
|
|
1439
|
+
|
|
1440
|
+
def open_url(self, url: str) -> None:
|
|
1441
|
+
self._blocking("open_url", self._desktop.open_url(url))
|
|
1442
|
+
|
|
1443
|
+
def request_stop(self) -> None:
|
|
1444
|
+
self.native.request_stop()
|
|
1445
|
+
|
|
1446
|
+
def __enter__(self) -> Application:
|
|
1447
|
+
return self.start()
|
|
1448
|
+
|
|
1449
|
+
def __exit__(self, *exc: object) -> None:
|
|
1450
|
+
self.shutdown()
|
|
1451
|
+
|
|
1452
|
+
def window(
|
|
1453
|
+
self,
|
|
1454
|
+
route: str = "/",
|
|
1455
|
+
*,
|
|
1456
|
+
title: str | None = None,
|
|
1457
|
+
width: int | None = None,
|
|
1458
|
+
height: int | None = None,
|
|
1459
|
+
options: Mapping[str, Any] | None = None,
|
|
1460
|
+
state: Mapping[str, Any] | None = None,
|
|
1461
|
+
) -> Window | None:
|
|
1462
|
+
"""Open another window. Before ``run()`` it opens at start (returns None).
|
|
1463
|
+
|
|
1464
|
+
``state`` is in the window's ``Window.state`` before its page is built
|
|
1465
|
+
(see :meth:`AsyncApplication.window`).
|
|
1466
|
+
"""
|
|
1467
|
+
kw: dict[str, Any] = {"title": title, "width": width, "height": height, "options": options}
|
|
1468
|
+
if self.native.state is core_app.AppState.CREATED:
|
|
1469
|
+
self._pending_windows.append((route, {**kw, "state": dict(state or {})}))
|
|
1470
|
+
return None
|
|
1471
|
+
runner = self.native._runner # pyright: ignore[reportPrivateUsage]
|
|
1472
|
+
if runner is None:
|
|
1473
|
+
raise StartupError("application is not running")
|
|
1474
|
+
try:
|
|
1475
|
+
on_loop = asyncio.get_running_loop() is runner.loop
|
|
1476
|
+
except RuntimeError:
|
|
1477
|
+
on_loop = False
|
|
1478
|
+
if on_loop:
|
|
1479
|
+
raise RuntimeError(
|
|
1480
|
+
"window() blocks: call it from a sync callback, or use the async facade"
|
|
1481
|
+
)
|
|
1482
|
+
w = self._core.new_window(route)
|
|
1483
|
+
w.title = title
|
|
1484
|
+
w.state.update(state or {})
|
|
1485
|
+
|
|
1486
|
+
async def create() -> Window:
|
|
1487
|
+
try:
|
|
1488
|
+
mw = await self.native.async_app.windows.create(self._core.window_url(w), **kw)
|
|
1489
|
+
except BaseException:
|
|
1490
|
+
self._core.windows.pop(w.token, None)
|
|
1491
|
+
await w.close_session()
|
|
1492
|
+
raise
|
|
1493
|
+
w.native = mw
|
|
1494
|
+
|
|
1495
|
+
async def watch() -> None:
|
|
1496
|
+
await mw.wait_closed()
|
|
1497
|
+
await w.close_session()
|
|
1498
|
+
self._core.windows.pop(w.token, None)
|
|
1499
|
+
|
|
1500
|
+
w._track(asyncio.ensure_future(watch())) # pyright: ignore[reportPrivateUsage]
|
|
1501
|
+
return Window(w)
|
|
1502
|
+
|
|
1503
|
+
return runner.run(create(), self.native.async_app.limits.startup_timeout + 10)
|
|
1504
|
+
|
|
1505
|
+
def wait_for_window(self, window: Window | None = None, timeout: float = 30.0) -> Window:
|
|
1506
|
+
"""Block until the window's page has applied its first tree (see
|
|
1507
|
+
:meth:`AsyncApplication.wait_for_window`)."""
|
|
1508
|
+
s = (window or self.main_window).session
|
|
1509
|
+
runner = self.native._runner # pyright: ignore[reportPrivateUsage]
|
|
1510
|
+
if runner is None:
|
|
1511
|
+
raise StartupError("application is not running")
|
|
1512
|
+
|
|
1513
|
+
async def wait() -> Window:
|
|
1514
|
+
deadline = asyncio.get_running_loop().time() + timeout
|
|
1515
|
+
while not (s.live and s.environment is not None):
|
|
1516
|
+
if s.closed:
|
|
1517
|
+
raise StartupError("window closed")
|
|
1518
|
+
if asyncio.get_running_loop().time() > deadline:
|
|
1519
|
+
raise TimeoutError("window did not mount")
|
|
1520
|
+
await asyncio.sleep(0.01)
|
|
1521
|
+
return Window(s)
|
|
1522
|
+
|
|
1523
|
+
return runner.run(wait(), timeout + 5)
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
def current_window() -> Window | None:
|
|
1527
|
+
"""The window whose callback or page builder is running."""
|
|
1528
|
+
s = _current_window.get()
|
|
1529
|
+
return Window(s) if s is not None else None
|