From: Jerome St-Louis Date: Sat, 18 Jun 2016 06:27:31 +0000 (-0400) Subject: bindings/c;python: Added caption properties; Window::Create(); background color X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?p=sdk;a=commitdiff_plain;h=a81a462ae46c3d84a7a40f0307661d45edf56a1f bindings/c;python: Added caption properties; Window::Create(); background color --- diff --git a/bindings/c/ecere.c b/bindings/c/ecere.c index fe66892..fe1b8b1 100644 --- a/bindings/c/ecere.c +++ b/bindings/c/ecere.c @@ -43,6 +43,8 @@ Property * property_Window_position; Property * property_Window_font; Method * method_Window_modal; +Method * method_Window_create; + Method * method_Window_onCreate; Method * method_Window_onRedraw; @@ -81,6 +83,8 @@ constString (* Window_get_caption)(Window w); DialogResult (* Window_modal)(Window); +bool (* Window_create)(Window); + Class * class_Button; Method * method_Button_notifyClicked; @@ -152,6 +156,11 @@ Module ecere_init(Module fromModule) method_Window_modal = Class_findMethod(class_Window, "Modal", module); if(method_Window_modal) Window_modal = (void *)method_Window_modal->function; + + method_Window_create = Class_findMethod(class_Window, "Create", module); + if(method_Window_create) + Window_create = (void *)method_Window_create->function; + method_Window_onCreate = Class_findMethod(class_Window, "OnCreate", module); if(method_Window_onCreate) Window_onCreate_vTblID = method_Window_onCreate->vid; diff --git a/bindings/c/ecere.h b/bindings/c/ecere.h index 2b547f1..ba85b74 100644 --- a/bindings/c/ecere.h +++ b/bindings/c/ecere.h @@ -261,6 +261,11 @@ extern constString (* Window_get_caption)(Window w); extern DialogResult (* Window_modal)(Window); extern Method * method_Window_modal; + +extern bool (* Window_create)(Window); + +extern Method * method_Window_create; + extern Method * method_Window_onCreate; extern int Window_onCreate_vTblID; diff --git a/bindings/python/cffi-ecere.h b/bindings/python/cffi-ecere.h index 92ac1c0..9ef461a 100644 --- a/bindings/python/cffi-ecere.h +++ b/bindings/python/cffi-ecere.h @@ -3,6 +3,10 @@ typedef Instance Module; typedef Module Application; typedef struct Class Class; typedef uint32_t bool; +typedef uint32_t Color; + +typedef char * String; +typedef const char * constString; //struct Class { ...; }; @@ -14,6 +18,8 @@ void Instance_evolve(Instance *instancePtr, Class * _class); Application eC_init(bool guiApp, int argc, char * argv[]); Module ecere_init(Module fromModule); +void Application_main(Application app); + extern void (*PrintLn)(Class * class_object, const void * object, ...); extern Class * class_String; @@ -32,9 +38,23 @@ typedef Instance Window; typedef int64_t DialogResult; extern DialogResult (* Window_modal)(Window); +extern bool (* Window_create)(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); + +extern void (* Window_set_caption)(Window w, constString caption); +extern constString (* Window_get_caption)(Window w); + +extern void (* Window_set_background)(Window w, Color background); +extern Color (* Window_get_background)(Window w); + +#define COLOR_r_MASK 0x00FF0000 +#define COLOR_r_SHIFT 16 +#define COLOR_g_MASK 0x0000FF00 +#define COLOR_g_SHIFT 8 +#define COLOR_b_MASK 0x000000FF +#define COLOR_b_SHIFT 0 diff --git a/bindings/python/pyEcere.epj b/bindings/python/pyEcere.epj index 6bbf605..2bc3bb6 100644 --- a/bindings/python/pyEcere.epj +++ b/bindings/python/pyEcere.epj @@ -4,7 +4,7 @@ "Options" : { "Warnings" : "All", "IncludeDirs" : [ - "c" + "../c" ], "TargetType" : "SharedLibrary", "TargetFileName" : "_pyEcere", @@ -41,10 +41,10 @@ { "Folder" : "c", "Files" : [ - "eC.h", - "ecere.h", - "ecere.c", - "eC.c" + "../c/eC.c", + "../c/eC.h", + "../c/ecere.c", + "../c/ecere.h" ] }, { @@ -54,9 +54,9 @@ ] }, "build_ecere.py", - "ex1.py", "cffi-ecere.h", - "pyEcere.py" + "pyEcere.py", + "samples/sample.py" ], "ResourcesPath" : "", "Resources" : [ diff --git a/bindings/python/pyEcere.py b/bindings/python/pyEcere.py index dbb5872..c768f69 100644 --- a/bindings/python/pyEcere.py +++ b/bindings/python/pyEcere.py @@ -1,12 +1,27 @@ import sys from _pyEcere import * -# lib.PrintLn(lib.class_String, fun.encode('utf8'), ffi.NULL) +def printLn(args): + lib.PrintLn(lib.class_String, args.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 Color: + def __init__(self, r = 0, g = 0, b = 0): + self.value = ((((r)) << lib.COLOR_r_SHIFT) | ((g) << lib.COLOR_g_SHIFT) | ((b)) << lib.COLOR_b_SHIFT) + + @property + def r(self): return ((((self.value)) & lib.COLOR_r_MASK) >> lib.COLOR_r_SHIFT) + @r.setter + def r(self, value): self.value = ((self.value) & ~(lib.COLOR_r_MASK)) | (((value)) << lib.COLOR_r_SHIFT) + + @property + def g(self): return ((((self.value)) & lib.COLOR_g_MASK) >> lib.COLOR_g_SHIFT) + @g.setter + def g(self, value): self.value = ((self.value) & ~(lib.COLOR_g_MASK)) | (((value)) << lib.COLOR_g_SHIFT) + + @property + def b(self): return ((((self.value)) & lib.COLOR_b_MASK) >> lib.COLOR_r_SHIFT) + @b.setter + def b(self, value): self.value = ((self.value) & ~(lib.COLOR_b_MASK)) | (((value)) << lib.COLOR_b_SHIFT) class Size: def __init__(self, w = 0, h = 0): @@ -17,11 +32,26 @@ class Size: class Instance(object): def __init__(self): self.this = ffi.NULL +class Application(Instance): + def __init__(self): + self.this = lib.eC_init(True, len(sys.argv), [ffi.new("char[]", i.encode('utf8')) for i in sys.argv]) + lib.ecere_init(self.this) + + def main(self): + lib.Application_main(self.this) + +class GuiApplication(Application): + def __init__(self): + Application.__init__(self) + rApp = ffi.new("Instance *"); rApp[0] = self.this; lib.Instance_evolve(rApp, lib.class_GuiApplication); self.this = rApp[0] + class Window(Instance): - def __init__(self, hasClose = None, clientSize = None): + def __init__(self, caption = None, hasClose = None, clientSize = None, background = None): self.this = lib.Instance_new(lib.class_Window) + if caption != None: self.caption = caption if hasClose != None: self.hasClose = hasClose if clientSize != None: self.clientSize = clientSize + if background != None: self.background = background def create(self): lib.Window_create(self.this) def modal(self): lib.Window_modal(self.this) @@ -35,3 +65,13 @@ class Window(Instance): 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) + + @property + def caption(self): value = lib.Window_get_caption(self.this); return ffi.string(value).decode('utf8') + @caption.setter + def caption(self, value): lib.Window_set_caption(self.this, value.encode('utf8')) + + @property + def background(self): value = Color(); lib.Window_get_background(self.this, value.this); return value + @background.setter + def background(self, value): lib.Window_set_background(self.this, value.value) diff --git a/bindings/python/sample.py b/bindings/python/sample.py deleted file mode 100644 index d1fb765..0000000 --- a/bindings/python/sample.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -from pyEcere import * -app_init() -Window(hasClose = True, clientSize = Size(640, 480)).modal() diff --git a/bindings/python/samples/sample.py b/bindings/python/samples/sample.py new file mode 100644 index 0000000..c1a25d3 --- /dev/null +++ b/bindings/python/samples/sample.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from pyEcere import * +app = GuiApplication() +Window(caption = "Hello, Python!!", hasClose = True, clientSize = Size(640, 480), background = Color(b = 255)) +Window(caption = "Bindings are cool", hasClose = True, clientSize = Size(320, 200), background = Color(255)) +app.main()