from customtkinter import *
from PIL import Image

class Fooled(CTkToplevel):
    """A custom Tkinter Toplevel window to display a text label and a GIF image of Jerry from the 'Tom and Jerry' cartoon."""
    def __init__(self):
        """Initialize the Fooled Toplevel window."""
        super().__init__()
        self.title("")
        set_appearance_mode("light")
        self.geometry("250x250")
        
        self.label = CTkLabel(self, text="Idk, just look outsidešŸ¤£")
        self.label.pack()
        self.forward_img = CTkImage(light_image=Image.open("images\\jerry.gif"), size=(199,199))
        self.front = CTkLabel(self, text="", image=self.forward_img)
        self.front.pack()


class ShowWhether(CTkToplevel):
    """A custom Tkinter Toplevel window that simulates a weather forecast process with text labels and a progress bar."""
    def __init__(self):
        """Initialize the ShowWhether Toplevel window."""
        super().__init__()
        self.title("AI weather forecast")
        set_appearance_mode("light")
        self.geometry("300x140")

        self.label = CTkLabel(self, text="Searching Location...")
        self.label.grid(row=0, padx=20, pady=20)

        self.label.after(1000, self.on_after)
        self.pb = CTkProgressBar(self, orientation="horizontal", mode="determinate")
        self.pb.grid(row=1, padx=20, pady=20)
        self.pb.set(0)
    def on_after(self):
        """Update the label text and progress bar after a delay."""
        self.label = CTkLabel(self, text="Analyzing the clouds...")
        self.label.grid(row=0, padx=20, pady=20)
        self.label.after(1000, self.on_after1)
        self.pb.set(0.25)

    def on_after1(self):
        """Update the label text and progress bar after a delay."""
        self.label = CTkLabel(self, text="Looking outside your window...")
        self.label.grid(row=0, padx=20, pady=20)
        self.label.after(1000, self.on_after2)
        self.pb.set(0.50)

    def on_after2(self):
        """Update the label text and progress bar after a delay."""
        self.label = CTkLabel(self, text="Gathering last the information...")
        self.label.grid(row=0, padx=20, pady=20)
        self.label.after(1000, self.last)
        self.pb.set(0.75)

    def last(self):
        """Finalize the weather forecast process and display the Fooled Toplevel window."""
        self.pb.set(1)
        show = Fooled()
        show.mainloop()


class Get_City(CTk):
    """A custom Tkinter main application class to get the user's location and initiate the weather forecast."""
    def __init__(self):
        """Initialize the Get_City application."""
        super().__init__()
        set_appearance_mode("light")
        self.title("AI weather forecast")

        self.geometry("400x175")
        self.label = CTkLabel(self, text="Enter your Location: ")
        self.label.pack(padx=20, pady=15)
        self.city = CTkEntry(self, placeholder_text="Enter Your city ")
        self.city.pack(padx=20, pady=10)

        self.check_weather = CTkButton(self, text="Check weather", command=self.weather)
        self.check_weather.pack(padx=20, pady=10)

    def weather(self):
        """Check if the city input is valid and initiate the weather forecast process."""
        if self.city.get() == "":
            print("Enter a city First")
        else:
            show = ShowWhether()
            show.mainloop()
if __name__ == "__main__":
    app = Get_City()
    app.mainloop()