Skip to content

Commit

Permalink
Merge pull request #6 from magistar0/dev
Browse files Browse the repository at this point in the history
Dev to release build 31 v1.1.1
  • Loading branch information
magistar0 authored Feb 27, 2023
2 parents f2a436e + 6db1180 commit 7791272
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 30 deletions.
9 changes: 9 additions & 0 deletions data/config/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
"SECRET": "Для Кристины",
"ACCEPT": "Применить",
"CANCEL": "Отмена",
"ENTER_NAME": "Введите сюда ваше имя...",
"ENTER_EMAIL": "Введите сюда ваш E-mail...",
"SETTINGS_NAME_TEXT": "Имя",
"SETTINGS_EMAIL_TEXT": "Электронная почта",
"WARNING_HEADER": "Предупреждение",
"EMAIL_WARNING_TEXT": "Кажется, вы указали некорректный адрес электронной почты. Убедитесь, что ваш Email указан корректно.",

"RELOAD_TITLE": "Требуется перезагрузка",
"RELOAD_REQUIRED_TEXT": "Для применения изменений требуется перезагрузить программу. Перезагрузить сейчас?",
Expand Down Expand Up @@ -84,6 +90,9 @@
"EMAIL_ASK_HEADER": "Отправка результата",
"EMAIL_ASK_TEXT": "Введите ваш Email:",
"EMAIL_NAME_ASK_TEXT": "Введите ваше имя:",
"EMAIL_TIP_NO_NAME_AND_EMAIL": "Совет: вы можете установить имя и Email\nв настройках, чтобы не вводить их вручную.",
"EMAIL_TIP_NO_NAME": "Совет: вы можете установить имя\nв настройках, чтобы не вводить его вручную.",
"EMAIL_TIP_NO_EMAIL": "Совет: вы можете установить Email\nв настройках, чтобы не вводить его вручную.",
"EMAIL_ERROR_HEADER": "Ошибка",
"EMAIL_ERROR_0": "Ошибка отправки Email: некорректный адрес.",
"EMAIL_ERROR_1": "Вы не ввели Email.",
Expand Down
4 changes: 2 additions & 2 deletions data/config/config.jet
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"TIMER_TIME_IN_SECONDS": 14101,
"TIMER_FORMAT": "%s:%s:%s",
"build": "27",
"build": "31",
"SIZE_PARAMETERS": {
"tiny": {
"multiplier": 0.7,
Expand Down Expand Up @@ -74,4 +74,4 @@
"wrong": "background-color: #ab3b2c; "
}
}
}
}
8 changes: 8 additions & 0 deletions data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import pathlib
import Levenshtein
import re
from github import Github
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
Expand Down Expand Up @@ -140,6 +141,13 @@ def checkIfNameNeedsToBeTriggered(name: str) -> bool:

def getButtonStyles() -> dict:
return Config.button_styles

def checkIfSizeWasChanged(old_settings: dict, new_settings: dict) -> bool:
return old_settings["size"] != new_settings["size"]

def emailIsValid(email: str) -> bool:
pattern = r"[^@]+@[^@]+\.[^@]+"
return not not re.match(pattern, email) or email is None


class Email(object):
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def main():
save_manager.addSettingsParameter()
if not "easteregg_unlocked" in save_manager.read_save():
save_manager.addEasterEggParameter()
if not "name" in save_manager.read_save()["settings"]:
save_manager.addNameEmailParameters()


currentExitCode = 1337
while currentExitCode == 1337:
Expand Down
14 changes: 9 additions & 5 deletions save_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
import datetime
import os
import platform
from collections import Counter
from data_manager import Config

Expand All @@ -27,7 +25,7 @@ def generate_empty_save() -> None:
for task in range(1, 28):
save_data[task] = []
save_ex = {"save_data": save_data, "easteregg_unlocked": False, "exam_history": [],
"settings": {"size": "default"},
"settings": {"size": "default", "name": None, "email": None},
'update_time': str(datetime.datetime.now())}
update_save(save_ex)

Expand Down Expand Up @@ -109,7 +107,7 @@ def getExamHistory() -> list:

def addSettingsParameter() -> None:
save_data = read_save()
save_data["settings"] = {"size": "default"}
save_data["settings"] = {"size": "default", "name": None, "email": None}
update_save(save_data)

