Skip to content

Commit 0fb8c26

Browse files
committed
Fix issue with examples attempting to import twice
1 parent 05c0977 commit 0fb8c26

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

backend.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ def fileSave():
5353

5454
def fileOpen(path=None):
5555
global categories, startColor, endColor, saved
56-
if saved != True:
57-
if not msg.askyesno("Changes Not Saved", "You've adjusted your separator list but haven't saved! Are you sure you want to open an example?"):
56+
if not saved:
57+
if not msg.askyesno("Changes Not Saved", "You've adjusted your separator list but haven't saved!\nAre you sure you want to open this file?"):
5858
return
59-
else:
60-
categories.clear()
61-
startColor = "#000000"
62-
endColor = "#ffffff"
63-
if path is None:
64-
path = prompt.askopenfilename(initialdir=initDir, filetypes=[("JSON", "*.json")], defaultextension=".json")
65-
if path:
59+
if path is None: path = prompt.askopenfilename(initialdir=initDir, filetypes=[("JSON", "*.json")], defaultextension=".json")
60+
if path:
6661
with open(path, "r") as f:
6762
data = json.load(f)
68-
categories = data["categories"]
63+
categories.clear()
64+
categories.update(data["categories"])
6965
startColor = data["gradient"]["startColor"]
7066
endColor = data["gradient"]["endColor"]
7167
saved = True
@@ -82,19 +78,23 @@ def exampleGet(bar, list, subBox, startIndicator, endIndicator, startLabel, endL
8278
log.info(f"Example Found: {file.removesuffix('.json')}")
8379

8480
def exampleOpen(path, tree, subBox, startIndicator, endIndicator, startLabel, endLabel):
85-
global startColor, endColor
81+
global startColor, endColor, categories, saved
82+
if not saved:
83+
if not msg.askyesno("Unsaved Changes", "You have unsaved changes. Are you sure you want to open an example?"):
84+
return
85+
saved = True
8686
log.info(f"Example Selected: {os.path.basename(path).removesuffix('.json')}")
8787
fileOpen(path)
8888
expanded_categories = set()
8989
for category_id in tree.get_children():
9090
if tree.item(category_id, 'open'): expanded_categories.add(tree.item(category_id, 'values')[0].strip())
9191
tree.delete(*tree.get_children())
92-
for category in categories:
93-
sepAdd("cat", category)
94-
#categoryID = tree.insert("", "end", text="", values=(category,))
95-
categoryID = categories[category]["id"]
96-
for subcategory in categories[category]["sub"]:
97-
sepAdd("sub", subcategory, category)
92+
for category, details in categories.items():
93+
categoryID = tree.insert("", "end", text="", values=(category,))
94+
categories[category]["id"] = categoryID
95+
for subcategory in details["sub"]:
96+
subcategoryID = tree.insert(categoryID, "end", text="", values=(f"\u00A0\u00A0\u00A0\u00A0{subcategory}",))
97+
categories[category]["sub"][subcategory]["id"] = subcategoryID
9898
if category in expanded_categories: tree.item(categoryID, open=True)
9999
subBox.config(values=list(categories.keys()))
100100
startIndicator.config(bg=startColor)

0 commit comments

Comments
 (0)