Skip to content

Commit

Permalink
feat: add the templates dir settings
Browse files Browse the repository at this point in the history
  • Loading branch information
daxartio committed Nov 16, 2024
1 parent 5aad9bd commit 6b4e580
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog_ru.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Список изменений

## next

+ Добавлена возможность выбрать директорию с шаблонами

## 2024-10-07 v1.7.1

- Перестройка индекса после основных операций удаления/изменения номера или чипа
Expand Down
6 changes: 6 additions & 0 deletions languages/ru_RU/LC_MESSAGES/sportorg.po
Original file line number Diff line number Diff line change
Expand Up @@ -1658,3 +1658,9 @@ msgstr "Открыть файл финиша orgeo.ru, CSV (https://orgeo.ru/eve

msgid "Miss penalty lap"
msgstr "Пропущен штрафной круг"

msgid "Select the templates directory"
msgstr "Выбрать директорию с шаблонами"

msgid "Open the templates directory"
msgstr "Открыть директорию с шаблонами"
5 changes: 5 additions & 0 deletions sportorg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def data_dir(*paths) -> str:
TEMPLATE_DIR = env.TEMPLATES_PATH or base_dir('templates')


def set_template_dir(dirpath: str) -> None:
global TEMPLATE_DIR
TEMPLATE_DIR = dirpath


def template_dir(*paths) -> str:
return os.path.join(TEMPLATE_DIR, *paths)

Expand Down
5 changes: 5 additions & 0 deletions sportorg/gui/dialogs/file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from sportorg.modules.configs.configs import Config, ConfigFile


def get_existing_directory(caption='', dir=''):
result = QFileDialog.getExistingDirectory(None, caption, dir)
return result


def get_open_file_name(caption='', filter_text='', set_dir=True):
result = QFileDialog.getOpenFileName(None, caption, get_default_dir(), filter_text)[
0
Expand Down
37 changes: 34 additions & 3 deletions sportorg/gui/dialogs/report_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

from sportorg import config
from sportorg.common.template import get_templates, get_text_from_file
from sportorg.gui.dialogs.file_dialog import get_open_file_name, get_save_file_name
from sportorg.gui.dialogs.file_dialog import (
get_existing_directory,
get_open_file_name,
get_save_file_name,
)
from sportorg.gui.global_access import GlobalAccess
from sportorg.gui.utils.custom_controls import AdvComboBox
from sportorg.language import translate
Expand All @@ -25,6 +29,7 @@
from sportorg.models.result.result_calculation import ResultCalculation
from sportorg.models.result.score_calculation import ScoreCalculation
from sportorg.models.result.split_calculation import RaceSplits
from sportorg.modules.configs.configs import Config

_settings = {
'last_template': None,
Expand Down Expand Up @@ -53,14 +58,40 @@ def init_ui(self):

self.label_template = QLabel(translate('Template'))
self.item_template = AdvComboBox()
self.item_template.addItems(get_templates(config.template_dir('reports')))
self.item_template.addItems(
sorted(get_templates(config.template_dir('reports')))
)
self.layout.addRow(self.label_template, self.item_template)
if _settings['last_template']:
self.item_template.setCurrentText(_settings['last_template'])

self.item_custom_dir = QPushButton(translate('Select the templates directory'))

def select_custom_dir() -> None:
dirpath = get_existing_directory(
translate('Open the templates directory'), config.template_dir()
)
if not dirpath:
return

self.item_custom_dirpath.setText(dirpath)
Config().templates.set('directory', dirpath)
config.set_template_dir(dirpath)
self.item_template.clear()
self.item_template.addItems(
sorted(get_templates(config.template_dir('reports')))
)

self.item_custom_dir.clicked.connect(select_custom_dir)
self.layout.addRow(self.item_custom_dir)

self.item_custom_dirpath = QLabel()
self.item_custom_dirpath.setText(config.template_dir())
self.layout.addRow(self.item_custom_dirpath)

self.item_custom_path = QPushButton(translate('Choose template'))

def select_custom_path():
def select_custom_path() -> None:
file_name = get_open_file_name(
translate('Open HTML template'), translate('HTML file (*.html)')
)
Expand Down
7 changes: 6 additions & 1 deletion sportorg/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ def conf_read(self):
except Exception as e:
logging.error(str(e))

self._handler.setLevel(Configuration().configuration.get('logging_level'))
level: str = Configuration().configuration.get('logging_level', 'INFO')
self._handler.setLevel(level)

dirpath = Configuration().templates.get('directory')
if dirpath:
config.set_template_dir(dirpath)

def conf_write(self):
Configuration().save()
Expand Down
6 changes: 6 additions & 0 deletions sportorg/modules/configs/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ConfigFile:
SOUND = 'sound'
PRINTER = 'printer'
RANKING = 'ranking'
TEMPLATES = 'templates'


class Parser:
Expand Down Expand Up @@ -122,6 +123,7 @@ def __init__(self):
}
),
ConfigFile.GEOMETRY: Configurations({'x': 0, 'y': 0}),
ConfigFile.TEMPLATES: Configurations({'directory': ''}),
}

@property
Expand All @@ -148,6 +150,10 @@ def ranking(self):
def geometry(self):
return self._configurations[ConfigFile.GEOMETRY]

@property
def templates(self):
return self._configurations[ConfigFile.TEMPLATES]

def read(self):
self.parser.read(sportorg_config.CONFIG_INI)

Expand Down

0 comments on commit 6b4e580

Please sign in to comment.