-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolInsertTool_GUI.py
More file actions
137 lines (109 loc) · 3.81 KB
/
SymbolInsertTool_GUI.py
File metadata and controls
137 lines (109 loc) · 3.81 KB
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
133
134
135
136
137
import tkinter as tk
from tkinter import filedialog
import os
import base64
import sqlite3
import json
def browse_folder():
folder_path = filedialog.askdirectory()
folder_entry.delete(0, tk.END)
folder_entry.insert(0, folder_path)
def browse_file():
file_path = filedialog.askopenfilename(filetypes=[("Stylx Files", "*.stylx")])
file_entry.delete(0, tk.END)
file_entry.insert(0, file_path)
def process_symbols():
symbol_directory = folder_entry.get()
stylx_path = file_entry.get()
symbol_size = size_entry.get()
# Validate size input
try:
symbol_size = float(symbol_size)
except ValueError:
result_label.config(text="Error: Please enter a valid number for symbol size.")
return
if not os.path.exists(stylx_path):
open(stylx_path, "w").close()
conn = sqlite3.connect(stylx_path, timeout=60)
cursor = conn.cursor()
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS ITEMS (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
CLASS INTEGER,
CATEGORY TEXT,
NAME TEXT,
TAGS TEXT,
CONTENT TEXT,
KEY TEXT
)
"""
)
for file_name in os.listdir(symbol_directory):
if file_name.endswith(".png"):
symbol_name = os.path.splitext(file_name)[0]
image_path = os.path.join(symbol_directory, file_name)
with open(image_path, "rb") as img_file:
img_data = img_file.read()
encoded_image = base64.b64encode(img_data).decode("utf-8")
new_symbol_json = {
"type": "CIMPointSymbol",
"symbolLayers": [
{
"type": "CIMPictureMarker",
"path": image_path,
"title": symbol_name,
"url": f"data:image/png;base64,{encoded_image}",
"size": symbol_size,
"enable": "true",
"colorLocked": "true",
"anchorPointUnits": "Relative",
"dominantSizeAxis3D": "Y",
"billboardMode3D": "FaceNearPlane",
"invertBackfaceTexture": "true",
"scaleX": 1,
"textureFilter": "Draft",
}
],
}
new_row = (
3,
"",
symbol_name,
"Landmark Symbol",
json.dumps(new_symbol_json),
symbol_name,
)
cursor.execute(
"INSERT INTO ITEMS(CLASS, CATEGORY, NAME, TAGS, CONTENT, KEY) VALUES(?,?,?,?,?,?)",
new_row,
)
conn.commit()
conn.close()
result_label.config(text="All symbols have been added to the .stylx file.")
# Setup GUI
root = tk.Tk()
root.title("Symbol Inserter Tool - Load symbols into style file")
folder_label = tk.Label(root, text="\n\nSelect PNG Symbol Directory:")
folder_label.pack()
folder_entry = tk.Entry(root, width=50)
folder_entry.pack()
folder_button = tk.Button(root, text="Browse", command=browse_folder)
folder_button.pack()
file_label = tk.Label(root, text="\nSelect Stylx File:")
file_label.pack()
file_entry = tk.Entry(root, width=50)
file_entry.pack()
file_button = tk.Button(root, text="Browse", command=browse_file)
file_button.pack()
size_label = tk.Label(root, text="\nEnter Symbol Size:")
size_label.pack()
size_entry = tk.Entry(root, width=10)
size_entry.insert(0, "20") # Default size
size_entry.pack()
tk.Label(root, text="\n\n").pack()
process_button = tk.Button(root, text="Load PNGs Into Style", command=process_symbols)
process_button.pack()
result_label = tk.Label(root, text="\n")
result_label.pack()
root.mainloop()