2023-04-08 07:08:13 +03:00
|
|
|
|
import datetime
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
import PySimpleGUI as Sgi
|
2023-05-28 15:59:32 +03:00
|
|
|
|
import gettext
|
|
|
|
|
import requests
|
2023-04-08 07:08:13 +03:00
|
|
|
|
|
|
|
|
|
from calculating import calculating, amortization, cost_prise
|
2023-06-09 22:16:49 +03:00
|
|
|
|
from setts import window_setts, language, currency_setts
|
2023-05-28 15:59:32 +03:00
|
|
|
|
from texts import calc, about, new_marge, ver, not_connect
|
2024-03-31 13:42:28 +03:00
|
|
|
|
from update import upd_check
|
2023-04-08 07:08:13 +03:00
|
|
|
|
|
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
|
|
|
|
|
|
|
2023-06-09 22:16:49 +03:00
|
|
|
|
lang = gettext.translation('locale', localedir='locale', languages=[language()])
|
2023-05-28 15:59:32 +03:00
|
|
|
|
lang.install()
|
|
|
|
|
_ = lang.gettext
|
|
|
|
|
|
|
|
|
|
|
2023-04-08 07:08:13 +03:00
|
|
|
|
def create_window():
|
2023-07-13 20:35:03 +03:00
|
|
|
|
with open(os.path.expanduser('setts.json')) as f:
|
2023-05-28 15:59:32 +03:00
|
|
|
|
theme = json.load(f)['settings']['theme']
|
2023-04-08 07:08:13 +03:00
|
|
|
|
Sgi.theme(theme)
|
|
|
|
|
menu_def = [
|
2023-05-28 15:59:32 +03:00
|
|
|
|
[_('Файл'), [_('Настройки')], [_('Выход')]],
|
|
|
|
|
[_('Помощь'), [_('Как рассчитывается стоимость'), _('Обо мне'), _('Проверить обновления')]],
|
2023-04-08 07:08:13 +03:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
layout = [
|
|
|
|
|
[Sgi.Menu(menu_def)],
|
|
|
|
|
[Sgi.Txt('_' * 46)],
|
|
|
|
|
[Sgi.Text('0', size=(7, 1), font=('Consolas', 32),
|
|
|
|
|
text_color='white', key='result', auto_size_text=True, justification='right', expand_x=True),
|
2023-06-09 22:16:49 +03:00
|
|
|
|
Sgi.Text(currency_setts(), font=('Consolas', 32), text_color='white', key='result')],
|
2023-05-28 15:59:32 +03:00
|
|
|
|
[Sgi.Text(_('Себестоимость:'), font=12, text_color='white'),
|
2023-04-08 07:08:13 +03:00
|
|
|
|
Sgi.Text('0', size=(7, 1), font=12, text_color='white', key='cost', auto_size_text=True,
|
|
|
|
|
justification='right', expand_x=True),
|
2023-06-09 22:16:49 +03:00
|
|
|
|
Sgi.Text(currency_setts(), font=('Consolas', 12), text_color='white', key='cost')],
|
2023-04-08 07:08:13 +03:00
|
|
|
|
[Sgi.Txt('_' * 46, pad=(10, 5))],
|
2023-05-28 15:59:32 +03:00
|
|
|
|
[Sgi.Text(_('Время печати')), Sgi.Push(), Sgi.InputText('0', size=(5, 20)), Sgi.Text(_('ч.')),
|
|
|
|
|
Sgi.InputText('0', size=(5, 0)), Sgi.Text(_('мин. '))],
|
2023-05-31 16:58:39 +03:00
|
|
|
|
[Sgi.Text(_('Масса детали')), Sgi.Push(), Sgi.InputText('0', size=(10, 20), justification='right', ),
|
|
|
|
|
Sgi.Text(_('г. '))],
|
2023-05-28 15:59:32 +03:00
|
|
|
|
[Sgi.Text(_('Количество экземпляров')), Sgi.Push(), Sgi.InputText('1', size=(10, 20), justification='right', ),
|
|
|
|
|
Sgi.Text(_('шт. '))],
|
2023-04-08 07:08:13 +03:00
|
|
|
|
[Sgi.Txt('_' * 46)],
|
2023-05-28 15:59:32 +03:00
|
|
|
|
[Sgi.Text(_('Моделирование')), Sgi.Push(), Sgi.InputText('0', size=(10, 20), justification='right', ),
|
2023-06-09 22:16:49 +03:00
|
|
|
|
Sgi.Text(f'{currency_setts()} ')],
|
2023-05-28 15:59:32 +03:00
|
|
|
|
[Sgi.Text(_('Постобработка')), Sgi.Push(), Sgi.InputText('0', size=(10, 20), justification='right', ),
|
2023-06-09 22:16:49 +03:00
|
|
|
|
Sgi.Text(f'{currency_setts()} ')],
|
2023-04-08 07:08:13 +03:00
|
|
|
|
[Sgi.Txt('_' * 46)],
|
2023-05-31 16:58:39 +03:00
|
|
|
|
[Sgi.Txt(' ' * 15), Sgi.ReadFormButton(_('Рассчитать'), size=(10, 2)), Sgi.Cancel(_('Выход'), size=(10, 2))]
|
2023-04-08 07:08:13 +03:00
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
return Sgi.Window(f'Calc3D by Risen ver.{ver}', layout, icon='logo.ico')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
window = create_window()
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
event, values = window.read()
|
|
|
|
|
|
2023-05-28 15:59:32 +03:00
|
|
|
|
if event == _("Настройки"):
|
2023-04-08 07:08:13 +03:00
|
|
|
|
window_setts()
|
|
|
|
|
window.close()
|
|
|
|
|
window = create_window()
|
|
|
|
|
|
2023-05-28 15:59:32 +03:00
|
|
|
|
elif event == _("Как рассчитывается стоимость"):
|
2023-04-08 07:08:13 +03:00
|
|
|
|
Sgi.popup_ok(calc)
|
|
|
|
|
|
2023-05-28 15:59:32 +03:00
|
|
|
|
elif event == _("Обо мне"):
|
2023-04-08 07:08:13 +03:00
|
|
|
|
Sgi.popup(about)
|
|
|
|
|
|
|
|
|
|
elif event == "Проверить обновления":
|
|
|
|
|
try:
|
|
|
|
|
upd_check()
|
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
|
Sgi.popup_ok(not_connect)
|
|
|
|
|
|
2023-05-31 16:58:39 +03:00
|
|
|
|
elif event == _('Рассчитать'):
|
2023-07-13 20:35:03 +03:00
|
|
|
|
with open(os.path.expanduser('setts.json')) as f:
|
2023-05-28 15:59:32 +03:00
|
|
|
|
params = json.load(f)["settings"]
|
2023-04-08 07:08:13 +03:00
|
|
|
|
try:
|
|
|
|
|
hours = float(values[1])
|
|
|
|
|
except ValueError:
|
|
|
|
|
hours = 0
|
|
|
|
|
try:
|
|
|
|
|
minutes = float(values[2])
|
|
|
|
|
except ValueError:
|
|
|
|
|
minutes = 0
|
|
|
|
|
|
|
|
|
|
if minutes > 60:
|
|
|
|
|
hours = hours + minutes // 60
|
|
|
|
|
minutes = minutes % 60
|
|
|
|
|
t = hours * 60 + minutes
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
md = values[3]
|
|
|
|
|
except ValueError:
|
|
|
|
|
md = 0
|
|
|
|
|
|
|
|
|
|
am = amortization(params['a'], t, params['spi'], now.year) # a, t, spi, year
|
|
|
|
|
|
|
|
|
|
cost = cost_prise(params['p'], t, params['h'], md, params['d'], params['st'], params['mk'], am,
|
|
|
|
|
values[6], values[4]) # p, t, h, md, d, st, mk, am, post, x
|
|
|
|
|
|
|
|
|
|
try:
|
2023-05-29 14:08:52 +03:00
|
|
|
|
result = calculating(abs(cost), values[5], params['marge']) # cost, mod, marg
|
2023-04-08 07:08:13 +03:00
|
|
|
|
except KeyError:
|
|
|
|
|
Sgi.popup_ok(new_marge)
|
|
|
|
|
result = 0
|
|
|
|
|
window.find_element('result').Update(result)
|
|
|
|
|
window.find_element('cost').Update(cost)
|
|
|
|
|
|
2023-05-28 15:59:32 +03:00
|
|
|
|
elif event in (Sgi.WIN_CLOSED, _('Выход')):
|
2023-04-08 07:08:13 +03:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|