0% found this document useful (0 votes)
7 views20 pages

Object Oriented Programming Coursework

The document outlines the coursework for COMP1752, focusing on the development of a Track Player system using Python and Tkinter. It details the design, testing, and fault management processes, highlighting key functionalities such as viewing tracks, creating playlists, and updating ratings. Additionally, it discusses future development opportunities and reflects on the learning experience throughout the project.

Uploaded by

magickill124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views20 pages

Object Oriented Programming Coursework

The document outlines the coursework for COMP1752, focusing on the development of a Track Player system using Python and Tkinter. It details the design, testing, and fault management processes, highlighting key functionalities such as viewing tracks, creating playlists, and updating ratings. Additionally, it discusses future development opportunities and reflects on the learning experience throughout the project.

Uploaded by

magickill124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COURSEWORK

COMP1752 – OBJECT ORIENTED PROGRAMING

Student Name : Nguyen Sy Nghia

Student ID : 001407019
1. Table of Contents
1. Table of Contents ................................................................................ 2
2. Introduction .......................................................................................... 4
3. Design and Development..................................................................... 4
1. Stage 1: .......................................................................................... 4
2. Stage 2 and 3: ................................................................................ 5
3. Stage 4, testing: .............................................................................. 8
4. Stage 5: Innovations: .................................................................... 10
4. Testing and Faults ............................................................................. 10
5. Summary of Testing................................................................... 10
Methodology ...................................................................................... 10
[Link] and Failures ................................................................................ 11
1. Addressed Issues: ............................................................................. 11
1. Non-Numeric Track Input Validation .............................................. 11
2. Handling Non-Existent Track Numbers .......................................... 11
3. UI Feedback and Error Messaging................................................. 12
4. Playlist Management and Empty Playlist Handling......................... 12
5. Unresolved Issues: ....................................................................... 13
Dynamic-Window Resizing: ............................................................... 13
6. Conclusions, Further Development, and Reflection ........................... 13
1. Summary of the Program .............................................................. 13
2. Further Development .................................................................... 13
1. Display a Picture for Each Track .................................................... 13
2. Filter Option for Viewing Tracks by Artist ....................................... 13
3. Store Track Library Data Externally in a CSV File .......................... 14
4. Implement Additional LibraryItem Subclasses................................ 14
5. Dynamic Resizing: ......................................................................... 14
3. Reflection ..................................................................................... 15
2. Introduction
This project aimed to develop a Track Player (aka. JukeBox) system that
enables users to manage and interact with music tracks. The primary
objectives included creating an interface for viewing track information,
building functionality for creating and managing playlists, with features to
update track ratings.

Key functionalities of the Track Player system include:


• View Tracks: Users can browse a tracks’ library, search by artist or
track name, and view details such as play count and ratings.
• Create Playlists: Users can add tracks to a playlist, reset the playlist,
and simulate playback with play count updates.
• Update Track Ratings: Users can modify the rating of any track,
ensuring the library reflects personal preferences.
The program was built using Python and Tkinter. The system provides a
seamless and user-friendly interaction with the underlying track library.

3. Design and Development


Using Python and Tkinter, the resulting code has been properly executed
1. Stage 1:
Comments have been added to the view_tracks.py file
2. Stage 2 and 3:

The create_track_list and update_track files are first added as GUI with no
fuctions and are added with working fuctions later on:
Create_track_lists: Allowed users to add tracks to a playlist, reset it,
and simulate playback by updating play counts.
Update_tracks: Enabled users to modify ratings for individual tracks,
with validation to ensure ratings were within an acceptable range.
3. Stage 4, testing:

Validation has been added to the code:


Unit testing of Library_item using Pytest is a success:
4. Stage 5: Innovations:

I decided to rewrite the entire code into a single combined_GUI.py


file, with the addition of a fuctional search bar:

4. Testing and Faults


1. Summary of Testing
Testing was conducted at two levels: individual module testing and
integrated system testing. Unit tests were used to verify the correctness of
each module (e.g., viewing tracks, creating playlists, and updating track
ratings). Functional tests were performed to ensure that the overall system
worked as expected when all modules were integrated.

