Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68640 > unrolled thread

CallBack function in C Libraries.

Started byfiensproto@gmail.com
First post2014-03-20 16:16 -0700
Last post2014-03-21 17:22 -0700
Articles 8 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  CallBack function in C Libraries. fiensproto@gmail.com - 2014-03-20 16:16 -0700
    Re: CallBack function in C Libraries. Mark H Harris <harrismh777@gmail.com> - 2014-03-20 18:42 -0500
      Re: CallBack function in C Libraries. fiensproto@gmail.com - 2014-03-20 16:56 -0700
        Re: CallBack function in C Libraries. 88888 Dihedral <dihedral88888@gmail.com> - 2014-03-20 17:04 -0700
        Re: CallBack function in C Libraries. "Rhodri James" <rhodri@wildebst.org.uk> - 2014-03-21 02:01 +0000
          Re: CallBack function in C Libraries. fiensproto@gmail.com - 2014-03-21 05:02 -0700
            Re: CallBack function in C Libraries. Mark H Harris <harrismh777@gmail.com> - 2014-03-21 11:50 -0500
              Re: CallBack function in C Libraries. fiensproto@gmail.com - 2014-03-21 17:22 -0700

#68640 — CallBack function in C Libraries.

Fromfiensproto@gmail.com
Date2014-03-20 16:16 -0700
SubjectCallBack function in C Libraries.
Message-ID<a9908cb7-3566-42a8-a468-8179ac1df7ab@googlegroups.com>
Hello. I want to use a c library. It is a complete graphic widget set.

Here code working. But i have problem with the callback function. The callback is executed while ClikOnForm is executed but i get a error message (see after code )
____________________________________________________________________

file fpgui-test.py

from ctypes import*

def TheProc(c_int): fpgui.fpgFormWindowTitle(0, 'Boum')
return 0

CMPFUNC = CFUNCTYPE(c_int)

TheProcF = CMPFUNC(TheProc)

fpgui = cdll.LoadLibrary("fpgui-32.dll")

fpgui.fpgInitialize() fpgui.fpgSetStyle('Demo Style') fpgui.fpgFormCreate(0, -1) fpgui.fpgFormSetPosition(0, 300,100,400,200) fpgui.fpgFormWindowTitle(0, 'Hello world!')

fpgui.fpgFormOnClick(0,TheProcF)

fpgui.fpgButtonCreate(0,0,-1) ; fpgui.fpgButtonSetPosition(0,0, 15, 10 , 150 , 40) fpgui.fpgButtonSetText(0,0, 'BUTTON1')

fpgui.fpgButtonCreate(0,1,-1) ; fpgui.fpgButtonSetPosition(0,1, 15, 70 , 150, 40) fpgui.fpgButtonSetText(0,1, 'Clickme')

fpgui.fpgFormShow(0) fpgui.fpgRun()

Here the error message if i click on form :

Traceback (most recent call last): File "_ctypes/callbacks.c", line 314, in 'calling callback function' TypeError: TheProc() takes exactly 1 argument (0 given)

What is wrong ?

Many thanks.

[toc] | [next] | [standalone]


#68642

FromMark H Harris <harrismh777@gmail.com>
Date2014-03-20 18:42 -0500
Message-ID<lgfucb$4q7$1@speranza.aioe.org>
In reply to#68640
On 3/20/14 6:16 PM, fiensproto@gmail.com wrote:

> def TheProc(c_int): fpgui.fpgFormWindowTitle(0, 'Boum')
> return 0

> TheProcF = CMPFUNC(TheProc)

> Traceback (most recent call last): File "_ctypes/callbacks.c",
> line 314, in 'calling callback function' TypeError: TheProc() takes
> exactly 1 argument (0 given)

> What is wrong ?

You defined TheProc(c_init) to take exactly 1 argument.

But when you called it, you didn't provide the argument.

So, you got a traceback indicating that TheProc() takes exactly one 
argument.

Give the function call its required argument and the error will go 
away... well, at least that one.


Cheers

[toc] | [prev] | [next] | [standalone]


#68643

