I added a new modal Dialog which will ask for a password whenever the user wants to delete rows. I created the GUI with Qt Designer. I can't call the inventoryTable in my GUI.
Everytime I call secureDelete function, an Attribute Error arises saying "'MainWindow_ui' object has no attribute 'inventoryTable'".
Can anyone tell me how I add other UIs properly and also be able to avoid this attribute errors in the future?
class Main(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.db = Database()
self.model = Model(self)
self.ui = MainWindow_ui()
self.ui.setupUi(self)
self.ui.removeItem.clicked.connect(lambda: self.start_Secure())
self.ui.removeItem.setShortcut("Del")
def start_Secure(self):
self.accessForm = confirmDialog(self)
self.accessForm.show()
class confirmDialog(QtGui.QDialog):
def __init__(self, parent=None):
super(confirmDialog, self).__init__(parent)
self.model = Model()
self.access_ui = Ui_Access()
self.access_ui.setupUi(self)
self.ui = MainWindow_ui()
self.access_ui.username.returnPressed.connect(self.secureDelete)
self.access_ui.password.returnPressed.connect(self.secureDelete)
self.access_ui.confirmButton.clicked.connect(self.secureDelete)
def secureDelete(self):
members = {'user': 'password'}
username = self.access_ui.username.text()
password = self.access_ui.password.text()
if username in members:
enteredPass = members.get(username)
indices = self.ui.inventoryTable.selectionModel().selectedRows()
if password == enteredPass:
for index in sorted(indices):
self.model.removeRow(index.row())
else:
self.model.revertRow(indices)