2. Methodology
1. Unit Testing:
• Verified individual functions, such as “get_name”, “set_rating”, and
“increment_play_count”, ensuring they produced accurate results.
• Tested GUI components, making sure that the inputs were correctly
processed and outputs were displayed as expected.

2. Integration Testing:
• Verified that updates made in one module (e.g., updating a track's
rating) were reflected across the system.
3. User Testing:
• Conducted tests with sample users to validate the user interface's
intuitiveness and functionality.

[Link] and Failures


1. Addressed Issues:
1. Non-Numeric Track Input Validation
- Fault: One of the early challenges was handling invalid inputs from
users, particularly when they entered non-numeric values for track numbers
(e.g., "four", "abc").
- Failure: The application originally did not validate that the input for track
numbers was numeric. As a result, users could input non-numeric
characters, leading to unexpected behavior or crashes when the system
tried to process those inputs as numbers.
- Correction: This issue was resolved by adding input validation in the
“view_track” method. Before attempting to retrieve track details, we now
check if the input consists of digits using “track_number.isdigit()”. If the
input is non-numeric, a message is shown to the user, guiding them to
enter a valid numeric track number. This significantly improved the
robustness of the app and enhanced user experience.
2. Handling Non-Existent Track Numbers
- Fault: Another issue was ensuring that users were aware when they
entered a track number that didn't exist in the library (e.g., "99" if track 99 is
not part of the collection).
- Failure: Without proper validation, users could input any number, and
the system would either crash or return misleading outputs if the track
wasn't found in the library. This led to confusion and a poor user
experience.
- Correction: The issue was addressed by adding a check to verify
whether a track exists in the library. If the track is not found, an error
message such as "Track not found" is displayed in the interface. This
helped to ensure that users are immediately notified when the track number
they entered is invalid.
3. UI Feedback and Error Messaging
- Fault: The user interface (UI) initially lacked clear feedback for error
scenarios. In particular, when invalid input was provided (e.g., an empty
field or incorrect track number), the system failed to provide informative
error messages, leading to confusion for the user.
- Failure: This lack of informative feedback resulted in an unclear
experience, where users weren’t sure what went wrong or how to correct
their input. The application sometimes failed silently or displayed cryptic
error messages that didn’t help the user.
- Correction: To address this, user-friendly error messages were
introduced for common failures, such as empty search fields or invalid track
numbers. Specifically, messages like "Please enter a search query" or
"Track not found" are now shown in the relevant parts of the app. This
provides a much clearer and more intuitive experience for the user.
4. Playlist Management and Empty Playlist Handling
- Fault: The playlist management functionality required careful handling of
scenarios where users attempted to play or reset an empty playlist.
- Failure: Initially, the "Play Playlist" and "Reset Playlist" functionalities
could operate even when the playlist was empty. This led to potential
confusion or errors, as users would expect to hear music or reset a
populated playlist.
- Correction: This was fixed by adding checks to verify whether the
playlist is empty before performing actions such as playing or resetting it. If
the playlist is empty, a warning message is shown, notifying the user that
the playlist needs to contain tracks to perform these actions.
3. Unresolved Issues:
Dynamic-Window Resizing:
Currently, the program relies on a fixed window size, which may not be
ideal for all screen resolutions. Further adjustments would be needed to
implement dynamic resizing.

6. Conclusions, Further Development, and


Reflection
1. Summary of the Program
The JukeBox system has successfully providing a user-friendly interface
interacting with the track library. Users have the ability view track details,
search for tracks by name, create and manage playlists, and update track
ratings. Each functionality operates independently while integrating
seamlessly into the system.

2. Further Development
Given additional time, several enhancements could be implemented to
improve the system:

1. Display a Picture for Each Track


One potential enhancement to the user interface is to display an
image (e.g., album cover or artist photo) alongside each track when
a user checks its details. This visual enhancement would make the
application more engaging and immersive for users.

