| Name | qtreload JSON |
| Version |
0.1.2
JSON |
| download |
| home_page | |
| Summary | Qt utilities to enable hot-reloading of python/Qt code |
| upload_time | 2023-11-04 14:11:05 |
| maintainer | |
| docs_url | None |
| author | |
| requires_python | >=3.8 |
| license | BSD 3-Clause License |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# qtreload
Qt utilities to enable hot-reloading of python/Qt code
[](https://github.com/lukasz-migas/qtreload/raw/main/LICENSE)
[](https://pypi.org/project/qtreload)
[](https://python.org)
[](https://github.com/lukasz-migas/qtreload/actions/workflows/test_and_deploy.yml)
[](https://codecov.io/gh/lukasz-migas/qtreload)
Have you been using Jupyter Notebook's magic functions such as
```
%load_ext autoreload
%autoreload 2
```
where you might have been editing code in VSCode or Pycharm and executing actions in Jupyter Notebook?
Or have you previously used [LiClipse](https://www.liclipse.com/) which has [Debugger Auto-Reload](https://www.pydev.org/manual_adv_debugger_auto_reload.html)?
Well, `qtreload` provides similar capabilities by 'hot-reloading' python modules when there are changes to
the source code. It operates by generating a list of all possible modules/submodules for a specific project and
then using `QFileWatcher` to observe any changes to these files.
This library should be used when developing Qt code in Python and you are not interested in continually having to restart your application. (See limitations to find out when its still required).
## Usage
You can instantiate the `QtReloadWidget` manually or using the `install_hot_reload` function.
Note! Make sure to instantiate QApplication before running this code.
Using `QtReloadWidget`:
```
from qtreload.qt_reload import QtReloadWidget
# you can specify list of modules that should be monitored
list_of_widgets = ["napari", "spyder", "..."]
widget = QtReloadWidget(list_of_modules)
```
That's pretty much it. Now every time you make changes to your source code in e.g. `napari` will be reflected in your interpreter.
Using `install_hot_reload` requires two environment variabels being set, namely:
```
QTRELOAD_HOT_RELOAD=1
QTRELOAD_HOT_RELOAD_MODULES="napari, spyder"
```
Then you can just execute the following:
```
from qtreload.install import install_hot_reload
install_hot_reload()
```
## When it works like magic
There are countless examples where this approach really well. Some examples:
- You are running your application where you have method `on_run` but when you execute this function, you notice that you misspelled some variable. In normal circumstances you would need to restart the application. Now, however, you can correct it in your IDE, save, and try running again.
- You are running your application and are modifying the layout of a popup window. Now you can do this and each time the dialog is reshown, the new version of the dialog will be shown.
## Limitations
While this approach can be extremely useful and can save a lot of time, it has a couple of limitations:
- code within the `___init__.py` cannot be reloaded
- some changes to GUI code cannot be reloaded - if e.g. you are modying the `QMainWindow` and just added a new button, this button will now be shown. In order to show it, you will still need to restart the application. If, however, you were modyfing a plugin or a dialog that is shown upon clicking on e.g. menu item, these changes WILL take place.
- modifying python properties (@setter/@getter) is not always reloaded
## Acknowledgements
The hot-reload code is directly copied from the PyDev debugger developed by [fabioz](https://github.com/fabioz) with minimal changes to remove any dependencies
See https://github.com/fabioz/PyDev.Debugger/blob/main/_pydevd_bundle/pydevd_reload.py
Raw data
{
"_id": null,
"home_page": "",
"name": "qtreload",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "\"Lukasz G. Migas\" <lukas.migas@yahoo.com>",
"download_url": "https://files.pythonhosted.org/packages/be/ab/8c55e6c7c0aeeb580f0c4928eea3bac326e24cfe9ff63a3622346f400bb7/qtreload-0.1.2.tar.gz",
"platform": null,
"description": "# qtreload\n Qt utilities to enable hot-reloading of python/Qt code\n\n[](https://github.com/lukasz-migas/qtreload/raw/main/LICENSE)\n[](https://pypi.org/project/qtreload)\n[](https://python.org)\n[](https://github.com/lukasz-migas/qtreload/actions/workflows/test_and_deploy.yml)\n[](https://codecov.io/gh/lukasz-migas/qtreload)\n\nHave you been using Jupyter Notebook's magic functions such as \n\n```\n%load_ext autoreload\n%autoreload 2\n```\n\nwhere you might have been editing code in VSCode or Pycharm and executing actions in Jupyter Notebook?\n\nOr have you previously used [LiClipse](https://www.liclipse.com/) which has [Debugger Auto-Reload](https://www.pydev.org/manual_adv_debugger_auto_reload.html)?\n\nWell, `qtreload` provides similar capabilities by 'hot-reloading' python modules when there are changes to\nthe source code. It operates by generating a list of all possible modules/submodules for a specific project and\nthen using `QFileWatcher` to observe any changes to these files.\n\nThis library should be used when developing Qt code in Python and you are not interested in continually having to restart your application. (See limitations to find out when its still required).\n\n\n## Usage\n\nYou can instantiate the `QtReloadWidget` manually or using the `install_hot_reload` function.\n\nNote! Make sure to instantiate QApplication before running this code.\n\n\nUsing `QtReloadWidget`:\n\n```\nfrom qtreload.qt_reload import QtReloadWidget\n\n# you can specify list of modules that should be monitored\nlist_of_widgets = [\"napari\", \"spyder\", \"...\"]\n\nwidget = QtReloadWidget(list_of_modules)\n```\n\nThat's pretty much it. Now every time you make changes to your source code in e.g. `napari` will be reflected in your interpreter.\n\nUsing `install_hot_reload` requires two environment variabels being set, namely:\n\n```\nQTRELOAD_HOT_RELOAD=1\nQTRELOAD_HOT_RELOAD_MODULES=\"napari, spyder\"\n```\n\nThen you can just execute the following:\n```\nfrom qtreload.install import install_hot_reload\n\ninstall_hot_reload()\n```\n\n## When it works like magic\n\n There are countless examples where this approach really well. Some examples:\n\n - You are running your application where you have method `on_run` but when you execute this function, you notice that you misspelled some variable. In normal circumstances you would need to restart the application. Now, however, you can correct it in your IDE, save, and try running again.\n - You are running your application and are modifying the layout of a popup window. Now you can do this and each time the dialog is reshown, the new version of the dialog will be shown.\n\n## Limitations\n\nWhile this approach can be extremely useful and can save a lot of time, it has a couple of limitations:\n\n- code within the `___init__.py` cannot be reloaded\n- some changes to GUI code cannot be reloaded - if e.g. you are modying the `QMainWindow` and just added a new button, this button will now be shown. In order to show it, you will still need to restart the application. If, however, you were modyfing a plugin or a dialog that is shown upon clicking on e.g. menu item, these changes WILL take place.\n- modifying python properties (@setter/@getter) is not always reloaded\n\n\n## Acknowledgements\n\nThe hot-reload code is directly copied from the PyDev debugger developed by [fabioz](https://github.com/fabioz) with minimal changes to remove any dependencies\n\nSee https://github.com/fabioz/PyDev.Debugger/blob/main/_pydevd_bundle/pydevd_reload.py\n\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License",
"summary": "Qt utilities to enable hot-reloading of python/Qt code",
"version": "0.1.2",
"project_urls": {
"homepage": "https://github.com/lukasz-migas/qtreload",
"repository": "https://github.com/lukasz-migas/qtreload"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f719d18e8c138a977fca9a8d40726c7529afd0732d6c36227703a6204ca5f673",
"md5": "b4ae238e87bff9196658c4582f6aba15",
"sha256": "7e9d730cffd1465571d80fee839813b1c060fb03b87914c731732e2f1db884b3"
},
"downloads": -1,
"filename": "qtreload-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b4ae238e87bff9196658c4582f6aba15",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 12559,
"upload_time": "2023-11-04T14:11:03",
"upload_time_iso_8601": "2023-11-04T14:11:03.996852Z",
"url": "https://files.pythonhosted.org/packages/f7/19/d18e8c138a977fca9a8d40726c7529afd0732d6c36227703a6204ca5f673/qtreload-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "beab8c55e6c7c0aeeb580f0c4928eea3bac326e24cfe9ff63a3622346f400bb7",
"md5": "57b3a78b96ad31c470aa37e68a398e0b",
"sha256": "149a5ed7f0ba8f1fe31855de7c6b9c0609a99d3b1a6a2245c4477753106edbe8"
},
"downloads": -1,
"filename": "qtreload-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "57b3a78b96ad31c470aa37e68a398e0b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 22199,
"upload_time": "2023-11-04T14:11:05",
"upload_time_iso_8601": "2023-11-04T14:11:05.457141Z",
"url": "https://files.pythonhosted.org/packages/be/ab/8c55e6c7c0aeeb580f0c4928eea3bac326e24cfe9ff63a3622346f400bb7/qtreload-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-04 14:11:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lukasz-migas",
"github_project": "qtreload",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "qtreload"
}