A Python module to display credits on pressing CTRL + O
Project description
Credito
License
This project is licensed under the GNU General Public License v3.0 (GPLv3). See LICENSE for details.
Documentation
Install with:
pip3 install credito
pip install credito
Configure and Use credito:
1. Import and Configure the Module:
You can import credito from the credito package and configure it with the path to your custom credits.cfg file. If you don’t specify a path, the default credits.cfg file included in the package will be used.
from credito import Credito
# Create an instance of Credito
credito = Credito()
# If you put nothing in the brackets then it will
# automatically use the default credits.cfg file included in the package.
credito.config()
# Or,
# Configure with a custom credits.cfg file
credito.config('path/to/your/custom/credits.cfg')
2. Start the Handler:
To start listening for the key combination (CTRL + O) and display the credits, you can call the handler function.
credito.handler()
3. Run the Module:
To have credito run in the background and listen for the key combination, you can run it as a standalone script or integrate it into your application.
If running as a standalone script, you can simply execute:
python -m credito
Or, integrate it into your application by calling the handler function as shown above.
How the Printing Works:
1. Configuration (credito.config):
- When you call
credito.config("path/to/custom/credits.cfg"), it loads the content of thecredits.cfgfile into memory by reading it and storing the content in theself.creditsvariable. - If you don't pass a path to the
configfunction, it will use the defaultcredits.cfgfile included in the package.
2. Keypress Handler(handler):
- When the
CTRL + Okey combination is detected by thelisten_for_keypressfunction, it triggers thehandler()function. The handler() function, in turn, callscredito.show_credits().
3. Displaying Credits (show_credits):
- Inside
show_credits(), the console is cleared usingos.system('cls' if os.name == 'nt' else 'clear'), and then the content ofself.credits(which contains the content fromcredits.cfg) is printed. - The program pauses for 10 seconds (
time.sleep(10)), allowing the user to see the credits, and then it optionally clears the screen again.
Additional Notes
Running in Background:
- The listen_for_keypress function runs in a separate thread, so the main program remains responsive. Make sure to handle this appropriately in your application.
No cross platform:
- Don't ask me to add cross platform. I am way too busy to be doing that. It might work cross platform it's just I can't test it and it might not be reliable. Credito was made to work for Windows only. The example provided is tailored for Windows using
ctypes. If you need cross-platform support, you may need to use different libraries or methods to handle global keypress events on other operating systems.
Permissions:
- Capturing global keypresses might require administrative or elevated permissions depending on the system and environment.
Credits printing:
- Credito will print everything in the
credits.cfgfile. Thecredits.cfgfile is like a text document for Credito. Make sure the file has the content you want to display, and that it is correctly loaded into the config using the method shown in the documentation above. The Credits will allways be visible for 10 seconds, then either the console will clear again, or the terminal application will resume as normal.
What is the default/auto config?
Thank you for using our application!
Credits:
- Developer: Your Name
- Support: support@example.com
Enjoy using our software!
- I chose this so it could be a template for easy testing. You are free to copy and change the default/auto config.
Directory Structure:
credito/ - # Base directory
├── credito/ - # Main package folder
│ ├── __init__.py - # Initializes the package
│ ├── credito.py - # Contains the Credito class and logic
│ └── data/ - # Contains seperate info
│ └── credits.cfg - # Default credits file
├── tests/ - # Tests folder
│ ├── __init__.py - # Can be empty or contain shared fixtures
│ ├── conftest.py - # Global fixtures and hooks for tests
│ ├── test_credito.py - # Unit tests for Credito class
├── README.md - # Project description
├── setup.py - # Setup script for packaging
└── LICENSE - # Obviously just a license
âš¡ Quote
"Talk is cheap. Show me the code."
-- Linus Torvalds --
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.