pythonnative 0.40.0__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pythonnative/__init__.py +411 -0
- pythonnative/_ios_log.py +92 -0
- pythonnative/_yoga.cp313-win_amd64.pyd +0 -0
- pythonnative/alerts.py +236 -0
- pythonnative/animated.py +1687 -0
- pythonnative/animation_graph.py +78 -0
- pythonnative/appearance.py +124 -0
- pythonnative/bootstrap.py +100 -0
- pythonnative/bridge/__init__.py +302 -0
- pythonnative/bridge/android.py +78 -0
- pythonnative/bridge/codec.py +170 -0
- pythonnative/bridge/commits.py +114 -0
- pythonnative/bridge/fake.py +243 -0
- pythonnative/bridge/ios.py +138 -0
- pythonnative/bridge/web.py +489 -0
- pythonnative/cli/__init__.py +7 -0
- pythonnative/cli/pn.py +1214 -0
- pythonnative/component.py +271 -0
- pythonnative/components/__init__.py +111 -0
- pythonnative/components/_base.py +166 -0
- pythonnative/components/controls.py +521 -0
- pythonnative/components/layout.py +518 -0
- pythonnative/components/lists.py +785 -0
- pythonnative/components/media.py +204 -0
- pythonnative/components/overlays.py +107 -0
- pythonnative/components/pressable.py +252 -0
- pythonnative/components/structural.py +167 -0
- pythonnative/components/text.py +291 -0
- pythonnative/devclient.py +824 -0
- pythonnative/devserver/__init__.py +34 -0
- pythonnative/devserver/server.py +718 -0
- pythonnative/devserver/static/animation_graph.js +82 -0
- pythonnative/devserver/static/bridge.js +147 -0
- pythonnative/devserver/static/colors.js +70 -0
- pythonnative/devserver/static/host.js +552 -0
- pythonnative/devserver/static/index.html +60 -0
- pythonnative/devserver/static/layout.js +85 -0
- pythonnative/devserver/static/preview.css +415 -0
- pythonnative/devserver/static/renderer.js +1994 -0
- pythonnative/devserver/static/shell.js +345 -0
- pythonnative/devserver/static/yoga/LICENSE +21 -0
- pythonnative/devserver/static/yoga/binaries/yoga-wasm-base64-esm.js +75 -0
- pythonnative/devserver/static/yoga/src/generated/YGEnums.d.ts +189 -0
- pythonnative/devserver/static/yoga/src/generated/YGEnums.js +211 -0
- pythonnative/devserver/static/yoga/src/generated/YGEnums.js.map +1 -0
- pythonnative/devserver/static/yoga/src/index.d.ts +12 -0
- pythonnative/devserver/static/yoga/src/index.js +16 -0
- pythonnative/devserver/static/yoga/src/index.js.map +1 -0
- pythonnative/devserver/static/yoga/src/load.d.ts +11 -0
- pythonnative/devserver/static/yoga/src/load.js +17 -0
- pythonnative/devserver/static/yoga/src/load.js.map +1 -0
- pythonnative/devserver/static/yoga/src/wrapAssembly.d.ts +155 -0
- pythonnative/devserver/static/yoga/src/wrapAssembly.js +125 -0
- pythonnative/devserver/static/yoga/src/wrapAssembly.js.map +1 -0
- pythonnative/devserver/watcher.py +267 -0
- pythonnative/devserver/ws.py +421 -0
- pythonnative/diagnostics.py +241 -0
- pythonnative/element.py +159 -0
- pythonnative/equality.py +19 -0
- pythonnative/events.py +231 -0
- pythonnative/gestures.py +1333 -0
- pythonnative/hooks.py +1621 -0
- pythonnative/hosts/__init__.py +63 -0
- pythonnative/hosts/base.py +596 -0
- pythonnative/hosts/native.py +302 -0
- pythonnative/hot_reload.py +585 -0
- pythonnative/layout.py +328 -0
- pythonnative/mutations.py +142 -0
- pythonnative/native/android/build.gradle +52 -0
- pythonnative/native/android/gradle.properties +3 -0
- pythonnative/native/android/settings.gradle +12 -0
- pythonnative/native/android/src/main/AndroidManifest.xml +11 -0
- pythonnative/native/android/src/main/cpp/CMakeLists.txt +9 -0
- pythonnative/native/android/src/main/cpp/yoga_jni.cpp +52 -0
- pythonnative/native/android/src/main/java/com/pythonnative/generated/NativeModules.kt +5 -0
- pythonnative/native/android/src/main/java/com/pythonnative/generated/NativeProps.kt +3705 -0
- pythonnative/native/android/src/main/java/com/pythonnative/generated/PNContracts.kt +129 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/PNBridge.kt +261 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/PythonHost.kt +20 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/AnimationGraph.kt +108 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/AnimationSpecs.kt +141 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/PNAnimator.kt +257 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/CommitState.kt +106 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/JsonUtil.kt +175 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/MainThread.kt +40 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNLog.kt +33 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNRegistry.kt +82 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNTransaction.kt +80 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/TransactionApplier.kt +117 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/ViewRegistry.kt +74 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/BuiltinComponents.kt +37 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ButtonManager.kt +32 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ComponentManager.kt +213 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ContainerManagers.kt +69 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ControlManagers.kt +186 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/DatePickerManager.kt +123 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ImageLoader.kt +141 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ImageManager.kt +162 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ModalManager.kt +134 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PNColor.kt +201 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PickerManager.kt +86 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PortalManager.kt +55 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PressableManager.kt +122 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ScreenStackManager.kt +110 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ScrollViewManager.kt +214 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/SegmentedControlManager.kt +113 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/StatusBarManager.kt +52 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TabBarManager.kt +131 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TextInputManager.kt +250 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TextManager.kt +233 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ViewStyler.kt +355 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/VirtualListManager.kt +159 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/WebViewManager.kt +149 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureArbiter.kt +233 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureCoordinator.kt +127 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureRecognizers.kt +527 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/layout/NativeLayout.kt +145 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/layout/YogaNode.kt +29 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/BuiltinModules.kt +73 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/DeviceModules.kt +316 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/HostModule.kt +61 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/MediaModules.kt +200 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/NativeModule.kt +158 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/NotificationsModule.kt +100 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/PermissionsModule.kt +99 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/StorageModules.kt +89 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/SystemModules.kt +178 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/plugins/GeneratedPlugins.kt +16 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/screens/PNScreenFragment.kt +188 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/screens/ScreenRegistry.kt +80 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNAccessibilityDelegate.kt +48 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNBorderDrawable.kt +76 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNEditText.kt +18 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNFrameLayout.kt +49 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/AnimationSpecsTest.kt +75 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/GestureArbiterTest.kt +197 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/PNColorTest.kt +47 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/PNTransactionTest.kt +78 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/PromiseTest.kt +89 -0
- pythonnative/native/ios/Package.swift +23 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Animation/PNAnimationGraph.swift +199 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Animation/PNAnimator.swift +312 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNBridge.swift +255 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNCommit.swift +104 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNRegistry.swift +142 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNTransaction.swift +166 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNViewRegistry.swift +53 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNButtonManagers.swift +207 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNColor.swift +173 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNComponentManager.swift +183 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNContainerView.swift +56 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNControlManagers.swift +281 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNImageManager.swift +222 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNOverlayManagers.swift +243 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNPressableManager.swift +114 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNScreenStackManager.swift +107 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNScrollViewManager.swift +197 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTabBarManager.swift +106 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTextInputManager.swift +297 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTextManager.swift +230 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTransform.swift +82 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewManager.swift +86 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewState.swift +87 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewStyler.swift +340 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNVirtualListManager.swift +155 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNWebViewManager.swift +124 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Generated/NativeModules.swift +1 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Generated/NativeProps.swift +3775 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Generated/PNContracts.swift +46 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Gestures/PNGestureCoordinator.swift +260 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Layout/PNLayout.swift +173 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/AlertModule.swift +92 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/HostModule.swift +80 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/LifecycleModules.swift +174 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/MediaModules.swift +177 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/PNNativeModule.swift +168 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/PermissionModules.swift +266 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/SystemModules.swift +251 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Plugins/PNPluginRegistration.swift +8 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Screens/PNScreenRegistry.swift +46 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Screens/PNViewController.swift +237 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNCompat.swift +46 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNJSON.swift +173 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNLog.swift +47 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNWindow.swift +51 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNAnimationGraphTests.swift +26 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNColorTests.swift +50 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNCommitTests.swift +86 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNGestureTests.swift +101 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNManagerTests.swift +126 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNModuleTests.swift +111 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNTransactionTests.swift +91 -0
- pythonnative/native/yoga/LICENSE +21 -0
- pythonnative/native/yoga/Package.swift +9 -0
- pythonnative/native/yoga/VENDORED.md +2 -0
- pythonnative/native/yoga/include/PNStyle.h +10 -0
- pythonnative/native/yoga/include/module.modulemap +5 -0
- pythonnative/native/yoga/include/yoga/YGConfig.h +158 -0
- pythonnative/native/yoga/include/yoga/YGEnums.h +142 -0
- pythonnative/native/yoga/include/yoga/YGMacros.h +99 -0
- pythonnative/native/yoga/include/yoga/YGNode.h +304 -0
- pythonnative/native/yoga/include/yoga/YGNodeLayout.h +35 -0
- pythonnative/native/yoga/include/yoga/YGNodeStyle.h +130 -0
- pythonnative/native/yoga/include/yoga/YGPixelGrid.h +29 -0
- pythonnative/native/yoga/include/yoga/YGValue.h +84 -0
- pythonnative/native/yoga/include/yoga/Yoga.h +21 -0
- pythonnative/native/yoga/python.cpp +16 -0
- pythonnative/native/yoga/style.cpp +272 -0
- pythonnative/native/yoga/yoga/CMakeLists.txt +41 -0
- pythonnative/native/yoga/yoga/YGConfig.cpp +92 -0
- pythonnative/native/yoga/yoga/YGConfig.h +158 -0
- pythonnative/native/yoga/yoga/YGEnums.cpp +262 -0
- pythonnative/native/yoga/yoga/YGEnums.h +142 -0
- pythonnative/native/yoga/yoga/YGMacros.h +99 -0
- pythonnative/native/yoga/yoga/YGNode.cpp +366 -0
- pythonnative/native/yoga/yoga/YGNode.h +304 -0
- pythonnative/native/yoga/yoga/YGNodeLayout.cpp +92 -0
- pythonnative/native/yoga/yoga/YGNodeLayout.h +35 -0
- pythonnative/native/yoga/yoga/YGNodeStyle.cpp +405 -0
- pythonnative/native/yoga/yoga/YGNodeStyle.h +130 -0
- pythonnative/native/yoga/yoga/YGPixelGrid.cpp +22 -0
- pythonnative/native/yoga/yoga/YGPixelGrid.h +29 -0
- pythonnative/native/yoga/yoga/YGValue.cpp +20 -0
- pythonnative/native/yoga/yoga/YGValue.h +84 -0
- pythonnative/native/yoga/yoga/Yoga.h +21 -0
- pythonnative/native/yoga/yoga/algorithm/AbsoluteLayout.cpp +563 -0
- pythonnative/native/yoga/yoga/algorithm/AbsoluteLayout.h +41 -0
- pythonnative/native/yoga/yoga/algorithm/Align.h +72 -0
- pythonnative/native/yoga/yoga/algorithm/Baseline.cpp +78 -0
- pythonnative/native/yoga/yoga/algorithm/Baseline.h +21 -0
- pythonnative/native/yoga/yoga/algorithm/BoundAxis.h +79 -0
- pythonnative/native/yoga/yoga/algorithm/Cache.cpp +121 -0
- pythonnative/native/yoga/yoga/algorithm/Cache.h +30 -0
- pythonnative/native/yoga/yoga/algorithm/CalculateLayout.cpp +2428 -0
- pythonnative/native/yoga/yoga/algorithm/CalculateLayout.h +38 -0
- pythonnative/native/yoga/yoga/algorithm/FlexDirection.h +120 -0
- pythonnative/native/yoga/yoga/algorithm/FlexLine.cpp +124 -0
- pythonnative/native/yoga/yoga/algorithm/FlexLine.h +75 -0
- pythonnative/native/yoga/yoga/algorithm/PixelGrid.cpp +132 -0
- pythonnative/native/yoga/yoga/algorithm/PixelGrid.h +29 -0
- pythonnative/native/yoga/yoga/algorithm/SizingMode.h +73 -0
- pythonnative/native/yoga/yoga/algorithm/TrailingPosition.h +44 -0
- pythonnative/native/yoga/yoga/config/Config.cpp +135 -0
- pythonnative/native/yoga/yoga/config/Config.h +92 -0
- pythonnative/native/yoga/yoga/debug/AssertFatal.cpp +53 -0
- pythonnative/native/yoga/yoga/debug/AssertFatal.h +29 -0
- pythonnative/native/yoga/yoga/debug/Log.cpp +107 -0
- pythonnative/native/yoga/yoga/debug/Log.h +34 -0
- pythonnative/native/yoga/yoga/enums/Align.h +47 -0
- pythonnative/native/yoga/yoga/enums/BoxSizing.h +40 -0
- pythonnative/native/yoga/yoga/enums/Dimension.h +40 -0
- pythonnative/native/yoga/yoga/enums/Direction.h +41 -0
- pythonnative/native/yoga/yoga/enums/Display.h +41 -0
- pythonnative/native/yoga/yoga/enums/Edge.h +47 -0
- pythonnative/native/yoga/yoga/enums/Errata.h +41 -0
- pythonnative/native/yoga/yoga/enums/ExperimentalFeature.h +39 -0
- pythonnative/native/yoga/yoga/enums/FlexDirection.h +42 -0
- pythonnative/native/yoga/yoga/enums/Gutter.h +41 -0
- pythonnative/native/yoga/yoga/enums/Justify.h +44 -0
- pythonnative/native/yoga/yoga/enums/LogLevel.h +44 -0
- pythonnative/native/yoga/yoga/enums/MeasureMode.h +41 -0
- pythonnative/native/yoga/yoga/enums/NodeType.h +40 -0
- pythonnative/native/yoga/yoga/enums/Overflow.h +41 -0
- pythonnative/native/yoga/yoga/enums/PhysicalEdge.h +21 -0
- pythonnative/native/yoga/yoga/enums/PositionType.h +41 -0
- pythonnative/native/yoga/yoga/enums/Unit.h +42 -0
- pythonnative/native/yoga/yoga/enums/Wrap.h +41 -0
- pythonnative/native/yoga/yoga/enums/YogaEnums.h +85 -0
- pythonnative/native/yoga/yoga/event/event.cpp +87 -0
- pythonnative/native/yoga/yoga/event/event.h +130 -0
- pythonnative/native/yoga/yoga/module.modulemap +21 -0
- pythonnative/native/yoga/yoga/node/CachedMeasurement.h +53 -0
- pythonnative/native/yoga/yoga/node/LayoutResults.cpp +48 -0
- pythonnative/native/yoga/yoga/node/LayoutResults.h +122 -0
- pythonnative/native/yoga/yoga/node/LayoutableChildren.h +148 -0
- pythonnative/native/yoga/yoga/node/Node.cpp +443 -0
- pythonnative/native/yoga/yoga/node/Node.h +337 -0
- pythonnative/native/yoga/yoga/numeric/Comparison.h +81 -0
- pythonnative/native/yoga/yoga/numeric/FloatOptional.h +93 -0
- pythonnative/native/yoga/yoga/style/SmallValueBuffer.h +133 -0
- pythonnative/native/yoga/yoga/style/Style.h +757 -0
- pythonnative/native/yoga/yoga/style/StyleLength.h +107 -0
- pythonnative/native/yoga/yoga/style/StyleValueHandle.h +98 -0
- pythonnative/native/yoga/yoga/style/StyleValuePool.h +127 -0
- pythonnative/native_modules/__init__.py +124 -0
- pythonnative/native_modules/app_state.py +99 -0
- pythonnative/native_modules/battery.py +75 -0
- pythonnative/native_modules/biometrics.py +42 -0
- pythonnative/native_modules/camera.py +65 -0
- pythonnative/native_modules/clipboard.py +46 -0
- pythonnative/native_modules/fallback.py +324 -0
- pythonnative/native_modules/file_system.py +145 -0
- pythonnative/native_modules/haptics.py +75 -0
- pythonnative/native_modules/linking.py +123 -0
- pythonnative/native_modules/location.py +75 -0
- pythonnative/native_modules/net_info.py +112 -0
- pythonnative/native_modules/notifications.py +129 -0
- pythonnative/native_modules/permissions.py +108 -0
- pythonnative/native_modules/registry.py +526 -0
- pythonnative/native_modules/secure_store.py +52 -0
- pythonnative/native_modules/share.py +51 -0
- pythonnative/native_views/__init__.py +375 -0
- pythonnative/native_views/base.py +316 -0
- pythonnative/native_views/bridge_backend.py +277 -0
- pythonnative/navigation/__init__.py +103 -0
- pythonnative/navigation/container.py +154 -0
- pythonnative/navigation/handle.py +540 -0
- pythonnative/navigation/hooks.py +133 -0
- pythonnative/navigation/host.py +58 -0
- pythonnative/navigation/linking.py +200 -0
- pythonnative/navigation/navigators.py +659 -0
- pythonnative/navigation/screen.py +149 -0
- pythonnative/navigation/state.py +269 -0
- pythonnative/net.py +248 -0
- pythonnative/platform.py +166 -0
- pythonnative/platform_metrics.py +252 -0
- pythonnative/preview.py +287 -0
- pythonnative/profiling.py +101 -0
- pythonnative/project/__init__.py +68 -0
- pythonnative/project/android.py +557 -0
- pythonnative/project/builder.py +817 -0
- pythonnative/project/config.py +773 -0
- pythonnative/project/deps.py +719 -0
- pythonnative/project/devices.py +304 -0
- pythonnative/project/doctor.py +283 -0
- pythonnative/project/fingerprint.py +171 -0
- pythonnative/project/icons.py +247 -0
- pythonnative/project/ios.py +325 -0
- pythonnative/project/lockfile.py +100 -0
- pythonnative/project/permissions.py +361 -0
- pythonnative/project/plugins.py +519 -0
- pythonnative/project/runtime_assets.py +183 -0
- pythonnative/py.typed +0 -0
- pythonnative/query.py +153 -0
- pythonnative/reconciler/__init__.py +29 -0
- pythonnative/reconciler/boundaries.py +375 -0
- pythonnative/reconciler/children.py +88 -0
- pythonnative/reconciler/core.py +1165 -0
- pythonnative/reconciler/layout_pass.py +393 -0
- pythonnative/reconciler/vnode.py +266 -0
- pythonnative/refresh.py +55 -0
- pythonnative/runtime.py +306 -0
- pythonnative/scheduler.py +159 -0
- pythonnative/sdk/__init__.py +153 -0
- pythonnative/sdk/_components.py +427 -0
- pythonnative/sdk/builtins.py +91 -0
- pythonnative/sdk/codegen.py +149 -0
- pythonnative/sdk/module_codegen.py +184 -0
- pythonnative/sdk/schema.py +224 -0
- pythonnative/sdk/templates/contracts.kt +46 -0
- pythonnative/sdk/templates/contracts.swift +46 -0
- pythonnative/storage.py +184 -0
- pythonnative/style.py +841 -0
- pythonnative/suspense.py +183 -0
- pythonnative/templates/android_template/app/build.gradle +75 -0
- pythonnative/templates/android_template/app/proguard-rules.pro +21 -0
- pythonnative/templates/android_template/app/src/androidTest/java/com/pythonnative/android_template/ExampleInstrumentedTest.kt +24 -0
- pythonnative/templates/android_template/app/src/debug/AndroidManifest.xml +7 -0
- pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +32 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +130 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/ScreenFragment.kt +13 -0
- pythonnative/templates/android_template/app/src/main/res/drawable/ic_launcher_background.xml +170 -0
- pythonnative/templates/android_template/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +30 -0
- pythonnative/templates/android_template/app/src/main/res/layout/activity_main.xml +10 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml +22 -0
- pythonnative/templates/android_template/app/src/main/res/values/colors.xml +5 -0
- pythonnative/templates/android_template/app/src/main/res/values/strings.xml +5 -0
- pythonnative/templates/android_template/app/src/main/res/values/themes.xml +9 -0
- pythonnative/templates/android_template/app/src/main/res/values-night/themes.xml +7 -0
- pythonnative/templates/android_template/app/src/main/res/xml/backup_rules.xml +13 -0
- pythonnative/templates/android_template/app/src/main/res/xml/data_extraction_rules.xml +19 -0
- pythonnative/templates/android_template/app/src/test/java/com/pythonnative/android_template/ExampleUnitTest.kt +17 -0
- pythonnative/templates/android_template/build.gradle +10 -0
- pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.jar +0 -0
- pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +6 -0
- pythonnative/templates/android_template/gradle.properties +23 -0
- pythonnative/templates/android_template/gradlew +185 -0
- pythonnative/templates/android_template/gradlew.bat +89 -0
- pythonnative/templates/android_template/settings.gradle +17 -0
- pythonnative/templates/ios_template/ios_template/AppDelegate.swift +51 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/AppIcon.appiconset/Contents.json +13 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/Contents.json +6 -0
- pythonnative/templates/ios_template/ios_template/Base.lproj/LaunchScreen.storyboard +25 -0
- pythonnative/templates/ios_template/ios_template/BridgingHeader.h +14 -0
- pythonnative/templates/ios_template/ios_template/Info.plist +28 -0
- pythonnative/templates/ios_template/ios_template/PythonRuntime.swift +390 -0
- pythonnative/templates/ios_template/ios_template/SceneDelegate.swift +61 -0
- pythonnative/templates/ios_template/ios_template/ViewController.swift +23 -0
- pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +745 -0
- pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift +36 -0
- pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift +41 -0
- pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift +32 -0
- pythonnative/testing/__init__.py +53 -0
- pythonnative/testing/backend.py +276 -0
- pythonnative/testing/harness.py +369 -0
- pythonnative/utils.py +145 -0
- pythonnative-0.40.0.dist-info/DELVEWHEEL +2 -0
- pythonnative-0.40.0.dist-info/METADATA +150 -0
- pythonnative-0.40.0.dist-info/RECORD +418 -0
- pythonnative-0.40.0.dist-info/WHEEL +5 -0
- pythonnative-0.40.0.dist-info/entry_points.txt +2 -0
- pythonnative-0.40.0.dist-info/licenses/LICENSE +21 -0
- pythonnative-0.40.0.dist-info/top_level.txt +1 -0
- pythonnative.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
pythonnative/style.py
ADDED
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
"""StyleSheet, typed `Style`, style resolution, and theming.
|
|
2
|
+
|
|
3
|
+
PythonNative ships a single, fully-typed [`Style`][pythonnative.Style]
|
|
4
|
+
TypedDict that enumerates every supported style property and constrains
|
|
5
|
+
enum-shaped values via [`typing.Literal`][typing.Literal]. The TypedDict
|
|
6
|
+
gives editors and type-checkers (mypy, pyright) full autocomplete and
|
|
7
|
+
validation: a typo such as ``flex_direction="collumn"`` is now a static
|
|
8
|
+
error, not a silent runtime no-op.
|
|
9
|
+
|
|
10
|
+
Style values remain plain dicts at runtime so they are trivial to
|
|
11
|
+
compose, diff, and store. Properties unrecognized by a platform handler
|
|
12
|
+
are still ignored, so third-party handlers may extend the palette
|
|
13
|
+
without modifying core types.
|
|
14
|
+
|
|
15
|
+
The runtime helpers ([`resolve_style`][pythonnative.style.resolve_style],
|
|
16
|
+
[`StyleSheet`][pythonnative.StyleSheet]) accept either a ``Style``
|
|
17
|
+
TypedDict, a regular ``Dict[str, Any]`` (for forward-compat or
|
|
18
|
+
unrestricted use), or a list of either kind of dict, and always
|
|
19
|
+
return a fresh, flat dict.
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
```python
|
|
23
|
+
import pythonnative as pn
|
|
24
|
+
|
|
25
|
+
styles = pn.StyleSheet.create(
|
|
26
|
+
title=pn.style(font_size=24, bold=True, color="#333"),
|
|
27
|
+
container=pn.style(padding=16, spacing=12),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
pn.Column(
|
|
31
|
+
pn.Text("Hello", style=styles["title"]),
|
|
32
|
+
style=styles["container"],
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
import dataclasses
|
|
38
|
+
import difflib
|
|
39
|
+
from dataclasses import dataclass
|
|
40
|
+
from typing import Any, Dict, List, Literal, Optional, Tuple, TypedDict, Union, get_args
|
|
41
|
+
|
|
42
|
+
from . import diagnostics
|
|
43
|
+
from .hooks import Context, create_context, use_color_scheme, use_context
|
|
44
|
+
|
|
45
|
+
# ======================================================================
|
|
46
|
+
# Atomic value types
|
|
47
|
+
# ======================================================================
|
|
48
|
+
|
|
49
|
+
Color = str
|
|
50
|
+
"""Color value: ``"#RRGGBB"``, ``"#AARRGGBB"``, or any string a platform
|
|
51
|
+
handler recognizes (e.g., ``"red"``). Stored verbatim and parsed by the
|
|
52
|
+
handler at apply-time, so palettes from third-party libraries pass through
|
|
53
|
+
unchanged."""
|
|
54
|
+
|
|
55
|
+
Dimension = Union[int, float, str]
|
|
56
|
+
"""A length value. Numbers are points/dp; strings ending in ``"%"`` are
|
|
57
|
+
parent-relative percentages."""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class EdgeInsets(TypedDict, total=False):
|
|
61
|
+
"""Per-edge spacing values used for ``padding`` and ``margin``.
|
|
62
|
+
|
|
63
|
+
Mirrors React Native's ``EdgeInsets`` shape with PythonNative's
|
|
64
|
+
convenience aliases. Any subset of keys may be supplied.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
top: Dimension
|
|
68
|
+
right: Dimension
|
|
69
|
+
bottom: Dimension
|
|
70
|
+
left: Dimension
|
|
71
|
+
horizontal: Dimension
|
|
72
|
+
vertical: Dimension
|
|
73
|
+
all: Dimension
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
EdgeValue = Union[Dimension, EdgeInsets]
|
|
77
|
+
"""Padding/margin value: a uniform number, a ``"%"`` string, or an
|
|
78
|
+
[`EdgeInsets`][pythonnative.EdgeInsets] dict."""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class AccessibilityState(TypedDict, total=False):
|
|
82
|
+
"""Current widget state exposed to assistive technology.
|
|
83
|
+
|
|
84
|
+
Passed via the ``accessibility_state=`` prop on interactive
|
|
85
|
+
components. All keys are optional; omitted keys are treated as
|
|
86
|
+
unset (not ``False``).
|
|
87
|
+
|
|
88
|
+
Attributes:
|
|
89
|
+
disabled: The widget is visible but not interactive.
|
|
90
|
+
selected: The widget is currently selected (e.g. the active
|
|
91
|
+
tab).
|
|
92
|
+
checked: Toggle/checkbox state. ``"mixed"`` represents a
|
|
93
|
+
tri-state checkbox.
|
|
94
|
+
busy: The widget is loading or otherwise temporarily busy.
|
|
95
|
+
expanded: A disclosure/accordion is currently expanded.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
disabled: bool
|
|
99
|
+
selected: bool
|
|
100
|
+
checked: Union[bool, Literal["mixed"]]
|
|
101
|
+
busy: bool
|
|
102
|
+
expanded: bool
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class ShadowOffset(TypedDict):
|
|
106
|
+
"""Shadow displacement in points."""
|
|
107
|
+
|
|
108
|
+
width: float
|
|
109
|
+
height: float
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
ShadowOffsetValue = Union[ShadowOffset, Tuple[float, float], List[float]]
|
|
113
|
+
"""``shadow_offset`` / ``text_shadow_offset`` value: an
|
|
114
|
+
[`ShadowOffset`][pythonnative.ShadowOffset] dict or an ``(x, y)`` pair."""
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# ----------------------------------------------------------------------
|
|
118
|
+
# Transforms
|
|
119
|
+
# ----------------------------------------------------------------------
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class TransformRotate(TypedDict):
|
|
123
|
+
"""Rotation transform in degrees (numeric) or with explicit unit suffix."""
|
|
124
|
+
|
|
125
|
+
rotate: Union[float, str]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class TransformScale(TypedDict):
|
|
129
|
+
"""Uniform scale transform."""
|
|
130
|
+
|
|
131
|
+
scale: float
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class TransformScaleX(TypedDict):
|
|
135
|
+
"""Horizontal-only scale transform."""
|
|
136
|
+
|
|
137
|
+
scale_x: float
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class TransformScaleY(TypedDict):
|
|
141
|
+
"""Vertical-only scale transform."""
|
|
142
|
+
|
|
143
|
+
scale_y: float
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class TransformTranslate(TypedDict, total=False):
|
|
147
|
+
"""Translation transform along one or both axes."""
|
|
148
|
+
|
|
149
|
+
translate_x: float
|
|
150
|
+
translate_y: float
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
TransformEntry = Union[
|
|
154
|
+
TransformRotate,
|
|
155
|
+
TransformScale,
|
|
156
|
+
TransformScaleX,
|
|
157
|
+
TransformScaleY,
|
|
158
|
+
TransformTranslate,
|
|
159
|
+
Dict[str, Any],
|
|
160
|
+
]
|
|
161
|
+
"""A single transform operation."""
|
|
162
|
+
|
|
163
|
+
TransformSpec = Union[TransformEntry, List[TransformEntry]]
|
|
164
|
+
"""``transform`` style value: a single operation or an ordered list."""
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
# ----------------------------------------------------------------------
|
|
168
|
+
# Enum-shaped style values
|
|
169
|
+
# ----------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
FlexDirection = Literal["row", "column", "row_reverse", "column_reverse"]
|
|
172
|
+
FlexWrap = Literal["nowrap", "wrap", "wrap_reverse"]
|
|
173
|
+
AlignContent = Literal[
|
|
174
|
+
"flex_start",
|
|
175
|
+
"center",
|
|
176
|
+
"flex_end",
|
|
177
|
+
"stretch",
|
|
178
|
+
"space_between",
|
|
179
|
+
"space_around",
|
|
180
|
+
"space_evenly",
|
|
181
|
+
]
|
|
182
|
+
LayoutDirection = Literal["ltr", "rtl"]
|
|
183
|
+
JustifyContent = Literal[
|
|
184
|
+
"flex_start",
|
|
185
|
+
"center",
|
|
186
|
+
"flex_end",
|
|
187
|
+
"space_between",
|
|
188
|
+
"space_around",
|
|
189
|
+
"space_evenly",
|
|
190
|
+
"start",
|
|
191
|
+
"leading",
|
|
192
|
+
"top",
|
|
193
|
+
"end",
|
|
194
|
+
"trailing",
|
|
195
|
+
"bottom",
|
|
196
|
+
]
|
|
197
|
+
AlignItems = Literal[
|
|
198
|
+
"stretch",
|
|
199
|
+
"flex_start",
|
|
200
|
+
"center",
|
|
201
|
+
"flex_end",
|
|
202
|
+
"baseline",
|
|
203
|
+
"auto",
|
|
204
|
+
"start",
|
|
205
|
+
"leading",
|
|
206
|
+
"top",
|
|
207
|
+
"end",
|
|
208
|
+
"trailing",
|
|
209
|
+
"bottom",
|
|
210
|
+
"fill",
|
|
211
|
+
]
|
|
212
|
+
AlignSelf = AlignItems
|
|
213
|
+
Position = Literal["relative", "absolute"]
|
|
214
|
+
Display = Literal["flex", "none"]
|
|
215
|
+
"""``display`` style value. ``"none"`` removes the node and its subtree
|
|
216
|
+
from layout entirely (no size, gap, or margin contribution; every frame
|
|
217
|
+
in the subtree is ``(0, 0, 0, 0)``)."""
|
|
218
|
+
Overflow = Literal["visible", "hidden", "scroll"]
|
|
219
|
+
TextAlign = Literal["left", "center", "right", "justify", "start", "end"]
|
|
220
|
+
TextDecoration = Literal["none", "underline", "line_through"]
|
|
221
|
+
TextTransform = Literal["none", "uppercase", "lowercase", "capitalize"]
|
|
222
|
+
"""``text_transform`` style value. Applied in Python before the string
|
|
223
|
+
reaches the native label, so measurement and rendering agree."""
|
|
224
|
+
MarginValue = Union[Dimension, Literal["auto"]]
|
|
225
|
+
"""A margin length: points, a ``"%"`` string, or ``"auto"`` to absorb free space."""
|
|
226
|
+
FontWeight = Literal[
|
|
227
|
+
"normal",
|
|
228
|
+
"bold",
|
|
229
|
+
"100",
|
|
230
|
+
"200",
|
|
231
|
+
"300",
|
|
232
|
+
"400",
|
|
233
|
+
"500",
|
|
234
|
+
"600",
|
|
235
|
+
"700",
|
|
236
|
+
"800",
|
|
237
|
+
"900",
|
|
238
|
+
]
|
|
239
|
+
ScaleType = Literal["cover", "contain", "stretch", "center"]
|
|
240
|
+
KeyboardType = Literal[
|
|
241
|
+
"default",
|
|
242
|
+
"email_address",
|
|
243
|
+
"number_pad",
|
|
244
|
+
"decimal_pad",
|
|
245
|
+
"phone_pad",
|
|
246
|
+
"url",
|
|
247
|
+
]
|
|
248
|
+
AutoCapitalize = Literal["none", "sentences", "words", "characters"]
|
|
249
|
+
ReturnKeyType = Literal["default", "done", "go", "next", "send", "search"]
|
|
250
|
+
PointerEvents = Literal["auto", "none", "box_none", "box_only"]
|
|
251
|
+
"""Touch-handling mode for a view and its subtree:
|
|
252
|
+
|
|
253
|
+
- ``"auto"``: the view and its children receive touches (default).
|
|
254
|
+
- ``"none"``: neither the view nor its children receive touches;
|
|
255
|
+
touches pass through to whatever is underneath.
|
|
256
|
+
- ``"box_none"``: the view itself ignores touches but its children
|
|
257
|
+
still receive them (decorative overlays with interactive content).
|
|
258
|
+
- ``"box_only"``: the view receives touches but its children do not.
|
|
259
|
+
"""
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
# ======================================================================
|
|
263
|
+
# Style TypedDict
|
|
264
|
+
# ======================================================================
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class Style(TypedDict, total=False):
|
|
268
|
+
"""Statically-typed style dictionary.
|
|
269
|
+
|
|
270
|
+
Lists every style property recognized by the built-in components
|
|
271
|
+
plus their layout engine, with enum-shaped values constrained via
|
|
272
|
+
[`Literal`][typing.Literal]. ``Style`` is a `total=False` TypedDict
|
|
273
|
+
so any subset of keys is valid at construction time.
|
|
274
|
+
|
|
275
|
+
Custom native components may accept additional, unlisted keys;
|
|
276
|
+
they are ignored by the built-in handlers but flow through the
|
|
277
|
+
reconciler unmodified, so third-party handlers can read them.
|
|
278
|
+
|
|
279
|
+
Example:
|
|
280
|
+
```python
|
|
281
|
+
import pythonnative as pn
|
|
282
|
+
|
|
283
|
+
title: pn.Style = {
|
|
284
|
+
"font_size": 24,
|
|
285
|
+
"color": "#0A84FF",
|
|
286
|
+
"text_align": "center",
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
pn.Text("Hello", style=title)
|
|
290
|
+
```
|
|
291
|
+
"""
|
|
292
|
+
|
|
293
|
+
# --- Layout: sizing ---
|
|
294
|
+
width: Dimension
|
|
295
|
+
height: Dimension
|
|
296
|
+
min_width: Dimension
|
|
297
|
+
max_width: Dimension
|
|
298
|
+
min_height: Dimension
|
|
299
|
+
max_height: Dimension
|
|
300
|
+
aspect_ratio: float
|
|
301
|
+
|
|
302
|
+
# --- Layout: flex ---
|
|
303
|
+
flex: float
|
|
304
|
+
flex_grow: float
|
|
305
|
+
flex_shrink: float
|
|
306
|
+
flex_basis: Dimension
|
|
307
|
+
flex_direction: FlexDirection
|
|
308
|
+
flex_wrap: FlexWrap
|
|
309
|
+
justify_content: JustifyContent
|
|
310
|
+
align_items: AlignItems
|
|
311
|
+
align_self: AlignSelf
|
|
312
|
+
align_content: AlignContent
|
|
313
|
+
direction: LayoutDirection
|
|
314
|
+
display: Display
|
|
315
|
+
|
|
316
|
+
# --- Layout: position ---
|
|
317
|
+
position: Position
|
|
318
|
+
top: Dimension
|
|
319
|
+
right: Dimension
|
|
320
|
+
bottom: Dimension
|
|
321
|
+
left: Dimension
|
|
322
|
+
start: Dimension
|
|
323
|
+
end: Dimension
|
|
324
|
+
|
|
325
|
+
# --- Layout: spacing ---
|
|
326
|
+
padding: EdgeValue
|
|
327
|
+
padding_top: Dimension
|
|
328
|
+
padding_bottom: Dimension
|
|
329
|
+
padding_left: Dimension
|
|
330
|
+
padding_right: Dimension
|
|
331
|
+
padding_start: Dimension
|
|
332
|
+
padding_end: Dimension
|
|
333
|
+
padding_horizontal: Dimension
|
|
334
|
+
padding_vertical: Dimension
|
|
335
|
+
margin: Union[MarginValue, EdgeInsets]
|
|
336
|
+
margin_top: MarginValue
|
|
337
|
+
margin_bottom: MarginValue
|
|
338
|
+
margin_left: MarginValue
|
|
339
|
+
margin_right: MarginValue
|
|
340
|
+
margin_start: MarginValue
|
|
341
|
+
margin_end: MarginValue
|
|
342
|
+
margin_horizontal: MarginValue
|
|
343
|
+
margin_vertical: MarginValue
|
|
344
|
+
spacing: float
|
|
345
|
+
gap: float
|
|
346
|
+
row_gap: float
|
|
347
|
+
column_gap: float
|
|
348
|
+
|
|
349
|
+
# --- Visual: clipping & overflow ---
|
|
350
|
+
overflow: Overflow
|
|
351
|
+
|
|
352
|
+
# --- Visual: colors ---
|
|
353
|
+
background_color: Color
|
|
354
|
+
color: Color
|
|
355
|
+
border_color: Color
|
|
356
|
+
placeholder_color: Color
|
|
357
|
+
tint_color: Color
|
|
358
|
+
|
|
359
|
+
# --- Visual: borders ---
|
|
360
|
+
border_width: float
|
|
361
|
+
border_radius: float
|
|
362
|
+
border_top_left_radius: float
|
|
363
|
+
border_top_right_radius: float
|
|
364
|
+
border_bottom_left_radius: float
|
|
365
|
+
border_bottom_right_radius: float
|
|
366
|
+
border_top_width: float
|
|
367
|
+
border_right_width: float
|
|
368
|
+
border_bottom_width: float
|
|
369
|
+
border_left_width: float
|
|
370
|
+
border_top_color: Color
|
|
371
|
+
border_right_color: Color
|
|
372
|
+
border_bottom_color: Color
|
|
373
|
+
border_left_color: Color
|
|
374
|
+
|
|
375
|
+
# --- Visual: typography ---
|
|
376
|
+
font_size: float
|
|
377
|
+
font_family: str
|
|
378
|
+
font_weight: FontWeight
|
|
379
|
+
bold: bool
|
|
380
|
+
italic: bool
|
|
381
|
+
text_align: TextAlign
|
|
382
|
+
text_decoration: TextDecoration
|
|
383
|
+
text_transform: TextTransform
|
|
384
|
+
line_height: float
|
|
385
|
+
letter_spacing: float
|
|
386
|
+
max_lines: int
|
|
387
|
+
text_shadow_color: Color
|
|
388
|
+
text_shadow_offset: ShadowOffsetValue
|
|
389
|
+
text_shadow_radius: float
|
|
390
|
+
|
|
391
|
+
# --- Visual: shadows / effects ---
|
|
392
|
+
shadow_color: Color
|
|
393
|
+
shadow_offset: ShadowOffsetValue
|
|
394
|
+
shadow_opacity: float
|
|
395
|
+
shadow_radius: float
|
|
396
|
+
elevation: float
|
|
397
|
+
opacity: float
|
|
398
|
+
transform: TransformSpec
|
|
399
|
+
|
|
400
|
+
# --- Interaction & stacking ---
|
|
401
|
+
z_index: int
|
|
402
|
+
pointer_events: PointerEvents
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
StyleProp = Union[Style, Dict[str, Any], List[Optional[Union[Style, Dict[str, Any]]]], None]
|
|
406
|
+
"""Public type for the ``style`` parameter on every component factory.
|
|
407
|
+
|
|
408
|
+
Accepts a [`Style`][pythonnative.Style] TypedDict (recommended), a
|
|
409
|
+
plain ``Dict[str, Any]`` (forward-compat / unrestricted), a list of
|
|
410
|
+
either with ``None`` entries skipped, or ``None``."""
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
# ======================================================================
|
|
414
|
+
# Runtime helpers
|
|
415
|
+
# ======================================================================
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def style(**properties: Any) -> Style:
|
|
419
|
+
"""Construct a [`Style`][pythonnative.Style] from keyword arguments.
|
|
420
|
+
|
|
421
|
+
Equivalent to ``Style(...)`` but works with any Python version
|
|
422
|
+
(``TypedDict.__init__`` is fragile prior to 3.11) and reads more
|
|
423
|
+
naturally inside expressions:
|
|
424
|
+
|
|
425
|
+
```python
|
|
426
|
+
pn.View(child, style=pn.style(padding=16, background_color="#fff"))
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Unknown keys are accepted at runtime to keep the door open for
|
|
430
|
+
third-party styling extensions; static type checkers will still
|
|
431
|
+
reject them when this helper's return type is annotated as
|
|
432
|
+
``Style``.
|
|
433
|
+
|
|
434
|
+
Args:
|
|
435
|
+
**properties: Style key/value pairs.
|
|
436
|
+
|
|
437
|
+
Returns:
|
|
438
|
+
A fresh ``Style`` dict containing the supplied entries.
|
|
439
|
+
"""
|
|
440
|
+
return properties # type: ignore[return-value]
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def resolve_style(value: StyleProp) -> Dict[str, Any]:
|
|
444
|
+
"""Flatten a `style` prop into a single dict.
|
|
445
|
+
|
|
446
|
+
Accepts ``None``, a single dict (``Style`` or untyped), or a list of
|
|
447
|
+
dicts (later entries override earlier ones, mirroring React Native's
|
|
448
|
+
array-style pattern). Used by every built-in element factory in
|
|
449
|
+
`pythonnative.components`.
|
|
450
|
+
|
|
451
|
+
Args:
|
|
452
|
+
value: The raw value of the component's `style` argument.
|
|
453
|
+
|
|
454
|
+
Returns:
|
|
455
|
+
A flat dict suitable for the native handler. Always a fresh
|
|
456
|
+
dict, never the input.
|
|
457
|
+
"""
|
|
458
|
+
if value is None:
|
|
459
|
+
return {}
|
|
460
|
+
if isinstance(value, dict):
|
|
461
|
+
return dict(value)
|
|
462
|
+
result: Dict[str, Any] = {}
|
|
463
|
+
for entry in value:
|
|
464
|
+
if entry:
|
|
465
|
+
result.update(entry)
|
|
466
|
+
return result
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
_KNOWN_STYLE_KEYS = frozenset(Style.__annotations__)
|
|
470
|
+
"""Every key declared on the [`Style`][pythonnative.Style] TypedDict."""
|
|
471
|
+
|
|
472
|
+
_STYLE_VALUE_CHOICES: Dict[str, frozenset] = {
|
|
473
|
+
"display": frozenset(get_args(Display)),
|
|
474
|
+
"position": frozenset(get_args(Position)),
|
|
475
|
+
"direction": frozenset(get_args(LayoutDirection)),
|
|
476
|
+
"text_decoration": frozenset(get_args(TextDecoration)),
|
|
477
|
+
"text_transform": frozenset(get_args(TextTransform)),
|
|
478
|
+
"pointer_events": frozenset(get_args(PointerEvents)),
|
|
479
|
+
}
|
|
480
|
+
"""Keys whose string values are checked against their ``Literal`` choices
|
|
481
|
+
in dev mode. Only keys whose handlers accept exactly the declared
|
|
482
|
+
literals are listed, so friendly aliases (``align_items: "leading"``,
|
|
483
|
+
``font_weight: "semibold"``) never trigger false positives."""
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _is_number(value: Any) -> bool:
|
|
487
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def _text_shadow_offset_ok(value: Any) -> bool:
|
|
491
|
+
if isinstance(value, dict):
|
|
492
|
+
return all(_is_number(value.get(k, 0)) for k in ("width", "height"))
|
|
493
|
+
if isinstance(value, (tuple, list)) and len(value) == 2:
|
|
494
|
+
return all(_is_number(v) for v in value)
|
|
495
|
+
return False
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _bad_value_message(key: str, value: Any) -> Optional[str]:
|
|
499
|
+
"""Return a description of why ``value`` is invalid for ``key``, or ``None``."""
|
|
500
|
+
choices = _STYLE_VALUE_CHOICES.get(key)
|
|
501
|
+
if choices is not None:
|
|
502
|
+
if not isinstance(value, str) or value not in choices:
|
|
503
|
+
allowed = ", ".join(repr(c) for c in sorted(choices))
|
|
504
|
+
return f"Invalid value {value!r} for style key {key!r}; expected one of {allowed}."
|
|
505
|
+
return None
|
|
506
|
+
if key == "text_shadow_offset" and not _text_shadow_offset_ok(value):
|
|
507
|
+
return (
|
|
508
|
+
f"Invalid value {value!r} for style key 'text_shadow_offset'; "
|
|
509
|
+
"expected {'width': x, 'height': y} or an (x, y) pair."
|
|
510
|
+
)
|
|
511
|
+
if key == "text_shadow_radius" and (not _is_number(value) or value < 0):
|
|
512
|
+
return f"Invalid value {value!r} for style key 'text_shadow_radius'; expected a non-negative number."
|
|
513
|
+
return None
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def validate_style_keys(style_dict: Dict[str, Any], owner: str = "") -> None:
|
|
517
|
+
"""Warn (once per key) about style keys no built-in handler reads.
|
|
518
|
+
|
|
519
|
+
Dev-mode only; production skips the scan entirely. Typos get a
|
|
520
|
+
"did you mean" suggestion via fuzzy matching against the declared
|
|
521
|
+
[`Style`][pythonnative.Style] keys. Unknown keys still flow through
|
|
522
|
+
to handlers untouched, so custom components that read extra keys
|
|
523
|
+
keep working (at the cost of one dev warning).
|
|
524
|
+
|
|
525
|
+
A small set of enum-shaped keys (``display``, ``position``,
|
|
526
|
+
``direction``, ``text_decoration``, ``text_transform``,
|
|
527
|
+
``pointer_events``) and the ``text_shadow_*`` keys also have their
|
|
528
|
+
values checked; a bad value warns once per key/value pair and is
|
|
529
|
+
otherwise passed through (the engine and handlers ignore values
|
|
530
|
+
they don't recognize).
|
|
531
|
+
|
|
532
|
+
Args:
|
|
533
|
+
style_dict: The flattened style dict about to be merged into an
|
|
534
|
+
element's props.
|
|
535
|
+
owner: Element type name for the warning message (e.g.
|
|
536
|
+
``"Text"``).
|
|
537
|
+
"""
|
|
538
|
+
if not diagnostics.is_dev() or not style_dict:
|
|
539
|
+
return
|
|
540
|
+
for key, value in style_dict.items():
|
|
541
|
+
if key in _KNOWN_STYLE_KEYS:
|
|
542
|
+
if value is None:
|
|
543
|
+
continue
|
|
544
|
+
problem = _bad_value_message(key, value)
|
|
545
|
+
if problem is not None:
|
|
546
|
+
diagnostics.warn_once(
|
|
547
|
+
problem + (f" (on {owner})" if owner else ""),
|
|
548
|
+
key=f"style-value:{owner}:{key}:{value!r}",
|
|
549
|
+
)
|
|
550
|
+
continue
|
|
551
|
+
matches = difflib.get_close_matches(str(key), _KNOWN_STYLE_KEYS, n=1)
|
|
552
|
+
hint = f" Did you mean {matches[0]!r}?" if matches else ""
|
|
553
|
+
diagnostics.warn_once(
|
|
554
|
+
f"Unknown style key {key!r}"
|
|
555
|
+
+ (f" on {owner}" if owner else "")
|
|
556
|
+
+ f".{hint} Built-in components ignore keys they don't recognize.",
|
|
557
|
+
key=f"style:{owner}:{key}",
|
|
558
|
+
)
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
# ======================================================================
|
|
562
|
+
# StyleSheet
|
|
563
|
+
# ======================================================================
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
class StyleSheet:
|
|
567
|
+
"""Utility for creating, composing, and flattening style dictionaries.
|
|
568
|
+
|
|
569
|
+
All methods are stateless and return fresh dicts, so the values can
|
|
570
|
+
be reused safely across components.
|
|
571
|
+
"""
|
|
572
|
+
|
|
573
|
+
@staticmethod
|
|
574
|
+
def create(**named_styles: Style) -> Dict[str, Style]:
|
|
575
|
+
"""Create a set of named styles from keyword arguments.
|
|
576
|
+
|
|
577
|
+
Args:
|
|
578
|
+
**named_styles: Each keyword argument is a style name
|
|
579
|
+
mapping to a [`Style`][pythonnative.Style] dict.
|
|
580
|
+
|
|
581
|
+
Returns:
|
|
582
|
+
A dict mapping each name to a copy of the supplied style,
|
|
583
|
+
so the caller can mutate the result without affecting the
|
|
584
|
+
originals.
|
|
585
|
+
|
|
586
|
+
Example:
|
|
587
|
+
```python
|
|
588
|
+
from pythonnative import StyleSheet, style
|
|
589
|
+
|
|
590
|
+
styles = StyleSheet.create(
|
|
591
|
+
heading=style(font_size=28, bold=True),
|
|
592
|
+
body=style(font_size=16),
|
|
593
|
+
)
|
|
594
|
+
```
|
|
595
|
+
"""
|
|
596
|
+
return {name: dict(props) for name, props in named_styles.items()} # type: ignore[misc]
|
|
597
|
+
|
|
598
|
+
@staticmethod
|
|
599
|
+
def compose(*styles: StyleProp) -> Style:
|
|
600
|
+
"""Merge multiple style dicts.
|
|
601
|
+
|
|
602
|
+
Args:
|
|
603
|
+
*styles: Style dicts to merge. Later dicts override keys
|
|
604
|
+
from earlier ones. Falsy entries (``None``) are skipped.
|
|
605
|
+
List entries are flattened in turn.
|
|
606
|
+
|
|
607
|
+
Returns:
|
|
608
|
+
A new ``Style`` dict containing the merged result.
|
|
609
|
+
"""
|
|
610
|
+
merged: Dict[str, Any] = {}
|
|
611
|
+
for entry in styles:
|
|
612
|
+
if entry is None:
|
|
613
|
+
continue
|
|
614
|
+
if isinstance(entry, dict):
|
|
615
|
+
merged.update(entry)
|
|
616
|
+
continue
|
|
617
|
+
for nested in entry:
|
|
618
|
+
if nested:
|
|
619
|
+
merged.update(nested)
|
|
620
|
+
return merged # type: ignore[return-value]
|
|
621
|
+
|
|
622
|
+
@staticmethod
|
|
623
|
+
def flatten(styles: StyleProp) -> Style:
|
|
624
|
+
"""Flatten a style value or list of styles into a single dict.
|
|
625
|
+
|
|
626
|
+
Equivalent to
|
|
627
|
+
[`resolve_style`][pythonnative.style.resolve_style] but exposed
|
|
628
|
+
on `StyleSheet` for parity with React Native's API and typed
|
|
629
|
+
as returning a ``Style``.
|
|
630
|
+
|
|
631
|
+
Args:
|
|
632
|
+
styles: A single dict, a list of dicts, or `None`.
|
|
633
|
+
|
|
634
|
+
Returns:
|
|
635
|
+
A flat ``Style`` dict combining the inputs.
|
|
636
|
+
"""
|
|
637
|
+
return resolve_style(styles) # type: ignore[return-value]
|
|
638
|
+
|
|
639
|
+
@staticmethod
|
|
640
|
+
def absolute_fill() -> Style:
|
|
641
|
+
"""Return a style that absolutely fills the parent.
|
|
642
|
+
|
|
643
|
+
Convenience preset matching React Native's
|
|
644
|
+
``StyleSheet.absoluteFill``: ``position: "absolute"`` with
|
|
645
|
+
every inset pinned to ``0``.
|
|
646
|
+
"""
|
|
647
|
+
return {"position": "absolute", "top": 0, "right": 0, "bottom": 0, "left": 0}
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
# ======================================================================
|
|
651
|
+
# Theming
|
|
652
|
+
# ======================================================================
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
@dataclass(frozen=True)
|
|
656
|
+
class Theme:
|
|
657
|
+
"""Design tokens read through [`use_theme`][pythonnative.use_theme].
|
|
658
|
+
|
|
659
|
+
A ``Theme`` is an immutable, fully typed record, so
|
|
660
|
+
``theme.text_color`` autocompletes and a typo is a static error
|
|
661
|
+
rather than a runtime ``KeyError``. Derive a custom theme from a
|
|
662
|
+
built-in one with [`replace`][pythonnative.style.Theme.replace]:
|
|
663
|
+
|
|
664
|
+
```python
|
|
665
|
+
brand = pn.DEFAULT_LIGHT_THEME.replace(primary_color="#FF2D55")
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
Attributes:
|
|
669
|
+
primary_color: Main accent color.
|
|
670
|
+
secondary_color: Secondary accent color.
|
|
671
|
+
background_color: Screen background.
|
|
672
|
+
surface_color: Raised surfaces such as cards and sheets.
|
|
673
|
+
text_color: Primary text.
|
|
674
|
+
text_secondary_color: De-emphasized text.
|
|
675
|
+
error_color: Destructive and error states.
|
|
676
|
+
success_color: Success states.
|
|
677
|
+
warning_color: Warning states.
|
|
678
|
+
font_size: Body text size, in points.
|
|
679
|
+
font_size_small: Caption size, in points.
|
|
680
|
+
font_size_large: Subtitle size, in points.
|
|
681
|
+
font_size_title: Title size, in points.
|
|
682
|
+
spacing: Base spacing unit, in points.
|
|
683
|
+
spacing_large: Large spacing unit, in points.
|
|
684
|
+
border_radius: Default corner radius, in points.
|
|
685
|
+
"""
|
|
686
|
+
|
|
687
|
+
primary_color: Color
|
|
688
|
+
secondary_color: Color
|
|
689
|
+
background_color: Color
|
|
690
|
+
surface_color: Color
|
|
691
|
+
text_color: Color
|
|
692
|
+
text_secondary_color: Color
|
|
693
|
+
error_color: Color
|
|
694
|
+
success_color: Color
|
|
695
|
+
warning_color: Color
|
|
696
|
+
font_size: float = 16
|
|
697
|
+
font_size_small: float = 13
|
|
698
|
+
font_size_large: float = 20
|
|
699
|
+
font_size_title: float = 28
|
|
700
|
+
spacing: float = 8
|
|
701
|
+
spacing_large: float = 16
|
|
702
|
+
border_radius: float = 8
|
|
703
|
+
|
|
704
|
+
def replace(self, **changes: Any) -> "Theme":
|
|
705
|
+
"""Return a copy of this theme with the given fields replaced.
|
|
706
|
+
|
|
707
|
+
Raises:
|
|
708
|
+
TypeError: If ``changes`` names a field that doesn't exist.
|
|
709
|
+
"""
|
|
710
|
+
return dataclasses.replace(self, **changes)
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
DEFAULT_LIGHT_THEME = Theme(
|
|
714
|
+
primary_color="#007AFF",
|
|
715
|
+
secondary_color="#5856D6",
|
|
716
|
+
background_color="#FFFFFF",
|
|
717
|
+
surface_color="#F2F2F7",
|
|
718
|
+
text_color="#000000",
|
|
719
|
+
text_secondary_color="#8E8E93",
|
|
720
|
+
error_color="#FF3B30",
|
|
721
|
+
success_color="#34C759",
|
|
722
|
+
warning_color="#FF9500",
|
|
723
|
+
)
|
|
724
|
+
"""Built-in light theme selected by [`use_theme`][pythonnative.use_theme]."""
|
|
725
|
+
|
|
726
|
+
DEFAULT_DARK_THEME = Theme(
|
|
727
|
+
primary_color="#0A84FF",
|
|
728
|
+
secondary_color="#5E5CE6",
|
|
729
|
+
background_color="#000000",
|
|
730
|
+
surface_color="#1C1C1E",
|
|
731
|
+
text_color="#FFFFFF",
|
|
732
|
+
text_secondary_color="#8E8E93",
|
|
733
|
+
error_color="#FF453A",
|
|
734
|
+
success_color="#30D158",
|
|
735
|
+
warning_color="#FF9F0A",
|
|
736
|
+
)
|
|
737
|
+
"""Built-in dark theme selected by [`use_theme`][pythonnative.use_theme]."""
|
|
738
|
+
|
|
739
|
+
_FOLLOW_SYSTEM_THEME = object()
|
|
740
|
+
"""Sentinel default for `ThemeContext`: resolve from the color scheme."""
|
|
741
|
+
|
|
742
|
+
ThemeContext: Context = create_context(_FOLLOW_SYSTEM_THEME)
|
|
743
|
+
"""Theme context that follows the system color scheme by default.
|
|
744
|
+
|
|
745
|
+
Without a provider, [`use_theme`][pythonnative.use_theme] resolves to
|
|
746
|
+
[`DEFAULT_LIGHT_THEME`][pythonnative.style.DEFAULT_LIGHT_THEME] or
|
|
747
|
+
[`DEFAULT_DARK_THEME`][pythonnative.style.DEFAULT_DARK_THEME] based on
|
|
748
|
+
the current appearance. Wrap a subtree in
|
|
749
|
+
[`ThemeContext.Provider(my_theme, ...)`][pythonnative.hooks.Context.Provider] to
|
|
750
|
+
pin an explicit theme for that subtree, then read it inside
|
|
751
|
+
descendants via [`use_theme`][pythonnative.use_theme] (or
|
|
752
|
+
[`use_context(ThemeContext)`][pythonnative.use_context]).
|
|
753
|
+
"""
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
def default_theme(scheme: str) -> Theme:
|
|
757
|
+
"""Return the built-in [`Theme`][pythonnative.Theme] for ``scheme`` (``"light"`` / ``"dark"``)."""
|
|
758
|
+
return DEFAULT_DARK_THEME if scheme == "dark" else DEFAULT_LIGHT_THEME
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
def use_theme() -> Theme:
|
|
762
|
+
"""Return the active [`Theme`][pythonnative.Theme], following the system appearance by default.
|
|
763
|
+
|
|
764
|
+
If an ancestor mounted a ``ThemeContext.Provider(...)``, that
|
|
765
|
+
theme is returned as-is. Otherwise the built-in light or dark
|
|
766
|
+
theme is selected from the effective color scheme (via
|
|
767
|
+
[`use_color_scheme`][pythonnative.use_color_scheme], so the
|
|
768
|
+
component re-renders when the system appearance flips).
|
|
769
|
+
|
|
770
|
+
Returns:
|
|
771
|
+
The active theme.
|
|
772
|
+
|
|
773
|
+
Raises:
|
|
774
|
+
RuntimeError: If called outside a `@component` function.
|
|
775
|
+
|
|
776
|
+
Example:
|
|
777
|
+
```python
|
|
778
|
+
import pythonnative as pn
|
|
779
|
+
|
|
780
|
+
@pn.component
|
|
781
|
+
def Card():
|
|
782
|
+
theme = pn.use_theme()
|
|
783
|
+
return pn.View(
|
|
784
|
+
pn.Text("Hello", style=pn.style(color=theme.text_color)),
|
|
785
|
+
style=pn.style(background_color=theme.surface_color),
|
|
786
|
+
)
|
|
787
|
+
```
|
|
788
|
+
"""
|
|
789
|
+
scheme = use_color_scheme()
|
|
790
|
+
theme = use_context(ThemeContext)
|
|
791
|
+
if theme is _FOLLOW_SYSTEM_THEME:
|
|
792
|
+
return default_theme(scheme)
|
|
793
|
+
if not isinstance(theme, Theme):
|
|
794
|
+
raise TypeError(f"ThemeContext.Provider expects a pn.Theme, got {type(theme).__name__}: {theme!r}")
|
|
795
|
+
return theme
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
__all__ = [
|
|
799
|
+
"AlignItems",
|
|
800
|
+
"AlignSelf",
|
|
801
|
+
"AutoCapitalize",
|
|
802
|
+
"Color",
|
|
803
|
+
"DEFAULT_DARK_THEME",
|
|
804
|
+
"DEFAULT_LIGHT_THEME",
|
|
805
|
+
"Dimension",
|
|
806
|
+
"Display",
|
|
807
|
+
"EdgeInsets",
|
|
808
|
+
"EdgeValue",
|
|
809
|
+
"FlexDirection",
|
|
810
|
+
"FontWeight",
|
|
811
|
+
"JustifyContent",
|
|
812
|
+
"KeyboardType",
|
|
813
|
+
"MarginValue",
|
|
814
|
+
"Overflow",
|
|
815
|
+
"PointerEvents",
|
|
816
|
+
"Position",
|
|
817
|
+
"ReturnKeyType",
|
|
818
|
+
"ScaleType",
|
|
819
|
+
"ShadowOffset",
|
|
820
|
+
"ShadowOffsetValue",
|
|
821
|
+
"Style",
|
|
822
|
+
"StyleProp",
|
|
823
|
+
"StyleSheet",
|
|
824
|
+
"TextAlign",
|
|
825
|
+
"TextDecoration",
|
|
826
|
+
"TextTransform",
|
|
827
|
+
"Theme",
|
|
828
|
+
"ThemeContext",
|
|
829
|
+
"TransformEntry",
|
|
830
|
+
"TransformRotate",
|
|
831
|
+
"TransformScale",
|
|
832
|
+
"TransformScaleX",
|
|
833
|
+
"TransformScaleY",
|
|
834
|
+
"TransformSpec",
|
|
835
|
+
"TransformTranslate",
|
|
836
|
+
"default_theme",
|
|
837
|
+
"resolve_style",
|
|
838
|
+
"style",
|
|
839
|
+
"use_theme",
|
|
840
|
+
"validate_style_keys",
|
|
841
|
+
]
|