Skip to content

Commit

Permalink
FIX AND ADD PATTERN THAT WOULD CREATE ON RUNTIME
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyMa-1 committed Jan 6, 2024
1 parent 75d0dbe commit 0574541
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

def ensure_if_ok_to_run():
PathManager.set_project_root(pathlib.Path(__file__).absolute().parent)
PathManager.create_settings_ini()
os.makedirs('configs', exist_ok=True)
os.makedirs('exports', exist_ok=True)
os.makedirs('pattern_gallery', exist_ok=True)
PathManager.create_square_pattern()


def init_language_settings():
Expand All @@ -40,7 +42,7 @@ def init_language_settings():
# Initialize translations using resource file
translator = QTranslator(app)
path = f':/translations/main_gui_{lang}.qm'
if translator.load(path):
if lang == 'ru' and translator.load(path):
app.installTranslator(translator)


Expand Down
23 changes: 22 additions & 1 deletion src/backend/PathManager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: ZyMa-1
"""

import os
import pathlib


Expand All @@ -20,3 +20,24 @@ def set_project_root(cls, path: pathlib.Path):
cls.EXPORTS_DIR = cls.PROJECT_ROOT / "exports"
cls.SETTINGS_INI = cls.PROJECT_ROOT / "settings.ini"
cls.PATTERN_GALLERY_DIR = cls.PROJECT_ROOT / "pattern_gallery"

@classmethod
def create_settings_ini(cls):
if not os.path.exists(cls.SETTINGS_INI):
with open(cls.SETTINGS_INI, 'w') as f:
f.write('[General]\nLanguage=en')

@classmethod
def create_square_pattern(cls):
with open(cls.PATTERN_GALLERY_DIR / "square.json", 'w') as f:
f.write(
"""{
"rows": 5,
"cols": 5,
"state": [["*","*","*","*","*"],
["*",".",".",".","*"],
["*",".",".",".","*"],
["*",".",".",".","*"],
["*","*","*","*","*"]],
"pattern_name": "Square"
}""")
8 changes: 0 additions & 8 deletions src/backend/SettingsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ class SettingsManager(QObject, metaclass=_SingletonMeta):
def __init__(self, parent=None):
super().__init__(parent)
settings_path = str(PathManager.SETTINGS_INI)

# Check if the INI file exists, and create it if not
if not os.path.exists(settings_path):
with open(settings_path, 'w'):
pass

self.settings = QSettings(settings_path, QSettings.Format.IniFormat)
if not self.settings.contains("Language"):
self.settings.setValue("Language", "en")

def settings_instance(self) -> QSettings:
return self.settings

0 comments on commit 0574541

Please sign in to comment.