0

I have this in my fb.h file:

static fbClass *getInstance();
void clearFBblit();
int getFBdiff(int ret);
void setFBdiff(int top, int right, int left, int bottom);

and myfb.cpp content:

void fbClass::clearFBblit()
{
    //set real frambuffer transparent
//  memset(lfb, 0x00, xRes * yRes * 4);
    blit();
}

int fbClass::getFBdiff(int ret)
{
    if(ret == 0)
        return topDiff;
    else if(ret == 1)
        return leftDiff;
    else if(ret == 2)
        return rightDiff;
    else if(ret == 3)
        return bottomDiff;
    else
        return -1;
}

void fbClass::setFBdiff(int top, int left, int right, int bottom)
{
    if(top < 0) top = 0;
    if(top > yRes) top = yRes;
    topDiff = top;
    if(left < 0) left = 0;
    if(left > xRes) left = xRes;
    leftDiff = left;
    if(right > 0) right = 0;
    if(-right > xRes) right = -xRes;
    rightDiff = right;
    if(bottom > 0) bottom = 0;
    if(-bottom > yRes) bottom = -yRes;
    bottomDiff = bottom;
}

and in another file I used this code:

def yellow(self):
    global top
    global right
    global bottom
    global left
    print '[OSD Adjustment] set Default Screen Settings'
    top = 0
    bottom = 0
    left = 0
    right = 0
    fbClass.getInstance().setFBdiff(0, 0, 0, 0)
    fbClass.getInstance().clearFBblit()

Now when I run my code I get this:

fbClass.getInstance().setFBdiff(0, 0, 0, 0) AttributeError: 'fbClass' object has no attribute 'setFBdiff'

What error am I making?

  • 1
    You need a bit more than a function declaration in an `.h` file to define a method on a Python class in a C extension. I suggest reading through https://docs.python.org/3/c-api/index.html – zvone Aug 25 '20 at 00:48
  • @zvone i edited my post.. please review my fb.cpp code .. sorry i forgot to post it in the question in first time . – Ahmed Moselhi Aug 25 '20 at 01:58
  • Your header file defines a `getInstance` function and then three other static functions, while your python code somehow tries to call `setFBdiff` as a method. Perhaps your Python code should just call `setFBdiff` as a function? – Botje Aug 25 '20 at 07:33
  • 1
    That is not the relevant code. Most important would be to correctly initialize the `PyTypeObject` structure, especially the `tp_methods`. See https://docs.python.org/3/c-api/typeobj.html – zvone Aug 25 '20 at 12:29

0 Answers0