Добавлен выбор валюты, исправления в локализации

This commit is contained in:
Risen 2023-06-09 22:16:49 +03:00
parent 53e56e4bec
commit 45bec6a575
5 changed files with 84 additions and 74 deletions

View File

@ -6,21 +6,14 @@ import gettext
import requests import requests
from calculating import calculating, amortization, cost_prise from calculating import calculating, amortization, cost_prise
from setts import window_setts from setts import window_setts, language, currency_setts
from texts import calc, about, new_marge, ver, not_connect from texts import calc, about, new_marge, ver, not_connect
from update import upd_check from update import upd_check
now = datetime.datetime.now() now = datetime.datetime.now()
with open('setts.json') as file: lang = gettext.translation('locale', localedir='locale', languages=[language()])
old_data = json.load(file)
if old_data['settings']["locale"] == 'English':
locale = 'en_US'
else:
locale = 'ru_RU'
lang = gettext.translation('locale', localedir='locale', languages=[locale])
lang.install() lang.install()
_ = lang.gettext _ = lang.gettext
@ -39,11 +32,11 @@ def create_window():
[Sgi.Txt('_' * 46)], [Sgi.Txt('_' * 46)],
[Sgi.Text('0', size=(7, 1), font=('Consolas', 32), [Sgi.Text('0', size=(7, 1), font=('Consolas', 32),
text_color='white', key='result', auto_size_text=True, justification='right', expand_x=True), text_color='white', key='result', auto_size_text=True, justification='right', expand_x=True),
Sgi.Text(_('руб.'), font=('Consolas', 32), text_color='white', key='result')], Sgi.Text(currency_setts(), font=('Consolas', 32), text_color='white', key='result')],
[Sgi.Text(_('Себестоимость:'), font=12, text_color='white'), [Sgi.Text(_('Себестоимость:'), font=12, text_color='white'),
Sgi.Text('0', size=(7, 1), font=12, text_color='white', key='cost', auto_size_text=True, Sgi.Text('0', size=(7, 1), font=12, text_color='white', key='cost', auto_size_text=True,
justification='right', expand_x=True), justification='right', expand_x=True),
Sgi.Text(_('руб.'), font=('Consolas', 12), text_color='white', key='cost')], Sgi.Text(currency_setts(), font=('Consolas', 12), text_color='white', key='cost')],
[Sgi.Txt('_' * 46, pad=(10, 5))], [Sgi.Txt('_' * 46, pad=(10, 5))],
[Sgi.Text(_('Время печати')), Sgi.Push(), Sgi.InputText('0', size=(5, 20)), Sgi.Text(_('ч.')), [Sgi.Text(_('Время печати')), Sgi.Push(), Sgi.InputText('0', size=(5, 20)), Sgi.Text(_('ч.')),
Sgi.InputText('0', size=(5, 0)), Sgi.Text(_('мин. '))], Sgi.InputText('0', size=(5, 0)), Sgi.Text(_('мин. '))],
@ -53,9 +46,9 @@ def create_window():
Sgi.Text(_('шт. '))], Sgi.Text(_('шт. '))],
[Sgi.Txt('_' * 46)], [Sgi.Txt('_' * 46)],
[Sgi.Text(_('Моделирование')), Sgi.Push(), Sgi.InputText('0', size=(10, 20), justification='right', ), [Sgi.Text(_('Моделирование')), Sgi.Push(), Sgi.InputText('0', size=(10, 20), justification='right', ),
Sgi.Text(_('руб. '))], Sgi.Text(f'{currency_setts()} ')],
[Sgi.Text(_('Постобработка')), Sgi.Push(), Sgi.InputText('0', size=(10, 20), justification='right', ), [Sgi.Text(_('Постобработка')), Sgi.Push(), Sgi.InputText('0', size=(10, 20), justification='right', ),
Sgi.Text(_('руб. '))], Sgi.Text(f'{currency_setts()} ')],
[Sgi.Txt('_' * 46)], [Sgi.Txt('_' * 46)],
[Sgi.Txt(' ' * 15), Sgi.ReadFormButton(_('Рассчитать'), size=(10, 2)), Sgi.Cancel(_('Выход'), size=(10, 2))] [Sgi.Txt(' ' * 15), Sgi.ReadFormButton(_('Рассчитать'), size=(10, 2)), Sgi.Cancel(_('Выход'), size=(10, 2))]

View File

@ -22,3 +22,5 @@ themes_list = ['Black', 'BlueMono', 'BluePurple', 'BrightColors', 'BrownBlue', '
'SandyBeach', 'SystemDefault', 'SystemDefault1', 'SystemDefaultForReal', 'Tan', 'TanBlue', 'SandyBeach', 'SystemDefault', 'SystemDefault1', 'SystemDefaultForReal', 'Tan', 'TanBlue',
'TealMono', 'Topanga'] 'TealMono', 'Topanga']
lang_list = ['Русский', 'English'] lang_list = ['Русский', 'English']
currency_list = ['руб.', '$', '']

