Skip to content

Commit

Permalink
раскрашиваем кнопки
Browse files Browse the repository at this point in the history
  • Loading branch information
magistar0 committed Feb 7, 2023
1 parent 849ebc4 commit 74d6645
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 43 deletions.
1 change: 1 addition & 0 deletions data/config/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"TIMER_TEXT_TIME_EXPIRED": "Время вышло!",
"TIMER_TEXT": "Оставшееся время: %s.",

"EXAM_TIMER_NOT_STARTED": "Таймер запустится, когда вы откроете любое задание.",
"EXAM_GET_DESTINATION_ERROR": "Недопустимое расположение файла. Попробуйте ещё раз.",
"EXAM_GET_FILE_ERROR": "Ошибка получения файла.",
"EXAM_SUCCESS": "Файл успешно сохранён. Имя файла: %s",
Expand Down
117 changes: 75 additions & 42 deletions data/config/config.jet
Original file line number Diff line number Diff line change
@@ -1,44 +1,77 @@
{
"POINTS": {
"0": "0",
"1": "7",
"2": "14",
"3": "20",
"4": "27",
"5": "34",
"6": "40",
"7": "43",
"8": "46",
"9": "48",
"10": "51",
"11": "54",
"12": "56",
"13": "59",
"14": "62",
"15": "64",
"16": "67",
"17": "70",
"18": "72",
"19": "75",
"20": "78",
"21": "80",
"22": "83",
"23": "85",
"24": "88",
"25": "90",
"26": "93",
"27": "95",
"28": "98",
"29": "100"
},
"TIMER_TIME_IN_SECONDS": 14101,
"TIMER_FORMAT": "%s:%s:%s",
"build": "24",
"SIZE_PARAMETERS":
{"tiny": {"multiplier": 0.7, "font": 14, "font-family": "Semibold"},
"default": {"multiplier": 1, "font": 18, "font-family": "Semibold"},
"big": {"multiplier": 1.3, "font": 24, "font-family": "Regular"},
"large": {"multiplier": 1.7, "font": 28, "font-family": "Regular"},
"secret": {"multiplier": 2.5, "font": 70, "font-family": "Semibold"}},
"EASTEREGG_TRIGGERS": "егор крид|кристина парфентьева"
"POINTS": {
"0": "0",
"1": "7",
"2": "14",
"3": "20",
"4": "27",
"5": "34",
"6": "40",
"7": "43",
"8": "46",
"9": "48",
"10": "51",
"11": "54",
"12": "56",
"13": "59",
"14": "62",
"15": "64",
"16": "67",
"17": "70",
"18": "72",
"19": "75",
"20": "78",
"21": "80",
"22": "83",
"23": "85",
"24": "88",
"25": "90",
"26": "93",
"27": "95",
"28": "98",
"29": "100"
},
"TIMER_TIME_IN_SECONDS": 14101,
"TIMER_FORMAT": "%s:%s:%s",
"build": "27",
"SIZE_PARAMETERS": {
"tiny": {
"multiplier": 0.7,
"font": 14,
"font-family": "Semibold"
},
"default": {
"multiplier": 1,
"font": 18,
"font-family": "Semibold"
},
"big": {
"multiplier": 1.3,
"font": 24,
"font-family": "Regular"
},
"large": {
"multiplier": 1.7,
"font": 28,
"font-family": "Regular"
},
"secret": {
"multiplier": 2.5,
"font": 70,
"font-family": "Semibold"
}
},
"EASTEREGG_TRIGGERS": "егор крид|кристина парфентьева",
"button_styles": {
"exam_in_progress": {
"current": "border: 4px solid #474747; border-radius: 7px; background-color: #3265b3; ",
"answered": "background-color: #99c5cf; ",
"skipped": "background-color: #e2f046; "
},
"exam_finished": {
"current": "border: 4px solid #474747; border-radius: 7px; ",
"correct": "background-color: #3eab48; ",
"wrong": "background-color: #ab3b2c; "
}
}
}
3 changes: 3 additions & 0 deletions data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def checkIfNameNeedsToBeTriggered(name: str) -> bool:
return True
return False

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


