473,770 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class __init__ trouble

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

Jan 16 '06 #1
2 1203
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
2997
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 updated proposal is at: www.python.org/peps/pep-0322.html In a nutshell, it proposes a builtin function that greatly simplifies reverse iteration. The core concept is that clarity comes from specifying a sequence in a forward direction and...
15
2490
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 z.modulus() or modulus(z)? Is there a difference between Python and C++ in this regard? from math import sqrt class xy: def __init__(self,x,y): self.x = x
50
6377
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 def foo(self, data): self.attr1=data self.attr2.append(data) The initialization of attr1 is obviously OK, all instances of Father redefine it in the method foo. But the initialization of attr2 is wrong
15
1449
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 | i.e. song name
1
2386
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 rest of my application (read this as for any imported module) if I import in in a 'higher-level' module. For example: A.py ====
5
2075
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 to edit the contents of that list and then pass back the results to the first class. So my question is, can a method in one class change an object in another class? If the answer is no, I suppose I could pass in the list as an argument when I...
2
3853
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 appreciated. Thanks,
6
2569
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
6258
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 the app is concerned). The problem is, If someone makes a typo, they may get an unexpected error due accidentally calling the original attribute instead of the wrapped version. Does anyone have a simple solution for this?
0
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.