473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Class __init__ trouble

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.Ge tPyDict,'pySky3D_Window');
pyGL_Class.AddClassMethod('__init__',pyWindowClass Init,'');
pyGL_Class.AddClassMethod('_Show',pyWindowShow,'') ;
pyGL_Class.AddClassMethod('_Hide',pyWindowHide,'') ;
pyGL_Class.AddClassMethod('_OnMouseOver',pyOnMouse Over,'');

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','MouseWinFu nc',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.Ge tPyDict,'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',1 5,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

Jan 16 '06 #1
2 1186
So any one have ideas how to solve this problem???

I think my problem in code that adds new methods in class. Every time i
add new methods it adds on single class or maybe globally.

How to make it correctly???

Jan 17 '06 #2
Problem was solved by adding classes into new separate modules.

Jan 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Raymond Hettinger | last post by:
Based on your extensive feedback, PEP 322 has been completely revised. The response was strongly positive, but almost everyone preferred having a function instead of multiple object methods. The...
15
by: beliavsky | last post by:
What are the pros and cons of defining a method of a class versus defining a function that takes an instance of the class as an argument? In the example below, is it better to be able to write...
50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
15
by: Tim Henderson | last post by:
Hi i have some errors in my code that i can't find the reason for here is the error i have 3 classes: -Song -Album -Artist Song has 3 pieces of data with getter and setter meathods: -Name...
1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
5
by: Stewart Midwinter | last post by:
I've got an app that creates an object in its main class (it also creates a GUI). My problem is that I need to pass this object, a list, to a dialog that is implemented as a second class. I want...
2
by: Podi | last post by:
Hi, Newbie question about unittest. I am having trouble passing a variable to a test class object. MyCase class will potentially have many test functions. Any help would be much...
6
by: gmarkowsky | last post by:
Hi all, I'm trying to import a class from a module. The class looks like this: class App: def __init__(self, master): frame = Frame(master) frame.pack()
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.