bindings/python: Initial bindings attempts for Python
authorJerome St-Louis <jerome@ecere.com>
Sat, 18 Jun 2016 05:36:27 +0000 (01:36 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 21 Nov 2016 14:18:57 +0000 (09:18 -0500)
bindings/python/build_ecere.py [new file with mode: 0644]
bindings/python/cffi-ecere.h [new file with mode: 0644]
bindings/python/pyEcere.epj [new file with mode: 0644]
bindings/python/pyEcere.py [new file with mode: 0644]
bindings/python/sample.py [new file with mode: 0644]

diff --git a/bindings/python/build_ecere.py b/bindings/python/build_ecere.py
new file mode 100644 (file)
index 0000000..ca0dfcc
--- /dev/null
@@ -0,0 +1,11 @@
+from cffi import FFI
+ffi = FFI()
+ffi.cdef(open('cffi-ecere.h').read())  
+ffi.set_source("_pyEcere",
+   '#include "ecere.h"',
+   sources = [ "../c/eC.c", "../c/ecere.c" ],
+   include_dirs = ["../c"],
+   libraries = ["ecere"],
+   library_dirs = ["C:/Program Files/Ecere SDK/bin"])
+if __name__ == "__main__":
+   ffi.compile(verbose=True)
diff --git a/bindings/python/cffi-ecere.h b/bindings/python/cffi-ecere.h
new file mode 100644 (file)
index 0000000..92ac1c0
--- /dev/null
@@ -0,0 +1,40 @@
+typedef struct class_members_Instance * Instance;
+typedef Instance Module;
+typedef Module Application;
+typedef struct Class Class;
+typedef uint32_t bool;
+
+//struct Class { ...; };
+
+Instance Instance_new(Class * _class);
+Instance Instance_newEx(Class * _class, bool bindingsAlloc);
+
+void Instance_evolve(Instance *instancePtr, Class * _class);
+
+Application eC_init(bool guiApp, int argc, char * argv[]);
+Module ecere_init(Module fromModule);
+
+extern void (*PrintLn)(Class * class_object, const void * object, ...);
+
+extern Class * class_String;
+extern Class * class_Window;
+extern Class * class_GuiApplication;
+
+#define false 0
+#define true 1
+
+typedef struct Size Size;
+struct Size { int w, h; };
+
+typedef Instance FontResource;
+
+typedef Instance Window;
+typedef int64_t DialogResult;
+
+extern DialogResult (* Window_modal)(Window);
+extern void (* FontResource_set_size)(FontResource f, float v);
+
+extern void (* Window_set_size)(Window w, const Size * v);
+
+extern void (* Window_set_hasClose)(Window w, bool hasClose);
+extern bool (* Window_get_hasClose)(Window w);
diff --git a/bindings/python/pyEcere.epj b/bindings/python/pyEcere.epj
new file mode 100644 (file)
index 0000000..6bbf605
--- /dev/null
@@ -0,0 +1,65 @@
+{
+   "Version" : 0.2,
+   "ModuleName" : "cffiEcere",
+   "Options" : {
+      "Warnings" : "All",
+      "IncludeDirs" : [
+         "c"
+      ],
+      "TargetType" : "SharedLibrary",
+      "TargetFileName" : "_pyEcere",
+      "Libraries" : [
+         "ecere",
+         "python3"
+      ]
+   },
+   "Configurations" : [
+      {
+         "Name" : "Debug",
+         "Options" : {
+            "Debug" : true,
+            "Optimization" : "None",
+            "PreprocessorDefinitions" : [
+               "_DEBUG"
+            ],
+            "FastMath" : false,
+            "PostbuildCommands" : [
+               "$(call cp,obj/debug.$(PLATFORM)$(COMPILER_SUFFIX)/_pyEcere.dll,_pyEcere.pyd)"
+            ]
+         }
+      },
+      {
+         "Name" : "Release",
+         "Options" : {
+            "Debug" : false,
+            "Optimization" : "Speed",
+            "FastMath" : true
+         }
+      }
+   ],
+   "Files" : [
+      {
+         "Folder" : "c",
+         "Files" : [
+            "eC.h",
+            "ecere.h",
+            "ecere.c",
+            "eC.c"
+         ]
+      },
+      {
+         "Folder" : "generated",
+         "Files" : [
+            "./_pyEcere.c"
+         ]
+      },
+      "build_ecere.py",
+      "ex1.py",
+      "cffi-ecere.h",
+      "pyEcere.py"
+   ],
+   "ResourcesPath" : "",
+   "Resources" : [
+
+   ]
+}
diff --git a/bindings/python/pyEcere.py b/bindings/python/pyEcere.py
new file mode 100644 (file)
index 0000000..dbb5872
--- /dev/null
@@ -0,0 +1,37 @@
+import sys
+from _pyEcere import *
+
+#   lib.PrintLn(lib.class_String, fun.encode('utf8'), ffi.NULL)
+
+def app_init():
+   app = lib.eC_init(True, len(sys.argv), [ffi.new("char[]", i.encode('utf8')) for i in sys.argv])
+   lib.ecere_init(app)
+   rApp = ffi.new("Instance *"); rApp[0] = app; lib.Instance_evolve(rApp, lib.class_GuiApplication); app = rApp[0]
+
+class Size:
+   def __init__(self, w = 0, h = 0):
+      self.this = ffi.new("Size *")
+      self.this.w = w
+      self.this.h = h
+
+class Instance(object):
+   def __init__(self): self.this = ffi.NULL
+
+class Window(Instance):
+   def __init__(self, hasClose = None, clientSize = None):
+      self.this = lib.Instance_new(lib.class_Window)
+      if hasClose != None:     self.hasClose = hasClose
+      if clientSize != None:   self.clientSize = clientSize
+
+   def create(self): lib.Window_create(self.this)
+   def modal(self): lib.Window_modal(self.this)
+
+   @property
+   def clientSize(self): value = Size(); lib.Window_get_size(self.this, value.this); return value
+   @clientSize.setter
+   def clientSize(self, value): lib.Window_set_size(self.this, value.this)
+
+   @property
+   def hasClose(self): value = ffi.new("bool *"); lib.Window_get_hasClose(self.this, value); return value
+   @hasClose.setter
+   def hasClose(self, value): lib.Window_set_hasClose(self.this, value)
diff --git a/bindings/python/sample.py b/bindings/python/sample.py
new file mode 100644 (file)
index 0000000..d1fb765
--- /dev/null
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+from pyEcere import *
+app_init()
+Window(hasClose = True, clientSize = Size(640, 480)).modal()