-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories.py
164 lines (145 loc) · 6.34 KB
/
categories.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'UI/categories.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets, QtSql
import sql
class Ui_Category(object):
def setupUi(self, Category):
Category.setObjectName("Category")
Category.resize(671, 523)
Category.setMinimumSize(QtCore.QSize(0, 0))
Category.setMaximumSize(QtCore.QSize(729, 540))
self.groupBox_2 = QtWidgets.QGroupBox(Category)
self.groupBox_2.setGeometry(QtCore.QRect(40, 430, 471, 71))
self.groupBox_2.setStyleSheet("border:1px solid #ccc;")
self.groupBox_2.setTitle("")
self.groupBox_2.setObjectName("groupBox_2")
self.categoryName = QtWidgets.QLineEdit(self.groupBox_2)
self.categoryName.setGeometry(QtCore.QRect(100, 19, 351, 31))
self.categoryName.setObjectName("categoryName")
self.label_2 = QtWidgets.QLabel(self.groupBox_2)
self.label_2.setGeometry(QtCore.QRect(10, 10, 81, 41))
font = QtGui.QFont()
font.setPointSize(13)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setStyleSheet("border:0;")
self.label_2.setLineWidth(0)
self.label_2.setObjectName("label_2")
self.categoryView = QtWidgets.QListView(Category)
self.categoryView.setGeometry(QtCore.QRect(40, 128, 591, 281))
self.categoryView.setStyleSheet("border:2px solid #dcdcdc;")
self.categoryView.setObjectName("categoryView")
self.label = QtWidgets.QLabel(Category)
self.label.setGeometry(QtCore.QRect(41, 90, 590, 41))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setStyleSheet("background-color: rgb(0, 48, 70);\n"
"color: rgb(255, 255, 255);")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.groupBox_3 = QtWidgets.QGroupBox(Category)
self.groupBox_3.setGeometry(QtCore.QRect(40, 0, 231, 71))
self.groupBox_3.setObjectName("groupBox_3")
self.filter = QtWidgets.QLineEdit(self.groupBox_3)
self.filter.setGeometry(QtCore.QRect(10, 30, 211, 31))
self.filter.setObjectName("filter")
self.btnUpdate = QtWidgets.QPushButton(Category)
self.btnUpdate.setGeometry(QtCore.QRect(520, 430, 111, 31))
self.btnUpdate.setObjectName("btnUpdate")
self.btnSave = QtWidgets.QPushButton(Category)
self.btnSave.setGeometry(QtCore.QRect(520, 470, 111, 31))
self.btnSave.setObjectName("btnSave")
self.groupBox_4 = QtWidgets.QGroupBox(Category)
self.groupBox_4.setGeometry(QtCore.QRect(300, 0, 331, 71))
self.groupBox_4.setObjectName("groupBox_4")
self.delete_select = QtWidgets.QComboBox(self.groupBox_4)
self.delete_select.setGeometry(QtCore.QRect(10, 30, 231, 31))
self.delete_select.setObjectName("delete_select")
self.btnDelete = QtWidgets.QPushButton(self.groupBox_4)
self.btnDelete.setGeometry(QtCore.QRect(250, 30, 71, 31))
self.btnDelete.setObjectName("btnDelete")
sql.connectDB()
model = QtSql.QSqlQueryModel()
qry = QtSql.QSqlQuery()
qry.exec_("select distinct name from categories")
model.setQuery(qry)
self.categoryView.setModel(model)
self.delete_select.setModel(model)
completer = QtWidgets.QCompleter()
completer.setModel(model)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
completer.setFilterMode(QtCore.Qt.MatchContains)
completer.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
completer.setWidget(self.filter)
self.filter.setCompleter(completer)
self.filter.textChanged.connect(lambda: self.get_category())
self.retranslateUi(Category)
QtCore.QMetaObject.connectSlotsByName(Category)
def retranslateUi(self, Category):
_translate = QtCore.QCoreApplication.translate
Category.setWindowTitle(_translate("Category", "Categories"))
self.label_2.setText(_translate("Category", "Category"))
self.label.setText(_translate("Category", "Categories"))
self.groupBox_3.setTitle(_translate("Category", "Filter"))
self.filter.setPlaceholderText(_translate("Category", "Filter"))
self.btnUpdate.setText(_translate("Category", "Update Item"))
self.btnSave.setText(_translate("Category", "Save New"))
self.groupBox_4.setTitle(_translate("Category", "Delete item"))
self.btnDelete.setText(_translate("Category", "Delete"))
def stylesheet(self):
return """
QListView::item {
padding: 10px 20px;
}
* {
font-size:14px;
}
QTableView::horizontalHeader{
background-color: #111111;
color: #efefef;
}
QPushButton:hover{
background-color:#ffffff;
color: #222222;
}
QPushButton{
background-color: #cdcdcd;
}
QTableView::row{
padding:15px;
}
QTableView::column{
padding:15px;
}
"""
def get_category(self):
sql.connectDB()
if not self.filter.text() == '' or not self.filter.text().isspace():
qry = QtSql.QSqlQuery()
qry.prepare("select name from categories where name LIKE '%{0}%'".format(str(
self.filter.text())))
if qry.exec_():
self.model = QtSql.QSqlQueryModel()
self.model.setQuery(qry)
self.categoryView.setModel(self.model)
self.categoryView.show()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Category = QtWidgets.QDialog()
ui = Ui_Category()
ui.setupUi(Category)
Category.show()
sys.exit(app.exec_())