-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd_retriever_gui.py
132 lines (108 loc) · 5.45 KB
/
std_retriever_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
122
123
124
125
126
127
128
129
130
131
132
"""
File: std_retriever_gui.py
Description: This script creates a GUI for the standards retriever.
Contributors:
Marcelo Santibáñez
Adrian Hassa
Created: 2024-11-13
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 std_retriever
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 StdRetriever:
def __init__(self, parent, config):
self.frame = ttk.Frame(parent)
self.config = config
self.series_var = tk.StringVar(value=config['series_no'])
self.search_keyword_var = tk.StringVar(value=config['phrase'])
self.download_dir_var = tk.StringVar(value=config['download_folder_path'])
self.tr_var = tk.BooleanVar(value=True)
self.ts_var = tk.BooleanVar(value=True)
self.series_label = tk.Label(self.frame, text = 'Series number', font=('arial',10))
self.series_entry = tk.Entry(self.frame, textvariable = self.series_var, font=('arial',10,'normal'), width=70)
self.search_keyword_label = tk.Label(self.frame, text = 'Search keyword', font=('arial',10))
self.search_keyword_entry = tk.Entry(self.frame, textvariable = self.search_keyword_var, font=('arial',10,'normal'), width=70)
self.type_label = tk.Label(self.frame, text = 'Type', font = ('arial',10,'normal'))
self.type_frame = tk.Frame(self.frame)
self.tr_checkbox = tk.Checkbutton(self.type_frame, text='Technical Report', variable=self.tr_var, command=self.update_checked)
self.ts_checkbox = tk.Checkbutton(self.type_frame, text='Technical Specification', variable=self.ts_var, command=self.update_checked)
self.tr_checkbox.grid(row=0, column=0, padx=25)
self.ts_checkbox.grid(row=0, column=1, padx=25)
self.download_dir_label = tk.Label(self.frame, text = 'Output folder', font=('arial',10))
self.download_dir_entry = tk.Entry(self.frame, textvariable = self.download_dir_var, font=('arial',10,'normal'), width=70, state="readonly")
self.download_dir_btn=tk.Button(self.frame,text = '...', command = self.select_download_dir, width=10)
self.download_btn=tk.Button(self.frame, text = 'Download', command = self.download, width=30)
self.status_label = tk.Label(self.frame, text = '', font = ('arial',10,'normal'))
# Place the widgets on the window grid
self.series_label.grid(row=0,column=0, padx=5)
self.series_entry.grid(row=0,column=1, pady=10)
self.search_keyword_label.grid(row=1,column=0, padx=5)
self.search_keyword_entry.grid(row=1,column=1, pady=10)
self.type_label.grid(row=2,column=0, padx=5)
self.type_frame.grid(row=2,column=1, pady=10)
self.download_dir_label.grid(row=3,column=0, padx=5)
self.download_dir_entry.grid(row=3,column=1, pady=10)
self.download_dir_btn.grid(row=3,column=2, pady=10)
self.download_btn.grid(row=4,column=1)
self.status_label.grid(row=5,column=1)
# Function to save the configuration to the JSON file
def save_config(self):
self.config['download_folder_path'] = self.download_dir_var.get()
self.config['phrase'] = self.search_keyword_var.get()
self.config['series_no'] = self.series_var.get()
self.config['type'] = self.update_checked()
with open('config.json', 'w') as f:
json.dump(self.config, f)
return self.config
# Callback function to update the download status
def update_download_status(self, message):
self.status_label.config(text=message)
# Function to start the download on button press
def download(self):
if self.download_dir_var.get() == "":
self.status_label.config(text="Please fill in the output folder field!")
else:
self.status_label.config(text="Processing the standards...")
config = self.save_config()
threading.Thread(target=std_retriever.download, args=(config, self.download_btn, self.update_download_status)).start()
def update_checked(self):
checked = []
if self.tr_var.get():
checked.append("Technical Report (TR)")
if self.ts_var.get():
checked.append("Technical Specification (TS)")
if len(checked) == 0:
checked = ["Technical Report (TR)", "Technical Specification (TS)"]
return checked
# Directory selection dialog
def select_download_dir(self):
dir = filedialog.askdirectory()
self.download_dir_var.set(dir)
self.download_dir_entry.delete(0, tk.END)
self.download_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", "Download Standards"))
std_retriever_gui = StdRetriever(root, config)
std_retriever_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()