-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddItemDialog.py
More file actions
114 lines (98 loc) · 4.61 KB
/
Copy pathAddItemDialog.py
File metadata and controls
114 lines (98 loc) · 4.61 KB
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
from PyQt5 import QtCore, QtGui, QtWidgets
from InvalidItemDialog import InvalidItemDialog
import csv
class AddItemDialog(object):
def setupAddItem(self, Dialog):
# Main Dialog
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
font = QtGui.QFont()
font.setPointSize(12)
Dialog.setFont(font)
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
Dialog.setWindowTitle("Add Item")
# Material Label
self.lbl_material = QtWidgets.QLabel(Dialog)
self.lbl_material.setObjectName("lbl_material")
self.gridLayout.addWidget(self.lbl_material, 0, 0, 1, 1)
self.lbl_material.setText("Item's Material:")
# Material Combo Box
self.cb_material = QtWidgets.QComboBox(Dialog)
self.cb_material.setObjectName("cb_material")
self.gridLayout.addWidget(self.cb_material, 0, 1, 1, 1)
material_list = ['', 'Paper', 'Plastic', 'Glass', 'Aluminum', 'Other']
self.cb_material.addItems(material_list)
# Recycle Label
self.lbl_recycle = QtWidgets.QLabel(Dialog)
self.lbl_recycle.setObjectName("lbl_recycle")
self.gridLayout.addWidget(self.lbl_recycle, 1, 0, 1, 1)
self.lbl_recycle.setText("Is it Recyclable?:")
# Recycle Combo Box
self.cb_recycle = QtWidgets.QComboBox(Dialog)
self.cb_recycle.setObjectName("cb_recycle")
self.gridLayout.addWidget(self.cb_recycle, 1, 1, 1, 1)
recycle_list = ['', 'Yes', 'No']
self.cb_recycle.addItems(recycle_list)
# Rinse Label
self.lbl_rinse = QtWidgets.QLabel(Dialog)
self.lbl_rinse.setObjectName("lbl_rinse")
self.gridLayout.addWidget(self.lbl_rinse, 2, 0, 1, 1)
self.lbl_rinse.setText("Does it need to be Rinsed?:")
# Rinse Combo Box
self.cb_rinse = QtWidgets.QComboBox(Dialog)
self.cb_rinse.setObjectName("cb_rinse")
self.gridLayout.addWidget(self.cb_rinse, 2, 1, 1, 1)
rinse_list = ['', 'Yes', 'No']
self.cb_rinse.addItems(rinse_list)
# Barcode Label
self.lbl_barcode = QtWidgets.QLabel(Dialog)
self.lbl_barcode.setObjectName("lbl_barcode")
self.gridLayout.addWidget(self.lbl_barcode, 3, 0, 1, 1)
self.lbl_barcode.setText("Click box and Scan Barcode:")
# Barcode Line Edit
self.le_barcode = QtWidgets.QLineEdit(Dialog)
self.le_barcode.setObjectName("le_barcode")
self.gridLayout.addWidget(self.le_barcode, 3, 1, 1, 1)
# Save Button Box
self.bb_save = QtWidgets.QDialogButtonBox(Dialog)
font = QtGui.QFont()
font.setPointSize(8)
self.bb_save.setFont(font)
self.bb_save.setOrientation(QtCore.Qt.Horizontal)
self.bb_save.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Save)
self.bb_save.setCenterButtons(True)
self.bb_save.setObjectName("bb_save")
self.gridLayout.addWidget(self.bb_save, 4, 0, 1, 2)
self.bb_save.accepted.connect(self.checkInput)
self.bb_save.accepted.connect(Dialog.accept)
self.bb_save.rejected.connect(Dialog.reject)
# takes current selections from comboboxes to create variables to add to database
def checkInput(self):
upc = self.le_barcode.text()
material = self.cb_material.currentText()
recycle = self.cb_recycle.currentText()
rinse = self.cb_rinse.currentText()
if (upc == '' or material == '' or recycle == '' or rinse == ''):
self.openInvalidItemDialog()
else:
self.newItem(upc, material, recycle, rinse)
def newItem(self, upc, material, recycle, rinse):
APPENDFILE = open('UPCList.csv', 'a') # opens file to append new entry
entryWriter = csv.writer(APPENDFILE, lineterminator = '\n')
entryWriter.writerow([upc, material, recycle, rinse]) # writes new item into database
APPENDFILE.close() # closes file to not cause errors
def openInvalidItemDialog(self):
self.Invalid = QtWidgets.QDialog()
self.ui = InvalidItemDialog()
self.ui.setupInvalidItemDialog(self.Invalid)
self.Invalid.show()
# only needed to run window by itself
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = AddItemDialog()
ui.setupAddItem(Dialog)
Dialog.show()
sys.exit(app.exec_())