def closeEvent(self, event):
        """
        Saves dirty editors on close and cancel the event if the user choosed
        to continue to work.

        :param event: close event
        """
        dirty_widgets = []
        for w in self.widgets(include_clones=False):
            if w.dirty:
                dirty_widgets.append(w)
        filenames = []
        for w in dirty_widgets:
            if os.path.exists(w.file.path):
                filenames.append(w.file.path)
            else:
                filenames.append(w.documentTitle())
        if len(filenames) == 0:
            self.close_all()
            return
        dlg = DlgUnsavedFiles(self, files=filenames)
        if dlg.exec_() == dlg.Accepted:
            if not dlg.discarded:
                for item in dlg.listWidget.selectedItems():
                    filename = item.text()
                    widget = None
                    for widget in dirty_widgets:
                        if widget.file.path == filename or \
                                widget.documentTitle() == filename:
                            break
                    tw = widget.parent_tab_widget
                    tw.save_widget(widget)
                    tw.remove_tab(tw.indexOf(widget))
            self.close_all()
        else:
            event.ignore()
def closeEvent ( self , event ) : dirty_widgets = [ ] for w in self . widgets ( include_clones = False ) : if w . dirty : dirty_widgets . append ( w ) filenames = [ ] for w in dirty_widgets : if os . path . exists ( w . file . path ) : filenames . append ( w . file . path ) else : filenames . append ( w . documentTitle ( ) ) if len ( filenames ) == 0 : self . close_all ( ) return dlg = DlgUnsavedFiles ( self , files = filenames ) if dlg . exec_ ( ) == dlg . Accepted : if not dlg . discarded : for item in dlg . listWidget . selectedItems ( ) : filename = item . text ( ) widget = None for widget in dirty_widgets : if widget . file . path == filename or widget . documentTitle ( ) == filename : break tw = widget . parent_tab_widget tw . save_widget ( widget ) tw . remove_tab ( tw . indexOf ( widget ) ) self . close_all ( ) else : event . ignore ( )
Saves dirty editors on close and cancel the event if the user choosed
        to continue to work.

        :param event: close event