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 pathadd_to_portfolio.py
83 lines (59 loc) · 2.5 KB
/
add_to_portfolio.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
import sys
import datetime
from PyQt5.QtWidgets import QApplication, QDialog, QFileDialog, QMessageBox
from py_ui.add_to_portfolio import Ui_Form
from service import *
class AddToPortfolio(QDialog, Ui_Form):
def __init__(self):
super().__init__()
self.portfolio_photo = None
self.setupUi(self)
self.btn_add_photo.clicked.connect(self.add_photo)
self.btn_add_to_portfolio.clicked.connect(self.add_to_portfolio)
def add_to_portfolio(self):
competitions_name = self.get_competitions_name()
place = self.get_place()
date = self.get_date()
photo = self.get_photo()
if not competitions_name:
self.show_error('Не выбрано название соревнований')
return
if not photo:
self.show_error('Не выбрана фотография')
return
res = add_to_portfolio(competitions_name, place, date, photo)
if res:
msg_box = QMessageBox()
user_ans = msg_box.information(self, 'Успешно!', 'Информация успешно добавлена в портфолио!')
if user_ans == QMessageBox.Ok:
self.close()
def show_error(self, error):
self.lbl_error.setText(error)
self.lbl_error.adjustSize()
def add_photo(self):
file_name = QFileDialog.getOpenFileName(self, 'Выбрать фотографию', '',
'Картинка (*.jpg, *.png);;Все файлы (*)')[0]
self.portfolio_photo = file_name
if file_name:
self.btn_add_photo.setText('Selected: ' + file_name)
else:
self.btn_add_photo.setText('Добавить фотографию')
def get_competitions_name(self):
return self.edit_competitions_name.text()
def get_place(self):
return self.cmb_place.currentText()
def get_date(self):
date = self.edit_date.date().toPyDate()
datetime_ = datetime.datetime.combine(date, datetime.time(0, 0, 0))
datetime_timestamp = datetime_.timestamp()
return int(datetime_timestamp)
def get_photo(self):
return self.portfolio_photo
def except_hook(cls, exception, traceback):
sys.__excepthook__(cls, exception, traceback)
if __name__ == '__main__':
app = QApplication(sys.argv)
app_ = AddToPortfolio()
app_.show()
sys.excepthook = except_hook
sys.exit(app.exec())