A code[
class ImageViewer:
    def __init__(self, root):
        self.SUPPORTED_EXTENSIONS = (".png", ".jpg", ".jpeg", ".gif", ".bmp", ".JPG", ".JPEG", ".BMP", ".GIF", ".webp", ".WEBP")
        self.button_style = {"font": ("consolas", 11), "fg": "white", "bg": "#3c3c3c", "relief": "flat"}
        self.bgcolor = "#242424"
        self.button_width = 3
        #self.image_loading_queue = Queue(maxsize=5)
        self.switch_timestamps = []

        self.root = root
        self.root.geometry("800x600")  # Initial window size
        self.root.title("Jestur Viewer")
        self.root.configure(bg=self.bgcolor)  # Set window background color
        self.root.attributes("-topmost", True)  # Make the window stay on top

        self.image_folder = ""
        self.image_files = []
        self.current_image_index = 0


    def select_folder(self):
        self.image_folder = filedialog.askdirectory()
        if self.image_folder:
            image_files = os.listdir(self.image_folder) # Get all files in the selected folder
            self.image_files = [file for file in image_files if file.endswith(self.SUPPORTED_EXTENSIONS)] # Filter image files
            self.rotated = 0
            if len(self.image_files) > 0:
                self.current_image_index = 0
                self.canvas.pack(fill=tk.BOTH, expand=True)
                self.select_folder_button.pack(side=tk.LEFT, padx=5, pady=5)
                self.root.title("Jesturing in " + self.image_folder)
                self.canvas.config(bg=self.bgcolor, highlightthickness=0)
                self.display_image()   
                self.start_button.config(**self.button_style)
            else:
                messagebox.showinfo("No Image Files", "The selected folder does not contain any image files.")
                self.image_folder = ""
                self.root.title("Jestur")
    def load_image(self, image_path):
        image = Image.open(image_path)
        
        # Check if the image has EXIF data
        if "exif" in image.info:
            exif_data = piexif.load(image.info["exif"])
            if piexif.ImageIFD.Orientation in exif_data["0th"]:
                orientation = exif_data["0th"][piexif.ImageIFD.Orientation]
                if orientation == 3:
                    image = image.rotate(180, expand=True)
                elif orientation == 6:
                    image = image.rotate(-90, expand=True)
                elif orientation == 8:
                    image = image.rotate(90, expand=True)

        if self.is_greyscale:
            image = image.convert("L")
    
        if self.is_mirrored:
            image = image.transpose(Image.FLIP_LEFT_RIGHT)
        
        if self.rotated != 0:
            image = image.rotate(self.rotated, expand=True)

        aspect_ratio = image.width / image.height
        canvas_width = self.canvas.winfo_width()
        canvas_height = self.canvas.winfo_height()
        max_width = min(canvas_width, int(aspect_ratio * canvas_height))
        max_height = min(canvas_height, int(canvas_width / aspect_ratio))
        scale_factor = min(max_width / image.width, max_height / image.height)
        new_width = int(image.width * scale_factor)
        new_height = int(image.height * scale_factor)

        if new_width > 0 and new_height > 0:
            resized_image = image.resize((new_width, new_height), Image.BICUBIC)
            self.photo = ImageTk.PhotoImage(resized_image)
            self.canvas.delete("all")
            self.canvas.create_image(canvas_width // 2, canvas_height // 2, image=self.photo)

    def display_image(self):
        if self.image_folder != "" and len(self.image_files) > 0:
            if self.update_switch_timestamps():
                # Show the text of the image name instead of loading the actual image
                image_name = self.image_files[self.current_image_index]
                self.canvas.delete("all")  # Clear the canvas
                self.canvas.create_text(
                    self.canvas.winfo_width() // 2, 
                    self.canvas.winfo_height() // 2,
                    text=image_name,
                    fill="white"
                )
                # Schedule the image load with a delay
                if self.timer is not None:
                    self.root.after_cancel(self.timer) # Cancel existing timer to avoid conflicts
                self.timer = self.root.after(500, self.load_image_delayed) # Set a new timer to load the image after 500ms

            else:
                # Load the image normally if not quick-switching
                image_path = os.path.join(self.image_folder, self.image_files[self.current_image_index])
                threading.Thread(target=self.load_image, args=(image_path,)).start()


    def load_image_delayed(self):
        # This method will be called after the 500ms delay if no keypress happens
        if self.timer is not None:
            self.root.after_cancel(self.timer)  # Cancel the existing timer
        self.timer = None  # Clear the timer ID
        image_path = os.path.join(self.image_folder, self.image_files[self.current_image_index])
        threading.Thread(target=self.load_image, args=(image_path,)).start()
        
        if not self.is_paused:
            self.timer = self.set_timer_interval
            self.root.after(500, self.start_timer)

    def next_image(self, event=None):
	    if self.image_folder != "":
            self.current_image_index = random.randint(0, len(self.image_files) - 1) # Randomly select 
            self.display_image()
            # Reset the timer interval to the stored set timer interval
            self.timer_interval = self.set_timer_interval

    def previous_image(self, event=None):
            if self.image_folder != "":
            self.current_image_index = random.randint(0, len(self.image_files) - 1) # Randomly select the next image index
            self.display_image()
            self.timer_interval = self.set_timer_interval  # Use the stored set timer interval
]


B code[

class ImageApp:
    def __init__(self, root):
        self.root = root
        self.current_folder = None
        self.folder_index = []
        self.history = []
        self.history_index = -1
        self.total_images = 0
        self.rest_interval = 5
        self.rest_counter = 0
        self.rest_var = tk.IntVar()  # Tkinter variable to hold the state of the checkbox

        
        self.open_button = tk.Button(root, text="Open Image", command=self.open_folder)
        self.open_button.pack()

        self.previous_button = tk.Button(root, text="Previous", command=self.previous_image)
        self.previous_button.pack(side='left')
        
        self.next_button = tk.Button(root, text="Next", command=self.next_image)
        self.next_button.pack(side='left')
        
        self.rest_checkbox = tk.Checkbutton(root, text="Rest", variable=self.rest_var)
        self.rest_checkbox.pack(side='left')

        self.spin_value = tk.IntVar(value=self.rest_interval)
        
        self.spinbox = tk.Spinbox(root, from_=1, to=100, textvariable=self.spin_value)
        self.spinbox.pack(side='left')

        self.total_images_label = tk.Label(root, text="Total images in folder: 0")
        self.total_images_label.pack()

        self.image_name_label = tk.Label(root, text="Image Name")
        self.image_name_label.pack()

    def open_folder(self):
        folder_path = filedialog.askdirectory()
        if folder_path and folder_path != self.current_folder:
            self.current_folder = folder_path
            
            self.folder_index = self.get_image_list(folder_path)
            self.total_images = len(self.folder_index)
            self.total_images_label.config(text=f"Total images in folder: {self.total_images}")
            self.history.clear()
            self.history_index = -1
            # Reset the rest counter and show
            
            self.rest_counter = 0  
            if self.folder_index:  # If there are images in the folder, display one
                self.add_image_to_history()
                self.display_image(self.history[self.history_index])
            else:
                self.image_name_label.config(text="No images found")
                
    def get_image_list(self, folder_path):
        extensions = ('.jpg', '.jpeg', '.png', '.gif', '.webp')
        image_list = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.endswith(extensions)]
        numbered_list = list(enumerate(image_list))
        return numbered_list

    def previous_image(self):
        if self.history_index > 0:
            self.history_index -= 1
            self.display_image(self.history[self.history_index])
   
    def next_image(self):
        # We will display "Rest" on every (spin_value + 1) image
        if (self.rest_counter + 1) % (self.spin_value.get() + 1) == 0 and self.rest_var.get() == 1:
            self.image_name_label.config(text="Rest")
        else:
            if self.history_index < len(self.history) - 1:
                self.history_index += 1
            else:
                if self.total_images == len(self.history):
                    self.history_index = 0
                else:
                    self.add_image_to_history()
            self.display_image(self.history[self.history_index])
        
        self.rest_counter += 1
    def add_image_to_history(self):
        remaining_images = set(range(self.total_images)) - set(idx for idx, img in self.history)
        if remaining_images:
            next_image_index = random.choice(list(remaining_images))
            next_image = self.folder_index[next_image_index]
            self.history.append(next_image)
            self.history_index += 1

    def display_image(self, image_info):
        # Image displayed logic here
        idx, image_path = image_info
        image_name = os.path.basename(image_path)
        self.image_name_label.config(text=image_name)
]

B code is just calling image name while code A is to show image. B code has the new behaviour that i want. give me A code function to call image with B code behaviour. or in other words to integrate new B code behaviour to A code. the b code is not to be changed. give me new A code