This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
102 lines (73 loc) · 3.44 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import datetime
from PyQt5.QtWidgets import QWidget, QTableWidgetItem, QFileDialog, QMessageBox, QHeaderView
from service import *
import py_ui.manage_tasks
import py_ui.tasks
class ManageTasksTab(QWidget, py_ui.manage_tasks.Ui_Form):
def __init__(self):
super(ManageTasksTab, self).__init__()
self.setupUi(self)
self.__material_photo = None
self.btn_add_material.clicked.connect(self.choice_photo)
self.btn_send.clicked.connect(self.send_task)
def get_title(self) -> str:
return self.edit_title.text()
def get_task_text(self) -> str:
return self.edit_text.toPlainText()
def get_task_date(self) -> int:
date = self.dtchoice_date.date().toPyDate()
datetime_ = datetime.datetime.combine(date, datetime.time())
return int(datetime_.timestamp())
def get_material_photo(self) -> str:
return self.__material_photo if self.__material_photo else None
def choice_photo(self) -> None:
file_name = QFileDialog.getOpenFileName(self, 'Выбрать фотографию', '',
'Картинка (*.jpg, *.png);;Все файлы (*)')[0]
self.__material_photo = file_name
def send_task(self) -> None:
title = self.get_title()
text = self.get_task_text()
date = self.get_task_date()
photo = self.get_material_photo()
created = create_task(title, text, date, photo)
if created:
if QMessageBox.information(self, 'Успешно!', 'Задача успешно отправлена'):
self.clear_all_fields()
def clear_all_fields(self):
self.edit_title.clear()
self.edit_text.clear()
self.__material_photo = None
self.btn_add_material.setText('Загрузить пример, материал')
class TasksTab(QWidget, py_ui.tasks.Ui_Form):
def __init__(self):
super(TasksTab, self).__init__()
self.setupUi(self)
self.fill_table()
self.setup_table()
def fill_table(self):
tasks = self.get_tasks()
self.tbl_tasks.setRowCount(0)
for i, row in enumerate(tasks):
self.tbl_tasks.setRowCount(self.tbl_tasks.rowCount() + 1)
for j, el in enumerate(row):
self.tbl_tasks.setItem(i, j, QTableWidgetItem(str(el)))
self.tbl_tasks.resizeRowsToContents()
def setup_table(self):
table_header = self.tbl_tasks.horizontalHeader()
table_header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
table_header.setSectionResizeMode(1, QHeaderView.Stretch)
table_header.setSectionResizeMode(2, QHeaderView.Stretch)
table_header.setSectionResizeMode(3, QHeaderView.ResizeToContents)
@staticmethod
def get_tasks() -> List[List]:
tasks = [list(task) for task in get_tasks()]
for i, task in enumerate(tasks):
for j, elem in enumerate(task):
# If elem column index is date columns index in table, format datetime timestamp
elem = datetime.datetime.fromtimestamp(elem).strftime('%d.%m.%Y') if j == 3 else elem
elem = '' if elem is None else elem
tasks[i][j] = elem
# in database: (0) id, (1) title, (2) text, (3) date, (4) photo
# in our table: (0) date, (1) title, (2) text, (3) photo
tasks[i] = [task[3], *task[1:3], task[4]]
return tasks