I create class:
FOClassName:= PyString_FromSt ring(ClasName);
FClass:= PyClass_New(nil , FDict, FOClassName);
PyDict_SetItemS tring(FDict, ClasName, FClass);
Py_DECREF(FOCla ssName);
Py_DECREF(FDict );
Py_DECREF(FClas s);
Add methods for it:
MyFunc:=PyCFunc tion_New(MyMeth od, nil);
MyMeth:=PyMetho d_New(MyFunc, nil, FClass);
PyDict_SetItemS tring(FDict, AMethodName, MyMeth);
Py_DECREF(MyFun c);
Py_DECREF(MyMet h);
I place all it in my Delphi class and then create 1 class:
pyGL_Class:=TPy thonClass.Creat e(Python.PyScri pt.GetPyDict,'p ySky3D_Window') ;
pyGL_Class.AddC lassMethod('__i nit__',pyWindow ClassInit,'');
pyGL_Class.AddC lassMethod('_Sh ow',pyWindowSho w,'');
pyGL_Class.AddC lassMethod('_Hi de',pyWindowHid e,'');
pyGL_Class.AddC lassMethod('_On MouseOver',pyOn MouseOver,'');
pyGL_Class.AddC lassProperty('_ Win_id','winid' );
pyGL_Class.AddC lassProperty('_ Winpos_x',0);
pyGL_Class.AddC lassProperty('_ Winpos_y',0);
pyGL_Class.AddC lassProperty('_ Win_width',0);
pyGL_Class.AddC lassProperty('_ Win_height',0);
pyGL_Class.AddC lassProperty('_ Win_header','wi ndow header');
pyGL_Class.AddC lassProperty('_ Visible',0);
pyGL_Class.Free ;
#Class defining window
class Sky3D_Windows(s ky3d.pySky3D_Wi ndow):
def test(self):
print "Hello"
def _OnMouseOver(se lf):
#self._Hide()
pass
MouseCursWin=Sk y3D_Windows('CM ouseWin','Mouse WinFunc',400,30 0,100,100,'Mous e','font5')
All work fine, but if i add new class same way
{pySky3D_Button }
pyGL_Class:=TPy thonClass.Creat e(Python.PyScri pt.GetPyDict,'p ySky3D_Button') ;
pyGL_Class.AddC lassMethod('pyS ky3D_Button.__i nit__',pyButton ClassInit,'');
pyGL_Class.AddC lassProperty('_ Btn_id','Button _id');
pyGL_Class.Free ;
it give me error:
Traceback (most recent call last):
File "D:\sky3d\src\s cript\sky3d.py" , line 32, in OnInit
from window import *
File "D:\sky3d\src\s cript\window.py ", line 18, in ?
CoordWin=Sky3D_ Windows('CoordW in','CoordWinFu nc',15,Sky3D_Ge tMainWinRec()[1]
- (250),150,200,' Camera','font5' )
TypeError
:
unbound method __init__() must be called with pySky3D_Button instance
as first argument (got str instance instead)
I to little know class embeding in Python, but suspect that __init__
become base for all classes??? Or what? In documentation i did not find
info about PyClass_New and other. But it says that i must some how use
instance of class, but i can't understand how i can get instance non
created class...
Full source in https://opensvn.csie.org/sky3d
or here
https://opensvn.csie.org/traccgi/sky3d