View File

@ -1,23 +1,39 @@
import json import json
import PySimpleGUI as Sgi import PySimpleGUI as Sgi
import gettext import gettext
import os
from texts import amortization_calc, new_sets from texts import amortization_calc, new_sets
from lists import themes_list, lang_list from lists import themes_list, lang_list, currency_list
with open('setts.json') as file: def language():
with open(os.path.expanduser('setts.json')) as file:
old_data = json.load(file) old_data = json.load(file)
if old_data['settings']["locale"] == 'English': if old_data['settings']["locale"] == 'English':
locale = 'en_US' locale = 'en_US'
else: else:
locale = 'ru_RU' locale = 'ru_RU'
return locale
lang = gettext.translation('locale', localedir='locale', languages=[locale])
lang = gettext.translation('locale', localedir='locale', languages=[language()])
lang.install() lang.install()
_ = lang.gettext _ = lang.gettext
def currency_setts():
with open('setts.json') as file:
old_data = json.load(file)
if old_data['settings']["currency"] == 'руб.':
currency = 'руб.'
elif old_data['settings']["currency"] == '$':
currency = '$'
else:
currency = ''
return currency
def window_setts(): def window_setts():
with open('setts.json') as file: with open('setts.json') as file:
old_data = json.load(file) old_data = json.load(file)
@ -29,6 +45,7 @@ def window_setts():
mk = old_data["settings"]["mk"] mk = old_data["settings"]["mk"]
a = old_data["settings"]["a"] a = old_data["settings"]["a"]
locale = old_data['settings']["locale"] locale = old_data['settings']["locale"]
currency = old_data['settings']["currency"]
try: try:
spi = old_data["settings"]["spi"] spi = old_data["settings"]["spi"]
except KeyError: except KeyError:
@ -46,7 +63,8 @@ def window_setts():
[Sgi.Text(_('Тариф электроэнергии, кВт/ч')), Sgi.Push(), [Sgi.Text(_('Тариф электроэнергии, кВт/ч')), Sgi.Push(),
Sgi.InputText(h, size=(10, 10), justification='right')], Sgi.InputText(h, size=(10, 10), justification='right')],
[Sgi.Text(_('Коэффициент выбраковки')), Sgi.Push(), Sgi.InputText(d, size=(10, 10), justification='right')], [Sgi.Text(_('Коэффициент выбраковки')), Sgi.Push(), Sgi.InputText(d, size=(10, 10), justification='right')],
[Sgi.Text(_('Стоимость катушки, руб.')), Sgi.Push(), Sgi.InputText(st, size=(10, 10), justification='right')], [Sgi.Text(_('Стоимость катушки, ')+f'{currency_setts()}'), Sgi.Push(),
Sgi.InputText(st, size=(10, 10), justification='right')],
[Sgi.Text(_('Вес катушки, гр.')), Sgi.Push(), [Sgi.Text(_('Вес катушки, гр.')), Sgi.Push(),
Sgi.Combo(['225', '250', '450', '500', '750', '850', '1000', '2250', Sgi.Combo(['225', '250', '450', '500', '750', '850', '1000', '2250',
'2500'], size=(8, 20), default_value=mk)], '2500'], size=(8, 20), default_value=mk)],
@ -54,7 +72,7 @@ def window_setts():
[Sgi.Text('')] [Sgi.Text('')]
] ]
layout2 = [ layout2 = [
[Sgi.Text(_('Стоимость вашего принтера, руб.')), Sgi.Push(), Sgi.InputText(a, size=(10, 10), [Sgi.Text(_('Стоимость вашего принтера, ')+f'{currency_setts()}'), Sgi.Push(), Sgi.InputText(a, size=(10, 10),
justification='right')], justification='right')],
[Sgi.Text(_('Срок полезного использования, лет.')), Sgi.Push(), Sgi.InputText(spi, size=(10, 10), [Sgi.Text(_('Срок полезного использования, лет.')), Sgi.Push(), Sgi.InputText(spi, size=(10, 10),
justification='right')], justification='right')],
@ -65,6 +83,7 @@ def window_setts():
[Sgi.Text(_('Оформление'))], [Sgi.Text(_('Оформление'))],
[Sgi.Text(_("Выбор темы")), Sgi.Push(), Sgi.Combo(themes_list, size=(20, 20), default_value=theme)], [Sgi.Text(_("Выбор темы")), Sgi.Push(), Sgi.Combo(themes_list, size=(20, 20), default_value=theme)],
[Sgi.Text(_("Язык")), Sgi.Push(), Sgi.Combo(lang_list, size=(20, 20), default_value=locale)], [Sgi.Text(_("Язык")), Sgi.Push(), Sgi.Combo(lang_list, size=(20, 20), default_value=locale)],
[Sgi.Text(_("Валюта")), Sgi.Push(), Sgi.Combo(currency_list, size=(20, 20), default_value=currency_setts())],
] ]
tab_group = [ tab_group = [
@ -85,6 +104,10 @@ def window_setts():
new_locale = locale new_locale = locale
else: else:
new_locale = values[9] new_locale = values[9]
if values[10] == currency:
new_currency = currency
else:
new_currency = values[10]
if values[0] == p: if values[0] == p:
new_p = p new_p = p
else: else:
@ -128,7 +151,8 @@ def window_setts():
"a": new_a, "a": new_a,
"spi": new_spi, "spi": new_spi,
"marge": new_marg, "marge": new_marg,
"locale": new_locale "locale": new_locale,
"currency": new_currency
} }
} }

