This project is a PyQt5 application for managing a scrap logbook for Cadorath Aerospace. It allows users to input, store, and view records of scrapped parts using a flexible database backend that supports both SQLite and MySQL.
- Form Input: Users can input details such as date, work order (W/O), part number, part description, serial number, initials, and remarks.
- Data Validation: Ensures that required fields (date and initials) are filled and that the date is in the correct format (YYYY-MM-DD).
- Flexible Database Storage: Records can be stored in either SQLite or MySQL databases, allowing for better multi-user concurrent access.
- Data Display: Records are displayed in a table with adjustable column widths.
- Record Count: Displays the total number of records in the database.
- Clear Form: Allows users to clear the form inputs.
- Insert Current Date: Provides a button to insert the current date into the date field.
- Database Migration: Includes a utility for migrating data from SQLite to MySQL.
The application supports two database backends:
- Simple file-based database, good for single-user scenarios
- No additional setup required
- Database file is stored at
X:\AEROSPACE\Aerospace YWG Scrap Parts Logbook\scrap_logbook.dbby default
- Server-based database, excellent for multi-user concurrent access
- Requires a MySQL server installation
- Configure using environment variables:
SCRAP_DB_TYPE=mysql
SCRAP_MYSQL_HOST=localhost
SCRAP_MYSQL_PORT=3306
SCRAP_MYSQL_USER=scrap_user
SCRAP_MYSQL_PASSWORD=scrap_password
SCRAP_MYSQL_DATABASE=scrap_logbook
-
Install the required dependencies:
pip install -r requirements.txt
-
(Optional) Set up a MySQL database for multi-user access:
- Install MySQL Server
- Create a database and user with appropriate permissions
- Set the environment variables as described above
-
(Optional) Migrate existing data from SQLite to MySQL:
python db_migration.py --mysql-host=localhost --mysql-user=scrap_user --mysql-password=scrap_password --mysql-database=scrap_logbook
-
Run the application:
python main.py
This project does not use Docker for development or deployment. Any previous Docker artifacts (Dockerfile, docker-compose.yml) have been deprecated and are kept only to avoid confusion in forks or cached IDE settings. Please run the application directly on Windows as described above, or package it with PyInstaller.
The application can be packaged as a standalone Windows executable (.exe) file using PyInstaller. This creates an executable that can be distributed and run without requiring Python or any dependencies to be installed.
-
Install the required dependencies (if not already installed):
pip install -r requirements.txt
-
Run the build script:
python build.py
-
The executable will be created in the
distdirectory asAerospace_Scrap_Logbook.exe. -
To run the application, simply double-click the executable file.
The build script (build.py) automatically configures PyInstaller with the following options:
- Single File (default): The application is packaged as a single .exe file with all dependencies included
- Directory Mode (optional): The application can be packaged as a directory containing the executable and dependencies
- No Console: The application runs without showing a console window
- Icon: Uses the Cadorath logo as the application icon (if available)
To use directory mode instead of single file mode (which can help with DLL loading issues):
python build.py --onedirIn directory mode, the executable will be created in dist/Aerospace_Scrap_Logbook/Aerospace_Scrap_Logbook.exe.
The build script has been enhanced to better handle pandas dependencies and prevent DLL loading errors:
- Runtime Hook: A special hook ensures all DLLs are loaded correctly at runtime
- Comprehensive Hidden Imports: Includes specific imports for all pandas C extensions
- Binary Dependencies: Explicitly includes binary dependencies when available
- Directory Mode Option: Provides an alternative packaging method that may resolve DLL issues
If you encounter issues with the packaged application:
- Make sure all dependencies are installed before running the build script
- Check that the application runs correctly with
python main.pybefore packaging - If the application fails to start, try running the executable from a command prompt to see any error messages
Pandas DLL Loading Error
If you encounter an error like ImportError: DLL load failed while importing aggregations: The specified module could not be found, try these solutions:
-
Use Directory Mode: Run the build script with the
--onediroption:python build.py --onedir
-
Install Microsoft Visual C++ Redistributable: Pandas C extensions require the Microsoft Visual C++ Redistributable package. Download and install the latest version from the Microsoft website.
-
Check Python Environment: Ensure pandas and its dependencies are correctly installed in your Python environment:
pip uninstall pandas numpy pip install pandas numpy
-
Run Directly: If issues persist, consider running the application directly with Python instead of using the executable:
python main.py
If you encounter similar DLL loading issues with other libraries, you may need to modify the build script to add appropriate hidden imports for those libraries. In the build.py script, you would add these options to the PyInstaller command like this:
# Example of how to add hidden imports to the PyInstaller command in build.py
# Method 1: If you're modifying the existing build.py script
# First, create the basic command list:
pyinstaller_cmd = [
"pyinstaller",
"--name", "Your_App_Name",
"--onefile",
"--windowed"
]
# Then add the hidden imports for problematic libraries:
pyinstaller_cmd.extend([
"--hidden-import", "problematic.module.name",
"--collect-all", "library_name"
])
# Finally, add the main script:
pyinstaller_cmd.append("your_main_script.py")
# Method 2: Include all options when creating the command list
pyinstaller_cmd = [
"pyinstaller",
"--name", "Your_App_Name",
"--onefile",
"--windowed",
# Add these lines for any problematic libraries:
"--hidden-import", "problematic.module.name",
"--collect-all", "library_name",
"your_main_script.py" # Your main Python script
]main.py: Main application file containing the PyQt5 GUI and logic.db_config.py: Database configuration module that supports both SQLite and MySQL.db_migration.py: Utility for migrating data from SQLite to MySQL.build.py: Script for packaging the application as a Windows executable using PyInstaller.requirements.txt: List of required Python packages.
- Python 3.x
- PyQt5
- pandas
- SQLAlchemy
- PyMySQL (for MySQL support)
- PyInstaller (for packaging as Windows executable)
- Pillow (for icon conversion during packaging)
The application now supports multiple users editing the database simultaneously:
- When using SQLite, the application uses WAL (Write-Ahead Logging) mode for better concurrency
- For true multi-user support, configure the application to use MySQL as described above
- The application handles connection errors gracefully with fallback mechanisms
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
For support, please contact alex.jessup@cadorath.com.