Fromfiensproto@gmail.com
Date2014-03-20 16:56 -0700
Message-ID<e469fc0a-596c-40b6-8b27-751a4fe84d85@googlegroups.com>
In reply to#68642
> Give the function call its required argument and the error will go 
> 
> away... well, at least that one.

Yep, many thanks for the answer.
But... im totally beginner with Python.
I develop in Pascal and C and want to understand the basics of Python.

In concrete, what must i change in the code ?

Many thanks.

[toc] | [prev] | [next] | [standalone]


#68644

From88888 Dihedral <dihedral88888@gmail.com>
Date2014-03-20 17:04 -0700
Message-ID<fc708c65-e591-4186-801a-a0bbeaf87ef0@googlegroups.com>
In reply to#68643
On Friday, March 21, 2014 7:56:43 AM UTC+8, fiens...@gmail.com wrote:
> > Give the function call its required argument and the error will go 
> 
> > 
> 
> > away... well, at least that one.
> 
> 
> 
> Yep, many thanks for the answer.
> 
> But... im totally beginner with Python.
> 
> I develop in Pascal and C and want to understand the basics of Python.
> 
> 
> 
> In concrete, what must i change in the code ?
> 
> 
> 
> Many thanks.

Python is a dynamical typed functional
language with OOP supports in the 
revisons, and well suited in the 
giga-byte dram capacity 
personal toy era that can relplace 
her mother lisp's unrealized AI 
project .

[toc] | [prev] | [next] | [standalone]


#68656

From"Rhodri James" <rhodri@wildebst.org.uk>
Date2014-03-21 02:01 +0000
Message-ID<op.xc1uldoj5079vu@gnudebeest>
In reply to#68643
On Thu, 20 Mar 2014 23:56:43 -0000, <fiensproto@gmail.com> wrote:

>> Give the function call its required argument and the error will go
>>
>> away... well, at least that one.
>
> Yep, many thanks for the answer.
> But... im totally beginner with Python.
> I develop in Pascal and C and want to understand the basics of Python.
>
> In concrete, what must i change in the code ?

In abstract, exactly the same thing that you would change if a C compiler  
had complained to you that you had failed to give a function call the  
right number of arguments.  More than that I have no idea; it's your code,  
presumably you know what it should be doing.  I have absolutely no idea  
how TheProc() is being called by your widgets.  Are you sure it should be  
declared as taking a single parameter?

I'm afraid it doesn't help that GoogleGroups has badly mangled the  
formatting of your code.  I'm not quite sure what to suggest since it  
isn't one of the usual problems, but you might find reading  
https://wiki.python.org/moin/GoogleGroupsPython helpful.  It will  
certainly help with the double-spacing in your quote above.

-- 
Rhodri James *-* Wildebeest Herder to the Masses

[toc] | [prev] | [next] | [standalone]


#68684

Fromfiensproto@gmail.com
Date2014-03-21 05:02 -0700
Message-ID<488fbd2c-1b99-482d-a282-f3f20defbc68@googlegroups.com>
In reply to#68656
> I'm afraid it doesn't help that GoogleGroups has badly mangled the  
> 
> formatting of your code.  I'm not quite sure what to suggest since it  
> 
> isn't one of the usual problems, but you might find reading  
> 
> https://wiki.python.org/moin/GoogleGroupsPython helpful.  It will  
> 
> certainly help with the double-spacing in your quote above.

> Rhodri James *-* Wildebeest Herder to the Masses


Yep, Many thanks for help....
Hum, i have find the solution, it was in "CallBack function" in help-doc.

=> 

#file fpgui-test.py
from ctypes import*

def TheProc():
    fpgui.fpgFormWindowTitle(0, 'Boum')
    return 0 

def TheProcBut0():
    fpgui.fpgButtonSetText(0,0, 'Boum also')
    return 0 
    
def TheProcBut1():
    fpgui.fpgButtonSetText(0,1, 'Boum too')
    return 0 
 
CMPFUNC = CFUNCTYPE(c_int)

