CallBack function in C Libraries.

2014-03-20 Thread fiensproto
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CallBack function in C Libraries.

2014-03-20 Thread fiensproto
> 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CallBack function in C Libraries.

2014-03-21 Thread fiensproto
> 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()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CallBack function in C Libraries.

2014-03-21 Thread fiensproto
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.
-- 
https://mail.python.org/mailman/listinfo/python-list