2022-08-30 12:28:59 +02:00
|
|
|
import tkinter as tk
|
2022-08-31 23:53:24 +02:00
|
|
|
import tkinter.font as tfont
|
2022-08-30 12:28:59 +02:00
|
|
|
from tkinter import ttk
|
2022-08-31 23:53:24 +02:00
|
|
|
from tkinter import scrolledtext as tst
|
2022-08-30 21:12:04 +02:00
|
|
|
from controller.HomeController import HomeController
|
2022-09-05 23:13:38 +02:00
|
|
|
from view.MainWindow import MainWindow
|
|
|
|
|
2022-08-30 12:28:59 +02:00
|
|
|
|
2022-08-30 21:12:04 +02:00
|
|
|
class HomeView(ttk.Frame):
|
|
|
|
"""
|
2022-09-05 23:13:38 +02:00
|
|
|
View - HomeWindow
|
2022-08-30 21:12:04 +02:00
|
|
|
|
2022-09-05 23:13:38 +02:00
|
|
|
This view allows you to start the scraping/downloading process,
|
|
|
|
as well as to display the progress of the process.
|
2022-08-30 21:12:04 +02:00
|
|
|
|
|
|
|
@author Jérémi Nihart / EndMove
|
|
|
|
@link https://git.endmove.eu/EndMove/WebPicDownloader
|
2022-09-05 23:13:38 +02:00
|
|
|
@version 1.0.1
|
|
|
|
@since 2022-09-05
|
2022-08-30 21:12:04 +02:00
|
|
|
"""
|
|
|
|
# Variables
|
|
|
|
__controller: HomeController = None
|
|
|
|
|
|
|
|
# Constructor
|
2022-09-05 23:13:38 +02:00
|
|
|
def __init__(self, parent: MainWindow, controller: HomeController):
|
2022-09-04 17:38:45 +02:00
|
|
|
"""
|
|
|
|
Constructor
|
2022-08-30 12:28:59 +02:00
|
|
|
|
2022-09-04 17:38:45 +02:00
|
|
|
* :parent: -> The main windows container.
|
|
|
|
* :controller: -> The view controller
|
|
|
|
"""
|
|
|
|
super().__init__(parent)
|
|
|
|
|
|
|
|
# Init view
|
|
|
|
self.__init_content()
|
2022-09-05 23:13:38 +02:00
|
|
|
|
|
|
|
# Save and setup controller
|
|
|
|
self.__controller = controller
|
|
|
|
controller.set_view(self)
|
2022-08-31 12:07:43 +02:00
|
|
|
|
2022-09-05 23:13:38 +02:00
|
|
|
# START Internal functions
|
2022-08-31 12:07:43 +02:00
|
|
|
def __init_content(self) -> None:
|
|
|
|
"""
|
|
|
|
[internal function]
|
|
|
|
=> Initialize the view content.
|
|
|
|
"""
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
self.columnconfigure(1, weight=3)
|
2022-08-30 12:28:59 +02:00
|
|
|
|
2022-08-31 12:07:43 +02:00
|
|
|
# Website link
|
|
|
|
self.web_label = ttk.Label(self, text="Website URL:")
|
2022-08-31 21:05:20 +02:00
|
|
|
self.web_label.grid(row=0, column=0, sticky=tk.W, padx=5, pady=5)
|
2022-08-31 12:07:43 +02:00
|
|
|
self.web_entry = ttk.Entry(self, width=50) # show="-"
|
2022-08-31 21:05:20 +02:00
|
|
|
self.web_entry.grid(row=0, column=1, sticky=tk.E, padx=5, pady=5, ipadx=2, ipady=2)
|
2022-08-31 12:07:43 +02:00
|
|
|
|
|
|
|
# Download name
|
|
|
|
self.name_label = ttk.Label(self, text="Download Name:")
|
2022-08-31 21:05:20 +02:00
|
|
|
self.name_label.grid(row=1, column=0, sticky=tk.W, padx=5, pady=5)
|
2022-08-31 12:07:43 +02:00
|
|
|
self.name_entry = ttk.Entry(self, width=50)
|
2022-08-31 21:05:20 +02:00
|
|
|
self.name_entry.grid(row=1, column=1, sticky=tk.E, padx=5, pady=5, ipadx=2, ipady=2)
|
2022-08-31 12:07:43 +02:00
|
|
|
|
|
|
|
# Logs area
|
2022-08-31 23:53:24 +02:00
|
|
|
log_textarea_font = tfont.Font(size=10)
|
|
|
|
self.log_textarea = tst.ScrolledText(self, font=log_textarea_font, wrap=tk.WORD, state=tk.DISABLED, width=40, height=8)#, font=("Times New Roman", 15))
|
2022-08-31 21:05:20 +02:00
|
|
|
self.log_textarea.grid(row=3, column=0, columnspan=2, sticky=tk.EW, pady=10, padx=10)
|
|
|
|
|
2022-09-05 23:13:38 +02:00
|
|
|
# Message state
|
2022-08-31 21:05:20 +02:00
|
|
|
self.message_label = ttk.Label(self, text='message label')
|
2022-08-31 12:07:43 +02:00
|
|
|
|
|
|
|
# Download button
|
2022-08-31 21:05:20 +02:00
|
|
|
self.download_button = ttk.Button(self, text="Start downloading", command=self.__event_button_download)
|
|
|
|
self.download_button.grid(row=5, column=1, sticky=tk.E, padx=5, pady=5, ipadx=5, ipady=2)
|
|
|
|
|
|
|
|
def __event_button_download(self) -> None:
|
|
|
|
"""
|
|
|
|
[internal function]
|
|
|
|
=> Function called when a download is requested.
|
|
|
|
"""
|
|
|
|
self.__controller.on_download_requested(self.web_entry.get(), self.name_entry.get())
|
2022-09-05 23:13:38 +02:00
|
|
|
# END Internal functions
|
2022-08-31 12:07:43 +02:00
|
|
|
|
|
|
|
# START Controller methods
|
|
|
|
def add_log(self, line: str) -> None:
|
|
|
|
"""
|
|
|
|
[function for controller]
|
2022-09-05 23:13:38 +02:00
|
|
|
=> Add a log in the textarea where the logs are displayed.
|
|
|
|
|
|
|
|
* :line: -> Log message to add.
|
2022-08-31 12:07:43 +02:00
|
|
|
"""
|
2022-08-31 21:05:20 +02:00
|
|
|
self.log_textarea.configure(state=tk.NORMAL)
|
2022-08-31 23:53:24 +02:00
|
|
|
self.log_textarea.insert(tk.END, f"~ {line}\n")
|
2022-09-01 11:47:34 +02:00
|
|
|
self.log_textarea.see(tk.END)
|
2022-08-31 21:05:20 +02:00
|
|
|
self.log_textarea.configure(state=tk.DISABLED)
|
2022-08-31 12:07:43 +02:00
|
|
|
|
2022-08-31 23:53:24 +02:00
|
|
|
def clear_logs(self) -> None:
|
2022-08-31 12:07:43 +02:00
|
|
|
"""
|
|
|
|
[function for controller]
|
2022-09-05 23:13:38 +02:00
|
|
|
=> Clean the textarea where the logs are displayed.
|
2022-08-31 12:07:43 +02:00
|
|
|
"""
|
2022-08-31 23:53:24 +02:00
|
|
|
self.log_textarea.configure(state=tk.NORMAL)
|
2022-09-01 11:47:34 +02:00
|
|
|
self.log_textarea.delete('1.0', tk.END)
|
2022-08-31 23:53:24 +02:00
|
|
|
self.log_textarea.configure(state=tk.DISABLED)
|
2022-08-31 21:05:20 +02:00
|
|
|
|
|
|
|
def show_error_message(self, message) -> None:
|
|
|
|
"""
|
|
|
|
[function for controller]
|
2022-09-05 23:13:38 +02:00
|
|
|
=> Display an error message on the interface.
|
|
|
|
|
|
|
|
* :message: -> Message to display.
|
2022-08-31 21:05:20 +02:00
|
|
|
"""
|
|
|
|
self.message_label.configure(text=message, foreground='red')
|
|
|
|
self.message_label.grid(row=4, column=0, columnspan=2, sticky=tk.NS, padx=2, pady=2)
|
2022-09-05 23:13:38 +02:00
|
|
|
self.message_label.after(25000, self.hide_message)
|
2022-08-31 21:05:20 +02:00
|
|
|
|
|
|
|
def show_success_message(self, message) -> None:
|
|
|
|
"""
|
|
|
|
[function for controller]
|
2022-09-05 23:13:38 +02:00
|
|
|
=> Display a success message on the interface.
|
|
|
|
|
|
|
|
* :message: -> Message to display.
|
2022-08-31 21:05:20 +02:00
|
|
|
"""
|
|
|
|
self.message_label.configure(text=message, foreground='green')
|
|
|
|
self.message_label.grid(row=4, column=0, columnspan=2, sticky=tk.NS, padx=2, pady=2)
|
2022-09-05 23:13:38 +02:00
|
|
|
self.message_label.after(25000, self.hide_message)
|
2022-08-31 12:07:43 +02:00
|
|
|
|
2022-08-31 21:05:20 +02:00
|
|
|
def hide_message(self) -> None:
|
|
|
|
"""
|
2022-09-05 23:13:38 +02:00
|
|
|
[function for controller and this view]
|
|
|
|
=> Hide the message on the interface.
|
2022-08-31 21:05:20 +02:00
|
|
|
"""
|
|
|
|
self.message_label.grid_forget()
|
2022-09-05 23:13:38 +02:00
|
|
|
|
|
|
|
def set_interface_state(self, disable: bool) -> None:
|
|
|
|
"""
|
|
|
|
[function for controller]
|
|
|
|
=> Allows to change the status of the interface with which the user
|
|
|
|
interacts by activating/deactivating it.
|
|
|
|
|
|
|
|
* :disabled: -> True: interface disabled, False: interface enabled.
|
|
|
|
"""
|
|
|
|
state = tk.DISABLED if disable else tk.NORMAL
|
|
|
|
self.web_entry['state'] = state
|
|
|
|
self.name_entry['state'] = state
|
|
|
|
self.download_button['state'] = state
|
2022-08-31 21:05:20 +02:00
|
|
|
# END Controller methods
|