diff --git a/editor/editor.py b/editor/editor.py index f29fb865..238a631c 100644 --- a/editor/editor.py +++ b/editor/editor.py @@ -673,6 +673,12 @@ def prepare_path_to_this_widget(self, node): continue self.prepare_path_to_this_widget(child) + def download(self): + print("test>>>>>>") + headers = {'Content-type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename="%s"' % "my_wonderful_script.py"} + content = self.save("my_wonderful_script.py", self.configuration) + return [content, headers] + def save(self, save_path_filename, configuration): compiled_code = '' @@ -698,7 +704,7 @@ def save(self, save_path_filename, configuration): modules_to_import = [] for w in self.known_project_children: - if not w.__module__ in modules_to_import and w.__module__ != "__main__" and w.__module__ != "project": + if not w.__module__ in modules_to_import and w.__module__ != "__main__" and w.__module__ != "project" and w.__module__ != "editor": modules_to_import.append(w.__module__) code_classes += main_code_class @@ -709,11 +715,13 @@ def save(self, save_path_filename, configuration): } print(compiled_code) - + """ if save_path_filename != None: f = open(save_path_filename, "w") f.write(compiled_code) f.close() + """ + return compiled_code self.lastUpdateTime = os.stat(save_path_filename).st_mtime @@ -782,11 +790,10 @@ def main(self): m12 = gui.MenuItem('Save Your App', width=150, height=30) #m12.style['visibility'] = 'hidden' m121 = gui.MenuItem('Save', width=100, height=30) - m122 = gui.MenuItem('Save as', width=100, height=30) + m122 = gui.MenuItem('Download', width=100, height=30) m123 = gui.MenuItem('Export widget as', width=200, height=30) - m124 = gui.MenuItem('Export widget for App Template', width=200, height=30) - m1.append([m10, m11, m12]) - m12.append([m121, m122, m123, m124]) + m1.append([m10, m12]) + m12.append([m122]) m2 = gui.MenuItem('Edit', width=100, height='100%') m21 = gui.MenuItem('Cut', width=100, height=30) @@ -832,9 +839,9 @@ def main(self): m10.onclick.do(self.menu_new_clicked) m11.onclick.do(self.fileOpenDialog.show) m121.onclick.do(self.menu_save_clicked) - m122.onclick.do(self.fileSaveAsDialog.show) + m122.onclick.do(self.menu_download_clicked) m123.onclick.do(self.menu_save_widget_clicked) - m124.onclick.do(self.menu_export_widget_clicked) + #m124.onclick.do(self.menu_export_widget_clicked) m21.onclick.do(self.menu_cut_selection_clicked) m22.onclick.do(self.menu_paste_selection_clicked) @@ -1206,6 +1213,13 @@ def onkeydown(self, emitter, key, keycode, ctrl, shift, alt): print("Key pressed: " + str(keycode) + " ctrl: " + str(ctrl) + " shift: " + str(shift)) + def menu_download_clicked(self, emitter): + #the dragHelper have to be removed + for drag_helper in self.drag_helpers: + drag_helper.setup(None, None) + self.project.configuration = self.projectConfiguration + self.execute_javascript('window.location = "/%s/download"'%str(self.project.identifier)) + def show_error_dialog(self, title, message): error_dialog = gui.GenericDialog(title, message) error_dialog.children["title"].style['background-color'] = 'red'