def changeSize(new_size: str) -> None:
Expand Down Expand Up @@ -138,4 +136,10 @@ def setEasterEggUnlocked() -> None:

def checkIfEasterEggIsUnlocked() -> bool:
save_data = read_save()
return save_data["easteregg_unlocked"]
return save_data["easteregg_unlocked"]

def addNameEmailParameters() -> None:
save_data = read_save()
save_data["settings"]["name"] = None
save_data["settings"]["email"] = None
update_save(save_data)
9 changes: 8 additions & 1 deletion task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ def choose_task(num: Union[int, str]) -> dict:
def get_task_list(num: Union[int, str]) -> list:
list_name = 'task_%s_list_of_dicts' % str(num)
data = data_manager.__dict__[list_name]
return data
return data

def get_task_by_id(task_num: Union[int, str], task_id: Union[int, str]) -> dict:
list_name = 'task_%s_list_of_dicts' % str(task_num)
data = data_manager.__dict__[list_name]
for dct in data:
if dct["id"] == str(task_id):
return dct
25 changes: 21 additions & 4 deletions ui_exam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import webbrowser
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtGui import QIcon, QPixmap, QFont

from task_manager import Task_Chooser
from data_manager import Localization, Config, Email, ID_Vars, Logger
Expand Down Expand Up @@ -1392,8 +1392,6 @@ def emailAction(self):
Logger.add_line_to_log("Succesfully sent Email to %s." % self.email)
QMessageBox.information(self, Localization.EMAIL_SUCCESS_HEADER, Localization.EMAIL_SUCCESS_TEXT, QMessageBox.Ok)
self.deleteResultFile()
else:
QMessageBox.critical(self, Localization.EMAIL_ERROR_HEADER, Localization.EMAIL_ERROR_1, QMessageBox.Ok)
else:
Logger.add_line_to_log("Error initializing Email module. Code: 2. Cause: no Internet access.")
QMessageBox.critical(self, Localization.EMAIL_ERROR_HEADER, Localization.EMAIL_ERROR_2, QMessageBox.Ok)
Expand Down Expand Up @@ -1428,11 +1426,30 @@ def __init__(self, parent=None):

self.first = QLineEdit(self)
self.second = QLineEdit(self)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self);
self.current_settings = save_manager.getCurrentSettings()
self.current_name = self.current_settings["name"]
self.current_email = self.current_settings["email"]
if self.current_name:
self.second.setText(self.current_name)
if self.current_email:
self.first.setText(self.current_email)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)

layout = QFormLayout(self)
layout.addRow(Localization.EMAIL_ASK_TEXT, self.first)
layout.addRow(Localization.EMAIL_NAME_ASK_TEXT, self.second)
if not self.current_name and not self.current_email:
self.tip_label = QLabel(Localization.EMAIL_TIP_NO_NAME_AND_EMAIL)
elif not self.current_name:
self.tip_label = QLabel(Localization.EMAIL_TIP_NO_NAME)
elif not self.current_email:
self.tip_label = QLabel(Localization.EMAIL_TIP_NO_EMAIL)
else:
self.tip_label = None
if self.tip_label:
self.tip_label.setFont(QFont("SF Pro Display", Config.multiplyNumberAccordingToSize(16, save_manager.getCurrentSettings()["size"])))
layout.addRow(self.tip_label)

layout.addWidget(buttonBox)

buttonBox.accepted.connect(self.acceptAction)
Expand Down
68 changes: 50 additions & 18 deletions ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,49 +217,81 @@ def clear_confirmed(self):

class UI_Settings(object):
def setupUi(self, SettingsWindow):
self.setMinimumSize(QSize(Config.multiplyNumberAccordingToSize(480, save_manager.getCurrentSettings()["size"]),
Config.multiplyNumberAccordingToSize(240, save_manager.getCurrentSettings()["size"])))
central_widget = QWidget(self)
self.setCentralWidget(central_widget)
current_settings = save_manager.getCurrentSettings()
self.setMinimumSize(QSize(Config.multiplyNumberAccordingToSize(480, current_settings["size"]),
Config.multiplyNumberAccordingToSize(240, current_settings["size"])))
self.central_widget = QWidget(self)
self.setCentralWidget(self.central_widget)
self.setWindowIcon(QIcon('icons/icon.png'))

