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

107 lines
3.6 KiB
Python
Raw Normal View History

import tkinter as tk
from tkinter import ttk
2022-08-31 12:07:43 +02:00
from tkinter import scrolledtext as st
2022-08-30 21:12:04 +02:00
from controller.Frames import Frames
from controller.HomeController import HomeController
2022-08-30 21:12:04 +02:00
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)
2022-08-31 12:07:43 +02:00
# Init view
self.__init_content()
# create widgets
# label
2022-08-31 12:07:43 +02:00
# self.label = ttk.Label(self, text='Email:')
# self.label.grid(row=1, column=0)
# email entry
2022-08-31 12:07:43 +02:00
# self.email_var = tk.StringVar()
# self.email_entry = ttk.Entry(self, textvariable=self.email_var, width=30)
# self.email_entry.grid(row=1, column=1, sticky=tk.NSEW)
# save button
2022-08-31 12:07:43 +02:00
# self.save_button = ttk.Button(self, text='Save', command=self.event_btn)
# self.save_button.grid(row=1, column=3, padx=10)
# message
2022-08-31 12:07:43 +02:00
# self.message_label = ttk.Label(self, text='coucou toi :D JE SUIS SUPER MAN héhéh', foreground='red')
# self.message_label.grid(row=2, column=1, sticky=tk.W)
2022-08-30 21:12:04 +02:00
# place this frame
# self.grid(row=0, column=0, padx=5, pady=5)
# self.pack(fill='both', expand=True)
2022-08-30 21:12:04 +02:00
# Save and setup main controller
self.__controller = controller
controller.set_view(self)
2022-08-31 12:07:43 +02:00
# START Internal function
def __init_content(self) -> None:
"""
[internal function]
=> Initialize the view content.
"""
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=3)
2022-08-31 12:07:43 +02:00
# Website link
self.web_label = ttk.Label(self, text="Website URL:")
self.web_label.grid(column=0, row=0, sticky=tk.W, padx=5, pady=5)
self.web_entry = ttk.Entry(self, width=50) # show="-"
self.web_entry.grid(column=1, row=0, 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(column=0, row=1, sticky=tk.W, padx=5, pady=5)
self.name_entry = ttk.Entry(self, width=50)
self.name_entry.grid(column=1, row=1, sticky=tk.E, padx=5, pady=5, ipadx=2, ipady=2)
# Logs area
self.log_area = st.ScrolledText(self, wrap=tk.WORD, state = tk.DISABLED, width=40, height=8)#, font=("Times New Roman", 15))
self.log_area.grid(column=0, row=3, sticky=tk.EW, columnspan=2, pady=10, padx=10)
# Download button
self.download_button = ttk.Button(self, text="Start downloading", command=self.event_btn)
self.download_button.grid(column=1, row=4, sticky=tk.E, padx=5, pady=5, ipadx=5, ipady=2)
# END Internal function
# START Controller methods
def add_log(self, line: str) -> None:
"""
[function for controller]
TODO desc
"""
print("ADD: ", line)
self.log_area.configure(state=tk.NORMAL)
self.log_area.insert(tk.END, f"{line}\n")
self.log_area.configure(state=tk.DISABLED)
def clear_log(self) -> None:
"""
[function for controller]
TODO desc
"""
self.log_area.delete(0, tk.END)
# END Controller methods
def event_btn(self) -> None:# TODO remove
2022-08-30 21:12:04 +02:00
print("you clicked ! And now you are on info page ... :D")
2022-08-31 12:07:43 +02:00
self.__controller.on_change_view(Frames.Info)