Topics: methods, inheritance, extending built-ins, exception, GUI Problem Statement: GUI Small Book Repository Design an

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Topics: methods, inheritance, extending built-ins, exception, GUI Problem Statement: GUI Small Book Repository Design an

Post by answerhappygod »

Topics Methods Inheritance Extending Built Ins Exception Gui Problem Statement Gui Small Book Repository Design An 1
Topics Methods Inheritance Extending Built Ins Exception Gui Problem Statement Gui Small Book Repository Design An 1 (245.66 KiB) Viewed 37 times
Given Class code:
class InvalidItem(Exception): def __str__(self): return 'Item not found!'
class BookList(list): def search(self, key, search_criteria): for book in self: if search_criteria =='t': #search by title ifkey.lower() == book.title.lower(): return book elif search_criteria =='i': #search by isbn if key ==book.isbn: return book elif search_criteria =='k': #search by keyword ifkey.lower() in book.title.lower(): return book return Falseclass Book(object): all_books = BookList() def __init__(self, genre, isbn,title, author,stack): self.genre = genre self.isbn = isbn self.title = title self.author = author self.stack = stack Book.all_books.append(self)
def __str__(self): return 'ISBN #: {}\nTitle: {}\nGenre:{}\nAuthor: {}\nStack :{}\n'.format(\ self.isbn, self.title, self.genre,self.author, self.stack)class Novel(Book): def __init__(self, genre, isbn,title, author, stack,sub_genre): super().__init__(genre, isbn, title,author, stack) self.sub_genre = sub_genre[0] #mystery,historic def __str__(self): return super().__str__() + 'Sub-genre:{}\n'.format(self.sub_genre)class Scifi(Book): def __init__(self, genre, isbn,title, author, stack, movie_night_date): super().__init__(genre, isbn, title,author, stack) if movie_night_date[0] == 'No upcomingmovie': self.date = 'Noupcoming movie' #date of upcoming movie night self.location = 'Nolocation information' else: self.date,self.location = movie_night_date def __str__(self): return super().__str__() + 'Movie date:{} and location:{}'.format(self.date, self.location)
def main(): with open('library.txt') as f: #process input file and creating Book objects for line in f: line = line.split(',') genre,isbn,title,author,stack = line[:5] additional_info =line[5:] #print(additional_info) if genre == 'Novel':#create a novel object n =Novel(genre,isbn,title,author, stack, additional_info) elif genre == 'Scifi':#create a scifi object s =Scifi(genre,isbn,title,author, stack, additional_info)main()
Given Code for GUI File:
from tkinter import *from Emaan_Khan_HA5_class import InvalidItem, BookList, Book,Novel, Scifi
class MyFrame(Frame):
def __init__(self, root): Frame.__init__(self, root) self.root = root self.data = StringVar(self, '-') self.create_components()
def clear_frame(self): #clears the previousframe for widget inself.winfo_children(): widget.destroy()
# Create GUI components def create_components(self): self.clear_frame() #do not remove thisline #your code here #create a welcome label andlayout #create three buttons for search andlayout #set command to appropriatehandler/method #for example: button for seach by titlecommand = self.title_btn_click #so when user clicks on Seach by titlebutton it will execute the title_btn_click method
def title_btn_click(self): self.clear_frame() # do not remove thisline # your code here # create a label Enter title and oneentry for user to enter a title of the book and layout
#next button self.button_next = Button(self, text ="Next", command = self.title_next_handler) self.button_next.grid(row=1,column=0)
#your code here #create and layout a button for mainmenu #so it will take back tocreate_components method #create and layout one label for'Search results appear below #set the self.data to empty stringclear the previous search results #create and layout a label for bookinfo to be displayed and set textvariable to self.data def isbn_btn_click(self): self.clear_frame() self.isbn_label = Label(self, text ='Enter ISBN: ') self.isbn_label.grid(row=0,column=0)
#your code here #follows same layout astitle_btn_click
def keyword_btn_click(self): #your code here #follows same layout astitle_btn_click
# Event handler for next button def title_next_handler(self): key = self.title_entry.get() #to getthe user input search_criteria = 't' #t is the searchcriteria for search method in class file. #your code here to search and displayresults #use a try-except block as HA4 #call search method from the classfile #if book is found then set theself.data to the book information #else raise InvalidItem #a sample except #except InvalidItem as item: #self.data.set(item)
def isbn_next_handler(self): #your code here #same as title_next_handler
def keyword_next_handler(self): #your code here #same as title_next_handler
# Configure frameroot = Tk()root.title("GUILibrary")
# your code here#create MyFrame object#layout the object#call mainloop method
Input file specification (same as HA4):
Novel,ISBN123,Girl with no name,Deborah Rai,S1234,Historic
Novel,ISBN234,Despicable me(1),Jane Joe,S245,Mystery
Novel,ISBN20034,Despicable me(2),Jane Joe,S245,Mystery
Scifi,ISBN4566,Journey to the moon,DeborahRai,S789,10.10.2018,Rm1
Scifi,ISBN0019,The calculating stars,Mary Kowal,S123,No upcomingmovie
Topics: methods, inheritance, extending built-ins, exception, GUI Problem Statement: GUI Small Book Repository Design and implement a simple interactive GUI Book repository for library users. This is an extension of HA4 with a graphical user interface. You can use the HA4 class definition or use the provided one with this assignment. Program Design: 1. This code will need two separate files: class file and then a GUI file. 2. Class File: The class file will be similar as your HA4 and you need to import the class file to GUI file to use the search method. The only changes the class file will have as below: a. No implementation of InvalidOption class - since options are clicked by button, no room for typo. b. No user menu for selection of choice criteria and the search key. This will be a part of GUI. You still need to read from the input file and create objects and store them in the list as before. 3. GUI File: Before starting of the program draw a general outline of how the graphical part looks like. A sample is provided in this spec file. a. Details of the GUI file is given below with sample I/O. Input file specification (same as HA4): Here is a sample example of the input file, (an input file named library.txt is attached with the assignment). Each line contains a record of book. The information is following in order (separated by comma): Novel,ISBN123,Girl with no name, Deborah Rai,S1234,Historic Novel,ISBN234,Despicable me, Jane Joe,S245, Mystery Scifi,ISBN4566,Journey to the moon,Ashley Howler,S789,10.10.2018,Rm1 Scifi, ISBN0019, The calculating stars, Mary Kowal,S123, No upcoming movie Genre,Title, ISBN no, Author(s), Stack no to locate the book in library (starts with S), Additional Information The additional Information depends on the genre of the book: 1. If the genre is novel then the additional information provide sub-genre information and it can be Mystery novel or Historic Novel. 2. Library often arranges a scifi movie night for its customer. If the genre is scifi the additional information provides the upcoming movie night date and location. Some scifi book does not have any upcoming movie date.
Sample I/O 1. Welcome Window: Contains one Welcome label and three buttons for Search GUILibrary Welcome to GUI Library Search by Title Search by ISBN Search by Keyword 2. User click on 'Search By Title' Button and it takes to the following screen. The screen contains Enter Title label, one entry for user input, Next and Main Menu Button and one more label for the results to be displayed. The results label need to use a textvariable to a string variable (StringVar) and this needs to be set when user hits 'Next' button. Hint: Use case on how to build a tip calculator. Enter Title: Next GUILibrary Main Menu Search results appear below: 3. User enters a title and hit next will display the results. User enters a title in the entry and clicking next button will display the results if there is match. Next GUILibrary Enter Title: Girl with no name Main Menu Search results appear below: ISBN #: ISBN123 Title: Girl with no name Genre: Novel Author: Deborah Rai Stack:S1234 Sub-genre: Historic 4. User can go back to main menu and select another option:
GUILibrary Welcome to GUI Library Search by Title Search by ISBN Search by Keyword 5. User selects Search by ISBN and the following window will appear. A similar window as #2 above. Enter ISBN: Next GUILibrary Main Menu Search results appear below: 6. User enters an invalid ISBN, click next and Item not Found Exception is displayed. Clicking on the Main Menu will take user back to #1 window. GUILibrary Enter ISBN: ISBN1234 Next Main Menu Search results appear below: Item not found! 7. User can choose Search by Keyword in the title as below. User enters 'stars' as a keyword and the search results appear below. GUILibrary Enter a keyword in the title: Next stars Main Menu Search results appear below: ISBN #: ISBN0019 Title: The calculating stars Genre: Scifi Author: Mary Kowal Stack:S123 Movie date: No upcoming movie and location:No location information
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply