def manageAttrib(self): attribs = [(i[0], i[1], i[3]) for i in self.getAttribs()] dat = [] for attr in self.attrPaths: txt = attr[0].longDescrip(attr[2]) active = attr in attribs dat.append([txt, active, attr]) if not dat: g.es('No attributes seen (yet)') return dat.sort(key=lambda x: x[0]) res = ListDialog(self.parent, "Enter attribute path", "Enter path to attribute (space separated words)", dat) res.exec_() if res.result() == QtWidgets.QDialog.Rejected: return # check for deletions for i in dat: if i[2] in attribs and not i[1]: res = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Question, "Really delete attributes?", "Really delete attributes?", QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel, self.parent) if res.exec_() == QtWidgets.QMessageBox.Cancel: return break # apply changes for i in dat: if i[2] in attribs and not i[1]: self.delAttrib(i[2]) elif i[2] not in attribs and i[1]: self.addAttrib(i[2]) self.updateEditorInt() self.c.redraw()
def delete(self): """Issue a prompt and delete the file if the user agrees.""" try: from send2trash import send2trash except Exception: if not self.send_to_trash_warning_given: self.send_to_trash_warning_given = True print("Deleting files requires send2trash") print("pip install Send2Trash") return file_name = self.files_list[self.slide_number] # Create the dialog without relying on g.app.gui. dialog = QtWidgets.QMessageBox(self) dialog.setStyleSheet("background: white;") yes = dialog.addButton('Yes', ButtonRole.YesRole) dialog.addButton('No', ButtonRole.NoRole) dialog.setWindowTitle("Delete File?") dialog.setText(f"Delete file {g.shortFileName(file_name)}?") dialog.setIcon(Information.Warning) dialog.setDefaultButton(yes) def dialog_keypress_event(event): s = event.text() if s == 'y': dialog.done(0) elif s == 'n' or s == '\x1b': # ESC. dialog.done(1) dialog.keyPressEvent = dialog_keypress_event dialog.raise_() result = dialog.exec() if isQt6 else dialog.exec_() if result == 0: # Move the file to the trash. send2trash(file_name) del self.files_list[self.slide_number] print(f"Deleted {file_name}") self.slide_number = max(0, self.slide_number - 1) self.next_slide() self.raise_()