2. Filter Option for Viewing Tracks by Artist


In the future, it would be beneficial to allow users to filter tracks by
artist, album, genre, or other metadata attributes. Filtering tracks by
artist or other attributes would significantly improve the user
experience, allowing users to quickly find the content they’re
interested in without manually searching or scrolling through the
entire list of tracks.

3. Store Track Library Data Externally in a CSV File


Storing the track library data in a CSV file would allow for data
persistence between sessions, making the app more practical for
long-term use. Additionally, the CSV file could serve as a backup or
allow for easy importing/exporting of track data.

4. Implement Additional Library_Item Subclasses


Introducing subclasses like “Library_Item_Album” and
“Library_Item_Artist” would make the data model more flexible and
capable of handling complex music data. This would also allow the
app to scale better as it manages a variety of media types, providing
richer features such as album views, artist discographies, and more.

5. Dynamic Resizing:
Enable the application to adapt dynamically to different screen sizes
and resolutions for improved usability.
3. Reflection

a) What did I achieve with this element of learning? Which were the most difficult
parts, and why were they difficult for me? Which were the most straightforward
parts, and why did I find these easy?

Through this project, I have gained significant insights into software


development, particularly in the context of building an interactive application with
a graphical user interface (GUI). The primary achievement has been the
successful implementation of a Music Library Manager using Python’s Tkinter
library. I have learned how to structure a GUI-based application with multiple tabs
for different functionalities, including viewing, searching, and updating track data.
Additionally, I have become more adept at working with external data sources
and integrating them with the application, such as managing track lists and
ratings using a simulated track library.

The most difficult part of this project was integrating data validation and error
handling, especially in the viewing and updating tracks functionalities. I had to
ensure that the user inputs, such as track numbers and ratings, were properly
validated before they could be processed. For instance, when a user inputs a
non-numeric value or a track number that doesn’t exist, the program must
respond with an appropriate error message. Handling these cases required more
care to prevent the program from crashing or displaying incorrect information. It
involved writing functions to check for these edge cases, which often required
debugging and testing to ensure that the error handling worked as expected.

On the other hand, the most straightforward part of the project was creating the
layout and the basic functionality of the GUI. Tkinter provided a simple way to
design the interface and arrange the widgets, making it relatively easy to build
the initial structure of the application. This part was simple because Tkinter's
widgets (such as buttons, labels, and entry fields) were intuitive to use, and there
were plenty of resources available to guide me through common tasks like
adding tabs, setting up buttons, and creating text boxes.
[Link]:
1. A. The commented version of the code that you worked on for Stage
1.
(This might be hard to see, I included the whole project in the folder)
import tkinter as tk # Import the tkinter library for creating GUI applications.
import [Link] as tkst # Import the ScrolledText widget from tkinter for creating text
areas with scrollbars.

import track_library as lib # Import the track_library module, which contains the library of
tracks.
import font_manager as fonts # Import the font_manager module to configure font settings.

# Helper function to set text in a text area


def set_text(text_area, content):
# This function deletes all existing text in the text area and inserts the provided content.
text_area.delete("1.0", [Link]) # Clears any existing text in the text area.
text_area.insert(1.0, content) # Inserts the new content into the text area.

# TrackViewer class represents the window where tracks can be viewed and interacted with
class TrackViewer():
def __init__(self, window):
# This initializes the TrackViewer window and sets up its components.
[Link]("750x350") # Sets the size of the window (750x350 pixels).
[Link]("View Tracks") # Sets the title of the window.

# Creates a button to list all tracks in the library and binds it to the method
list_tracks_clicked.
list_tracks_btn = [Link](window, text="List All Tracks",
command=self.list_tracks_clicked)
list_tracks_btn.grid(row=0, column=0, padx=10, pady=10) # Places the button in the
window grid.
# Label asking for track number input
enter_lbl = [Link](window, text="Enter Track Number")
enter_lbl.grid(row=0, column=1, padx=10, pady=10) # Places the label next to the button
in the grid.

# Creates an entry field for the user to input a track number


