def open(self, event=None):
        """
        Creates a new tab with the editor containing the code from a file
        selected by the user.
        """
        filters = 'Python files (*.py);;Lua files (*.lua);;Lisp files (*.lisp);;JSON files (*.json);;All files (*.*)'
        path, filter = QtWidgets.QFileDialog.getOpenFileName(
            self,
            directory=self.last_dir,
            filter=filters,
            initialFilter=self.last_selected_filter)

        if not path:
            return

        self.last_selected_filter = filter
        self.last_dir = dirname(path)

        try:
            self.add(HtmlEditor.from_file(path))
        except Exception as e:
            print(traceback.format_exc())

            title = 'Error opening {}'.format(path)
            text = 'Exception encountered while opening {}:\n\n{}.\n\nThe full traceback has been printed to stdout.'.format(
                path, e)
            QtWidgets.QMessageBox.critical(self, title, text)
 def accept(self):
     try:
         text = self.textedit.toPlainText()
         self.editor = HtmlEditor.from_string(text, 'py')
         super(CodeInput, self).accept()
     except ParseException:
         QtWidgets.QMessageBox.critical(self, "Parsing error", "Could not parse the given text.")
    def open(self, event=None):
        """
        Creates a new tab with the editor containing the code from a file
        selected by the user.
        """
        filters = 'Python files (*.py);;Lua files (*.lua);;Lisp files (*.lisp);;JSON files (*.json);;All files (*.*)';
        path, filter = QtWidgets.QFileDialog.getOpenFileName(self,
                directory=self.last_dir,
                filter=filters,
                initialFilter=self.last_selected_filter)

        if not path:
            return

        self.last_selected_filter = filter
        self.last_dir = dirname(path)

        try:
            self.add(HtmlEditor.from_file(path))
        except Exception as e:
            print(traceback.format_exc())

            title = 'Error opening {}'.format(path)
            text = 'Exception encountered while opening {}:\n\n{}.\n\nThe full traceback has been printed to stdout.'.format(path, e)
            QtWidgets.QMessageBox.critical(self, title, text)
 def accept(self):
     try:
         text = self.textedit.toPlainText()
         self.editor = HtmlEditor.from_string(text, 'py')
         super(CodeInput, self).accept()
     except ParseException:
         QtWidgets.QMessageBox.critical(self, "Parsing error",
                                        "Could not parse the given text.")
 def new(self, language='py'):
     """
     Creates a new tab with an empty editor.
     """
     self.add(HtmlEditor.new_empty(language))
 def new(self, language='py'):
     """
     Creates a new tab with an empty editor.
     """
     self.add(HtmlEditor.new_empty(language))