Comp1752 Report
Comp1752 Report
COMP1752
COURSEWORK
TEACHER: AUTHORS:
DOAN DINH HO Vương Quốc Anh: 001340603
04/2024
1
Review
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
2
Table of Contents
1. Introduction:.................................................................................................... 4
2. Design and Development .................................................................................. 4
2.1 Design: ......................................................................................................... 4
2.2 Development ................................................................................................ 7
3. Testing and faults: ........................................................................................... 18
3.1 Uni test: ...................................................................................................... 18
3.2 Manual Test: .............................................................................................. 20
4. Innovation: ...................................................................................................... 23
5. Conclusions, further development and reflection ........................................... 24
5.1 Conclusion ................................................................................................. 24
5.2 Further development .................................................................................. 24
5.3 Reflection ............................................................................................... 24
6. Reference: ....................................................................................................... 25
3
1. Introduction:
-Object-Oriented Programming (OOP) is essential for developers. Key OOP
concepts include classes, objects, attributes, methods, and class templates.
Popular OOP languages include C++, Java, Python, and more. OOP principles
encompass inheritance, encapsulation, abstraction, and polymorphism.
(Chambers. J, 2014)
- This report highlights progress in creating a simulated video player
application, akin to a simplified Windows Media Player. We start with a pre-
existing code template in the PyCharm project ‘VideoPlayer.’ The
‘video_player.py’ file serves as the primary element. The report will detail the
step-by-step procedure, design, functionality, and overall framework of the
application.
video_player.py:
This is what the video player GUI looks like when run:
Figure 1: GUI
-Currently, the two buttons labeled "Create Video List" and "Update Videos"
are non-functional. The aim of my work today is to design and implement the
necessary code to enable the proper functioning of these buttons. As such, I will
be focused on the task of ensuring that both buttons are fully operational.
4
This is my first design of two buttons I draw using draw.io.com.:
Play video button first design:
- In the design, users input a number, click ‘Add to Playlist’ to add a video,
‘Play All’ to play videos, and ‘Remove’ to delete unwanted videos from the
playlist.
5
Update video button first design:
-In this particular design, it is requested that the user enters the video number in
the designated empty space situated on the left side of the screen. Following
this, the rating - which is a numerical value - must be imported into the system.
The final step in the process involves the clicking of the "update" button, which
will add the rating to the video in question.
6
2.2 Development
Play video button:
7
Figure 5: playlist
8
+ A treeview widget (`info_box`) is created with columns for "name",
"director", "rating", and "Play count". Column headings are also set up.
These widgets are positioned in the window using the `.place()` method.
Overall, this code sets up a graphical user interface (GUI) with widgets such as
labels, entry fields, buttons, and treeview boxes to manage video playlists in a
Python tkinter module application.
The code presented below defines a `get_one_item` method within a class that
takes a single parameter, `self`.
The method attempts to obtain the ID of the first selected item from an
`info_box` widget. If there is no selected item available (which results in an
IndexError), a warning message box will be displayed.
However, if there is a selected item, the method will retrieve the text of the
selected item and iterate through a list named `play_list`. If the text matches any
video's key in the playlist, the `play()` method on that video object will be
called, and the loop will be exited. Finally, the method calls another method
named `display_tree()` before returning.
9
Figure 7: add video
The present code section carries out several functions related to adding a new
video to a playlist. Firstly, the method retrieves the text entered by the user from
an Entry widget, which corresponds to a video number. Subsequently, it verifies
if the video is already present in the playlist by calling a method, not shown
here, that searches the playlist for a video with the number entered by the user.
If the video is already present in the playlist, an error message box is displayed
through the `messagebox.showinfo()` method.
In case the video is not present in the playlist, the method calls a function from
a library to retrieve the rating of the video based on its number. If the rating is -
1, the number is deemed invalid, and an error message box is displayed.
If the video number is both valid and absent from the playlist, a new `PlayList`
object is created, likely representing a new video entry with a name, director,
rating, and video number. The object is added to the playlist using the
`self.play_list.append(i)` method. Additionally, the method inserts the new
video details into a Treeview widget using `self.info_box.insert()`, thereby
displaying the video in the GUI.
Overall, this method adds a new video to the playlist, updates both the internal
playlist data structure and the GUI display, and ensures that the playlist does not
contain duplicates.
10
Figure 8: Find, Play, Pop out
Figure 9: Tree
The first method, find_video(self, list, value), determines whether a video with
a given value (video number) exists in the playlist (list). The method iterates
11
through each video in the playlist and compares the video key (presumably the
video number) with the input value. If a matching video is found, the method
returns True, indicating that the video exists in the playlist. In cases where there
is no match, the method returns False. For instance, the method can be called as
follows: if self.find_video(self.play_list, txt1).
The second function, play_the_list(self), increases the play count for all videos
in the playlist. The method iterates through each video in the playlist
(self.play_list) and calls the play() method on each video. After updating the
play counts, the method calls self.display_tree() to refresh the display in the
GUI.
The third method, pop_out(self), resets the entire playlist. The method iterates
through each video in the playlist and calls the remove_item() method (not
shown) on each video. The method then clears the self.play_list by setting it to
an empty list. Finally, the method calls self.display_tree() to update the display
in the GUI.
The fourth function, display_tree(self), updates the display of the playlist in the
Treeview widget (self.info_box). The method first deletes all existing items
from the Treeview using self.info_box.delete(item). It then iterates through each
video in the playlist (self.play_list) and inserts a new row into the Treeview
with the video details (name, director, rating, and play count).
The final block of code, if __name__ == "__main__", ensures that the following
lines are executed only when the script is run as a standalone program (not
when imported as a module). The code initializes a tk.Tk() object, which is the
main application window, configures the fonts (presumably defined elsewhere
in the code), creates an instance of the playlist class, passing the root (main
window) as an argument, and starts the main event loop using root.mainloop().
This keeps the GUI responsive by handling button presses and other events.
It is important to note that this code snippet only defines methods for managing
a playlist. The actual implementation of PlayList and its methods (play(),
12
remove_item(), etc.) is not shown here, but is necessary for the complete
functionality of the application.
Update button:
The following code includes a set of import statements that are crucial for
making a Graphical User Interface (GUI) application using the Python tkinter
library.
The first import statement imports the tkinter library and assigns it an alias (tk).
It offers various widgets like buttons, labels, and entry fields that help in
creating GUIs.
The second import statement imports the messagebox module from the tkinter
library. This module provides a range of functions to display different types of
message boxes, such as informational, warning, and error messages, in a GUI
application.
The third import statement imports the ttk (themed tkinter) module from the
tkinter library. This module provides themed widgets with a modern and
consistent appearance that is superior to standard tkinter widgets.
The fourth import statement imports a custom module named video_library and
assigns it an alias (lib). This module most likely contains functions or classes
for managing video data and retrieving video details based on video numbers.
13
The fifth import statement imports another custom module named font_manager
and assigns it an alias (fonts). This module handles font-related tasks such as
configuring fonts for a GUI application.
In summary, these import statements set up the necessary libraries and custom
modules for building a GUI application using tkinter. With these libraries, you
can create windows, buttons, labels, and other GUI components, display
message boxes, and use themed widgets.
The following code exemplifies how to develop a graphical user interface (GUI)
aimed at updating video ratings. The window is set to be 1080 pixels wide and
450 pixels tall, with a title of "Update videos". An entry widget is created for
text input, with a width of 10, and positioned at coordinates (350, 15) within the
window. Additionally, a label is created with the text "Enter video's number:".
A button with the text "Update video's rating" is also included, which invokes
the self.get_data method when clicked.
14
Moreover, a Treeview widget is instantiated with columns for the video’s
number, name, director, and rating, which is conveniently used to showcase a
table of content. It is worth noticing that the self.get_data method is not shown
in the code snippet, though it is presumably defined elsewhere in the class. This
method contains the logic for updating the video’s rating based on the user’s
input.
This GUI enables the user to enter a video’s number, enter a new rating for the
video, and update the rating. Additionally, it displays a list of videos with their
details. It is important to note that the actual functionality for updating the
video’s rating in the backend (such as a database or a list) would be
implemented in the self.get_data method.
The variables, self.var1 and self.var2, are temporarily assigned to store the
user's input from the entry widgets, namely get_text1 and get_text2. The tuple,
star, holds strings of valid ratings, ranging from "1" to "5". The function call,
lib.get_name(self.var1), retrieves the video's name with the number stored in
self.var1 from the lib module, which is presumably video_library. In case the
function returns None, it suggests that the video number is not valid. An error
message box is displayed with the function, messagebox.showinfo("Error",
"Video does not exist"), if the video number is invalid.
The elif statement checks whether the rating entered (self.var2) is one of the
valid options in the tuple, star. If the rating entered is not within the valid range,
an error message box is displayed using the function,
messagebox.showinfo("Error", "Rating must be from 1 to 5").
15
If both checks pass, the self.add_to_tree() method is invoked, which probably
updates the Treeview widget with the new rating for the video. Although this
method is not defined in the provided code, it ensures that the user enters valid
video number and rating before attempting to update the video's information in
the GUI.
The method calls a function from the `lib` module, presumably `video_library`,
to modify the rating of the video identified by the video number stored in
`self.var1`. The new rating is converted to an integer using `int(self.var2)`.
16
which contains the video number. `values=(lib.get_name(self.var1),
lib.get_director(self.var1), lib.get_rating(self.var1), self.var1)` sets the values
for the remaining columns: name, director, and rating, respectively.
The `if __name__ == "__main__":` conditional block ensures that the lines that
follow are only executed when the script is run as a standalone program, not
when imported as a module. The code then creates a `tk.Tk()` object,
representing the primary application window, configures fonts (presumably
defined elsewhere in the code), creates an instance of the `UpdateVideos` class,
passing the window (main window) as an argument, and starts the main event
loop using `window.mainloop()`, which keeps the GUI responsive by handling
button presses and other events.
In summary, the `add_to_tree` method updates the video rating, inserts the
updated video details into the `Treeview` widget, and maintains the GUI's
responsiveness when the script runs.
17
3. Testing and faults:
- Both manual and unit testing techniques are essential in software development.
Manual testing focuses on user interaction, while unit testing verifies code at a
granular level, detects defects early, and ensures quality. Manual testing is
performed manually to validate that the software meets specific requirements,
while unit testing tests individual units of code. Combining both methods saves
time and resources, improves software quality, and ultimately enhances
customer satisfaction.( A. Bacchell, P. Ciancari, D. Rossi, 2008)
3.1 Uni test:
This code is a test code for two classes: `LibraryItem` and `PlayList`.
18
The `test_LibraryItem` function creates an instance of the `LibraryItem` class
with specific values for its attributes. The function then asserts various
conditions to confirm the correct creation of the instance. To temporarily
disable capturing of standard output, it employs the `capsys.disabled()` method.
Finally, the function prints a success message indicating the successful
completion of the test.
Overall, these functions provide unit tests to verify that instances of both classes
are created correctly and their methods return expected results. Their purpose is
to ensure the functionality of `LibraryItem` and `PlayList` classes through
rigorous testing.
19
3.2 Manual Test:
20
No Sample Sample Expected Actual Output Result
input Action Output
1 Nothing click Display an Pass
“Add toerror
playlist”
message
Button.with
content
“Invalid
video’s
number”
2 Enter click Display a Pass
“2” “Add to row at the
To playlist” with
“Enter Button attributes
Video “Video’s
Number” number: 2
Entry Name: To
Kill a
Mockingbird
Director:
Harper Lee
rating: 4
plays: 0”
In the
treeview
3 Enter click Display an Pass
“3” “Add to error
To playlist” message
“Enter Button with
Video content
Number” “Video
Entry already
exists”
4 Enter Dobble Play all Pass
“3; 4; 2” click videos in
To “Play current
“Enter all playlist.
Video videos” Increased
play count
Number” Button of the list by
Entry 2 each click
increased
by 1
5 Nothing click Display an Pass
“Play error
one message
video. with content
Button “Please
select a
video”
21
6 Select click Increase
number” the number 2 Pass
2” and “Play play count
then one by 1
video”
22
4. Innovation:
-Innovations in software refer to proposed features that enhance quality and user
experience. By incorporating innovative elements, companies can gain a
competitive edge and improve user satisfaction
-The incorporation of a CSV file as a database in the current system has been
deemed a more adaptable solution, and as such, I have implemented it as a new
feature. This modification enhances the system's flexibility and is expected to
improve its overall efficiency.
23
5. Conclusions, further development and reflection
5.1 Conclusion
- The application meets all criteria with a user-friendly interface, organized
playlists, and video rating features. It includes unique functions recommended
by academic sources, though logic errors and hardware limitations may pose
challenges.
5.2 Further development
-A three-month extension would significantly reduce errors and enhance the
report’s quality. It would allow us to add a GUI and a search tool for data
filtering, and consider cloud storage for efficient data management.
5.3 Reflection
- The course expanded my knowledge beyond single-file programming to
project management and coding clarity, with a focus on optimizing code
readability and team communication. The in-depth study of Object-Oriented
Programming (OOP) was especially beneficial.
24
6. Reference:
Chambers. J (2014). OBJECT-ORIENTED PROGRAMMING IN THE BETA
PROGRAMMING LANGUAGE.
Available at: https://projecteuclid.org/journals/statistical-science/volume-
29/issue-2/Object-Oriented-Programming-Functional-Programming-and-
R/10.1214/13-STS452.pdf.
Bacchell, P. Ciancari, D. Rossi (2008). On the effectiveness of manual and
automatic unit test generation.
Available at: http://sback.it/publications/icsea2008.pdf.
25