Skip to content

Commit

Permalink
Refactor to update YAML configuration
Browse files Browse the repository at this point in the history
- Load and update  with pinned flags.
- Append new flags to the  section.
- Initialize  as an empty dictionary.
- Save updated configuration back to .
- Automatically call  on initialization.
  • Loading branch information
healthonrails committed Dec 19, 2024
1 parent 24cbe9c commit 32ce52d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions annolid/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import csv
import os.path as osp
import time
import yaml
import html
import shutil
import sys
Expand Down Expand Up @@ -185,7 +186,7 @@ def __init__(self,
self.auto_recovery_missing_instances = False
self.compute_optical_flow = True
self.behaviors = None
self.pinned_flags = None
self.pinned_flags = {}
# Create progress bar
self.progress_bar = QtWidgets.QProgressBar()
self.progress_bar.setRange(0, 100)
Expand Down Expand Up @@ -226,6 +227,8 @@ def __init__(self,
self.flag_widget.flagsSaved.connect(self.handle_flags_saved)
self.flag_widget.rowSelected.connect(self.handle_row_selected)

self.handle_flags_saved()

self.setCentralWidget(scrollArea)

self.createPolygonSAMMode = action(
Expand Down Expand Up @@ -579,8 +582,30 @@ def __init__(self,

self.populateModeActions()

def handle_flags_saved(self, flags):
self.loadFlags(flags)
def handle_flags_saved(self, flags={}):
default_config = self.here.parent.resolve() / 'configs' / 'behaviors.yaml'

# Load the existing configuration from the YAML file
try:
with open(default_config, 'r') as file:
config_data = yaml.safe_load(file) or {}
except FileNotFoundError:
config_data = {}

# Append the pinned flags to the existing configuration
if 'pinned_flags' not in config_data:
config_data['pinned_flags'] = []
config_data['pinned_flags'].extend(flags) # Append the new flags
pinned_flags = {
pinned_flag: False for pinned_flag in config_data['pinned_flags']}

# Save the updated configuration back to the YAML file
with open(default_config, 'w') as file:
yaml.dump(config_data, file, default_flow_style=False)

# Update the pinned_flags attribute and load the flags
self.pinned_flags = pinned_flags
self.loadFlags(pinned_flags)

def handle_row_selected(self, flag_name: str):
self.event_type = flag_name
Expand Down

0 comments on commit 32ce52d

Please sign in to comment.