2015-12-06 3 views
0

Я написал следующую программу командной строки, чтобы обеспечить автоматический способ тестирования моего основного скрипта - приложения gui, реализованного в модуле (gui.py), который Я импортирую в CLI «комплект тестирования».Параметры в скрипте CLI в Python не работают

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) 

Для -t аргумента, с 1 по 3 будет производить желаемые результаты, который является другим графиком для каждой задачу идентификатора, реализуются через панда и библиотеки matplot. Но когда я предоставляю необходимые аргументы (например, путь к файлу для -t = 4) вместе с опцией -t для остальных доступных опций (с 4 по 6), никакого эффекта нет. Что должно произойти, так это отображение списка в новом окне. Ниже приведен код для класса View, который я импортирую, и методы, которые должны выполнять требуемые задачи.

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) 

Следует также упомянуть, что эти методы работают должным образом через графический интерфейс пользователя.

Любая помощь будет очень признательна!

+1

Похоже, что вам не хватает основного магазина tkinter. – rfkortekaas

+0

Yeap, в этом была проблема. Дайте ответ, и я его выберу :) – AutomEng

ответ

1

Вам нужно позвонить в mainlop tkinter, чтобы окна отображали op.

Смежные вопросы