This repository has been archived on 2023-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
WebPicDownloader/view/HomeView.py

118 lines
4.0 KiB
Python

import tkinter as tk
import tkinter.font as tfont
from tkinter import ttk
from tkinter import scrolledtext as tst
from controller.Frames import Frames
from controller.HomeController import HomeController
class HomeView(ttk.Frame):
"""
View - MainWindow
dec...
@author Jérémi Nihart / EndMove
@link https://git.endmove.eu/EndMove/WebPicDownloader
@version 1.0.0
@since 2022-08-30
"""
# Variables
__controller: HomeController = None
# Constructor
def __init__(self, parent, controller: HomeController):
super().__init__(parent)
# Init view
self.__init_content()
# Save and setup main controller
self.__controller = controller
controller.set_view(self)
# START Internal function
def __init_content(self) -> None:
"""
[internal function]
=> Initialize the view content.
"""
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=3)
# Website link
self.web_label = ttk.Label(self, text="Website URL:")
self.web_label.grid(row=0, column=0, sticky=tk.W, padx=5, pady=5)
self.web_entry = ttk.Entry(self, width=50) # show="-"
self.web_entry.grid(row=0, column=1, sticky=tk.E, padx=5, pady=5, ipadx=2, ipady=2)
# Download name
self.name_label = ttk.Label(self, text="Download Name:")
self.name_label.grid(row=1, column=0, sticky=tk.W, padx=5, pady=5)
self.name_entry = ttk.Entry(self, width=50)
self.name_entry.grid(row=1, column=1, sticky=tk.E, padx=5, pady=5, ipadx=2, ipady=2)
# Logs area
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))
self.log_textarea.grid(row=3, column=0, columnspan=2, sticky=tk.EW, pady=10, padx=10)
self.message_label = ttk.Label(self, text='message label')
# Download button
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())
# END Internal function
# START Controller methods
def add_log(self, line: str) -> None:
"""
[function for controller]
TODO desc
"""
self.log_textarea.configure(state=tk.NORMAL)
self.log_textarea.insert(tk.END, f"~ {line}\n")
self.log_textarea.see(tk.END)
self.log_textarea.configure(state=tk.DISABLED)
def clear_logs(self) -> None:
"""
[function for controller]
TODO desc
"""
self.log_textarea.configure(state=tk.NORMAL)
self.log_textarea.delete('1.0', tk.END)
self.log_textarea.configure(state=tk.DISABLED)
def show_error_message(self, message) -> None:
"""
[function for controller]
TODO desc
"""
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)
self.message_label.after(30000, self.hide_message)
def show_success_message(self, message) -> None:
"""
[function for controller]
TODO desc
"""
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)
self.message_label.after(30000, self.hide_message)
def hide_message(self) -> None:
"""
[function for controller]
TODO desc
"""
self.message_label.grid_forget()
# END Controller methods