View File

@ -2,7 +2,6 @@ import gettext
import json import json
import os import os
if not os.path.isfile('setts.json'): if not os.path.isfile('setts.json'):
with open('setts.json', 'w') as file: with open('setts.json', 'w') as file:
data = {"settings": {"theme": "Dark", data = {"settings": {"theme": "Dark",
@ -14,7 +13,8 @@ if not os.path.isfile('setts.json'):
"a": "0", "a": "0",
"spi": "3", "spi": "3",
"marg": "0", "marg": "0",
"locale": "Ru"}} "locale": "Ru",
"currency": "руб."}}
json.dump(data, file, indent=2) json.dump(data, file, indent=2)
with open('setts.json') as file: with open('setts.json') as file:
@ -28,7 +28,6 @@ lang = gettext.translation('locale', localedir='locale', languages=[locale])
lang.install() lang.install()
_ = lang.gettext _ = lang.gettext
calc = (_("Формула расчета стоимости печати выглядит так:\n\n" calc = (_("Формула расчета стоимости печати выглядит так:\n\n"
"S = ((p/1000*t/60*h)+(md*d*st/mk)+am+post))*x+mod\n\n" "S = ((p/1000*t/60*h)+(md*d*st/mk)+am+post))*x+mod\n\n"
"где:\n" "где:\n"
@ -50,10 +49,7 @@ calc = (_("Формула расчета стоимости печати выг
"считается как 1,5 детали " "считается как 1,5 детали "
"Можете изменить этот пункт в настройках.\n\n")) "Можете изменить этот пункт в настройках.\n\n"))
about = (_("Программа написана потому, что мне было скучно\n" about = (_("По вопросам и предложениям писать в телеграм на @RisenYT\n\n"))
"Использовать её или нет дело ваше, мне все равно\n"
"Распространяется по принципу 'как есть'\n"
"По вопросам и предложениям писать в телеграм на @RisenYT\n\n"))
amortization_calc = (_('Как считается амортизация:\n\n' amortization_calc = (_('Как считается амортизация:\n\n'
'Отчисления записываются \n' 'Отчисления записываются \n'
@ -77,4 +73,4 @@ new_sets = (_('Задайте стоимость принтера, \n'
new_marge = (_('Задайте процент желаемой наценки\n' new_marge = (_('Задайте процент желаемой наценки\n'
'в настройках (можно просто проставить ноль)')) 'в настройках (можно просто проставить ноль)'))
ver = '0.6.0' ver = '0.6.1'

View File

@ -6,15 +6,10 @@ import os
import gettext import gettext
from texts import ver from texts import ver
from setts import language
with open(os.path.expanduser('setts.json')) as file:
old_data = json.load(file)
if old_data['settings']["locale"] == 'English':
locale = 'en_US'
else:
locale = 'ru_RU'
lang = gettext.translation('locale', localedir='locale', languages=[locale]) lang = gettext.translation('locale', localedir='locale', languages=[language()])
lang.install() lang.install()
_ = lang.gettext _ = lang.gettext
@ -50,7 +45,7 @@ def upd_check():
else: else:
Sgi.theme(set_theme) Sgi.theme(set_theme)
layout = [ layout = [
[Sgi.Text(_(f"Последняя версия: {version_new}\nВаша версия: {version_old}\n\nОбновление не требуется"))], [Sgi.Text(_('Последняя версия: ')+f'{version_new}'+_('\nВаша версия: ')+f'{version_old}'+_('\n\nОбновление не требуется'))],
[Sgi.Button(_(' Закрыть '))] [Sgi.Button(_(' Закрыть '))]
] ]