The ContactLensCalculator application is a desktop tool designed for validating and calculating contact lens parameters based on user input. It provides features for analyzing eye test data (SPH, CYL, AXIS, etc.) and converting them into precise lens values (spherical and toric).
- User-friendly interface built with PyQt5.
- Validates eye test data such as SPH, CYL, and AXIS.
- Converts input data into lens types (Spheric and Toric).
- Displays results in a clear and organized table.
- Custom styling for enhanced usability and visual appeal.
- Python 3.8 or later
- Required Python libraries:
PyQt5
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory:
cd EyeContactLens
- Install the required dependencies:
pip install -r requirements.txt
- Run the application:
python EyeContactLens.py
- Launch the application.
- Enter eye test parameters (e.g., SPH, CYL, AXIS) into the input table.
- Click the Calculate button to validate and process the input data.
- Review the calculated lens values in the results table.
- EyeContactLens.py: Main application file for GUI setup and functionality.
- py/: Directory containing helper modules:
EyeContactLensValidator
: Validates and formats contact lens data.EyeTestValidator
: Handles eye test data validation.functian
: Provides utility functions like loading stylesheets.
- static/: Directory for static resources, including stylesheets (
lens_table_styles.qss
).
Checks if a value is a multiple of 0.25.
- Parameters:
value
(str): The value to check.
- Returns:
bool
: True if the value is valid, False otherwise.
Formats and validates eye test power values.
- Parameters:
value
(str): The value to validate.
- Returns:
str
: Formatted value orFalse
if invalid.
Validates the axis value (1-180).
- Parameters:
value
(str): Axis value.
- Returns:
bool
: True if valid, False otherwise.
Validates the PD (Pupillary Distance) value (19-85).
- Parameters:
value
(str): PD value.
- Returns:
bool
: True if valid, False otherwise.
Removes the sign from a value and formats it to 2 decimal places.
- Parameters:
value
(str): Value to format.
- Returns:
str
: Formatted value orNone
if invalid.
Validates the ADD (Addition) value (0.25-4).
- Parameters:
value
(str): Addition value.
- Returns:
bool
: True if valid, False otherwise.
Formats SPH, CYL, and AX values based on rules.
- Parameters:
data
(dict): Dictionary of values.
- Returns:
dict
: Formatted values.
Checks if CYL and AX values are not null or inconsistent.
- Parameters:
data
(dict): Dictionary with CYL and AX values.
- Returns:
bool
: True if valid, False otherwise.
Validates the SG value (7-50).
- Parameters:
value
(str): SG value.
- Returns:
bool
: True if valid, False otherwise.
Validates the Back Vertex Distance (10-14).
- Parameters:
value
(str): Distance value.
- Returns:
bool
: True if valid, False otherwise.
Converts eyeglass prescriptions to spherical contact lens prescriptions.
- Parameters:
data
(dict): Dictionary containing SPH, CYL, AX, ADD, and BV values.
- Returns:
dict
: Spherical contact lens prescription.
Converts eyeglass prescriptions to toric contact lens prescriptions.
- Parameters:
data
(dict): Dictionary containing SPH, CYL, AX, ADD, and BV values.
- Returns:
dict
: Toric contact lens prescription.
Calculates spherical power adjusted for vertex distance.
- Parameters:
sphere
(float): Sphere value.vertex_distance
(float): Vertex distance (e.g., 12mm).
- Returns:
float
: Adjusted spherical power.
Calculates the spherical equivalent for a given sphere and cylinder.
- Parameters:
sphere
(float): Sphere value.cylinder
(float): Cylinder value.
- Returns:
float
: Spherical equivalent.
Rounds a number to the nearest 0.25.
- Parameters:
num
(float): Number to round.
- Returns:
float
: Rounded number.
Formats SPH and CYL values to the nearest 0.25.
- Parameters:
value
(dict): Dictionary with SPH and CYL values.
- Returns:
dict
: Formatted values.
Checks if a value is a multiple of 0.25.
- Parameters:
value
(str): Value to check.
- Returns:
bool
: True if valid, False otherwise.
Sets up the user interface, including input tables, result tables, and buttons for validation.
Creates a table with the specified rows, columns, and headers.
- Parameters:
rows
(int): Number of rows.cols
(int): Number of columns.headers
(list): List of column headers.
Validates the input data and processes it to calculate lens powers (spheric and toric).
Converts filtered eye test data into contact lens parameters.
- Parameters:
filtered_data
(list): List of validated eye test data.
- Returns:
- Processed lens data (list of dictionaries).
Populates the result table with processed lens data, applying styles and formatting.
- Parameters:
lens_data
(list): List of dictionaries containing calculated lens parameters.
Validates the value entered in a specific cell of the input table.
- Parameters:
row
(int): Row index.col
(int): Column index.value
(str): Cell value.
- Returns:
- A tuple indicating validity, formatted value, and whether the next cell should be updated.
- Modify the UI or styles by updating
lens_table_styles.qss
. - Extend functionality by editing the validator classes in the
py
directory.
To test the application components:
- Install
pytest
:pip install pytest
- Run tests:
pytest
Developed by Elhussein Taha
Version 1.0
For queries or contributions, please contact [email@example.com].
This project is licensed under the MIT License. See the LICENSE
file for details.