Reputation: 455
I have written the following command line program in order to provide for an automated way to test my main script - a gui application, implemented in a module (gui.py), which I import in the CLI "testing suite".
import argparse
from data import Document
from gui import View
parser = argparse.ArgumentParser()
parser.add_argument("-f", type=str, help="Path of the JSON file to be used.")
parser.add_argument("-u", type=str, help="User UUID.")
parser.add_argument("-d", type=str, help="Document UUID.")
parser.add_argument("-t", type=int, help="Task ID. ID's range from 2 to 5, as per coursework instructions.")
args = parser.parse_args()
doc = Document(args.f)
view = View()
if args.t == 1:
view.display_views_by_country(doc, args.d)
elif args.t == 2:
view.display_views_by_cnt(doc, args.d)
elif args.t == 3:
view.display_browser_hist(doc)
elif args.t == 4:
view.top10_window(doc)
elif args.t == 5:
view.also_likes_most_viewers_window(doc, args.u, args.d)
elif args.t == 6:
view.also_likes_timeread_window(doc, args.u, args.d)
For the -t argument, 1 through 3 will produce the desired outputs which is a different graph for each task id, being implemented through the pandas and matplot libraries. But when I provide the necessary arguments (for example the file path for -t = 4) along with the -t option for the rest of the available options (4 through 6) there is no effect. What should be happening is the displaying of a list on a new window. Below is the code for the View class which I am importing and the methods that should be implementing the desired tasks.
class View(tk.Frame):
def __init__(self, *args, **kwargs):
"""Constructor of the Frame widget, representing the initial window.
Main objective is to add the widgets through which the user will initialize
the application by entering the path of the json file to be processed.
:param args: Parent widget
:param kwargs: Config options
:return: None
"""
tk.Frame.__init__(self)
self.master.title("Document Analytics")
self.master.rowconfigure(0, weight=1)
self.master.columnconfigure(0, weight=1)
self.grid(sticky=W+E+N+S)
self.text_filepath = tk.Text(self, width=45, height=1)
self.text_filepath.grid(sticky=W+E+N+S)
self.text_filepath.insert(tk.INSERT, "Insert the path of the file to be processed")
self.text_filepath.config(state=tk.DISABLED)
self.entry_filepath = tk.Entry(self, width=20)
self.entry_filepath.grid(sticky=W+E+N+S, row=0, column=1, columnspan=3)
self.button_filepath = tk.Button(self, text="Initialize", command=self.new_window, width=25)
self.button_filepath.grid(row=1, column=1, sticky=W+E+N+S)
self.rowconfigure(1, weight=1)
self.columnconfigure(1, weight=1)
def top10_window(self, data):
"""Method which displays a list of the top 10 readers
based on reading time.
:param data: Reference to a Document object.
:return: None
"""
window = tk.Toplevel(self)
list_box = tk.Listbox(window)
list_box.pack()
for item in data.top10_readers():
list_box.insert(tk.END, item)
def also_likes_most_viewers_window(self, data, visitor_id, doc_id):
"""Method which implements the 'also likes' functionality.
Creates a new window which displays a list of top 10 relevant documents.
Sorting is based on number of viewers of each document document.
:param data: Reference to a Document object.
:param visitor_id: The visitor UUID.
:param doc_id: The document UUID.
:return: None
"""
window = tk.Toplevel(self)
list_box = tk.Listbox(window)
list_box.pack()
for item in data.also_likes_most_viewers(visitor_id, doc_id):
list_box.insert(tk.END, item)
def also_likes_timeread_window(self, data, visitor_id, doc_id):
"""Method which implements the 'also likes' functionality.
Creates a new window which displays a list of top 10 relevant documents.
Sorting is based on reading time spent on each document.
:param data: Reference to a Document object.
:param visitor_id: The visitor UUID.
:param doc_id: The document UUID.
:return: None
"""
window = tk.Toplevel(self)
list_box = tk.Listbox(window)
list_box.pack()
for item in data.also_likes_reader_profile(visitor_id, doc_id):
list_box.insert(tk.END, item)
I should also mention that these methods work as expected through the GUI.
Any help will be much appreciated!
Upvotes: 0
Views: 42
Reputation: 6484
You need to call the tkinter mainloop in order to let the windows show op.
Upvotes: 1