grid_layout = QGridLayout()
central_widget.setLayout(grid_layout)
grid_layout.addWidget(QLabel(Localization.SETTING_SIZE_TEXT, self), 0, 0)
self.grid_layout = QGridLayout()
self.central_widget.setLayout(self.grid_layout)
self.grid_layout.addWidget(QLabel(Localization.SETTING_SIZE_TEXT, self), 0, 0)

self.available_sizes = ["tiny", "default", "big", "large"]
if save_manager.checkIfEasterEggIsUnlocked():
self.available_sizes.append("secret")
self.combo = QComboBox()
self.list_of_items = [Localization.getPrintfText(key) for key in self.available_sizes]
self.combo.addItems(self.list_of_items)
self.combo.setCurrentText(Localization.getPrintfText(save_manager.getCurrentSettings()["size"]))
self.combo.setCurrentText(Localization.getPrintfText(current_settings["size"]))

self.current_name, self.current_email = current_settings["name"], current_settings["email"]
self.name_blank = QLineEdit()
self.name_blank.setPlaceholderText(Localization.ENTER_NAME)
self.email_blank = QLineEdit()
self.email_blank.setPlaceholderText(Localization.ENTER_EMAIL)
if self.current_name:
self.name_blank.setText(self.current_name)
if self.current_email:
self.email_blank.setText(self.current_email)

self.ok_btn = QPushButton(Localization.ACCEPT)
self.cancel_btn = QPushButton(Localization.CANCEL)
self.cancel_btn.clicked.connect(lambda: self.close())
self.ok_btn.clicked.connect(self.ok_btn_clicked)

grid_layout.addWidget(self.combo, 1, 0, 1, 2)
grid_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding), 2, 0, 1, 2)
grid_layout.addWidget(self.ok_btn, 3, 0)
grid_layout.addWidget(self.cancel_btn, 3, 1)
self.grid_layout.addWidget(self.combo, 1, 0, 1, 2)
self.grid_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding), 2, 0, 1, 2)
self.grid_layout.addWidget(QLabel(Localization.SETTINGS_NAME_TEXT, self), 3, 0)
self.grid_layout.addWidget(self.name_blank, 4, 0, 1, 2)
self.grid_layout.addWidget(QLabel(Localization.SETTINGS_EMAIL_TEXT, self), 5, 0)
self.grid_layout.addWidget(self.email_blank, 6, 0, 1, 2)
self.grid_layout.addWidget(self.ok_btn, 7, 0)
self.grid_layout.addWidget(self.cancel_btn, 7, 1)

def ok_btn_clicked(self):
current_settings = save_manager.getCurrentSettings()
new_settings = deepcopy(current_settings)

sizes = {
0: "tiny", 1: "default", 2: "big", 3: "large", 4: "secret"
}
size_index = self.combo.currentIndex()
current_settings = save_manager.getCurrentSettings()
new_settings = deepcopy(current_settings)

new_size = sizes[size_index]
new_settings["size"] = new_size
if not new_settings == current_settings:

name = self.name_blank.text()
email = self.email_blank.text()
new_settings["name"] = name if name else None
new_settings["email"] = email if email else None

settings_was_changed = new_settings != current_settings
reload_required = Config.checkIfSizeWasChanged(current_settings, new_settings)
email_was_changed = new_settings["email"] != current_settings["email"]
email_is_valid = True
if email_was_changed:
email_is_valid = Config.emailIsValid(new_settings["email"])
if settings_was_changed and reload_required:
if not email_is_valid:
QMessageBox.information(self, Localization.WARNING_HEADER, Localization.EMAIL_WARNING_TEXT, QMessageBox.Ok)
save_manager.updateSettings(new_settings)
self.ask_for_reload()
else:
self.close()
elif settings_was_changed:
save_manager.updateSettings(new_settings)
if not email_is_valid:
QMessageBox.information(self, Localization.WARNING_HEADER, Localization.EMAIL_WARNING_TEXT, QMessageBox.Ok)
self.close()

def ask_for_reload(self):
box = QMessageBox()
Expand Down

0 comments on commit 7791272

Please sign in to comment.