From f273936b13898147c0d0918efca3a61a28f937ae Mon Sep 17 00:00:00 2001 From: Davide Rosa Date: Tue, 14 Jan 2020 12:24:16 +0100 Subject: [PATCH 1/2] Made the changes to make the editor working on replit --- editor/editor.py | 25 ++++++++++++++++++++----- editor/widgets/toolbox_opencv.py | 5 ----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/editor/editor.py b/editor/editor.py index bc78004d..903adbe7 100644 --- a/editor/editor.py +++ b/editor/editor.py @@ -531,6 +531,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 = '' code_classes = '' @@ -566,11 +572,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 class Editor(App): @@ -600,10 +608,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) - m1.append([m10, m11, m12]) - m12.append([m121, m122, m123]) + m1.append([m10, m12]) + m12.append([m122]) m2 = gui.MenuItem('Edit', width=100, height='100%') m21 = gui.MenuItem('Cut', width=100, height=30) @@ -649,7 +657,7 @@ 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) m21.onclick.do(self.menu_cut_selection_clicked) m22.onclick.do(self.menu_paste_selection_clicked) @@ -988,6 +996,13 @@ def onkeydown(self, emitter, key, keycode, ctrl, shift, alt): self.toolbar_delete_clicked(None) print("Key pressed: " + str(keycode)) + 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' diff --git a/editor/widgets/toolbox_opencv.py b/editor/widgets/toolbox_opencv.py index db3c9872..69bc72d2 100644 --- a/editor/widgets/toolbox_opencv.py +++ b/editor/widgets/toolbox_opencv.py @@ -78,11 +78,6 @@ def __init__(self, filename='', *args, **kwargs): super(OpencvImage, self).__init__(filename, *args, **kwargs) OpencvWidget._setup(self) - def _need_update(self, emitter=None): - #overriding this method allows to correct the image url that gets updated by the editor - gui.Image.set_image(self, '/%(id)s/get_image_data?index=%(frame_index)s'% {'id': self.identifier, 'frame_index':str(time.time())}) - super(OpencvImage, self)._need_update(emitter) - def on_new_image_listener(self, emitter): if emitter.img is None: return From 258600dafbe957eaa47c2cc33ef2eb1fd983938a Mon Sep 17 00:00:00 2001 From: Davide Rosa Date: Fri, 14 Feb 2020 09:56:28 +0100 Subject: [PATCH 2/2] Editor: removed import editor that obligate users to launch the script from editor folder. --- editor/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/editor.py b/editor/editor.py index 9885ca44..8c7b3abc 100644 --- a/editor/editor.py +++ b/editor/editor.py @@ -562,7 +562,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