From 63175dcbda9c34613c18cc3d0828f2ddafbc4278 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 18 Apr 2013 14:07:10 +0200 Subject: [PATCH] Save levels --- erdslangetjie/editor/editor.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/erdslangetjie/editor/editor.py b/erdslangetjie/editor/editor.py index 1606fd6..a8737e1 100644 --- a/erdslangetjie/editor/editor.py +++ b/erdslangetjie/editor/editor.py @@ -8,6 +8,7 @@ from kivy.uix.widget import Widget from kivy.uix.floatlayout import FloatLayout from kivy.graphics import Color, Rectangle from kivy.uix.label import Label +from kivy.uix.popup import Popup from kivy.utils import platform from kivy.config import Config @@ -110,7 +111,25 @@ class EditorWindow(FloatLayout): self.add_widget(save_label) def do_save(self, label, ref): - pass + try: + self.level_obj.validate() + except RuntimeError as err: + print err + popup = Popup(title='Error', + content=Label(text='Level not valid: %s' % err), + size_hint=(.5, .5)) + popup.open() + return + save_data = self.level_obj.get_level_data() + savefile = file(filepath(self.level), 'w') + savefile.write(save_data) + savefile.write('\n') + savefile.close() + popup = Popup(title='Success', + content=Label(text='Level saved to %s' % self.level), + size_hint=(.5, .5)) + popup.open() + def change_tool(self, label, ref): self.tool = ref -- 2.34.1