@@ -53,19 +53,15 @@ def fileSave():
53
53
54
54
def fileOpen (path = None ):
55
55
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!\n Are you sure you want to open this file ?" ):
58
58
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 :
66
61
with open (path , "r" ) as f :
67
62
data = json .load (f )
68
- categories = data ["categories" ]
63
+ categories .clear ()
64
+ categories .update (data ["categories" ])
69
65
startColor = data ["gradient" ]["startColor" ]
70
66
endColor = data ["gradient" ]["endColor" ]
71
67
saved = True
@@ -82,19 +78,23 @@ def exampleGet(bar, list, subBox, startIndicator, endIndicator, startLabel, endL
82
78
log .info (f"Example Found: { file .removesuffix ('.json' )} " )
83
79
84
80
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
86
86
log .info (f"Example Selected: { os .path .basename (path ).removesuffix ('.json' )} " )
87
87
fileOpen (path )
88
88
expanded_categories = set ()
89
89
for category_id in tree .get_children ():
90
90
if tree .item (category_id , 'open' ): expanded_categories .add (tree .item (category_id , 'values' )[0 ].strip ())
91
91
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
98
98
if category in expanded_categories : tree .item (categoryID , open = True )
99
99
subBox .config (values = list (categories .keys ()))
100
100
startIndicator .config (bg = startColor )
0 commit comments