예제 #1
0
    def __init__(self, parent, controller, **kwargs):
        tk.Frame.__init__(self, parent, **kwargs)
        self.controller = controller
        self.configure(bg=theme.background_color)

        self.grid_columnconfigure(0, weight=1)

        # top_navbar
        top_frame = tk.Frame(self)
        top_frame.configure(bg=theme.background_color_accent)
        top_frame.grid(sticky="ew")
        # top_frame.pack_propagate(False)

        top_frame.grid_columnconfigure(0, weight=1)
        top_frame.grid_columnconfigure(1, weight=1)
        top_frame.grid_columnconfigure(2, weight=1)
        top_frame.grid_rowconfigure(0, minsize=100, weight=1)

        # top_navbar common
        download_button = common.Button(
            top_frame,
            command=lambda: controller.set_current_frame("CreateCorpusView"),
            text="Download New Data",
        )
        download_button.configure(padx=10, pady=10)

        create_report_button = common.Button(
            top_frame,
            command=lambda: controller.set_current_frame("CreateReportView"),
            text="Create New Report",
        )
        create_report_button.configure(padx=10, pady=10)

        lexicon_button = common.Button(
            top_frame,
            command=lambda: controller.set_current_frame("CreateLexiconView"),
            text="Create New Lexicon",
        )
        lexicon_button.configure(padx=10, pady=10)

        top_frame.grid(row=0, column=0, columnspan=1)
        download_button.grid(row=0, column=0)
        create_report_button.grid(row=0, column=1)
        lexicon_button.grid(row=0, column=2)

        welcome_header = common.Label(self,
                                      text="Welcome!",
                                      justify=tk.LEFT,
                                      size=20)
        welcome_header.grid(column=0, row=1)

        welcome_message = common.Label(
            self,
            text=
            "To get started, select 'Download New Data' or 'Create New Lexicon'.",
            justify=tk.LEFT,
            size=12,
        )
        welcome_message.grid(column=0, row=2)
예제 #2
0
    def update_dashboard(self, _):
        current_report = self.controller.current_report.get()

        frame = self.content.scrollable_frame

        for widget in frame.winfo_children():
            widget.destroy()

        if current_report is None:
            self.report = None
            return

        print("report updated, report is", current_report)

        self.report = self.controller.reports.get()[current_report]

        common.Label(
            frame,
            text=self.report.name,
            justify=tk.LEFT,
            size=20,
        ).grid(column=0, row=0, sticky="w")

        common.Label(
            frame,
            text=f"Corpus: {self.report.corpus_name}",
            justify=tk.LEFT,
        ).grid(column=0, row=1, sticky="w")

        common.Label(
            frame,
            text=f"Lexica: {', '.join(self.report.lexicon_names)}",
            justify=tk.LEFT,
        ).grid(column=0, row=2, sticky="w")

        self.run_progress = ttk.Progressbar(
            frame, orient=tk.HORIZONTAL, length=100, mode="indeterminate"
        )
        run_report_button = common.Button(
            frame,
            self.run_report,
            "Run Report",
        )
        if self.run_in_progress:
            self.run_progress.grid(column=0, row=3)
        else:
            run_report_button.grid(column=0, row=3)

        if self.report.complete:
            report_results = common.Label(
                frame, text=self.report.get_results(), justify=tk.LEFT
            )
            report_results.grid(column=0, row=4)
