code: def save_data(self, filename=None):
          
          if filename is None:
              filename = self.filename
              if filename is None:
                  filename = getcwd_or_home()
              filename, _selfilter = getsavefilename(self, _("Save data"),
                                                     filename,
                                                     iofunctions.save_filters)
              if filename:
                  self.filename = filename
              else:
                  return False
          QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
          QApplication.processEvents()
  
          error_message = self.shellwidget.save_namespace(self.filename)
          self.shellwidget._kernel_reply = None
  
          QApplication.restoreOverrideCursor()
          QApplication.processEvents()
          if error_message is not None:
              if 'Some objects could not be saved:' in error_message:
                  save_data_message = (
                      _('<b>Some objects could not be saved:</b>')
                      + '<br><br><code>{obj_list}</code>'.format(
                          obj_list=error_message.split(': ')[1]))
              else:
                  save_data_message = _(
                      '<b>Unable to save current workspace</b>'
                      '<br><br>Error message:<br>') + error_message
              QMessageBox.critical(self, _("Save data"), save_data_message)
          self.save_button.setEnabled(self.filename is not None)
docs: Save data