├── .assets ├── communism.png ├── logo │ ├── png │ │ ├── banner_dark.png │ │ └── banner_light.png │ ├── previews │ │ ├── Banner (Dark).png │ │ ├── Banner (Light).png │ │ ├── Main (Dark.png │ │ └── Main (Light).png │ └── svg │ │ ├── logo_dark.svg │ │ └── logo_light.svg ├── with.gif └── without.gif ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md └── workflows │ ├── publish.yaml │ └── test.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── example ├── README.md └── sample_app.py ├── pyproject.toml ├── tests ├── __init__.py ├── test_app_event_handler.py ├── test_auto_reload.py ├── test_file_utils.py └── test_main.py └── tkreload ├── __init__.py ├── app_event_handler.py ├── auto_reload.py ├── file_utils.py ├── help.py ├── main.py └── progress.py /.assets/communism.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/communism.png -------------------------------------------------------------------------------- /.assets/logo/png/banner_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/logo/png/banner_dark.png -------------------------------------------------------------------------------- /.assets/logo/png/banner_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/logo/png/banner_light.png -------------------------------------------------------------------------------- /.assets/logo/previews/Banner (Dark).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/logo/previews/Banner (Dark).png -------------------------------------------------------------------------------- /.assets/logo/previews/Banner (Light).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/logo/previews/Banner (Light).png -------------------------------------------------------------------------------- /.assets/logo/previews/Main (Dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/logo/previews/Main (Dark.png -------------------------------------------------------------------------------- /.assets/logo/previews/Main (Light).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/logo/previews/Main (Light).png -------------------------------------------------------------------------------- /.assets/logo/svg/logo_dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.assets/logo/svg/logo_light.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.assets/with.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/with.gif -------------------------------------------------------------------------------- /.assets/without.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/.assets/without.gif -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | # To publish a new version, push a new tag to the repository with the format vX.Y.Z 2 | name: Publish Python Package 3 | 4 | on: 5 | push: 6 | tags: 7 | - "v[0-9]+.[0-9]+.[0-9]+" 8 | - "v[0-9]+.[0-9]+.[0-9]+.post[0-9]+" 9 | - "v[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+" 10 | - "v[0-9]+.[0-9]+.[0-9]+rc[0-9]+" 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | environment: release 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Set up Python 19 | uses: actions/setup-python@v5 20 | with: 21 | python-version: 3.x 22 | - name: Install dependencies 23 | run: pip install build 24 | - name: Create packages 25 | run: python -m build 26 | - name: Archive packages 27 | uses: actions/upload-artifact@v4 28 | with: 29 | name: dist 30 | path: dist 31 | 32 | publish: 33 | needs: build 34 | runs-on: ubuntu-latest 35 | environment: release 36 | permissions: 37 | id-token: write 38 | steps: 39 | - name: Retrieve packages 40 | uses: actions/download-artifact@v4 41 | - name: Upload packages 42 | uses: pypa/gh-action-pypi-publish@release/v1 43 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test suite 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | 8 | jobs: 9 | test: 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | os: [ubuntu-latest] 14 | python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] 15 | runs-on: ${{ matrix.os }} 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v5 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | allow-prereleases: true 23 | cache: pip 24 | cache-dependency-path: pyproject.toml 25 | - name: Install dependencies 26 | run: pip install -e .[test] 27 | - name: Test with pytest 28 | run: pytest -v 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *.cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # Jupyter Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # SageMath parsed files 79 | *.sage.py 80 | 81 | # Environments 82 | .env 83 | .venv 84 | env/ 85 | venv/ 86 | ENV/ 87 | 88 | # Spyder project settings 89 | .spyderproject 90 | .spyproject 91 | 92 | # Rope project settings 93 | .ropeproject 94 | 95 | # mkdocs documentation 96 | /site 97 | 98 | # mypy 99 | .mypy_cache/ -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | dyeusyt@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2024 Arsh (@iamDyeus) 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # ![TkReload-Logo](https://github.com/iamDyeus/tkreload/blob/main/.assets/logo/svg/logo_light.svg?raw=true) 4 | 5 | ![Static Badge](https://img.shields.io/badge/pip_install-tkreload-purple) 6 | ![Static Badge](https://img.shields.io/badge/Language-Python-red) 7 | ![GitHub last commit](https://img.shields.io/github/last-commit/iamDyeus/tkreload) 8 | 9 |

10 | tkreload | Automated Tkinter App Reloading for a Smoother Development Workflow 11 |

12 | 13 |

14 | Effortlessly reload Tkinter-based Python applications in the terminal, saving valuable development time. 15 |

16 | 17 | [Installation](#installation) • [Usage](#usage) • [Features](#features) • [Testing](#testing) • [Contributing](#contributing) • [License](#license) 18 | 19 |
20 | 21 | --- 22 | 23 | ## 🚀 Problem Statement 24 | 25 | For developers, frequent manual restarts of terminal applications during development can add up quickly, especially in complex Tkinter projects that require regular updates. `tkreload` provides a solution to this by automating the reload process, resulting in significant time savings. 26 | 27 | ### ⏳ Estimated Time Saved with tkreload 28 | 29 | Imagine restarting your terminal application **15 times daily**, with each reload taking **30 seconds**. That’s approximately **7.5 minutes daily** or about **3 hours per month**. `tkreload` helps avoid this productivity drain. 30 | 31 | --- 32 | 33 | ## 🔍 Solution Overview 34 | 35 | `tkreload` automates reloading for terminal-based Python applications, designed specifically for **Tkinter**. By eliminating the need for manual restarts, it streamlines the development process, saving developers valuable time and enhancing productivity. 36 | 37 | **Without tkreload:** 38 | ![Without tkreload](https://github.com/iamDyeus/tkreload/blob/main/.assets/without.gif?raw=true) 39 | 40 | **With tkreload:** 41 | ![With tkreload](https://github.com/iamDyeus/tkreload/blob/main/.assets/with.gif?raw=true) 42 | 43 | --- 44 | 45 | ## 🛠️ Getting Started 46 | 47 | ### Prerequisites 48 | - **Python** 3.9+ 49 | - **pip** for dependency management 50 | 51 | ### Installation 52 | 53 | #### 1. Clone the Repository 54 | ```sh 55 | git clone https://github.com/iamDyeus/tkreload.git 56 | cd tkreload 57 | ``` 58 | #### 2. Create and activate a virtual environment: 59 | ```sh 60 | python -m venv venv 61 | source venv/bin/activate # On Windows, use `venv\Scripts\activate` 62 | ``` 63 | 64 | 3. Install tkreload (in editable mode): 65 | ```sh 66 | pip install -e.[test] 67 | ``` 68 | 69 | # Usage 70 | 71 | To run the app with `tkreload`, use the following command in your terminal: 72 | 73 | ```bash 74 | tkreload your_app.py 75 | ``` 76 | 77 | Now, whenever you save changes to your script, tkreload will automatically reload your application. 78 | 79 | ## 🌟 Features 80 | 81 | - **Automatic Reloading:** Automatically restarts Tkinter apps upon file changes. 82 | - **Command-Based Control:** 83 | - **`H`:** View help commands 84 | - **`R`:** Restart the application 85 | - **`A`:** Toggle auto-reload 86 | - **`Ctrl + C`:** Exit the application 87 | - **Real-Time Feedback:** Uses `rich` for styled console feedback and progress indicators. 88 | 89 | 90 | 91 | ## Testing 92 | To verify tkreload functionality, follow these steps: 93 | 94 | 1.Install Testing Dependencies: Make sure all testing libraries are installed as per the requirements.txt file. 95 | 96 | 2.Run Tests Using Pytest 97 | ```bash 98 | pytest -v 99 | ``` 100 | This will run the test suite and confirm tkreload is working as expected. 101 | 102 | # Contributing 103 | 104 | Contributions are welcome and greatly appreciated! Here's how you can contribute: 105 | 106 | 1. Fork the Project 107 | 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) 108 | 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) 109 | 4. Push to the Branch (`git push origin feature/AmazingFeature`) 110 | 5. Open a Pull Request 111 | 112 | ![COMMUNISM](https://github.com/iamDyeus/tkreload/blob/main/.assets/communism.png?raw=true) 113 | 114 | # License 115 | 116 | Distributed under the Apache-2.0 License. See [`LICENSE`](LICENSE) for more information. 117 | 118 | # Acknowledgments 119 | - Inspired by the need for efficient development workflows 120 | - Thanks to all contributors and supporters of this project 121 | 122 | ## Star History 123 | [![Star History Chart](https://api.star-history.com/svg?repos=iamDyeus/tkreload&type=Date)](https://star-history.com/#iamDyeus/tkreload&Date) 124 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Demo App 2 | 3 | this directory contains sample_app.py, which is a simple tkinter app that demonstrates the use of `tkreload`. 4 | 5 | to run the app with `tkreload`, use the following command in your terminal: 6 | 7 | ```bash 8 | tkreload sample_app.py 9 | ``` 10 | 11 | > **Note:** 12 | > you'll need to install `tkreload` using `pip install tkreload` first. 13 | > or install it using `pip install .` from the root directory. (inside `src` folder) 14 | -------------------------------------------------------------------------------- /example/sample_app.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | 3 | def on_button_click(): 4 | print("Hello World!") 5 | 6 | # Create the main application window 7 | app = tk.Tk() 8 | app.title("Demo Application") 9 | 10 | # set size to 500x500 11 | app.geometry("500x500") 12 | 13 | 14 | 15 | # Create a label 16 | label = tk.Label(app, text="Hello from iamDyeus 👋", font=("Helvetica", 16)) 17 | label.pack(pady=50) 18 | 19 | label = tk.Label(app, text="use `tkreload` to open this app, and play around!", font=("Helvetica", 12)) 20 | label.pack(pady=30) 21 | 22 | label = tk.Label(app, text="in your terminal: `tkreload sample_app.py`", font=("Helvetica", 12)) 23 | label.pack(pady=5) 24 | 25 | label = tk.Label(app, text="When the reloader is running, press 'H' to see list of commands", font=("Helvetica", 10)) 26 | label.pack(pady=10) 27 | 28 | # Create a button 29 | button = tk.Button(app, text="Click Me!", command=on_button_click) 30 | button.pack(pady=10) 31 | 32 | # Run the application 33 | app.mainloop() 34 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools >= 64", 4 | "setuptools_scm >= 6.4" 5 | ] 6 | build-backend = "setuptools.build_meta" 7 | 8 | [project] 9 | name = "tkreload" 10 | description = "A library that auto reloads your tkinter app whenever file changes are detected." 11 | readme = "README.md" 12 | authors = [{name = "iamDyeus", email = "dyeusyt@gmail.com"}] 13 | license = {text = "Apache License 2.0"} 14 | classifiers = [ 15 | "Development Status :: 5 - Production/Stable", 16 | "Intended Audience :: Developers", 17 | "Topic :: Software Development :: Build Tools", 18 | "License :: OSI Approved :: Apache Software License", 19 | "Programming Language :: Python :: 3", 20 | ] 21 | requires-python = ">=3.9" 22 | dependencies = [ 23 | "watchdog >= 5.0.3", 24 | "rich >= 13.9.2" 25 | ] 26 | dynamic = ["version"] 27 | 28 | [project.urls] 29 | Documentation = "https://github.com/iamDyeus/tkreload/blob/main/README.md" 30 | "Bug Tracker" = "https://github.com/iamDyeus/tkreload/issues" 31 | "Source code" = "https://github.com/iamDyeus/tkreload" 32 | 33 | [project.optional-dependencies] 34 | test = [ 35 | "pytest >= 7", 36 | "pytest-cov" 37 | ] 38 | 39 | [project.scripts] 40 | tkreload = "tkreload.main:main" 41 | 42 | [tool.setuptools.packages.find] 43 | include = ["tkreload", "tkreload.*"] 44 | namespaces = false 45 | 46 | [tool.setuptools_scm] 47 | version_scheme = "post-release" 48 | local_scheme = "dirty-tag" 49 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamDyeus/tkreload/cfec9796efeb7d62e97e6dc4732ecaab5eeb6b88/tests/__init__.py -------------------------------------------------------------------------------- /tests/test_app_event_handler.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from tkreload.app_event_handler import AppFileEventHandler 3 | from tkreload.auto_reload import AutoReloadManager 4 | from unittest.mock import Mock, MagicMock 5 | from watchdog.events import FileModifiedEvent 6 | from rich.console import Console 7 | 8 | class TestAppFileEventHandler(unittest.TestCase): 9 | 10 | def setUp(self): 11 | self.callback = Mock() 12 | self.console = MagicMock(spec=Console) 13 | self.auto_reload_manager = AutoReloadManager(self.console) 14 | self.handler = AppFileEventHandler(self.callback, 'example/sample_app.py', self.auto_reload_manager) 15 | 16 | def test_on_modified_app_file_auto_reload_enabled(self): 17 | # Auto-reload is enabled by default 18 | event = FileModifiedEvent('example/sample_app.py') 19 | self.handler.on_modified(event) 20 | self.callback.assert_called_once() 21 | 22 | def test_on_modified_app_file_auto_reload_disabled(self): 23 | self.auto_reload_manager.toggle() # Disable auto-reload 24 | event = FileModifiedEvent('example/sample_app.py') 25 | self.handler.on_modified(event) 26 | self.callback.assert_not_called() 27 | 28 | def test_on_modified_unrelated_file(self): 29 | event = FileModifiedEvent('other_file.py') 30 | self.handler.on_modified(event) 31 | self.callback.assert_not_called() 32 | 33 | def test_auto_reload_manager_toggle(self): 34 | initial_status = self.auto_reload_manager.get_status() 35 | self.auto_reload_manager.toggle() 36 | self.assertNotEqual(initial_status, self.auto_reload_manager.get_status()) 37 | self.auto_reload_manager.toggle() 38 | self.assertEqual(initial_status, self.auto_reload_manager.get_status()) 39 | 40 | def test_auto_reload_manager_initial_state(self): 41 | self.assertTrue(self.auto_reload_manager.get_status()) 42 | 43 | if __name__ == '__main__': 44 | unittest.main() 45 | -------------------------------------------------------------------------------- /tests/test_auto_reload.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import sys 3 | import os 4 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))) 5 | 6 | from tkreload.auto_reload import AutoReloadManager 7 | from rich.console import Console 8 | 9 | 10 | class TestAutoReloadManager(unittest.TestCase): 11 | 12 | def setUp(self): 13 | self.console = Console() 14 | self.manager = AutoReloadManager(self.console) 15 | 16 | def test_initial_status(self): 17 | # Test if the auto-reload is initially set to True 18 | self.assertTrue(self.manager.get_status()) 19 | 20 | def test_toggle_off(self): 21 | # Test if toggling changes the auto-reload status to False 22 | self.manager.toggle() 23 | self.assertFalse(self.manager.get_status()) 24 | 25 | def test_toggle_on(self): 26 | # Test if toggling twice turns auto-reload on again 27 | self.manager.toggle() # First toggle to False 28 | self.manager.toggle() # Second toggle to True 29 | self.assertTrue(self.manager.get_status()) 30 | 31 | if __name__ == '__main__': 32 | unittest.main() 33 | -------------------------------------------------------------------------------- /tests/test_file_utils.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import os 3 | import sys 4 | from unittest.mock import patch 5 | from tkreload.file_utils import file_exists, clear_terminal 6 | 7 | class TestFileUtils(unittest.TestCase): 8 | 9 | def test_file_exists(self): 10 | self.assertTrue(file_exists(__file__)) 11 | self.assertFalse(file_exists('non_existent_file.txt')) 12 | 13 | @patch('os.system') 14 | def test_clear_terminal_windows(self, mock_system): 15 | with patch.object(os, 'name', 'nt'): 16 | clear_terminal() 17 | mock_system.assert_called_once_with('cls') 18 | 19 | @patch('os.system') 20 | def test_clear_terminal_unix(self, mock_system): 21 | with patch.object(os, 'name', 'posix'): 22 | clear_terminal() 23 | mock_system.assert_called_once_with('clear') 24 | 25 | def test_file_exists_with_relative_path(self): 26 | relative_path = os.path.join('tests', 'test_file_utils.py') 27 | self.assertTrue(file_exists(relative_path)) 28 | 29 | if __name__ == '__main__': 30 | unittest.main() 31 | -------------------------------------------------------------------------------- /tests/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch, Mock, MagicMock 3 | from tkreload.main import TkreloadApp, main 4 | from rich.console import Console 5 | import sys 6 | import time 7 | import os 8 | 9 | sys.path.insert( 10 | 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")) 11 | ) 12 | 13 | 14 | class TestTkreloadApp(unittest.TestCase): 15 | 16 | @patch("tkreload.main.subprocess.Popen") 17 | @patch("tkreload.main.show_progress") 18 | def test_run_tkinter_app(self, mock_show_progress, mock_popen): 19 | app = TkreloadApp("example/sample_app.py") 20 | process = Mock() 21 | mock_popen.return_value = process 22 | 23 | result = app.run_tkinter_app() 24 | mock_show_progress.assert_called_once() 25 | mock_popen.assert_called_once_with([sys.executable, "example/sample_app.py"]) 26 | self.assertEqual(result, process) 27 | 28 | @patch("tkreload.main.Observer") 29 | @patch("tkreload.main.AppFileEventHandler") 30 | def test_monitor_file_changes(self, mock_event_handler, mock_observer): 31 | app = TkreloadApp("example/sample_app.py") 32 | mock_callback = Mock() 33 | 34 | observer = app.monitor_file_changes(mock_callback) 35 | mock_event_handler.assert_called_once() 36 | mock_observer().schedule.assert_called_once() 37 | mock_observer().start.assert_called_once() 38 | 39 | # @patch('tkreload.main.time.sleep', side_effect=KeyboardInterrupt) 40 | # @patch('tkreload.main.subprocess.Popen') 41 | # def test_start_keyboard_interrupt(self, mock_popen, mock_sleep): 42 | # app = TkreloadApp('example/sample_app.py') 43 | # mock_process = Mock() 44 | # mock_popen.return_value = mock_process 45 | 46 | # with self.assertRaises(SystemExit): 47 | # app.start() 48 | 49 | # mock_process.terminate.assert_called_once() 50 | 51 | @patch("tkreload.main.sys.argv", ["tkreload", "example/sample_app.py"]) 52 | @patch("tkreload.main.file_exists", return_value=True) 53 | @patch("tkreload.main.TkreloadApp") 54 | def test_main_function(self, mock_tkreload_app, mock_file_exists): 55 | main() 56 | mock_file_exists.assert_called_once_with("example/sample_app.py") 57 | mock_tkreload_app.assert_called_once_with("example/sample_app.py") 58 | mock_tkreload_app().start.assert_called_once() 59 | 60 | @patch("tkreload.main.sys.argv", ["tkreload"]) 61 | @patch("tkreload.main.Console") 62 | @patch("tkreload.main.argparse.ArgumentParser") 63 | def test_main_function_no_file_provided(self, mock_parser, mock_console): 64 | mock_parser_instance = Mock() 65 | mock_parser.return_value = mock_parser_instance 66 | mock_parser_instance.parse_args.side_effect = SystemExit(2) 67 | 68 | with self.assertRaises(SystemExit) as cm: 69 | main() 70 | 71 | self.assertEqual(cm.exception.code, 2) 72 | 73 | 74 | if __name__ == "__main__": 75 | unittest.main() 76 | -------------------------------------------------------------------------------- /tkreload/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tkreload: A tool for automatically reloading Tkinter applications during development. 3 | 4 | This package provides functionality to monitor and automatically reload Tkinter 5 | applications, enhancing the development workflow for Tkinter-based projects. 6 | """ 7 | 8 | __all__ = ["TkreloadApp", "AutoReloadManager", "show_help"] 9 | 10 | from .main import TkreloadApp 11 | from .auto_reload import AutoReloadManager 12 | from .help import show_help 13 | -------------------------------------------------------------------------------- /tkreload/app_event_handler.py: -------------------------------------------------------------------------------- 1 | from watchdog.events import FileSystemEventHandler 2 | 3 | class AppFileEventHandler(FileSystemEventHandler): 4 | """Handles file changes to trigger app reload.""" 5 | def __init__(self, callback, app_file, auto_reload_manager): 6 | self.callback = callback 7 | self.app_file = app_file 8 | self.auto_reload_manager = auto_reload_manager 9 | self.last_content = None 10 | 11 | def on_modified(self, event): 12 | """ 13 | Called when a file is modified. 14 | 15 | This method checks if the modified file is the one being monitored 16 | and if the auto-reload manager is active. If the content of the file 17 | has changed, it triggers the provided callback function. 18 | 19 | Args: 20 | event: The event object containing information about the file modification. 21 | """ 22 | if event.src_path.endswith(self.app_file) and self.auto_reload_manager.get_status(): 23 | current_content = self.read_file_content(self.app_file) 24 | if current_content != self.last_content: 25 | self.last_content = current_content 26 | self.callback() 27 | 28 | def read_file_content(self, file_path): 29 | """ 30 | Reads the content of a file. 31 | 32 | This method opens the specified file in read mode and returns its content 33 | as a string. 34 | 35 | Args: 36 | file_path (str): The path to the file to be read. 37 | 38 | Returns: 39 | str: The content of the file. 40 | """ 41 | with open(file_path, 'r') as file: 42 | return file.read() 43 | -------------------------------------------------------------------------------- /tkreload/auto_reload.py: -------------------------------------------------------------------------------- 1 | from rich.console import Console 2 | 3 | class AutoReloadManager: 4 | """Class to manage the auto-reload feature.""" 5 | 6 | def __init__(self, console): 7 | self.console = console 8 | self.auto_reload = True # Initially set to True 9 | 10 | def toggle(self): 11 | """Toggles the auto-reload feature on or off.""" 12 | self.auto_reload = not self.auto_reload 13 | status = "Enabled" if self.auto_reload else "Disabled" 14 | self.console.print(f"[bold yellow]Auto-reload is now {status}.[/bold yellow]") 15 | 16 | def get_status(self): 17 | """Returns the current status of auto-reload.""" 18 | return self.auto_reload 19 | -------------------------------------------------------------------------------- /tkreload/file_utils.py: -------------------------------------------------------------------------------- 1 | # /src/tkreload/file_utils.py 2 | 3 | import os 4 | import sys 5 | 6 | def clear_terminal(): 7 | """Clear the terminal screen.""" 8 | os.system('cls' if os.name == 'nt' else 'clear') 9 | 10 | def file_exists(file_path): 11 | """Check if a file exists.""" 12 | return os.path.exists(file_path) 13 | -------------------------------------------------------------------------------- /tkreload/help.py: -------------------------------------------------------------------------------- 1 | # /src/tkreload/help.py 2 | 3 | from rich.console import Console 4 | 5 | console = Console() 6 | 7 | def show_help(auto_reload): 8 | """Displays help commands with detailed info and rich formatting.""" 9 | console.print("\n[bold yellow]Tkreload Help:[/bold yellow] [dim](detailed command info)[/dim]\n") 10 | console.print("[bold cyan]→[/bold cyan] [bold white]Press H[/bold white] : Display this help section.") 11 | console.print("[bold cyan]→[/bold cyan] [bold white]Press R[/bold white] : Restart the Tkinter app.") 12 | console.print( 13 | f"[bold cyan]→[/bold cyan] [bold white]Press A[/bold white] : Toggle auto-reload " 14 | f"(currently [bold magenta]{auto_reload}[/bold magenta])." 15 | ) 16 | console.print("[bold cyan]→[/bold cyan] [bold white]Ctrl + C[/bold white] : Exit the development server.\n") 17 | -------------------------------------------------------------------------------- /tkreload/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import subprocess 3 | import time 4 | import os 5 | import select 6 | import platform 7 | import argparse 8 | from rich.console import Console 9 | from watchdog.observers import Observer 10 | from .app_event_handler import AppFileEventHandler 11 | from .file_utils import clear_terminal, file_exists 12 | from .progress import show_progress 13 | from .help import show_help 14 | from .auto_reload import AutoReloadManager 15 | 16 | # Only import `msvcrt` on Windows 17 | if platform.system() == "Windows": 18 | import msvcrt 19 | 20 | 21 | class TkreloadApp: 22 | """Main application class for managing the Tkinter app.""" 23 | 24 | def __init__(self, app_file): 25 | self.console = Console() 26 | self.auto_reload_manager = AutoReloadManager(console=self.console) 27 | self.app_file = app_file 28 | self.process = None 29 | self.observer = None 30 | self.reload_count = 0 31 | self.startup_time=0 32 | 33 | def run_tkinter_app(self): 34 | """Run the given Tkinter app.""" 35 | show_progress() 36 | self.process = subprocess.Popen([sys.executable, self.app_file]) 37 | return self.process 38 | 39 | def monitor_file_changes(self, on_reload): 40 | """Monitors app file for changes and triggers reload.""" 41 | if self.observer: 42 | self.observer.stop() 43 | self.observer.join() 44 | 45 | event_handler = AppFileEventHandler( 46 | on_reload, self.app_file, self.auto_reload_manager 47 | ) 48 | self.observer = Observer() 49 | self.observer.schedule( 50 | event_handler, path=os.path.dirname(self.app_file) or ".", recursive=False 51 | ) 52 | self.observer.start() 53 | return self.observer 54 | 55 | def restart_app(self): 56 | """Restarts the Tkinter app.""" 57 | if self.process: 58 | self.reload_count += 1 59 | self.console.log( 60 | f"[bold yellow]Restarting the Tkinter app... (x{self.reload_count})[/bold yellow]" 61 | ) 62 | self.process.terminate() 63 | self.process.wait() 64 | time.sleep(1) 65 | self.run_tkinter_app() 66 | 67 | def start(self): 68 | """Starts the application, including monitoring and handling commands.""" 69 | start_time = time.time() # Record the start time 70 | self.run_tkinter_app() 71 | self.monitor_file_changes(self.restart_app) 72 | self.startup_time = (time.time() - start_time) * 1000 # Calculate startup time in milliseconds 73 | 74 | try: 75 | self.console.print( 76 | f"\n[bold white]Tkreload ✅[/bold white] [dim](ready in {self.startup_time:.2f} ms)[/dim]\n" 77 | f"\t[bold cyan]→[/bold cyan] [bold white]Auto-reload:[/bold white] [bold magenta]{'Enabled' if self.auto_reload_manager.get_status() else 'Disabled'}[/bold magenta]\n" 78 | "\t[bold cyan]→[/bold cyan] [bold white]Help:[/bold white] Press [bold cyan]H[/bold cyan]\n" 79 | "\t[bold cyan]→[/bold cyan] [bold white]Restart:[/bold white] Press [bold cyan]R[/bold cyan]\n" 80 | "\t[bold cyan]→[/bold cyan] [bold white]Exit:[/bold white] Press [bold red]Ctrl + C[/bold red]" 81 | ) 82 | 83 | 84 | while True: 85 | if platform.system() == "Windows": 86 | if msvcrt.kbhit(): # Check for keyboard input (Windows only) 87 | user_input = ( 88 | msvcrt.getch().decode("utf-8").lower() 89 | ) # Read single character input 90 | self.handle_input(user_input) 91 | else: 92 | # Use select for Unix-like systems 93 | if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: 94 | user_input = sys.stdin.read( 95 | 1 96 | ).lower() # Capture a single character input 97 | self.handle_input(user_input) 98 | 99 | time.sleep(0.1) 100 | 101 | except KeyboardInterrupt: 102 | self.console.print("[bold red]Ctrl + C detected. Exiting...[/bold red]") 103 | self.process.terminate() 104 | if self.observer: 105 | self.observer.stop() 106 | self.observer.join() 107 | 108 | def handle_input(self, user_input): 109 | """Handles the user input commands.""" 110 | if user_input == "h": 111 | show_help( 112 | "Enabled" if self.auto_reload_manager.get_status() else "Disabled" 113 | ) 114 | elif user_input == "r": 115 | self.restart_app() 116 | elif user_input == "a": 117 | self.toggle_auto_reload() 118 | 119 | def toggle_auto_reload(self): 120 | """Toggles auto-reload and updates file monitoring accordingly.""" 121 | self.auto_reload_manager.toggle() 122 | if self.auto_reload_manager.get_status(): 123 | self.reload_count = 0 124 | status = "Enabled" if self.auto_reload_manager.get_status() else "Disabled" 125 | 126 | 127 | def main(): 128 | parser = argparse.ArgumentParser( 129 | description="Real-time reload Tkinter app", 130 | formatter_class=argparse.RawDescriptionHelpFormatter, 131 | ) 132 | parser.add_argument("app_file", help="Tkinter app file path") 133 | 134 | args = parser.parse_args() 135 | 136 | app_file = args.app_file 137 | 138 | if not file_exists(app_file): 139 | Console().print(f"[bold red]Error: File '{app_file}' not found![/bold red]") 140 | sys.exit(1) 141 | 142 | tkreload_app = TkreloadApp(app_file) 143 | tkreload_app.start() 144 | 145 | 146 | if __name__ == "__main__": 147 | clear_terminal() 148 | main() 149 | -------------------------------------------------------------------------------- /tkreload/progress.py: -------------------------------------------------------------------------------- 1 | # /src/tkreload/progress.py 2 | 3 | import time 4 | from rich.console import Console 5 | from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn 6 | 7 | console = Console() 8 | 9 | def show_progress(): 10 | """Display a progress animation when starting the app.""" 11 | with Progress( 12 | SpinnerColumn(), 13 | TextColumn("[bold green]Booting Tkinter app...[/bold green]"), 14 | BarColumn(bar_width=None), 15 | TextColumn("[progress.percentage]{task.percentage:>3.0f}%"), 16 | transient=True 17 | ) as progress: 18 | task = progress.add_task("[green]Starting up...", total=100) 19 | for _ in range(10): 20 | progress.update(task, advance=2) 21 | time.sleep(0.05) 22 | --------------------------------------------------------------------------------