class Email(object):
def send_message(receiver_email: str) -> tuple:
Expand Down
38 changes: 37 additions & 1 deletion ui_exam.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def setupUi(self, BaseWindow):
for button in self.buttons_list[1:]:
self.nums_widget_layout.addWidget(button, self.placing_x, 0)
self.placing_x = self.placing_x + 1
self.buttons_style_list = [None] + ["transition-duration: 0.1s; " for _ in range(1, 28)]
self.contents_nums.setLayout(self.nums_widget_layout)

self.contents_tasks = QStackedWidget()
Expand All @@ -123,10 +124,11 @@ def setupUi(self, BaseWindow):
self.count = 0
self.timer.timeout.connect(self.timerAction)
self.timer.start(1000)
self.timer_text_lbl = QLabel('Таймер запустится, когда вы откроете любое задание.')
self.timer_text_lbl = QLabel(Localization.EXAM_TIMER_NOT_STARTED)
self.timer_isnt_started = True
self.timer_has_ended = False
self.var_saved = False
self.user_finished = False


# 111111111
Expand Down Expand Up @@ -1195,7 +1197,10 @@ def task_27_get_file_b_button_clicked():
for key in self.widgets_list:
self.contents_tasks.addWidget(self.widgets_list[key])

self.opened_nums = []
def btn_clicked(button_num):
styles = Config.getButtonStyles()
self.opened_nums.append(button_num)
try:
if self.timer_isnt_started and not self.timer_has_ended:
self.timerSetup()
Expand All @@ -1210,11 +1215,33 @@ def btn_clicked(button_num):
except:
pass
self.contents_tasks.setCurrentIndex(button_num)
self.style_key = "exam_in_progress" if not self.user_finished else "exam_finished"
self.buttons_style_list[button_num] += styles[self.style_key]["current"]
for n in range(1, 28):
if n != button_num:
self.buttons_style_list[n] = self.buttons_style_list[n].replace(styles[self.style_key]["current"], "")
if not self.user_finished:
for n in range(1, 28):
if self.user_answers[n] is None and n in self.opened_nums and n != button_num:
if not styles["exam_in_progress"]["skipped"] in self.buttons_style_list[n]:
self.buttons_style_list[n] += styles["exam_in_progress"]["skipped"]
if (not (self.user_answers[n] is None)) and n in self.opened_nums:
if styles["exam_in_progress"]["skipped"] in self.buttons_style_list[n]:
self.buttons_style_list[n] = self.buttons_style_list[n].replace(styles["exam_in_progress"]["skipped"], "")
if not styles["exam_in_progress"]["answered"] in self.buttons_style_list[n]:
self.buttons_style_list[n] += styles["exam_in_progress"]["answered"]
update_button_styles()
except KeyError:
pass

def buttons_set(num):
self.buttons_list[num].clicked.connect(lambda: btn_clicked(num))
self.buttons_list[num].setStyleSheet(self.buttons_style_list[num])

def update_button_styles():
for num in range(1, 28):
self.buttons_list[num].setStyleSheet(self.buttons_style_list[num])

for num in range(1, 28):
buttons_set(num)

Expand Down Expand Up @@ -1311,6 +1338,15 @@ def finish(self):
self.number_of_completed_tasks = self.user_results.count(True)
self.result_text = Localization.RESULT % self.number_of_completed_tasks

self.button_styles = Config.getButtonStyles()
for task in range(1, 28):
if self.user_results[task]:
self.buttons_style_list[task] = "transition-duration: 0.1s; " + self.button_styles["exam_finished"]["correct"]
else:
self.buttons_style_list[task] = "transition-duration: 0.1s; " + self.button_styles["exam_finished"]["wrong"]
self.buttons_list[task].setStyleSheet(self.buttons_style_list[task])


self.first_points = 0
for ind in range(1, 28):
if self.user_results[ind] and ind < 26:
Expand Down

0 comments on commit 74d6645

Please sign in to comment.