BSCS 3A
Submitted by:
- Eugene P. Aquilino
- Mary France B. San Andres
This project demonstrates how to enhance a basic Python application, specifically a Phone Number Tracker, with robust defensive programming techniques.
The original project was a Phone Number Tracker application built using Python and Tkinter for the Graphical User Interface (GUI). Its core function was to accept a phone number as input and then determine the associated country.
We selected this project to illustrate the practical application of:
- GUI Integration: Combining front-end user interaction with backend logic.
- Data Processing: Handling user input and processing it in real-time.
- External Libraries: Utilizing external resources (like
pycountryandphone_iso3166) for enhanced functionality.
Our enhancements focused on improving the application's reliability, user-friendliness, and code quality:
- Robust Input Validation: Implemented stricter checks to ensure valid phone number formats.
- Comprehensive Error Handling: Added
try-exceptblocks to gracefully handle potential errors and provide informative feedback to the user. - Enhanced User Interface: Refined the GUI layout and added a "Clear" button for better usability.
- Detailed Error Messages: Improved the clarity of error messages to help users understand and resolve issues.
Follow these steps to set up the development environment and run the enhanced application.
-
Clone the Repository:
git clone [repository_url]
(Replace
[repository_url]with the actual URL of your project repository). -
Navigate to the Project Directory:
cd [project_directory_name] -
Install Dependencies:
pip install -r requirements.txt
- Python 3.x
- Tkinter: (Usually comes bundled with Python)
- pycountry:
pip install pycountry - phone_iso3166:
pip install phone-iso3166
Learn how to use the enhanced Phone Number Tracker application.
- Save the Code: Save the Python code as a file named
app.py(or any.pyfile). - Run the Application: Execute the script from your terminal:
python app.py
- Enter a Phone Number: Input a phone number into the entry field.
- Track the Country: Click the "Track Country" button.
- View Results: The application will display the country associated with the phone number. If the country cannot be determined, it will display "Country is Unknown."
- Clear Button: A new "Clear" button resets the input field, making it easier to enter new numbers.
- Enhanced Error Handling: The application is more resilient to invalid inputs and provides more informative error messages.
This section provides in-depth information about the technical aspects of the project.
-The overall architecture of the application changed the font size, color of a simple GUI application with a main window, entry field, button, and label.
- No New Classes: The project's structure remains similar to the original.
- Enhanced Methods: The
track_locationandclear_fieldsmethods were improved for better functionality and error handling.
- Input Validation: We implemented strict checks to ensure the entered phone number consists of valid digits only.
- Exception Handling:
try-exceptblocks are used to catch potential errors during country information retrieval, preventing crashes and providing user-friendly error messages.
This section details the code improvements made during the project.
- Improved Input Validation: The
track_locationmethod now includes more robust validation of the phone number input. - Enhanced Error Messages: Error messages are more descriptive and user-friendly.
- Clear Button Functionality: Added the functionality for the "Clear" button to reset the input field.
Refactoring was essential to:
- Improve Code Readability: Make the code easier to understand and maintain.
- Enhance Maintainability: Simplify future modifications and debugging.
- Improve User Experience: Provide a smoother and more intuitive interaction for the user.
This section outlines the testing strategy and results.
We employed manual testing to verify the application's functionality and the effectiveness of the enhancements.
| Test Case | Input | Expected Result | Actual Result | Status |
|---|---|---|---|---|
| Valid Phone Number | +15551234567 | Country: United States | Country: United States | Pass |
| Invalid Phone Number | abc | Error: Invalid phone number format | Error: Invalid phone number format | Pass |
| Clear Button | (Any input) | Input field is cleared | Input field is cleared | Pass |
| Country not found | +9999999999 | Country is Unknown | Country is Unknown | Pass |
Here, we discuss the challenges faced and how we overcame them.
- Handling Invalid Phone Number Inputs: Ensuring the application gracefully handles various invalid input formats.
- Managing Exceptions: Dealing with potential errors during country information retrieval from external libraries.
- Input Validation: Implemented rigorous input validation using conditional statements to check for valid digits before processing.
- Exception Handling: Added
try-exceptblocks to catch exceptions, preventing the application from crashing and providing informative error messages to the user.
We propose the following enhancements for future development:
- Support for International Formats: Extend the application to handle a wider range of international phone number formats.
- Robust Testing Framework: Implement automated unit and integration tests using a framework like
unittestorpytest. - GUI Enhancements: Improve the user interface with:
- More advanced styling (e.g., using themed Tkinter widgets).
- Additional features (e.g., displaying the country flag, a map).
- Original Project:
- Alternative Project: https://github.com/Kalebu/Python-phonenumber-tracker-App.git