-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvs_to_dzi.py
42 lines (34 loc) · 1.34 KB
/
svs_to_dzi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import subprocess
import tkinter as tk
from tkinter import filedialog, messagebox
def convert_svs_to_dzi():
# Open file dialog to select SVS files
file_paths = filedialog.askopenfilenames(
title="Select SVS files",
filetypes=[("SVS files", "*.svs")]
)
if not file_paths:
messagebox.showinfo("Info", "No files selected.")
return
for file_path in file_paths:
# Get the directory and filename without extension
directory = os.path.dirname(file_path)
filename = os.path.splitext(os.path.basename(file_path))[0]
# Construct the output path
output_path = os.path.join(directory, filename)
# Run the VIPS command
try:
subprocess.run(["vips", "dzsave", file_path, output_path], check=True)
# messagebox.showinfo("Success", f"Converted {filename}.svs to DZI format.")
except subprocess.CalledProcessError as e:
messagebox.showerror("Error", f"Failed to convert {filename}.svs: {str(e)}")
# Create the main window
root = tk.Tk()
root.title("SVS to DZI Converter")
root.geometry("300x100")
# Create and pack the convert button
convert_button = tk.Button(root, text="Select and Convert SVS Files", command=convert_svs_to_dzi)
convert_button.pack(expand=True)
# Start the GUI event loop
root.mainloop()