Class __init__ trouble

SkyRanger skyr at newmail.ru
Mon Jan 16 11:20:54 CET 2006


I create class:

  FOClassName:= PyString_FromString(ClasName);
  FClass:= PyClass_New(nil, FDict, FOClassName);
  PyDict_SetItemString(FDict, ClasName, FClass);
  Py_DECREF(FOClassName);
  Py_DECREF(FDict);
  Py_DECREF(FClass);

Add methods for it:

  MyFunc:=PyCFunction_New(MyMethod, nil);
  MyMeth:=PyMethod_New(MyFunc, nil, FClass);
	PyDict_SetItemString(FDict, AMethodName, MyMeth);
  Py_DECREF(MyFunc);
  Py_DECREF(MyMeth);

I place all it in my Delphi class and then create 1 class:


pyGL_Class:=TPythonClass.Create(Python.PyScript.GetPyDict,'pySky3D_Window');
  pyGL_Class.AddClassMethod('__init__',pyWindowClassInit,'');
  pyGL_Class.AddClassMethod('_Show',pyWindowShow,'');
  pyGL_Class.AddClassMethod('_Hide',pyWindowHide,'');
  pyGL_Class.AddClassMethod('_OnMouseOver',pyOnMouseOver,'');

  pyGL_Class.AddClassProperty('_Win_id','winid');
  pyGL_Class.AddClassProperty('_Winpos_x',0);
  pyGL_Class.AddClassProperty('_Winpos_y',0);
  pyGL_Class.AddClassProperty('_Win_width',0);
  pyGL_Class.AddClassProperty('_Win_height',0);
  pyGL_Class.AddClassProperty('_Win_header','window header');
  pyGL_Class.AddClassProperty('_Visible',0);
  pyGL_Class.Free;


#Class defining window
class Sky3D_Windows(sky3d.pySky3D_Window):
	def test(self):
		print "Hello"
	def _OnMouseOver(self):
		#self._Hide()
		pass

MouseCursWin=Sky3D_Windows('CMouseWin','MouseWinFunc',400,300,100,100,'Mouse','font5')

All work fine, but if i add new class same way

{pySky3D_Button}

pyGL_Class:=TPythonClass.Create(Python.PyScript.GetPyDict,'pySky3D_Button');

pyGL_Class.AddClassMethod('pySky3D_Button.__init__',pyButtonClassInit,'');

  pyGL_Class.AddClassProperty('_Btn_id','Button_id');
  pyGL_Class.Free;

it give me error:

Traceback (most recent call last):
File "D:\sky3d\src\script\sky3d.py", line 32, in OnInit

from window import *
File "D:\sky3d\src\script\window.py", line 18, in ?

CoordWin=Sky3D_Windows('CoordWin','CoordWinFunc',15,Sky3D_GetMainWinRec()[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




More information about the Python-list mailing list