From: Neil Date: Sun, 14 Apr 2013 13:48:55 +0000 (+0200) Subject: Add specifying filename to editor X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=db0462036d92f8178523490f82c14eed17043de9;p=erdslangetjie.git Add specifying filename to editor --- diff --git a/erdslangetjie/editor/editor.py b/erdslangetjie/editor/editor.py index 2d635d5..ffff296 100644 --- a/erdslangetjie/editor/editor.py +++ b/erdslangetjie/editor/editor.py @@ -1,4 +1,7 @@ +import sys +import os import kivy +from erdslangetjie.data import filepath, load kivy.require('1.6.0') @@ -6,18 +9,41 @@ from kivy.app import App from kivy.uix.widget import Widget + class EditorWindow(Widget): - pass + def __init__(self, level): + if os.path.exists(filepath(level)): + self.level_data = load(level) + self.level = level + elif os.path.exists(filepath('levels/' + level)): + self.level_data = load('levels/' + level) + self.level = 'levels/' + level + else: + print 'Unable to find %s - treating this as a new level' % level + self.level_data = load('levels/blank.txt') + if 'levels/' in level: + self.level = level + else: + self.level = 'levels/' + level + super(EditorWindow, self).__init__() class EditorApp(App): + def __init__(self, level): + self.level = level + super(EditorApp, self).__init__() + def build(self): - return EditorWindow() + return EditorWindow(self.level) def main(): - EditorApp().run() + if len(sys.argv) > 1: + level = sys.argv[1] + else: + level = 'level1.txt' + EditorApp(level).run() if __name__ == '__main__':