-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagrams_gui.py
121 lines (95 loc) · 4.59 KB
/
diagrams_gui.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""
File: diagrams_gui.py
Description: This script creates a GUI for the diagrams processer.
Contributors:
Adrian Hassa
Created: 2024-12-02
Last Modified: 2024-12-09
Project: 3GPP Requirement Tools
URL: https://github.com/Adrian2901/3gpp-requirements-tools
License: MIT License (see LICENSE file for details)
"""
import json
import os
import tkinter as tk
from tkinter import ttk, filedialog
import process_images
import threading
import sys
# Change the working directory to the directory of the executable for PyInstaller
os.chdir(sys._MEIPASS) if getattr(sys, 'frozen', False) else os.chdir(os.path.dirname(os.path.abspath(__file__)))
class DiagramProcessor:
def __init__(self, parent, config):
self.frame = ttk.Frame(parent)
self.config = config
self.ip_var=tk.StringVar(value=config['llm_address'])
self.input_var = tk.StringVar(value="")
self.output_var = tk.StringVar(value="")
# LLM IP address and port input in the GUI
self.ip_label = tk.Label(self.frame, text = 'LLM address:port', font=('arial',10))
self.ip_entry = tk.Entry(self.frame, textvariable = self.ip_var, font=('arial',10,'normal'), width=70)
self.input_label = tk.Label(self.frame, text = 'Input file', font=('arial',10))
self.input_entry = tk.Entry(self.frame, textvariable = self.input_var, font=('arial',10,'normal'), width=70, state="readonly")
self.input_btn=tk.Button(self.frame,text = '...', command = self.select_input_file, width=10)
self.output_dir_label = tk.Label(self.frame, text = 'Output folder', font=('arial',10))
self.output_dir_entry = tk.Entry(self.frame, textvariable = self.output_var, font=('arial',10,'normal'), width=70, state="readonly")
self.output_dir_btn=tk.Button(self.frame,text = '...', command = self.select_output_dir, width=10)
self.run_btn=tk.Button(self.frame, text = 'Run', command = self.run, width=30)
self.status_label = tk.Label(self.frame, text = '', font = ('arial',10,'normal'))
self.progressbar = ttk.Progressbar(self.frame, length=500)
# Place the widgets on the window grid
self.ip_label.grid(row=0,column=0, padx=5)
self.ip_entry.grid(row=0,column=1, pady=10)
self.input_label.grid(row=1,column=0, padx=5)
self.input_entry.grid(row=1,column=1, pady=10)
self.input_btn.grid(row=1,column=2, pady=10)
self.output_dir_label.grid(row=2,column=0, padx=5)
self.output_dir_entry.grid(row=2,column=1, pady=10)
self.output_dir_btn.grid(row=2,column=2, pady=10)
self.run_btn.grid(row=3,column=1)
self.status_label.grid(row=4,column=1)
# Callback function to update the download status
def update_status(self, message, progress=None):
self.status_label.config(text=message)
if progress is not None:
self.progressbar.grid(row=5,column=1)
self.progressbar.config(value=progress*100)
else:
self.progressbar.grid_forget()
# Function to start the download on button press
def run(self):
if self.input_var.get() == "" :
self.update_status("Please fill in the input folder field!")
elif self.output_var.get() == "":
self.update_status("Please fill in the output folder field!")
else:
self.update_status("Reading the document...")
threading.Thread(target=process_images.process_docx, args=(self.input_var.get(), self.output_var.get(), self.ip_var.get(), self.update_status)).start()
# File selection dialog
def select_input_file(self):
file = filedialog.askopenfilename(filetypes=[("Microsoft Word document", ".docx")])
self.input_var.set(file)
self.input_entry.delete(0, tk.END)
self.input_entry.insert(0, file)
# Directory selection dialog
def select_output_dir(self):
dir = filedialog.askdirectory()
self.output_var.set(dir)
self.output_dir_entry.delete(0, tk.END)
self.output_dir_entry.insert(0, dir)
if __name__ == "__main__":
# File path for the configuration file
CONFIG_FILE = 'config.json'
# Function to load the configuration from the JSON file
with open(CONFIG_FILE, 'r') as f:
config = json.load(f)
# Create the main window
root = tk.Tk()
root.title(config.get("title", "Extract Text from Diagrams"))
diagrams_gui = DiagramProcessor(root, config)
diagrams_gui.frame.pack(expand=True, fill="both")
# Set window size and disable resizing
root.geometry("700x400")
root.resizable(False, False)
# Run the application
root.mainloop()