예제 #3
0
    def __init__(self, parent, controller, **kwargs):
        tk.Frame.__init__(self, parent, **kwargs)
        self.controller = controller
        self.configure(bg=theme.background_color)
        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        # labels
        self.reddit_label = common.Label(self, text="Download from Reddit")
        self.reddit_label.grid(columnspan=2, sticky="new")
        self.start_label = common.Label(self,
                                        text="Start Date and (optional) Time")
        self.start_label.grid(column=0, row=1, sticky="new")
        self.end_label = common.Label(self,
                                      text="End Date and (optional) Time")
        self.end_label.grid(column=0, row=2, sticky="new")
        self.subs_label = common.Label(self, text="Subreddit(s), one per line")
        self.subs_label.grid(column=0, row=3, sticky="new")
        self.name_label = common.Label(self, text="Corpus Name")
        self.name_label.grid(column=0, row=4, sticky="new")

        self.start_entry = common.Entry(self)
        self.start_entry.grid(column=1, row=1, sticky="new")
        self.end_entry = common.Entry(self)
        self.end_entry.grid(column=1, row=2, sticky="new")
        self.subs_entry = tk.Text(self)
        self.subs_entry.grid(column=1, row=3, sticky="new")
        self.name_entry = common.Entry(self)
        self.name_entry.grid(column=1, row=4, sticky="new")

        # button
        bottom_frame = tk.Frame(self)
        bottom_frame.configure(bg=theme.background_color_accent)
        bottom_frame.grid(column=0, columnspan=2, sticky="nesw")
        bottom_frame.grid_columnconfigure(0, weight=1)
        bottom_frame.grid_columnconfigure(2, weight=1)

        self.download_button = common.Button(
            bottom_frame,
            command=self.download,
            text="Download",
        )
        self.download_button.configure(padx=10, pady=5)
        self.download_button.grid(column=1, row=4, sticky="sew")
        self.download_in_progress = False

        self.download_progress = ttk.Progressbar(bottom_frame,
                                                 orient=tk.HORIZONTAL,
                                                 length=100,
                                                 mode="indeterminate")
예제 #4
0
    def __init__(self, parent: tk.Frame, controller: "App", **kwargs: Any):
        tk.Frame.__init__(self, parent, **kwargs)
        self.controller = controller
        self.configure(bg=theme.background_color)
        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        # labels
        self.corpus_label = common.Label(self, text="Select a Corpus")
        self.corpus_label.grid(column=0, row=0, rowspan=1, sticky="sew")
        self.lexicon_label = common.Label(
            self, text="Select Lexica (click to select multiple)")
        self.lexicon_label.grid(column=1, row=0, rowspan=1, sticky="sew")

        self.corpus_listbox = common.Listbox(self, exportselection=0)
        self.corpus_listbox.grid(column=0, row=1, sticky="nsew")

        self.lexicon_listbox = common.Listbox(self,
                                              selectmode="multiple",
                                              exportselection=0)
        self.lexicon_listbox.grid(column=1, row=1, sticky="nsew")

        self.corpus_names: List[str] = []
        self.lexicon_names: List[str] = []

        self.controller.corpora.subscribe(self.update_corpora)
        self.controller.lexica.subscribe(self.update_lexica)

        # button
        bottom_frame = tk.Frame(self)
        bottom_frame.configure(bg=theme.background_color_accent)
        bottom_frame.grid(column=0, columnspan=2, sticky="nesw")
        bottom_frame.grid_columnconfigure(0, weight=1)
        bottom_frame.grid_columnconfigure(2, weight=1)

        report_name_label = common.Label(bottom_frame, text="Report Name:")
        report_name_label.grid(column=0, row=0)

        self.report_name_entry = common.Entry(bottom_frame)
        self.report_name_entry.grid(column=1, row=0, sticky="ns")

        report_params_button = common.Button(
            bottom_frame,
            command=self.create_report,
            text="Confirm Selections",
        )
        report_params_button.grid(column=2, row=0, sticky="ns")

        report_params_button.configure(padx=10, pady=5)
예제 #5
0
    def __init__(self, parent: tk.Frame, controller: "App", **kwargs: Any):
        tk.Frame.__init__(self, parent, **kwargs)
        self.controller = controller
        self.configure(bg=theme.background_color_accent)
        self.grid_columnconfigure(0, weight=1)
        # self.grid_columnconfigure(1, weight=1)

        # labels
        self.name_label = common.Label(self, text="Name:")
        self.name_label.grid(column=0, row=0, rowspan=1, sticky="w")

        self.name_entry = common.Entry(self)
        self.name_entry.grid(column=0, row=1, sticky="w")

        self.words_label = common.Label(self, text="Words:")
        self.words_label.grid(column=0, row=2, sticky="w")

        self.words_text = common.Text(self)
        self.words_text.grid(column=0, row=3, sticky="ns")
        self.grid_rowconfigure(3, weight=1)

        # button
        bottom_frame = tk.Frame(self)
        bottom_frame.configure(bg=theme.background_color_accent)
        bottom_frame.grid(column=0, columnspan=1, sticky="nesw")
        bottom_frame.grid_columnconfigure(0, weight=1)
        # bottom_frame.grid_columnconfigure(2, weight=1)

        self.confirm_button = common.Button(
            bottom_frame,
            command=self.create_lexicon,
            text="Confirm Selections",
        )
        self.controller.current_lexicon.subscribe(self.update_info)
        self.confirm_button.grid(column=1, row=0, sticky="ns")

        self.confirm_button.configure(padx=10, pady=5)
