I need to show a MessageBox to let the user deicide if He wants to overwrite a file.
# ----------------FILE CREDENTIALS CREATION-----------------------------
def create_credentials_file(self, samba_user, samba_pass, samba_domain, credentials_filepath):
"""Create the file with credentials in specified path"""
print("Entering to function create_credentials_file...")
if os.path.isfile(credentials_filepath):
self.message_overwrite_credentials(samba_user, samba_pass, samba_domain, credentials_filepath)
def message_overwrite_credentials(self, samba_user, samba_pass, samba_domain, credentials_filepath):
"""Message box to confirm overwrite"""
msg_overwrite = QMessageBox.warning(self,"Overwrite Credentials File",
"File already exists. Do you want to overwrite it?", QMessageBox.Yes | QMessageBox.No)
if msg_overwrite == QMessageBox.Yes:
self.write_credentials_file(samba_user, samba_pass, samba_domain, credentials_filepath)
else:
self.text_edit.append(" Credentials file not overwritten...")
def write_credentials_file(self, samba_user, samba_pass, samba_domain, credentials_filepath):
"""Create the file with credentials in specified path"""
with open(credentials_filepath,'w',0o600) as file:
file.write("username="+samba_user+"n")
file.write("password="+samba_pass+"n")
file.write("domain="+samba_domain+"n")
self.text_edit.append(" Credentials file overwritten...")
self.button_apply.setEnabled(True)
Then I call the methods like this
def apply_clicked(self):
"""Events when accept button is pushed"""
self.button_apply.setEnabled(False)
self.text_edit.append("button clicked")
QTimer.singleShot(1000, lambda: self.create_credentials_folder(self.samba_path_credentials))
QTimer.singleShot(1000, lambda: self.create_credentials_file(self.samba_user, self.samba_pass, self.samba_domain, self.credentials_filepath))
I was suggested to use threading, but what is the best approach?