-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.py
93 lines (80 loc) · 3.66 KB
/
services.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
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtGui import QIcon
from data.all_models import *
from PyQt5 import uic
from utitlities import get_without_failing
from PyQt5.QtWidgets import QApplication
from data.config import *
from error import Error
class Service(QMainWindow):
def __init__(self):
super().__init__()
uic.loadUi(SERVICE_UI, self)
self.setWindowTitle('Добавление услуг')
self.setWindowIcon(QIcon(ICON))
self.type = 'service'
self.services_push_button.clicked.connect(self.set_services)
self.preparations_push_button.clicked.connect(self.set_preparations)
self.add_push_button.clicked.connect(self.add_service)
self.set_list_widget()
self.services_push_button.setStyleSheet("QPushButton"
"{"
"background-color : lightgrey;"
"}")
self.error_widget = Error('')
self.error_widget.accept_push_button.clicked.connect(self.ok)
def set_services(self):
self.services_push_button.setStyleSheet("QPushButton"
"{"
"background-color : lightgrey;"
"}")
self.preparations_push_button.setStyleSheet("QPushButton"
"{"
"background-color : white;"
"}")
self.type = 'service'
self.set_list_widget()
def set_preparations(self):
self.services_push_button.setStyleSheet("QPushButton"
"{"
"background-color : white;"
"}")
self.preparations_push_button.setStyleSheet("QPushButton"
"{"
"background-color : lightgrey;"
"}")
self.type = 'preparations'
self.set_list_widget()
def add_service(self):
if not self.check_line_edits():
self.error_widget.label.setText('Проверьте правильность введенных данных')
self.error_widget.show()
return
if self.type == 'service':
Services.create(article=self.article_line_edit.text(), name=self.name_line_edit.text())
else:
Preparations.create(article=self.article_line_edit.text(), name=self.name_line_edit.text())
Price.create(article=self.article_line_edit.text(), price=self.price_line_edit.text())
self.set_list_widget()
self.error_widget.label.setText('Успешно')
self.error_widget.show()
def set_list_widget(self):
self.list_widget.clear()
if self.type == 'service':
s = get_without_failing(Services, Services.id)
else:
s = get_without_failing(Preparations, Preparations.id)
if s:
for i in s:
self.list_widget.addItem(i.name)
def check_line_edits(self):
return len(self.article_line_edit.text()) > 0 and len(self.name_line_edit.text()) > 0 and len(
self.price_line_edit.text()) > 0
def ok(self):
self.error_widget.hide()
if __name__ == '__main__':
app = QApplication(sys.argv)
main_ex = Service()
sys.excepthook = except_hook
main_ex.show()
sys.exit(app.exec())