class CustomTimeDialog(simpledialog.Dialog):
    def __init__(self, parent, current_session_timings=None, is_session_mode=False, **kwargs):
        self.sessionlist = []
        # Only set defaults if current_session_timings is None or empty
        if not current_session_timings:  # This checks both None and empty list [] conditions
            # Set default initial list here (only if there are no existing session timings)
            current_session_timings = ['3 pic for 2s', '3 pic for 1s', '1 pic for 3s']
        self.current_session_timings = current_session_timings
        self.is_session_mode = is_session_mode
        super().__init__(parent, **kwargs)
    
    def body(self, master):
        self.timebutton_style = {"font": ("consolas", 11), 
        "fg": "white", "bg": "#3c3c3c", "relief": "flat"}
        self.title('Custom Time')
        self.time_background = "#242424"
        self.time_fg="white"

        master.configure(bg=self.time_background)
        self.configure(bg=self.time_background)

        self.ico = self.resource_path_timer("icon.ico")
        self.iconbitmap(self.ico)

        #timebox--------------------------------------------------
        ctime_frame = tk.Frame(master, bg=self.time_background)
        ctime_frame.grid(row=0, column=0)
        self.timebox = tk.Listbox(ctime_frame, height=6, width=15, font=self.timebutton_style["font"], borderwidth=0, bg=self.timebutton_style["bg"], fg="#dddddd", selectbackground="#222222")

        for time_string in ['15s', '30s', '45s', '1m', '5m', '10m']:
            self.timebox.insert(tk.END, time_string)
        self.timebox.grid(row=0, column=0)
        self.timebox.bind('<<ListboxSelect>>', self.set_spinboxes_from_selection)

        #minutebox-----------------------------------------------
        # Main frame to contain the minutes and seconds frames
        time_frame = tk.Frame(ctime_frame, bg=self.time_background)
        time_frame.grid(row=1, column=0, pady=5)# side=tk.TOP, fill=tk.X, padx=5, pady=5)

        # Create a frame for the minutes spinbox and label
        minutes_frame = tk.Frame(time_frame, bg=self.time_background)
        minutes_frame.pack(side=tk.LEFT, fill=tk.X)#, padx=5)

        tk.Label(minutes_frame, text="Minutes:", bg=self.time_background, fg=self.time_fg, font=self.timebutton_style["font"]).pack(side=tk.TOP)
        self.spin_minutes = tk.Spinbox(minutes_frame, from_=0, to=59, width=5, font=self.timebutton_style["font"])
        self.spin_minutes.pack(side=tk.TOP)

        # Create a frame for the seconds spinbox and label
        seconds_frame = tk.Frame(time_frame, bg=self.time_background)
        seconds_frame.pack(side=tk.LEFT, fill=tk.X, padx=0)

        tk.Label(seconds_frame, text="Seconds:", bg=self.time_background, fg=self.time_fg, font=self.timebutton_style["font"]).pack(side=tk.TOP)
        self.spin_seconds = tk.Spinbox(seconds_frame, from_=0, to=59, width=5, font=self.timebutton_style["font"], wrap=True, textvariable = tk.IntVar(value=30))
        self.spin_seconds.pack(side=tk.TOP)


        
        
        self.togsess_mode.set(self.is_session_mode)
        if self.is_session_mode:
            self.toggle_togsess()  # Initialize the state of session elements based on current setting

        # Update the Listbox content with the current session timings:
        self.sessionString.set(self.current_session_timings)
        self.sessionlist = list(self.current_session_timings)

        return self.spin_seconds  # initial focus



        
    def buttonbox(self):
        box = tk.Frame(self, bg=self.time_background)
        self.ok_button = tk.Button(box, text="Apply", width=16, command=self.ok, default=tk.NORMAL)
        self.ok_button.config(**self.timebutton_style)
        self.ok_button.pack(side=tk.TOP, ipadx=5, pady=5)
        box.pack()

    def apply(self):
        if self.togsess_mode.get():
            # In session mode, store the list of session strings directly
            self.result = self.sessionlist  # Use the list directly instead of self.sessionString.get()
        else:
            # In standard mode, parse and combine minutes and seconds to a single interval in seconds
            try:
                minutes = int(self.spin_minutes.get())
                seconds = int(self.spin_seconds.get())
                self.result = minutes * 60 + seconds  # Total time in seconds
            except ValueError:
                # Fall back to a default interval as needed
                self.result = 1  # Default to 1 second

    def validate(self):
        try:
            minutes = int(self.spin_minutes.get())
            seconds = int(self.spin_seconds.get())
            int(self.img_togsess.get())
            return True
        except ValueError:
            self.bell()
            return False
            
i want the message to save the value of minute and seconds value when i press apply so that when it opens it has the last set value as new initial value, replacing the initial value