App Time Blocker is a Windows application designed to help users manage their time by blocking specified programs after a user-defined time limit each day. Once the set time is reached, the chosen application will be blocked for the remainder of the day, with the block automatically resetting the next day.
- Application Selection: Allows users to select any executable application (
.exe) for monitoring and blocking. - Customizable Block Time: Users can define a specific time (in HH:MM format) after which the application's usage will be restricted.
- Daily Reset: The block is enforced for the rest of the day and automatically resets on the following day.
- Background Monitoring: The application monitors the target program in the background without constant user interaction.
- System Tray Integration:
- Includes a system tray icon for easy access.
- Options to show/hide the main application window.
- Option to exit the application directly from the tray menu.
- Configuration Persistence: User settings (selected application path, block time, language preference) are saved locally and reloaded when the application starts.
- Administrator Privileges:
- Checks if it's running with administrator privileges, which are often required to terminate other applications effectively.
- Prompts the user to restart as administrator if necessary.
- Modular Codebase: The source code is organized into modules for configuration, core blocking logic, and GUI, facilitating easier maintenance and future development.
- Internationalization (i18n): Supports multiple languages through
gettext. - Language Selection: Choose between available languages (currently English and Arabic [placeholder translations]). A restart is required for changes to take full effect.
- Python: Python 3.x (developed with 3.10+)
- wxPython: A cross-platform GUI toolkit for Python.
- Installation:
pip install wxpython
- Installation:
- psutil: A cross-platform library for retrieving information on running processes and system utilization.
- Installation:
pip install psutil
- Installation:
- Pillow (Optional): Python Imaging Library, used in this project to create a dummy tray icon if
icon.pngis missing.- Installation:
pip install Pillow
- Installation:
- gettext (for developers adding translations): GNU gettext utilities are needed to work with
.poand.mofiles (e.g.,msgfmt,pygettext3).
- Ensure all prerequisites are installed.
- The main entry point for the application is
app_blocker/main.py. - To run the application, navigate to the project's root directory in your terminal and execute:
(Use
python -m app_blocker.main
python3instead ofpythonif that's how your system is configured). - Tray Icon:
- For the best experience, place a 16x16 or 32x32
icon.pngfile in the root directory of the project. This icon will be used for the system tray. - If
icon.pngis not found and Pillow is installed, a simple dummy icon will be generated at runtime.
- For the best experience, place a 16x16 or 32x32
The application's main window provides the following controls:
- Application to Block:
- A read-only text field displaying the path to the selected application.
- "Browse..." button: Opens a file dialog to select the
.exefile of the application you wish to block.
- Block After (HH:MM):
- Two spin controls to set the hour (0-23) and minute (0-59) after which the selected application will be blocked.
- Controls:
- "Start Monitoring" button: Begins monitoring the selected application. Settings are saved when monitoring starts.
- "Stop Monitoring" button: Stops the current monitoring process.
- Language Menu:
- Located in the menu bar (Language > Select Language).
- Allows switching between English and Arabic.
- The application saves this preference and must be restarted for the language change to fully apply to all UI elements.
- Status Log:
- A text area that displays real-time status messages, such as when monitoring starts/stops, when an application is blocked, or any errors that occur.
- The application settings are stored in a JSON file located in the user's local application data directory.
- Path:
%APPDATA%\Local\AppBlockerWxV2\app_blocker_config_wx_v2.json- This typically translates to
C:\Users\<YourUsername>\AppData\Local\AppBlockerWxV2\app_blocker_config_wx_v2.jsonon Windows. - The directory and file are created automatically if they don't exist.
- This typically translates to
- This file stores the selected application path, block time, daily block status, and chosen language.
The application is organized within the app_blocker package:
app_blocker/__init__.py: Makesapp_blockera Python package.main.py: The main entry point of the application. It initializes thewx.Appand the main application frame (AppBlockerFrame). It also handles the initialgettextsetup based on the configured language.gui.py: Contains all wxPython UI classes, includingAppBlockerFrame(the main window) andAppTaskBarIcon(the system tray icon). It manages UI layout, event handling, language selection menu, and interactions with the other modules. Internationalization for UI strings is primarily handled here.blocker.py: Implements the core logic for monitoring the target application's process and terminating it when the block condition is met. It usespsutilfor process iteration andthreadingto run the monitoring loop in the background.config.py: Manages loading and saving the application's configuration (target application path, block time, daily block status, language) to a JSON file. It also defines constants related to configuration paths and default values.
The application uses the gettext module for internationalization, allowing UI strings to be translated into multiple languages.
- Current Languages:
- English (
en) - Default - Arabic (
ar) - Placeholder translations
- English (
- Translation Files Location:
locale/directory in the project root.locale/messages.pot: This is the template file generated bypygettext3. It contains all strings extracted from the source code that are marked for translation.locale/<lang_code>/LC_MESSAGES/messages.po: These are human-readable plain text files for each supported language (e.g.,locale/en/LC_MESSAGES/messages.pofor English). Translators edit these files to provide translations for eachmsgid.locale/<lang_code>/LC_MESSAGES/messages.mo: These are compiled, machine-readable binary files generated from the.pofiles. The application uses these.mofiles at runtime to load translations.
- Create Language Directory:
Replace
mkdir -p locale/<lang_code>/LC_MESSAGES/
<lang_code>with the appropriate ISO 639-1 language code (e.g.,frfor French,esfor Spanish). - Create
.poFile: Copy the template file to your new language directory:cp locale/messages.pot locale/<lang_code>/LC_MESSAGES/messages.po
- Translate Strings: Edit the new
locale/<lang_code>/LC_MESSAGES/messages.pofile:- For each
msgid "Original string", fill in themsgstr "Translated string"with the translation. - Update the header fields in the
.pofile (e.g.,Language: <lang_code>,Last-Translator,Language-Team,Plural-Forms).
- For each
- Compile
.moFile: Usemsgfmt(part of thegettexttools) to compile your.pofile into a.mofile:Ensuremsgfmt -o locale/<lang_code>/LC_MESSAGES/messages.mo locale/<lang_code>/LC_MESSAGES/messages.po
gettexttools are installed on your system (on Debian/Ubuntu:sudo apt-get install gettext). - Application Integration:
- Add the new language option to the "Language" menu in
app_blocker/gui.py(AppBlockerFrame.InitUI). - Update the
on_select_languagehandler inapp_blocker/gui.pyto recognize the new language code. - The application's
gettextsetup inapp_blocker/main.pyandapp_blocker/gui.pyshould automatically pick up the new language if the.mofile is correctly placed and the language code is used.
- Add the new language option to the "Language" menu in
Contributions are welcome! Please feel free to submit pull requests or open issues.
To help streamline the process, we have provided templates for issues and pull requests:
- Issue Templates: When creating an issue, please use one of the available templates (Bug Report, Feature Request) to provide detailed and structured information. These can be found when you click "New Issue" on GitHub, and the template files are located in the
.github/ISSUE_TEMPLATEdirectory of this repository. - Pull Request Template: When submitting a pull request, GitHub will automatically populate the PR description with the template from
.github/PULL_REQUEST_TEMPLATE.md. Please fill this out to describe your changes, related issues, and testing performed.
New translations are also a very welcome form of contribution. Please follow the guide under "Adding a New Language" and submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.