Skip to content

Commit

Permalink
fix: settings transfer (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneGit authored Dec 4, 2023
1 parent 9de5d8a commit 248de87
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/entry_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ def open_existing_project(self):
# add existing project to recent projects
self.add_recent_project(selected_project)

self.сheck_project_version(selected_project)
if not self.сheck_project_version(selected_project):
return

# emit signal with path to project file
self.open_project_signal.emit(selected_project)
Expand All @@ -225,7 +226,7 @@ def сheck_project_version(self, project_path):
message_box.addButton(QMessageBox.Yes)
message_box.addButton(QMessageBox.No)
message_box.button(QMessageBox.Yes).setText(locale.Update)
message_box.button(QMessageBox.No).setText(locale.ContinueWithoutUpdating)
message_box.button(QMessageBox.No).setText(locale.Cancel)

reply = message_box.exec()

Expand All @@ -235,3 +236,8 @@ def сheck_project_version(self, project_path):
shutil.copyfile("settings.yaml", project_settings_filename)
paths_transfer_in_settings(project_settings_old_filename, project_settings_filename)
set_version(project_settings_filename, build_version)
return True

return False

return True
6 changes: 2 additions & 4 deletions src/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ class Locale:
DefaultPrinterWarn = "Be aware that you are using default printer. New data might be removed after update. We recommend to create new printer and calibrate it."
CheckUpdates = "Check for updates"
ProjectUpdate = "Project update"
SettingsUpdate = "The current project's settings are outdated. This may lead to errors in the program. Do you want to update? New setting's fields will be set to default values, please recheck."
SettingsUpdate = "We want to update the project settings. Please check the values of the new fields. They will be set to default values."
Update = "Update"
ContinueWithoutUpdating = "Continue without updating"
EmptyDescription = "The error description cannot be empty"

def __init__(self, **entries):
Expand Down Expand Up @@ -265,9 +264,8 @@ def __init__(self, **entries):
DefaultPrinterWarn = "Будьте внимательны, Вы используете принтер по умолчанию. Данные этого принтера будут перезаписываться при обновлениях. Мы рекомендуем создать и использовать свою конфигурацию принтера.",
CheckUpdates = "Проверить наличие обновлений",
ProjectUpdate = "Обновление проекта",
SettingsUpdate = "Настройки текущего проекта устарели. Это может привести к ошибкам в работе программы. Хотите обновить? Новые поля настроек будут выставлены в значения по умолчанию, пожалуйста проверьте.",
SettingsUpdate = "Мы хотим обновить настройки проекта. Пожалуйста, проверьте значения новых полей. Они будут выставлены в значения по умолчанию.",
Update = "Обновить",
ContinueWithoutUpdating = "Продолжить без обновления",
EmptyDescription = "Описание ошибки не может быть пустым",
),
}
Expand Down
16 changes: 8 additions & 8 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ def paths_transfer_in_settings(initial_settings_filename, final_settings_filenam
with open(final_settings_filename, "w") as settings_file:
yaml.dump(final_settings, settings_file, default_flow_style=False)

def compare_settings(settings1, settings2):
for key in set(settings2):
if isinstance(settings2[key], dict):
compare_settings(settings1[key], settings2[key])
else:
if key in settings1:
if not settings1[key] is None:
settings2[key] = settings1[key]
def compare_settings(initial_settings, final_settings):
for key in set(final_settings):
if key in initial_settings:
if isinstance(final_settings[key], dict):
compare_settings(initial_settings[key], final_settings[key])
else:
if not initial_settings[key] is None:
final_settings[key] = initial_settings[key]

class Settings(object):
def __init__(self, d):
Expand Down

0 comments on commit 248de87

Please sign in to comment.