def _do_save_python_cb(self, widget): ''' Callback for saving the project as Python code. ''' # catch PyExportError and display a user-friendly message instead try: pythoncode = save_python(self.tw) except PyExportError as pyee: if pyee.block is not None: pyee.block.highlight() self.tw.showlabel('status', str(pyee)) print pyee return if not pythoncode: return # use name of TA project if it has been saved already default_name = self.tw.save_file_name if default_name is None: default_name = _("myproject") elif default_name.endswith(".ta") or default_name.endswith(".tb"): default_name = default_name[:-3] save_type = '.py' self.tw.load_save_folder = self._get_execution_dir() filename, self.tw.load_save_folder = get_save_name( save_type, self.tw.load_save_folder, default_name) if isinstance(filename, unicode): filename = filename.encode('utf-8') if filename is not None: f = file(filename, 'w') f.write(pythoncode) f.close()
def _do_save_python_cb(self, widget): ''' Callback for saving the project as Python code. ''' # catch PyExportError and display a user-friendly message instead try: pythoncode = save_python(self.tw) except PyExportError as pyee: if pyee.block is not None: pyee.block.highlight() self.tw.showlabel('status', str(pyee)) print pyee return if not pythoncode: return # use name of TA project if it has been saved already default_name = self.tw.save_file_name if default_name is None: default_name = _("myproject") elif default_name.endswith(".ta") or default_name.endswith(".tb"): default_name = default_name[:-3] save_type = '.py' filename, self.tw.load_save_folder = get_save_name( save_type, None, default_name) if isinstance(filename, unicode): filename = filename.encode('utf-8') if filename is not None: f = file(filename, 'w') f.write(pythoncode) f.close()