[Bf-python] Callback types

Willian Padovani Germano wgermano at ig.com.br
Sat Jan 22 20:04:49 CET 2005


Hi,

(about patch to Window.File/ImageSelector)

Michael Reimpell wrote:

>Here is an enhanced version of the patch.
>
Thanks, I committed it yesterday with other pending patches and two 
script updates.

>A remaining issue is, that if the user presses the "cancel" button the 
>getSelectedFile c function that manages the python callback is not called.
>
Yep, there are a few ways to solve this.  One is passing another 
callback (e.g. sfile->atexit, that for the rest of Blender -- aka not 
from Window_FileSelector -- would simply be NULL) to activate_filesel 
that gets called to clean things when file selection is canceled.  It 
can also be a general "atexit" callback called whether or not the user 
cancelled file selection where we'd decref the file callback.

For that we can either modify activate_filesel directly or make 
activate_filesel a wrapper for an activate_filesel_ex (Blender does 
things like this here and there) function that expects both file and 
"atexit" callbacks, so bpython would use the _ex one and the rest of 
Blender would keep using activate_filesel):

activate_filesel(..., callback) {
  activate_filesel_ex(..., callback, NULL)
}

Anyway, we think a little then talk to Ton.

Another issue is when a second script calls the fileseletor while it is 
still open for the first one that called it.  Either we write something 
robust that works in general or -- ugh -- simply return an error when 
that happens: "Error %t|Only one script can call the file selector at a 
time".  For a proper solution we can make the callback pointer part of 
the Script struct and pass the script name or pointer to e.g. 
activate_filesel_ex instead of a second callback.  This way we can 
retrieve the right callback to decref and it works for as many scripts 
at a time as the user wants to use.

Only mentioned file selector, but of course the same is valid for the 
image selector.

-- 
Willian




More information about the Bf-python mailing list