Skip to content

Commit

Permalink
Rename id to profile_id where applicable
Browse files Browse the repository at this point in the history
`profile_id` is explicit.
`id()` is a built-in function, see https://docs.python.org/3.10/library/functions.html#id
  • Loading branch information
zas authored and phw committed Sep 7, 2023
1 parent 6f46ebc commit 971d88e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
18 changes: 9 additions & 9 deletions picard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,23 @@ def _get_active_profile_ids(self):
yield profile["id"]

def _get_active_profile_settings(self):
for id in self._get_active_profile_ids():
yield id, self._get_profile_settings(id)
for profile_id in self._get_active_profile_ids():
yield profile_id, self._get_profile_settings(profile_id)

def _get_profile_settings(self, id):
def _get_profile_settings(self, profile_id):
if self.settings_override is None:
profile_settings = self.__qt_config.profiles[self.SETTINGS_KEY][id]
profile_settings = self.__qt_config.profiles[self.SETTINGS_KEY][profile_id]
else:
profile_settings = self.settings_override[id]
profile_settings = self.settings_override[profile_id]
if profile_settings is None:
log.error("Unable to find settings for user profile '%s'", id)
log.error("Unable to find settings for user profile '%s'", profile_id)
return {}
return profile_settings

def __getitem__(self, name):
# Don't process settings that are not profile-specific
if name in UserProfileGroups.ALL_SETTINGS:
for id, settings in self._get_active_profile_settings():
for profile_id, settings in self._get_active_profile_settings():
if name in settings and settings[name] is not None:
return settings[name]
opt = Option.get(self.__name, name)
Expand All @@ -195,9 +195,9 @@ def __getitem__(self, name):
def __setitem__(self, name, value):
# Don't process settings that are not profile-specific
if name in UserProfileGroups.ALL_SETTINGS:
for id, settings in self._get_active_profile_settings():
for profile_id, settings in self._get_active_profile_settings():
if name in settings:
self._save_profile_setting(id, name, value)
self._save_profile_setting(profile_id, name, value)
return
key = self.key(name)
self.__qt_config.setValue(key, value)
Expand Down
38 changes: 19 additions & 19 deletions picard/ui/options/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def load(self):
if last_selected_profile:
self.ui.profile_list.setCurrentItem(last_selected_profile)
last_selected_profile.setSelected(True)
id = last_selected_profile.profile_id
self.current_profile_id = id
settings = self.get_settings_for_profile(id)
profile_id = last_selected_profile.profile_id
self.current_profile_id = profile_id
settings = self.get_settings_for_profile(profile_id)
self.make_setting_tree(settings=settings)
self.update_config_overrides()
self.loading = False
Expand All @@ -179,21 +179,21 @@ def update_config_overrides(self, reset=False):
config.setting.set_profiles_override(self._clean_and_get_all_profiles())
config.setting.set_settings_override(self.profile_settings)

def get_settings_for_profile(self, id):
def get_settings_for_profile(self, profile_id):
"""Get the settings for the specified profile ID. Automatically adds an empty
settings dictionary if there is no settings dictionary found for the ID.
Args:
id (str): ID of the profile
profile_id (str): ID of the profile
Returns:
dict: Profile settings
"""
# Add empty settings dictionary if no dictionary found for the profile.
# This happens when a new profile is created.
if id not in self.profile_settings:
self.profile_settings[id] = {}
return self.profile_settings[id]
if profile_id not in self.profile_settings:
self.profile_settings[profile_id] = {}
return self.profile_settings[profile_id]

def _all_profiles(self):
"""Get all profiles from the profiles list in order from top to bottom.
Expand All @@ -219,7 +219,7 @@ def make_setting_tree(self, settings=None):
if settings is None:
return
self.building_tree = True
for id, group in UserProfileGroups.SETTINGS_GROUPS.items():
for group in UserProfileGroups.SETTINGS_GROUPS.values():
title = group["title"]
group_settings = group["settings"]
widget_item = QtWidgets.QTreeWidgetItem([title])
Expand Down Expand Up @@ -326,10 +326,10 @@ def profile_selected(self, update_settings=True):
"""
item = self.get_current_selected_item()
if item:
id = item.profile_id
self.current_profile_id = id
profile_id = item.profile_id
self.current_profile_id = profile_id
if update_settings:
settings = self.get_settings_for_profile(id)
settings = self.get_settings_for_profile(profile_id)
self.make_setting_tree(settings=settings)
else:
self.current_profile_id = None
Expand Down Expand Up @@ -421,12 +421,12 @@ def copy_profile(self):
"""Make a copy of the currently selected profile.
"""
item = self.get_current_selected_item()
id = str(uuid.uuid4())
profile_id = str(uuid.uuid4())
settings = deepcopy(self.profile_settings[self.current_profile_id])
self.profile_settings[id] = settings
self.profile_settings[profile_id] = settings
base_title = "%s %s" % (get_base_title(item.name), gettext_constants(DEFAULT_COPY_TEXT))
name = self.ui.profile_list.unique_profile_name(base_title)
self.ui.profile_list.add_profile(name=name, profile_id=id)
self.ui.profile_list.add_profile(name=name, profile_id=profile_id)
self.update_config_overrides()
self.reload_all_page_settings()

Expand Down Expand Up @@ -456,11 +456,11 @@ def _clean_and_get_all_profiles(self):
all_profile_ids = set(x['id'] for x in all_profiles)
keys = set(self.profile_settings.keys())
# Add any missing profile settings
for id in all_profile_ids.difference(keys):
self.profile_settings[id] = {}
for profile_id in all_profile_ids.difference(keys):
self.profile_settings[profile_id] = {}
# Remove any "orphan" profile settings
for id in keys.difference(all_profile_ids):
del self.profile_settings[id]
for profile_id in keys.difference(all_profile_ids):
del self.profile_settings[profile_id]
return all_profiles

def save(self):
Expand Down

0 comments on commit 971d88e

Please sign in to comment.