Skip to content

GimpyHand/Windows-Scrap-Logbook

Repository files navigation

Cadorath Aerospace Scrap Logbook

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.

Features

  • 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.

Database Configuration

The application supports two database backends:

SQLite (Default)

  • 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.db by default

MySQL

  • 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

Usage

  1. Install the required dependencies:

    pip install -r requirements.txt
  2. (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
  3. (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
  4. Run the application:

    python main.py

No Docker Usage

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.

Packaging as Windows Executable

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.

  1. Install the required dependencies (if not already installed):

    pip install -r requirements.txt
  2. Run the build script:

    python build.py
  3. The executable will be created in the dist directory as Aerospace_Scrap_Logbook.exe.

  4. To run the application, simply double-click the executable file.

Build Options

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 --onedir

In directory mode, the executable will be created in dist/Aerospace_Scrap_Logbook/Aerospace_Scrap_Logbook.exe.

Enhanced Build Process

The build script has been enhanced to better handle pandas dependencies and prevent DLL loading errors:

  1. Runtime Hook: A special hook ensures all DLLs are loaded correctly at runtime
  2. Comprehensive Hidden Imports: Includes specific imports for all pandas C extensions
  3. Binary Dependencies: Explicitly includes binary dependencies when available
  4. Directory Mode Option: Provides an alternative packaging method that may resolve DLL issues

Troubleshooting

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.py before packaging
  • If the application fails to start, try running the executable from a command prompt to see any error messages

Known Issues and Solutions

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:

  1. Use Directory Mode: Run the build script with the --onedir option:

    python build.py --onedir
  2. 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.

  3. Check Python Environment: Ensure pandas and its dependencies are correctly installed in your Python environment:

    pip uninstall pandas numpy
    pip install pandas numpy
  4. 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
]

Project Structure

  • 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.

Dependencies

  • Python 3.x
  • PyQt5
  • pandas
  • SQLAlchemy
  • PyMySQL (for MySQL support)
  • PyInstaller (for packaging as Windows executable)
  • Pillow (for icon conversion during packaging)

Multi-User Support

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

Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For support, please contact alex.jessup@cadorath.com.

About

A Windows desktop app written in python to track aerospace scrap

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages