pydux-store 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Neuri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: pydux-store
3
+ Version: 0.1.0
4
+ Summary: A Redux Toolkit-inspired state container for Python desktop applications.
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Keywords: python,state-management,redux,redux-toolkit,desktop-app,gui,qt,pyside,pyqt,kivy,tkinter,qyro
8
+ Author: Neuri
9
+ Author-email: ppg@neuri.ai
10
+ Maintainer: Luis Alfredo De Los Reyes
11
+ Maintainer-email: luisalfredoreyes98@gmail.com
12
+ Requires-Python: >=3.10,<3.13.20
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Typing :: Typed
25
+ Provides-Extra: all
26
+ Provides-Extra: kivy
27
+ Provides-Extra: psx
28
+ Provides-Extra: pyqt5
29
+ Provides-Extra: pyqt6
30
+ Provides-Extra: pyside2
31
+ Provides-Extra: pyside6
32
+ Provides-Extra: qyro
33
+ Requires-Dist: PyQt5 (>=5.15.0) ; (python_version < "3.14") and (extra == "all")
34
+ Requires-Dist: PyQt5 (>=5.15.0) ; (python_version < "3.14") and (extra == "pyqt5")
35
+ Requires-Dist: PyQt6 (>=6.5.0) ; extra == "all"
36
+ Requires-Dist: PyQt6 (>=6.5.0) ; extra == "pyqt6"
37
+ Requires-Dist: PySide2 (>=5.15.0) ; (python_version < "3.11") and (extra == "all")
38
+ Requires-Dist: PySide2 (>=5.15.0) ; (python_version < "3.11") and (extra == "pyside2")
39
+ Requires-Dist: PySide6 (>=6.5.0) ; (python_version < "3.14") and (extra == "all")
40
+ Requires-Dist: PySide6 (>=6.5.0) ; (python_version < "3.14") and (extra == "pyside6")
41
+ Requires-Dist: kivy (>=2.2.0) ; extra == "all"
42
+ Requires-Dist: kivy (>=2.2.0) ; extra == "kivy"
43
+ Requires-Dist: qyro-engine (>=0.1.0,<1.0.0) ; extra == "all"
44
+ Requires-Dist: qyro-engine (>=0.1.0,<1.0.0) ; extra == "qyro"
45
+ Requires-Dist: velto-core (>=0.1.0,<1.0.0) ; extra == "all"
46
+ Requires-Dist: velto-core (>=0.1.0,<1.0.0) ; extra == "psx"
47
+ Project-URL: Homepage, https://github.com/Neuri-AI/pydux
48
+ Project-URL: Issues, https://github.com/Neuri-AI/pydux/issues
49
+ Project-URL: Repository, https://github.com/Neuri-AI/pydux
50
+ Description-Content-Type: text/markdown
51
+
52
+ # PyDux
53
+
54
+ > **A Redux Toolkit-inspired state container for Python desktop applications.**
55
+
56
+ [![Python](https://img.shields.io/badge/Python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue.svg)](https://python.org)
57
+ ![GitHub Release](https://img.shields.io/github/v/release/Neuri-AI/pydux?include_prereleases&display_name=release&color=stable)
58
+ ![GitHub Issues](https://img.shields.io/github/issues/Neuri-AI/pydux?color=%23ab7df8)
59
+ ![GitHub Issues Closed](https://img.shields.io/github/issues-closed/Neuri-AI/pydux?color=green)
60
+ ![GitHub forks](https://img.shields.io/github/forks/Neuri-AI/pydux)
61
+ ![GitHub stars](https://img.shields.io/github/stars/Neuri-AI/pydux)
62
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
63
+ [![Sponsor](https://img.shields.io/badge/Sponsor-Buy%20Me%20a%20Coffee-FFDD00?logo=buymeacoffee&logoColor=000000)](https://buymeacoffee.com/neuri)
64
+
65
+
66
+ PyDux gives Python desktop apps one observable source of truth. Dispatch actions,
67
+ let reducers update state, and subscribe only to the values a view needs.
68
+
69
+ ## Features
70
+
71
+ - Redux Toolkit-style slices with generated action creators.
72
+ - Selectors and selective subscriptions.
73
+ - Async thunks with `pending`, `fulfilled`, and `rejected` actions.
74
+ - Optional DevTools, time travel, and a local web inspector.
75
+ - Adapters for Qt, Tkinter, Kivy, and [Qyro](https://github.com/Neuri-AI/qyro).
76
+
77
+ ## Installation
78
+
79
+ ```bash
80
+ pip install pydux
81
+
82
+ # With Qyro and PySide6
83
+ pip install "pydux[qyro,pyside6]"
84
+ ```
85
+
86
+ See the [English installation guide](docs/en/getting-started/installation.mdx)
87
+ or the [guía de instalación en español](docs/es/getting-started/installation.mdx)
88
+ for every optional framework extra and Poetry command.
89
+
90
+ ## Quick example
91
+
92
+ ```python
93
+ from pydux import configure_store, create_slice
94
+
95
+ counter = create_slice(
96
+ name="counter",
97
+ initial_state={"value": 0},
98
+ reducers={
99
+ "increment": lambda state, action: state.update(value=state["value"] + 1),
100
+ },
101
+ )
102
+
103
+ store = configure_store({"counter": counter}, devtools=False)
104
+ store.dispatch(counter.actions.increment())
105
+
106
+ print(store.get_state()) # {"counter": {"value": 1}}
107
+ ```
108
+
109
+ ## Documentation
110
+
111
+ The complete Mintlify documentation lives in [`docs/`](docs/en/index.mdx), in
112
+ [English](docs/en/index.mdx) and [español](docs/es/index.mdx):
113
+
114
+ - [Get started](docs/en/getting-started/quickstart.mdx) / [Primeros pasos](docs/es/getting-started/quickstart.mdx)
115
+ - [PyDux + Qyro for beginners](docs/en/getting-started/qyro-for-beginners.mdx) / [PyDux + Qyro para principiantes](docs/es/getting-started/qyro-for-beginners.mdx)
116
+ - [API reference](docs/en/reference/api.mdx) / [Referencia de API](docs/es/reference/api.mdx)
117
+
118
+ To preview it locally, install Mintlify and run `mint dev` from `docs/`.
119
+
120
+ ## Qyro ecosystem
121
+
122
+ PyDux manages state. [Qyro Runtime](https://github.com/Neuri-AI/qyro) provides
123
+ application context, resources, settings, and lifecycle; [Qyro CLI](https://github.com/Neuri-AI/qyro-cli)
124
+ scaffolds, builds, packages, and signs applications.
125
+
126
+ ---
127
+
128
+ ## License
129
+
130
+ MIT. See [LICENSE](LICENSE).
131
+ ---
132
+
133
+ ## 👥 Organization & Maintainers
134
+
135
+ - **Organization:** [Neuri](https://github.com/Neuri-AI)
136
+ - **Lead Maintainer:** Luis Alfredo De Los Reyes ([luisalfredoreyes98@gmail.com](mailto:luisalfredoreyes98@gmail.com))
137
+ - **Ecosystem:** [Qyro](https://github.com/Neuri-AI/qyro) • [Qyro CLI](https://github.com/Neuri-AI/qyro-cli) • [Boilerplates](https://github.com/Neuri-AI)
138
+
@@ -0,0 +1,86 @@
1
+ # PyDux
2
+
3
+ > **A Redux Toolkit-inspired state container for Python desktop applications.**
4
+
5
+ [![Python](https://img.shields.io/badge/Python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue.svg)](https://python.org)
6
+ ![GitHub Release](https://img.shields.io/github/v/release/Neuri-AI/pydux?include_prereleases&display_name=release&color=stable)
7
+ ![GitHub Issues](https://img.shields.io/github/issues/Neuri-AI/pydux?color=%23ab7df8)
8
+ ![GitHub Issues Closed](https://img.shields.io/github/issues-closed/Neuri-AI/pydux?color=green)
9
+ ![GitHub forks](https://img.shields.io/github/forks/Neuri-AI/pydux)
10
+ ![GitHub stars](https://img.shields.io/github/stars/Neuri-AI/pydux)
11
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
12
+ [![Sponsor](https://img.shields.io/badge/Sponsor-Buy%20Me%20a%20Coffee-FFDD00?logo=buymeacoffee&logoColor=000000)](https://buymeacoffee.com/neuri)
13
+
14
+
15
+ PyDux gives Python desktop apps one observable source of truth. Dispatch actions,
16
+ let reducers update state, and subscribe only to the values a view needs.
17
+
18
+ ## Features
19
+
20
+ - Redux Toolkit-style slices with generated action creators.
21
+ - Selectors and selective subscriptions.
22
+ - Async thunks with `pending`, `fulfilled`, and `rejected` actions.
23
+ - Optional DevTools, time travel, and a local web inspector.
24
+ - Adapters for Qt, Tkinter, Kivy, and [Qyro](https://github.com/Neuri-AI/qyro).
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install pydux
30
+
31
+ # With Qyro and PySide6
32
+ pip install "pydux[qyro,pyside6]"
33
+ ```
34
+
35
+ See the [English installation guide](docs/en/getting-started/installation.mdx)
36
+ or the [guía de instalación en español](docs/es/getting-started/installation.mdx)
37
+ for every optional framework extra and Poetry command.
38
+
39
+ ## Quick example
40
+
41
+ ```python
42
+ from pydux import configure_store, create_slice
43
+
44
+ counter = create_slice(
45
+ name="counter",
46
+ initial_state={"value": 0},
47
+ reducers={
48
+ "increment": lambda state, action: state.update(value=state["value"] + 1),
49
+ },
50
+ )
51
+
52
+ store = configure_store({"counter": counter}, devtools=False)
53
+ store.dispatch(counter.actions.increment())
54
+
55
+ print(store.get_state()) # {"counter": {"value": 1}}
56
+ ```
57
+
58
+ ## Documentation
59
+
60
+ The complete Mintlify documentation lives in [`docs/`](docs/en/index.mdx), in
61
+ [English](docs/en/index.mdx) and [español](docs/es/index.mdx):
62
+
63
+ - [Get started](docs/en/getting-started/quickstart.mdx) / [Primeros pasos](docs/es/getting-started/quickstart.mdx)
64
+ - [PyDux + Qyro for beginners](docs/en/getting-started/qyro-for-beginners.mdx) / [PyDux + Qyro para principiantes](docs/es/getting-started/qyro-for-beginners.mdx)
65
+ - [API reference](docs/en/reference/api.mdx) / [Referencia de API](docs/es/reference/api.mdx)
66
+
67
+ To preview it locally, install Mintlify and run `mint dev` from `docs/`.
68
+
69
+ ## Qyro ecosystem
70
+
71
+ PyDux manages state. [Qyro Runtime](https://github.com/Neuri-AI/qyro) provides
72
+ application context, resources, settings, and lifecycle; [Qyro CLI](https://github.com/Neuri-AI/qyro-cli)
73
+ scaffolds, builds, packages, and signs applications.
74
+
75
+ ---
76
+
77
+ ## License
78
+
79
+ MIT. See [LICENSE](LICENSE).
80
+ ---
81
+
82
+ ## 👥 Organization & Maintainers
83
+
84
+ - **Organization:** [Neuri](https://github.com/Neuri-AI)
85
+ - **Lead Maintainer:** Luis Alfredo De Los Reyes ([luisalfredoreyes98@gmail.com](mailto:luisalfredoreyes98@gmail.com))
86
+ - **Ecosystem:** [Qyro](https://github.com/Neuri-AI/qyro) • [Qyro CLI](https://github.com/Neuri-AI/qyro-cli) • [Boilerplates](https://github.com/Neuri-AI)
@@ -0,0 +1,69 @@
1
+ """
2
+ PyDux 3.0 — UI-Agnostic State Management for Python Desktop Applications.
3
+ Supports modern Redux Toolkit style (create_slice, configure_store, create_async_thunk)
4
+ with memoized selectors, zero redundant re-renders, and full Qyro/PySide/Tkinter/Kivy support.
5
+ """
6
+
7
+ # Redux Toolkit style modern API
8
+ from pydux.toolkit.slice import create_slice, Slice
9
+ from pydux.toolkit.configure_store import configure_store, combine_reducers
10
+ from pydux.toolkit.hot_reload import reconfigure_store
11
+ from pydux.toolkit.async_thunk import create_async_thunk, create_thunk_middleware
12
+
13
+ # Core Store & Selectors
14
+ from pydux.core.store import Store
15
+ from pydux.core.selector import create_selector, shallow_equal, deep_equal, is_identical
16
+ from pydux.core.types import Action, Reducer, Selector, Middleware, Dispatch
17
+
18
+ # DevTools & Time-Travel
19
+ from pydux.devtools.tracker import PyDuxDevTools, devtools_middleware
20
+ from pydux.devtools.inspector import PyDuxInspectorServer, start_inspector
21
+
22
+ # UI Adapters & Framework Bridges
23
+ from pydux.adapters.base import MainThreadBridge, ReactiveBinding, connect
24
+ from pydux.adapters.qyro import Reactive, connect_qyro
25
+ try: # Optional: importing Pydux core does not require PSX.
26
+ from pydux.adapters.psx import StoreProvider, use_dispatch, use_selector
27
+ except ModuleNotFoundError as exc: # pragma: no cover - depends on installation extras
28
+ if exc.name != "psx":
29
+ raise
30
+
31
+ __version__ = "3.0.0"
32
+ __all__ = [
33
+ # Redux Toolkit API
34
+ "create_slice",
35
+ "configure_store",
36
+ "create_async_thunk",
37
+ "create_thunk_middleware",
38
+ "combine_reducers",
39
+ "reconfigure_store",
40
+ "Slice",
41
+
42
+ # Core Store & Selectors
43
+ "Store",
44
+ "create_selector",
45
+ "shallow_equal",
46
+ "deep_equal",
47
+ "is_identical",
48
+ "Action",
49
+ "Reducer",
50
+ "Selector",
51
+ "Middleware",
52
+ "Dispatch",
53
+
54
+ # DevTools
55
+ "PyDuxDevTools",
56
+ "devtools_middleware",
57
+ "PyDuxInspectorServer",
58
+ "start_inspector",
59
+
60
+ # Adapters
61
+ "MainThreadBridge",
62
+ "ReactiveBinding",
63
+ "connect",
64
+ "Reactive",
65
+ "connect_qyro",
66
+ ]
67
+
68
+ if "StoreProvider" in globals():
69
+ __all__ += ["StoreProvider", "use_dispatch", "use_selector"]
@@ -0,0 +1,113 @@
1
+ """
2
+ UI-Agnostic Reactive Binding & Thread Dispatcher.
3
+ Decouples PyDux from any concrete GUI library while providing
4
+ rock-solid main thread synchronization.
5
+ """
6
+
7
+ from typing import (
8
+ Callable,
9
+ Any,
10
+ Optional,
11
+ Protocol,
12
+ TypeVar,
13
+ Dict,
14
+ )
15
+ from pydux.core.store import Store
16
+ from pydux.core.types import Selector, Unsubscribe, EqualityFn
17
+
18
+ T = TypeVar("T")
19
+
20
+
21
+ class MainThreadBridge(Protocol):
22
+ """
23
+ Protocol to safely schedule a callable onto the GUI's main thread.
24
+ Required by desktop frameworks (Qt, Tkinter, Kivy) to avoid threading crashes.
25
+ """
26
+
27
+ def schedule_on_main_thread(self, fn: Callable[[], None]) -> None:
28
+ ...
29
+
30
+
31
+ class DirectThreadBridge:
32
+ """Default fallback bridge for pure synchronous execution or tests."""
33
+
34
+ def schedule_on_main_thread(self, fn: Callable[[], None]) -> None:
35
+ fn()
36
+
37
+
38
+ class ReactiveBinding:
39
+ """
40
+ Connects a specific PyDux selector to any widget setter or callback.
41
+ Automatically handles main-thread dispatching.
42
+
43
+ Example:
44
+ ReactiveBinding(
45
+ store=store,
46
+ selector=lambda s: s["user"]["name"],
47
+ target=lambda name: label.config(text=name),
48
+ bridge=TkinterBridge(root)
49
+ )
50
+ """
51
+
52
+ def __init__(
53
+ self,
54
+ store: Store[Any],
55
+ selector: Selector[Any, T],
56
+ target: Callable[[T], None],
57
+ equality_fn: Optional[EqualityFn] = None,
58
+ bridge: Optional[MainThreadBridge] = None,
59
+ ):
60
+ self._bridge = bridge or DirectThreadBridge()
61
+ self._target = target
62
+
63
+ def safe_listener(value: T):
64
+ self._bridge.schedule_on_main_thread(lambda: self._target(value))
65
+
66
+ self._unsubscribe = store.select(
67
+ selector=selector,
68
+ listener=safe_listener,
69
+ equality_fn=equality_fn,
70
+ fire_immediately=True,
71
+ )
72
+
73
+ def dispose(self) -> None:
74
+ """Tears down the subscription."""
75
+ if self._unsubscribe:
76
+ self._unsubscribe()
77
+ self._unsubscribe = None
78
+
79
+
80
+ def connect(
81
+ store: Store[Any],
82
+ map_state_to_props: Optional[Callable[[Any], Dict[str, Any]]] = None,
83
+ bridge: Optional[MainThreadBridge] = None,
84
+ ):
85
+ """
86
+ Class decorator for framework-agnostic component state injection.
87
+ """
88
+ def decorator(cls):
89
+ orig_init = cls.__init__
90
+
91
+ def new_init(self, *args, **kwargs):
92
+ orig_init(self, *args, **kwargs)
93
+ self._pydux_unsubscribers = []
94
+ active_bridge = bridge or getattr(self, "_pydux_bridge", DirectThreadBridge())
95
+
96
+ if map_state_to_props:
97
+ def on_state_slice(props: Dict[str, Any]):
98
+ for prop_name, prop_val in props.items():
99
+ setattr(self, prop_name, prop_val)
100
+ if hasattr(self, "on_props_changed") and callable(self.on_props_changed):
101
+ self.on_props_changed()
102
+
103
+ unsub = store.select(
104
+ selector=map_state_to_props,
105
+ listener=lambda p: active_bridge.schedule_on_main_thread(lambda: on_state_slice(p)),
106
+ fire_immediately=True,
107
+ )
108
+ self._pydux_unsubscribers.append(unsub)
109
+
110
+ cls.__init__ = new_init
111
+ return cls
112
+
113
+ return decorator
@@ -0,0 +1,24 @@
1
+ """
2
+ Kivy Adapter for PyDux 3.0.
3
+ Schedules state updates via Kivy's Clock.schedule_once.
4
+ """
5
+
6
+ from typing import Callable, Any
7
+ from pydux.adapters.base import MainThreadBridge
8
+
9
+
10
+ class KivyBridge:
11
+ """Ensures Kivy widgets and canvas instructions update on the Kivy Clock loop."""
12
+
13
+ def __init__(self):
14
+ try:
15
+ from kivy.clock import Clock
16
+ self._clock = Clock
17
+ except ImportError:
18
+ self._clock = None
19
+
20
+ def schedule_on_main_thread(self, fn: Callable[[], None]) -> None:
21
+ if self._clock:
22
+ self._clock.schedule_once(lambda dt: fn(), 0)
23
+ else:
24
+ fn()
@@ -0,0 +1,97 @@
1
+ """Optional Pydux state hooks for declarative PSX component trees."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable
6
+ from typing import Any, TypeVar, cast
7
+
8
+ from psx import component
9
+ from psx.core.errors import PSXError
10
+ from psx.core.hooks import provide_context, use_context, use_effect, use_state
11
+ from psx.core.vnode import VNode
12
+
13
+ TState = TypeVar("TState")
14
+ TSelected = TypeVar("TSelected")
15
+ _STORE_CONTEXT = object()
16
+
17
+
18
+ def StoreProvider(store: object, child: VNode) -> VNode:
19
+ """Provide exactly one existing Pydux store to a PSX subtree."""
20
+ _validate_store(store)
21
+ return _StoreProvider(child, store=store)
22
+
23
+
24
+ @component
25
+ def _StoreProvider(store: object, children: tuple[object, ...]) -> VNode:
26
+ provide_context(_STORE_CONTEXT, store)
27
+ use_effect(lambda: _lease_inspector(store), [store])
28
+ if len(children) != 1 or not isinstance(children[0], VNode):
29
+ raise TypeError("StoreProvider requires exactly one VNode child.")
30
+ return children[0]
31
+
32
+
33
+ def use_dispatch() -> Callable[[object], object]:
34
+ """Return the dispatch method of the nearest explicit StoreProvider."""
35
+ store = _store_from_context()
36
+ return cast(Callable[[object], object], getattr(store, "dispatch"))
37
+
38
+
39
+ def use_selector(
40
+ selector: Callable[[TState], TSelected],
41
+ equality_fn: Callable[[TSelected, TSelected], bool] | None = None,
42
+ ) -> TSelected:
43
+ """Subscribe the current PSX component to a selected Pydux slice."""
44
+ store = _store_from_context()
45
+ initial = selector(cast(TState, store.get_state()))
46
+ selected, set_selected = use_state(lambda: initial)
47
+
48
+ def subscribe() -> Callable[[], None]:
49
+ def on_change(value: TSelected) -> None:
50
+ set_selected(value)
51
+
52
+ return store.select(
53
+ selector=selector,
54
+ listener=on_change,
55
+ equality_fn=equality_fn,
56
+ fire_immediately=True,
57
+ )
58
+
59
+ use_effect(subscribe, [store, selector, equality_fn])
60
+ return cast(TSelected, selected)
61
+
62
+
63
+ def _store_from_context() -> Any:
64
+ try:
65
+ store = use_context(_STORE_CONTEXT)
66
+ except LookupError as exc:
67
+ raise PSXError("use_selector() and use_dispatch() require an ancestor StoreProvider.") from exc
68
+ _validate_store(store)
69
+ return store
70
+
71
+
72
+ def _validate_store(store: object) -> None:
73
+ required = ("get_state", "dispatch", "select")
74
+ missing = [name for name in required if not callable(getattr(store, name, None))]
75
+ if missing:
76
+ raise TypeError(f"StoreProvider expected a Pydux-compatible store; missing {', '.join(missing)}.")
77
+
78
+
79
+ def _lease_inspector(store: object) -> Callable[[], None]:
80
+ """Stop an auto-started inspector after its last provider unmounts."""
81
+ leases = int(getattr(store, "_pydux_psx_inspector_leases", 0)) + 1
82
+ setattr(store, "_pydux_psx_inspector_leases", leases)
83
+
84
+ def release() -> None:
85
+ remaining = max(0, int(getattr(store, "_pydux_psx_inspector_leases", 1)) - 1)
86
+ setattr(store, "_pydux_psx_inspector_leases", remaining)
87
+ if remaining:
88
+ return
89
+ inspector = getattr(store, "inspector", None)
90
+ stop = getattr(inspector, "stop", None)
91
+ if callable(stop):
92
+ stop()
93
+
94
+ return release
95
+
96
+
97
+ __all__ = ["StoreProvider", "use_dispatch", "use_selector"]
@@ -0,0 +1,29 @@
1
+ """
2
+ Qt Adapter for PySide6, PySide2, PyQt5, and PyQt6.
3
+ Uses Qt MetaObject and QTimer.singleShot safely on the Qt event loop,
4
+ without locking PyDux core to Qt dependencies.
5
+ """
6
+
7
+ from typing import Callable, Any, Optional
8
+ from pydux.adapters.base import MainThreadBridge
9
+
10
+
11
+ class QtMainThreadBridge:
12
+ """Dispatches calls onto the Qt GUI event loop safely."""
13
+
14
+ def __init__(self):
15
+ # Auto-detect Qt binding
16
+ self._qtimer = None
17
+ for mod_name in ("PySide6.QtCore", "PyQt6.QtCore", "PySide2.QtCore", "PyQt5.QtCore"):
18
+ try:
19
+ mod = __import__(mod_name, fromlist=["QTimer"])
20
+ self._qtimer = getattr(mod, "QTimer")
21
+ break
22
+ except ImportError:
23
+ continue
24
+
25
+ def schedule_on_main_thread(self, fn: Callable[[], None]) -> None:
26
+ if self._qtimer:
27
+ self._qtimer.singleShot(0, fn)
28
+ else:
29
+ fn()