# PySimplePreview
[![PyPI version shields.io](https://img.shields.io/pypi/v/PySimplePreview.svg)](https://pypi.org/project/PySimplePreview/)
[![GitHub license](https://img.shields.io/github/license/MaxBQb/WinMagnification.svg)](https://github.com/MaxBQb/PySimplePreview/blob/master/LICENSE.md)
---
This is python tool which provide realtime/live/hot preview of [PySimpleGUI](https://pypi.org/project/PySimpleGUI/) layouts.
This tool assumes that developer writes layouts as separate method/function(-s).
> Note: Layout is simply list of lists of PySimpleGUI elements.
## Usage
### Installation
Simply use pip:
```sh
pip install PySimplePreview
```
### Prepare your project
This tool is development-only dependency, so before you start using it, lets help python resolve it as optional dependency:
1. First, if you store dependencies in `requirements.txt`, add separate file e.g. `requirements-dev.txt`
(you will be able to install all requirement with `pip install -r requirements.txt -r requirements-dev.txt`).
2. Then I suggest create new module (you may also inline it's content in your code which is bad, but possible).
With this content:
```py
# Use this to not couple with develop-only dependency
try: # Used when package installed
# noinspection PyUnresolvedReferences
from PySimplePreview import *
except ImportError: # Used when no dependency found
# noinspection PyUnusedLocal
def preview(*args, **ignored):
def dummy_wrapper(f):
return f
if args[0] is not None and not isinstance(args[0], str):
return args[0]
return dummy_wrapper
def params(*args, **kwargs):
return args, kwargs
group_previews = preview
method_previews = preview
```
3. If you've created separate module, then you can simply import anything from it instead of PySimplePreview.
> Note: You can always use custom technique to manage optional python dependencies, this is just example.
Now your app can work with and without PySimplePreview!
### Examples
1. First you need to import `preview` decorator from PySimplePreview (or yours custom module which tries to import it).
```py
import PySimpleGUI as sg
import PySimplePreview as psp
# ... or custom module name, e.g. _PySimplePreview
import _PySimplePreview as psp
```
2. Then you can decorate any callable that returns layout with `preview`.
Example:
```py
@psp.preview
def get_layout():
return [
[sg.Text("Hello, world!")]
]
```
3. Now you can run PySimplePreview with `python -m PySimplePreview`.
4. Select path to your project's root and choose preview to be shown.
5. Edit your layout without closing PySimplePreview.
Example:
```py
@psp.preview
def get_layout():
return [
[sg.Text("Hello, world!")],
[sg.Text("Previews are cool!")],
]
```
6. Remember to save your changes and *magic happens*: it's reflected in preview window.
For more complex cases see [examples](examples/).
## Features
### PySimplePreview API
1. `@preview` without params for functions and static methods.
1. `@preview()` for parameters:
2. Custom name of preview.
3. Parameters for function to be called with (can be evaluated lazily).
4. Custom group name (use for ease of searching, and maybe for something special later on).
5. Custom window (Use own PySimpleGUI windows to preview own layouts).
3. `@method_preview` same as `@preview` but for class methods and properties.
1. Have same parameters as `@preview()`, additionally have optional `instance_provider` parameter to provide `self` for methods.
2. `instance_provider` can use cls parameter to create class instance.
3. `instance_provider` can have no parameters to provide class instance from some other place.
4. `instance_provider` can be omitted, then no-args constructor of class will be used.
4. Multiple previews may be applied to same callable.
5. `@group_previews` can be used to set group_name for multiple previews of same callable.
1. `@group_previews()` name can be set as parameter.
6. In case when preview_name omitted, fully-qualified callable name will be used (`package.module.function_name` or `module.function_name`).
7. Same goes for `group_previews` no-param form.
### PySimplePreview App
1. Preview Theme can be customised.
2. App remembers its position and size (toggleable).
3. App stays on top of other windows (toggleable).
4. Preview window can be separated from main app window.
5. Previews can be filtered by groups.
6. App supports execution params see `python -m PySimplePreview -h`.
7. See app logs for more info (it also contains handled user-defined events from layout previewed).
8. If you want to see update on any module edited (when layout depends on other module), you may toggle Reload All option.
9. App supports observing single module, package with `__init__.py` file and just flat-layout (folder with `.py` files).
# Docs
There is no readthedocs page for this project for now (it may be changed soon).
But public API well-documented in code and covered with typehints (supported by PyCharm).
All features using can be found in [examples](examples/).
# Compatability
## Python versions support
For now only Python 3.11 tested, but older versions support planned.
## PySimpleGUI versions support
Currently tested on PySimpleGUI 4.60.5,
I'll think about adding support for older versions later,
better use latest releases anyway :)
## Different PySimpleGUI backends
Currently tested only with tkinter backend,
I have plans for framework-agnostic version.
# Contribution
Feel free to [open issues](https://github.com/MaxBQb/PySimplePreview/issues/new), but be careful with PR's (small fixes are OK, but this is MVP project,
it's implementation can be changed in any way).
Also note that I may have not enough free time, so have patience.
Raw data
{
"_id": null,
"home_page": "",
"name": "PySimplePreview",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": "",
"keywords": "PySimpleGUI,preview,live-preview,realtime-preview,GUI",
"author": "MaxBQb",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/03/41/84391e41a092a4a904706be4eeb1a15b8454e6d68386cbd36bf64a076c8d/PySimplePreview-0.0.2.tar.gz",
"platform": null,
"description": "# PySimplePreview\n[![PyPI version shields.io](https://img.shields.io/pypi/v/PySimplePreview.svg)](https://pypi.org/project/PySimplePreview/)\n[![GitHub license](https://img.shields.io/github/license/MaxBQb/WinMagnification.svg)](https://github.com/MaxBQb/PySimplePreview/blob/master/LICENSE.md)\n---\n\nThis is python tool which provide realtime/live/hot preview of [PySimpleGUI](https://pypi.org/project/PySimpleGUI/) layouts.\nThis tool assumes that developer writes layouts as separate method/function(-s).\n> Note: Layout is simply list of lists of PySimpleGUI elements.\n## Usage\n### Installation\nSimply use pip:\n```sh\npip install PySimplePreview\n```\n### Prepare your project\nThis tool is development-only dependency, so before you start using it, lets help python resolve it as optional dependency:\n1. First, if you store dependencies in `requirements.txt`, add separate file e.g. `requirements-dev.txt`\n (you will be able to install all requirement with `pip install -r requirements.txt -r requirements-dev.txt`).\n2. Then I suggest create new module (you may also inline it's content in your code which is bad, but possible).\nWith this content:\n```py\n# Use this to not couple with develop-only dependency\ntry: # Used when package installed\n # noinspection PyUnresolvedReferences\n from PySimplePreview import *\nexcept ImportError: # Used when no dependency found\n # noinspection PyUnusedLocal\n def preview(*args, **ignored):\n def dummy_wrapper(f):\n return f\n\n if args[0] is not None and not isinstance(args[0], str):\n return args[0]\n\n return dummy_wrapper\n\n def params(*args, **kwargs):\n return args, kwargs\n\n group_previews = preview\n method_previews = preview\n```\n\n3. If you've created separate module, then you can simply import anything from it instead of PySimplePreview.\n> Note: You can always use custom technique to manage optional python dependencies, this is just example.\n\nNow your app can work with and without PySimplePreview!\n\n### Examples\n1. First you need to import `preview` decorator from PySimplePreview (or yours custom module which tries to import it).\n```py\nimport PySimpleGUI as sg\nimport PySimplePreview as psp\n# ... or custom module name, e.g. _PySimplePreview\nimport _PySimplePreview as psp\n```\n2. Then you can decorate any callable that returns layout with `preview`.\nExample:\n```py\n@psp.preview\ndef get_layout():\n return [\n [sg.Text(\"Hello, world!\")]\n ]\n```\n3. Now you can run PySimplePreview with `python -m PySimplePreview`.\n4. Select path to your project's root and choose preview to be shown.\n5. Edit your layout without closing PySimplePreview.\nExample:\n```py\n@psp.preview\ndef get_layout():\n return [\n [sg.Text(\"Hello, world!\")],\n [sg.Text(\"Previews are cool!\")],\n ]\n```\n6. Remember to save your changes and *magic happens*: it's reflected in preview window.\n\nFor more complex cases see [examples](examples/).\n\n## Features \n### PySimplePreview API\n1. `@preview` without params for functions and static methods.\n 1. `@preview()` for parameters:\n 2. Custom name of preview.\n 3. Parameters for function to be called with (can be evaluated lazily).\n 4. Custom group name (use for ease of searching, and maybe for something special later on).\n 5. Custom window (Use own PySimpleGUI windows to preview own layouts).\n3. `@method_preview` same as `@preview` but for class methods and properties.\n 1. Have same parameters as `@preview()`, additionally have optional `instance_provider` parameter to provide `self` for methods.\n 2. `instance_provider` can use cls parameter to create class instance.\n 3. `instance_provider` can have no parameters to provide class instance from some other place.\n 4. `instance_provider` can be omitted, then no-args constructor of class will be used.\n4. Multiple previews may be applied to same callable.\n5. `@group_previews` can be used to set group_name for multiple previews of same callable.\n 1. `@group_previews()` name can be set as parameter.\n6. In case when preview_name omitted, fully-qualified callable name will be used (`package.module.function_name` or `module.function_name`).\n7. Same goes for `group_previews` no-param form.\n\n### PySimplePreview App\n1. Preview Theme can be customised.\n2. App remembers its position and size (toggleable).\n3. App stays on top of other windows (toggleable).\n4. Preview window can be separated from main app window.\n5. Previews can be filtered by groups.\n6. App supports execution params see `python -m PySimplePreview -h`.\n7. See app logs for more info (it also contains handled user-defined events from layout previewed).\n8. If you want to see update on any module edited (when layout depends on other module), you may toggle Reload All option.\n9. App supports observing single module, package with `__init__.py` file and just flat-layout (folder with `.py` files).\n\n# Docs\nThere is no readthedocs page for this project for now (it may be changed soon).\nBut public API well-documented in code and covered with typehints (supported by PyCharm).\nAll features using can be found in [examples](examples/).\n\n# Compatability\n## Python versions support\nFor now only Python 3.11 tested, but older versions support planned.\n\n## PySimpleGUI versions support\nCurrently tested on PySimpleGUI 4.60.5, \nI'll think about adding support for older versions later,\nbetter use latest releases anyway :)\n\n## Different PySimpleGUI backends\nCurrently tested only with tkinter backend, \nI have plans for framework-agnostic version.\n\n# Contribution\nFeel free to [open issues](https://github.com/MaxBQb/PySimplePreview/issues/new), but be careful with PR's (small fixes are OK, but this is MVP project, \nit's implementation can be changed in any way).\nAlso note that I may have not enough free time, so have patience.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Realtime (live/hot) preview of PySimpleGUI layouts",
"version": "0.0.2",
"project_urls": {
"Bug Tracker": "https://github.com/MaxBQb/PySimplePreview/issues",
"Homepage": "https://github.com/MaxBQb/PySimplePreview"
},
"split_keywords": [
"pysimplegui",
"preview",
"live-preview",
"realtime-preview",
"gui"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e6e1a12293d0c5c52b5fa30a3a69da9a0f756fff647ed3acd5900aac1e0fb031",
"md5": "c1a09d787309a0b95d3a5a8a72dcbfa3",
"sha256": "27428f5d1d0f7db30d9d9e8711583cecf79bcecbb1ea7b2ba602a28415481d0f"
},
"downloads": -1,
"filename": "PySimplePreview-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1a09d787309a0b95d3a5a8a72dcbfa3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 33800,
"upload_time": "2023-07-09T21:49:18",
"upload_time_iso_8601": "2023-07-09T21:49:18.269726Z",
"url": "https://files.pythonhosted.org/packages/e6/e1/a12293d0c5c52b5fa30a3a69da9a0f756fff647ed3acd5900aac1e0fb031/PySimplePreview-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "034184391e41a092a4a904706be4eeb1a15b8454e6d68386cbd36bf64a076c8d",
"md5": "29fd2a48105a3e127ca902c66855ddd4",
"sha256": "198feada3e108b94daeaccaeae637b59ac3bf87d0a9091bfbd88905c572d6ec6"
},
"downloads": -1,
"filename": "PySimplePreview-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "29fd2a48105a3e127ca902c66855ddd4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 24535,
"upload_time": "2023-07-09T21:49:19",
"upload_time_iso_8601": "2023-07-09T21:49:19.738695Z",
"url": "https://files.pythonhosted.org/packages/03/41/84391e41a092a4a904706be4eeb1a15b8454e6d68386cbd36bf64a076c8d/PySimplePreview-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-09 21:49:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MaxBQb",
"github_project": "PySimplePreview",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pysimplepreview"
}