TheProcF = CMPFUNC(TheProc)
TheProcB0 = CMPFUNC(TheProcBut0)
TheProcB1 = CMPFUNC(TheProcBut1)

fpgui = cdll.LoadLibrary("fpgui-32.dll")

fpgui.fpgInitialize()
fpgui.fpgSetStyle('Demo Style')
fpgui.fpgFormCreate(0, -1)
fpgui.fpgFormSetPosition(0, 300,100,400,200)
fpgui.fpgFormWindowTitle(0, 'Hello world!')

fpgui.fpgFormOnClick(0,TheProcF) 

fpgui.fpgButtonCreate(0,0,-1) ;
fpgui.fpgButtonSetPosition(0,0, 15, 10 , 150 , 40)
fpgui.fpgButtonSetText(0,0, 'BUTTON1')
fpgui.fpgButtonOnClick(0,0,TheProcB0) 

fpgui.fpgButtonCreate(0,1,-1) ;
fpgui.fpgButtonSetPosition(0,1, 15, 70 , 150, 40)
fpgui.fpgButtonSetText(0,1, 'Clickme')
fpgui.fpgButtonOnClick(0,1,TheProcB1)

fpgui.fpgFormShow(0)
fpgui.fpgRun()

[toc] | [prev] | [next] | [standalone]


#68701

FromMark H Harris <harrismh777@gmail.com>
Date2014-03-21 11:50 -0500
Message-ID<lghqk7$suf$1@speranza.aioe.org>
In reply to#68684
On 3/21/14 7:02 AM, fiensproto@gmail.com wrote:
> Yep, Many thanks for help....
> Hum, i have find the solution, it was in "CallBack function" in help-doc.

    No, it was not in the "CallBack function" in help-doc ...

>
> def TheProc():         <================== you moved c_int from here ...
>      fpgui.fpgFormWindowTitle(0, 'Boum')
>      return 0
>
{snip}
>
> CMPFUNC = CFUNCTYPE(c_int)   <============ and placed it here ...
>
> TheProcF = CMPFUNC(TheProc)    <========== so that when you called TheProc ...


... it wasn't "expecting" exactly one parameter. So, your python 
traceback no longer warns about the parameter 'mismatch' in the defined 
function  TheProc().

    I'm not picking on you, but this error was obvious; as was it's 
solution, so I'm just wondering ?

Cheers

[toc] | [prev] | [next] | [standalone]


#68729

Fromfiensproto@gmail.com
Date2014-03-21 17:22 -0700
Message-ID<c451c8e3-90fb-40b9-85a5-cdcb6e9efb8a@googlegroups.com>
In reply to#68701
Le vendredi 21 mars 2014 16:50:18 UTC, Mark H. Harris a écrit :
> > def TheProc():         <================== you moved c_int from here ...
> 
> >      fpgui.fpgFormWindowTitle(0, 'Boum')
> 
> >      return 0

> > CMPFUNC = CFUNCTYPE(c_int)   <============ and placed it here ...

> 
> 
> ... it wasn't "expecting" exactly one parameter. So, your python 
> 
> traceback no longer warns about the parameter 'mismatch' in the defined 
> 
> function  TheProc().
> 
> 
> 
>     I'm not picking on you, but this error was obvious; as was it's 
> 
> solution, so I'm just wondering ?
> 

Hello and thanks for answer.

Hum, i do not understand why, but the code is working ... ;-)

Some remarks :

> def TheProc():   
>      fpgui.fpgFormWindowTitle(0, 'Boum')
>      return 0        <================== that does the trick...


And 

> > CMPFUNC = CFUNCTYPE(c_int)   <======== 1 argument minimum..

It seems that CFUNCTYPE() want minimum 1 argument, even if TheProc() is a simple procedure, without argument...

Hum, it is my really first program in Python and im impressed how easy it was to do my Pascal (fpc) library work!
Im busy to try to do it work for java programs but it is not so easy.

By the way, is it possible to hide the terminal-window ?

That library is a complete graphic widget set (from Form to Stringgrid and more).
So, i will prefer that the console was hided...

And last question, how to retrieve the directory of the main Python application ?

Many thanks.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web