self.input_txt = [Link](window, width=3)
self.input_txt.grid(row=0, column=2, padx=10, pady=10) # Places the input field in the
window.

# Button to view details of the track with the entered track number, calls
view_tracks_clicked method.
check_track_btn = [Link](window, text="View Track",
command=self.view_tracks_clicked)
check_track_btn.grid(row=0, column=3, padx=10, pady=10) # Places the button next to
the entry field.

# ScrolledText widget to display a list of all tracks


self.list_txt = [Link](window, width=48, height=12, wrap="none")
self.list_txt.grid(row=1, column=0, columnspan=3, sticky="W", padx=10, pady=10) #
Places the scrolled text box in the window.

# Text widget to display individual track details when a track is viewed.


self.track_txt = [Link](window, width=24, height=4, wrap="none")
self.track_txt.grid(row=1, column=3, sticky="NW", padx=10, pady=10) # Places the text
box to the right.

# Status label that shows status messages when buttons are clicked.
self.status_lbl = [Link](window, text="", font=("Helvetica", 10))
self.status_lbl.grid(row=2, column=0, columnspan=4, sticky="W", padx=10, pady=10) #
Status label at the bottom of the window.
# Automatically call the list_tracks_clicked method to display the list of tracks when the
window is created.
self.list_tracks_clicked()

# Method to handle the "View Track" button click


def view_tracks_clicked(self):
key = self.input_txt.get() # Retrieves the track number entered by the user.
name = lib.get_name(key) # Fetches the track name using the track number from
the library.

if name is not None: # If the track is found in the library.


artist = lib.get_artist(key) # Fetches the artist name from the library.
rating = lib.get_rating(key) # Fetches the rating of the track.
play_count = lib.get_play_count(key) # Fetches the play count of the track.

# Formats the track details into a readable string.


track_details = f"{name}\n{artist}\nrating: {rating}\nplays: {play_count}"
set_text(self.track_txt, track_details) # Updates the track details display with the
formatted string.
else:
# If the track was not found, display an error message.
set_text(self.track_txt, f"Track {key} not found")

# Updates the status label to indicate that the "View Track" button was clicked.
self.status_lbl.configure(text="View Track button was clicked!")
if not [Link](): # Check if input is numeric
set_text(self.track_txt, "Invalid input. Please enter a numeric track number (e.g., '04').")
self.status_lbl.configure(text="Invalid input detected.")
return

# Method to handle the "List All Tracks" button click


def list_tracks_clicked(self):
track_list = lib.list_all() # Calls the list_all function from the library to get a list of all tracks.
set_text(self.list_txt, track_list) # Updates the list display with the full list of tracks.

# Updates the status label to indicate that the "List Tracks" button was clicked.
self.status_lbl.configure(text="List Tracks button was clicked!")

# The following code will only execute if this script is run as a standalone program (not when
imported as a module).
if __name__ == "__main__":
window = [Link]() # Creates the main tkinter window.
[Link]() # Configures the fonts using the font_manager module.
TrackViewer(window) # Creates an instance of the TrackViewer class to initialize the GUI.
[Link]() # Starts the Tkinter event loop, keeping the window open and
responsive to user actions.
2. B. Test table and results (updated with any changes you have made
to the code in Stage 5).
Test Input Action Expected Output Actual
ID Output

1 “04” Enter track number Track details for same as


and press "View Shape of You should expected
Track". display with rating output
and play count.

2 “four” Enter track number Error message: same as


and press "View Invalid input. Please expected
Track". enter a numeric track output
number

3 “99” Enter track number Error message: Track same as


and press "View not found. expected
Track". output

4 “Vivaldi” Enter name into Only the tracks with same as


search bar and the name Vivaldi expected
press”Search”. would shows up output

5 “two” for Enter non-numeric Error message: same as


rating rating. Invalid input. Please expected
enter a numeric rating output
between 1 and 5.

6 rating > Enter “9” for rating. Error message: same as


5 Invalid input. Please expected
enter a numeric rating output
between 1 and 5.

You might also like