Name | wxcompose JSON |
Version |
1.0.0
JSON |
| download |
home_page | None |
Summary | Declarative UI style and view model binding for wxPython |
upload_time | 2025-08-03 18:37:25 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
binding
wxpython
mvvm
view model
wx
compose
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# wxcompose
[](https://github.com/eumis/wxcompose/actions/workflows/ci.yml)
Declarative UI style and view model binding for wxPython
## Installation
```bash
pip install wxcompose
```
## Usage
### Using components
Here is comparison between wxpython and wxcompose
```python
import wx
app = wx.App()
frame = wx.Frame(None, title="Test", style=wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN)
sizer = wx.BoxSizer(wx.VERTICAL)
txt = wx.StaticText(frame)
txt.SetLabel("Some text")
sizer.Add(txt, flag=wx.EXPAND | wx.ALL)
frame.Show()
app.MainLoop()
```
```python
import wx
from wxcompose import core as wxc
from wxcompose.component import layout
with wxc.App() as app:
with wxc.Frame(title="Test", style=wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN) as frame:
with wxc.BoxSizer(orient=wx.VERTICAL):
with wxc.StaticText() as _:
_.Label = "Some text"
layout(flag=wx.EXPAND | wx.ALL)
frame.Show()
app.MainLoop()
```
---
`wxcompose.core` contains components for core wxpython controls, such as `wx.Frame`, `wx.BoxSizer`, `wx.StaticText`, etc.
Examples of using generic component for controls
```python
import wx
from wx.lib.agw import pygauge
from wxcompose import core as wxc
from wxcompose.component import Component, cmp, parent
with wxc.Frame(title="Test", style=wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN) as frame:
with Component(pygauge.PyGauge(frame)) as gauge:
pass
with Component(pygauge.PyGauge(parent())):
pass
with cmp(pygauge.PyGauge(parent())):
pass
with cmp(pygauge.PyGauge):
pass
```
### Binding
`bind()` can be used to bind control property to view model
```python
from wxcompose import core as wxc
from wxcompose.binding import bind
from wxcompose.viewmodel import ViewModel
class TestViewModel(ViewModel):
def __init__(self):
super().__init__()
self.name = "label"
self.label = "label"
view_model = TestViewModel()
with wxc.StaticText() as _:
_.Label = bind(lambda: f"{view_model.name}: {view_model.label}")
```
---
if control property should be updated only when some specific view model field is changed, when() can be used
```python
from wxcompose import core as wxc
from wxcompose.binding import bind
from wxcompose.viewmodel import ViewModel
class TestViewModel(ViewModel):
def __init__(self):
super().__init__()
self.name = "label"
self.label = "label"
view_model = TestViewModel()
with wxc.StaticText() as _:
_.Label = bind(lambda: f"{view_model.name}: {view_model.label}").when(lambda: view_model.name)
```
---
two way binding - on() method can be used to set ui event when view model should be updated and mapper
```python
import wx
from wxcompose import core as wxc
from wxcompose.binding import bind
from wxcompose.viewmodel import ViewModel
class TestViewModel(ViewModel):
def __init__(self):
super().__init__()
self.value = 0
view_model = TestViewModel()
with wxc.TextCtrl() as _:
_.Value = bind(lambda: str(view_model)).on(wx.EVT_TEXT, lambda v: int(v))
```
## License
[MIT](LICENSE)
Raw data
{
"_id": null,
"home_page": null,
"name": "wxcompose",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "binding, wxpython, mvvm, view model, wx, compose",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/15/77/d37c40fa5bd4a1f1d275efac78fdc2097bbdbdcc9fc55db315b91f64ffbb/wxcompose-1.0.0.tar.gz",
"platform": null,
"description": "# wxcompose\n\n[](https://github.com/eumis/wxcompose/actions/workflows/ci.yml)\n\nDeclarative UI style and view model binding for wxPython\n\n## Installation\n\n```bash\npip install wxcompose\n```\n\n## Usage\n\n### Using components\n\nHere is comparison between wxpython and wxcompose\n\n```python\nimport wx\n\napp = wx.App()\nframe = wx.Frame(None, title=\"Test\", style=wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN)\nsizer = wx.BoxSizer(wx.VERTICAL)\ntxt = wx.StaticText(frame)\ntxt.SetLabel(\"Some text\")\nsizer.Add(txt, flag=wx.EXPAND | wx.ALL)\n\nframe.Show()\napp.MainLoop()\n```\n\n```python\nimport wx\n\nfrom wxcompose import core as wxc\nfrom wxcompose.component import layout\n\nwith wxc.App() as app:\n with wxc.Frame(title=\"Test\", style=wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN) as frame:\n with wxc.BoxSizer(orient=wx.VERTICAL):\n with wxc.StaticText() as _:\n _.Label = \"Some text\"\n layout(flag=wx.EXPAND | wx.ALL)\n frame.Show()\n app.MainLoop()\n```\n\n---\n\n`wxcompose.core` contains components for core wxpython controls, such as `wx.Frame`, `wx.BoxSizer`, `wx.StaticText`, etc.\nExamples of using generic component for controls\n\n```python\nimport wx\nfrom wx.lib.agw import pygauge\n\nfrom wxcompose import core as wxc\nfrom wxcompose.component import Component, cmp, parent\n\nwith wxc.Frame(title=\"Test\", style=wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN) as frame:\n with Component(pygauge.PyGauge(frame)) as gauge:\n pass\n\n with Component(pygauge.PyGauge(parent())):\n pass\n\n with cmp(pygauge.PyGauge(parent())):\n pass\n\n with cmp(pygauge.PyGauge):\n pass\n```\n\n### Binding\n\n`bind()` can be used to bind control property to view model\n\n```python\nfrom wxcompose import core as wxc\nfrom wxcompose.binding import bind\nfrom wxcompose.viewmodel import ViewModel\n\n\nclass TestViewModel(ViewModel):\n def __init__(self):\n super().__init__()\n self.name = \"label\"\n self.label = \"label\"\n\n\nview_model = TestViewModel()\n\nwith wxc.StaticText() as _:\n _.Label = bind(lambda: f\"{view_model.name}: {view_model.label}\")\n```\n\n---\n\nif control property should be updated only when some specific view model field is changed, when() can be used\n\n```python\nfrom wxcompose import core as wxc\nfrom wxcompose.binding import bind\nfrom wxcompose.viewmodel import ViewModel\n\n\nclass TestViewModel(ViewModel):\n def __init__(self):\n super().__init__()\n self.name = \"label\"\n self.label = \"label\"\n\n\nview_model = TestViewModel()\n\nwith wxc.StaticText() as _:\n _.Label = bind(lambda: f\"{view_model.name}: {view_model.label}\").when(lambda: view_model.name)\n```\n\n---\n\ntwo way binding - on() method can be used to set ui event when view model should be updated and mapper\n\n```python\nimport wx\n\nfrom wxcompose import core as wxc\nfrom wxcompose.binding import bind\nfrom wxcompose.viewmodel import ViewModel\n\n\nclass TestViewModel(ViewModel):\n def __init__(self):\n super().__init__()\n self.value = 0\n\n\nview_model = TestViewModel()\n\nwith wxc.TextCtrl() as _:\n _.Value = bind(lambda: str(view_model)).on(wx.EVT_TEXT, lambda v: int(v))\n```\n\n## License\n\n[MIT](LICENSE)\n",
"bugtrack_url": null,
"license": null,
"summary": "Declarative UI style and view model binding for wxPython",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/eumis/wxcompose"
},
"split_keywords": [
"binding",
" wxpython",
" mvvm",
" view model",
" wx",
" compose"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0a4d261c7452450024cd97bfbc67ce6bf5f24671ca5208bcbff5582aba169673",
"md5": "44ba5e1c4a183c49fc80c89b5ff1fdbc",
"sha256": "d19f26037cbd4dc647e5124dddefccd2589a2773e8f1993bcafb83b07b573dae"
},
"downloads": -1,
"filename": "wxcompose-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "44ba5e1c4a183c49fc80c89b5ff1fdbc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 11098,
"upload_time": "2025-08-03T18:37:24",
"upload_time_iso_8601": "2025-08-03T18:37:24.218386Z",
"url": "https://files.pythonhosted.org/packages/0a/4d/261c7452450024cd97bfbc67ce6bf5f24671ca5208bcbff5582aba169673/wxcompose-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "1577d37c40fa5bd4a1f1d275efac78fdc2097bbdbdcc9fc55db315b91f64ffbb",
"md5": "033075c615e235d478187cfd5f6bd153",
"sha256": "3b0c1796bbfbe5fa101803db00b94ee88d773091c8d2ca78df6e9cb1045ceb3c"
},
"downloads": -1,
"filename": "wxcompose-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "033075c615e235d478187cfd5f6bd153",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 11604,
"upload_time": "2025-08-03T18:37:25",
"upload_time_iso_8601": "2025-08-03T18:37:25.324932Z",
"url": "https://files.pythonhosted.org/packages/15/77/d37c40fa5bd4a1f1d275efac78fdc2097bbdbdcc9fc55db315b91f64ffbb/wxcompose-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-03 18:37:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "eumis",
"github_project": "wxcompose",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "wxcompose"
}