Skip to content

Commit 81e0082

Browse files
committed
groups now appear ordered
1 parent 22e683c commit 81e0082

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

deepcave/layouts/general.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,25 +292,23 @@ def callback(group_names, all_run_paths, i): # type: ignore
292292
raise PreventUpdate()
293293

294294
# For the default group names, if no name was entered
295-
if "group_counter" not in globals():
296-
globals()["group_counter"] = 0
295+
group_counter = 0
297296

298297
groups = {}
299298
for group_name, run_paths in zip(group_names, all_run_paths):
300299
if group_name is None or group_name == "":
301300
# Set the default group name with a counter,
302301
# so the groups dont overwrite themselves
303-
group_counter = globals().get("group_counter")
304302
group_name_unavailable = True
305303

304+
# Check to see that no group name that already exists
305+
# gets picked
306306
while group_name_unavailable:
307307
group_name = f"Group {group_counter}"
308308
if group_name not in c.get("groups").keys():
309309
group_name_unavailable = False
310310
else:
311311
group_counter += 1
312-
313-
globals()["group_counter"] = group_counter
314312

315313
if run_paths is None or len(run_paths) == 0:
316314
continue
@@ -325,16 +323,20 @@ def callback(group_names, all_run_paths, i): # type: ignore
325323

326324
groups[group_name] = valid_run_paths
327325

326+
# Sort the groups alphabetically, so when added
327+
# they appear ordered
328+
sorted_groups = dict(sorted(groups.items()))
329+
328330
try:
329331
# Now save it
330-
run_handler.update_groups(groups)
332+
run_handler.update_groups(sorted_groups)
331333
except NotMergeableError:
332334
notification.update("The selected runs are not mergeable.")
333335

334336
# This will automatically trigger the group display s.t. the selection is redo.
335337
return i + 1
336338

337-
self.logger.debug(f"Groups: {groups}")
339+
self.logger.debug(f"Groups: {sorted_groups}")
338340

339341
raise PreventUpdate()
340342

0 commit comments

Comments
 (0)