OS-agnostic threaded keypress event detector for killing loops.
Project description
riceprint
About
Author: Kevin Sacca ssriceboat@gmail.com
A simple threaded Python keypress event detector for stopping loops or other threads. Effective for safely stopping large for-loops, continuous functions, and enabling keypress directives for GUIs.
Works on Linux, macOS, Windows.
License
MIT License
Copyright (c) 2019 ssriceboat
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Installation using pip
pip install ricekey
Usage:
After you have installed the package, check that its working by running the module directly. This will demonstrate an example keypress kill event.
cd /path/to/ricekey-package/src/ricekey/
python ricekey.py
Below is an example of how you can use ricekey to stop your main thread if you need to:
from ricekey import kbcontrol
from riceprint import ConsolePrinter, pprint, tprint, progressbar
cp = ConsolePrinter()
import threading
import time
# Start the keypress monitoring thread
thread = threading.Thread(target=kbcontrol, args=())
thread.start()
# While the thread is alive, do something.
i = 0
while thread.isAlive():
c = cp.palette.colors[i % 16]
progressbar(i%100, 100, color=c, char='\u2587', lend='|', rend='|')
time.sleep(0.01)
i+=1
pprint('Done! I hope you use this package!', 'dm')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ricekey-1.0.1.tar.gz
.
File metadata
- Download URL: ricekey-1.0.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a20bece53d5c3c47e5bd4c018f945c3749243c18a349675f9ae0619c09aec6c9 |
|
MD5 | f7e54de5f30da6f39f8abbf1f0aa6ca8 |
|
BLAKE2b-256 | 2a674e6df7a0af46bae45da485c0f3240e72229a94d43bcfb004e9ceaf2d07dc |