예제 #6
0
    def __init__(self, parent, controller, **kwargs):
        tk.Frame.__init__(self, parent, **kwargs)
        self.controller = controller
        self.configure(bg=theme.background_color_accent)
        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        # labels
        self.name_label = common.Label(self, text="Name")
        self.name_label.grid(column=0, row=0, rowspan=1, sticky="sew")
        self.words_label = common.Label(self, text="Words")
        self.words_label.grid(column=0, row=1, rowspan=1, sticky="new")

        self.name_listbox = common.Entry(self)
        self.name_listbox.grid(column=1, row=0, sticky="nsew")

        self.words_listbox = tk.Text(self)
        self.words_listbox.grid(column=1, row=1, sticky="nsew")

        # button
        bottom_frame = tk.Frame(self)
        bottom_frame.configure(bg=theme.background_color_accent)
        bottom_frame.grid(column=0, columnspan=2, sticky="nesw")
        bottom_frame.grid_columnconfigure(0, weight=1)
        bottom_frame.grid_columnconfigure(2, weight=1)

        report_params_button = common.Button(
            bottom_frame,
            command=self.create_lexicon,
            text="Confirm Selections",
        )
        self.controller.current_frame.subscribe(self.update_info)
        report_params_button.grid(column=1, row=0, sticky="ns")

        report_params_button.configure(padx=10, pady=5)
예제 #7
0
    def update_dashboard(self, _: Any) -> None:
        """Reset the page when the current report changes"""
        frame = self.content.interior
        frame.grid_columnconfigure(0, weight=1)

        for widget in frame.winfo_children():
            widget.destroy()

        reports = self.controller.reports.get()
        current_report = self.controller.current_report.get()

        if current_report is None or current_report not in reports:
            self.report = None
            self.in_progress_observer.stop()
            self.progress_observer.stop()
            return

        self.report = reports[current_report]
        assert self.report

        self.progress_observer.set_observable(self.report.progress, call=False)
        self.in_progress_observer.set_observable(self.report.in_progress, call=False)

        common.Label(
            frame,
            text=self.report.name,
            justify=tk.LEFT,
            size=20,
        ).grid(column=0, row=0, sticky="w")

        common.Label(
            frame,
            text=f"Corpus: {self.report.corpus_name}",
            justify=tk.LEFT,
        ).grid(column=0, row=1, sticky="w")

        common.Label(
            frame,
            text=f"Lexica: {', '.join(self.report.lexicon_names)}",
            justify=tk.LEFT,
        ).grid(column=0, row=2, sticky="w")

        run_report_button = common.Button(
            frame,
            self.run_report,
            "Run Report",
        )

        if self.report.in_progress.get():
            self.progressbar = ttk.Progressbar(
                frame, orient=tk.HORIZONTAL, length=100, mode="determinate"
            )
            self.progressbar.grid(column=0, row=3)
            return

        run_report_button.grid(column=0, row=4)
        include_body_button = common.Checkbutton(
            frame,
            text="Include body of comments in report",
            variable=self.include_body,
        )
        include_body_button.grid(column=0, row=3)

        if self.report.complete:
            export_button = common.Button(
                frame,
                self.export,
                "Export as TSV",
            )
            export_button.grid(column=0, row=5)

            current_row = 6

            df = self.report.get_results()
            figure = self.make_timeseries_figure(df)
            if figure is not None:
                canvas = FigureCanvasTkAgg(figure, master=frame)
                canvas.draw()

                canvas_widget = canvas.get_tk_widget()
                canvas_widget.grid(column=0, row=current_row, sticky="nesw")
                current_row += 1

            for lexicon_name in self.report.lexicon_names:
                if lexicon_name == DefaultLexicon.name:
                    continue

                df = self.report.get_frequencies()
                figure = self.make_frequency_figure(df, lexicon_name)

                if figure is None:
                    continue

                canvas = FigureCanvasTkAgg(figure, master=frame)
                canvas.draw()
                canvas_widget = canvas.get_tk_widget()
                canvas_widget.grid(column=0, row=current_row, sticky="nesw")
                current_row += 1