def set_external_editor_path(path=None, ask_user=False): """ Prompts the user for a new external editor path. TODO: Set temp program if none found. """ root, editor_elements = get_editor_xml() for e in editor_elements: root.remove(e) if ask_user and not path: from PythonEditor.ui.Qt import QtWidgets dialog = QtWidgets.QInputDialog() args = (dialog, u'Get Editor Path', u'Path to external text editor:') results = QtWidgets.QInputDialog.getText(*args) path, ok = results if not ok: msg = 'Certain features will not work without '\ 'an external editor. \nYou can add or change '\ 'an external editor path later in Edit > Preferences.' msgBox = QtWidgets.QMessageBox() msgBox.setText(msg) msgBox.exec_() return None if path and os.path.isdir(os.path.dirname(path)): editor_path = path os.environ['EXTERNAL_EDITOR_PATH'] = editor_path element = ETree.Element('external_editor_path') element.text = path root.append(element) writexml(root) return path elif ask_user: from PythonEditor.ui.Qt import QtWidgets msg = u'External editor not found. '\ 'Certain features will not work.'\ '\nYou can add or change an external '\ 'editor path later in Edit > Preferences.' msgBox = QtWidgets.QMessageBox() msgBox.setText(msg) msgBox.exec_() return None
def prompt_user_to_save(self, index): """ Ask the user if they wish to close a tab that has unsaved contents. """ name = self.tabText(index) msg_box = QtWidgets.QMessageBox() msg_box.setWindowTitle('Save changes?') msg_box.setText('%s has not been saved to a file.' % name) msg_box.setInformativeText('Do you want to save your changes?') buttons = (msg_box.Save | msg_box.Discard | msg_box.Cancel) msg_box.setStandardButtons(buttons) msg_box.setDefaultButton(msg_box.Save) ret = msg_box.exec_() user_cancelled = (ret == msg_box.Cancel) if (ret == msg_box.Save): data = self.tabData(index) path = save.save(data['text'], data['path']) if path is None: user_cancelled = True if user_cancelled: return False return True