class ImageViewer:
    def __init__(self, root):

    def toggle_grid(self):
        grid_types = ["a", "b",]
        
        if not hasattr(self, "grid_type"):
            self.grid_type = grid_types[0]
        else:
            current_index = grid_types.index(self.grid_type)
            next_index = (current_index + 1) % len(grid_types)
            self.grid_type = grid_types[next_index]
        self.display_image()

    def draw_grid(self, grid_type, image_width, image_height):
        # Calculate center position to center the grid on the image
        canvas_width = self.canvas.winfo_width()
        canvas_height = self.canvas.winfo_height()
        x_center = canvas_width // 2
        y_center = canvas_height // 2

        # Calculate the top-left corner position of the image
        x_start = x_center - (image_width // 2)
        y_start = y_center - (image_height // 2)
        grid_color = "grey"
        if grid_type == "b":
            # Draw a simple 3x3 grid
            for i in range(1, 3):
                self.canvas.create_line(x_start + image_width * i / 3, y_start, x_start + image_width * i / 3, y_start + image_height, fill=grid_color)
                self.canvas.create_line(x_start, y_start + image_height * i / 3, x_start + image_width, y_start + image_height * i / 3, fill=grid_color)
        elif grid_type == "a":
            pass

    def load_image(self, image_path):
        image = Image.open(image_path)
        
        # Check if the image has EXIF data
        if "exif" in image.info:
            try:
                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)
            except ValueError as e:
                pass
            
        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)

        if self.grid_type:
            self.draw_grid(self.grid_type, new_width, new_height)

make it so when i run toggle_grid, it opens a dialog in a new class that has two spinboxes that sets the the grid division instead of just 3x3. below that add 3 buttons, disable grid, apply and ok button. disable grid will set the grid type to “a” and run display_image. the apply button will set the values for the grid division and run display_image to refresh without closing the window while ok button does the same and closes the dialog window. give the new codeblock