From: regrain Date: Wed, 11 Feb 2004 12:20:58 +0000 (+0000) Subject: * bug fix for python's None object X-Git-Tag: Version0.5.bp~308 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=45822871269cb2ac9d19beb53062bf7ee52a6553;p=gdcm.git * bug fix for python's None object * Add a new python demo -- BeNours --- diff --git a/gdcmPython/demo/makeDicomDir.py b/gdcmPython/demo/makeDicomDir.py new file mode 100644 index 00000000..869441fb --- /dev/null +++ b/gdcmPython/demo/makeDicomDir.py @@ -0,0 +1,43 @@ +from gdcmPython import * +import sys + +### Get filename from command line or default it +try: + FileName = sys.argv[1] +except IndexError: + FileName = os.path.join(GDCM_DATA_PATH, "DICOMDIR") + +try: + printLevel = int(sys.argv[2]) +except IndexError: + printLevel = 1 +print FileName + +### Build the header element list +toRead = gdcmDicomDir(FileName) + +def startMethod(): + print "Python start" + +def endMethod(): + print "Python end" + +def progressMethod(): + print "Python progress",toRead.GetProgress() + +toRead.SetStartMethod(None) +toRead.SetProgressMethod(progressMethod) +toRead.SetEndMethod(endMethod) +toRead.ParseDirectory() + +print "##############################################################" +print "### Display all the elements and their respective values" +print "## found in the ", FileName, " file." +print "##############################################################" +toRead.SetPrintLevel(-1) +toRead.Print() + +ValDict = toRead.GetEntry() +for key in ValDict.keys(): + print "[%s] = [%s]" %(key, ValDict[key]) + diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index b731cedd..439884ea 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -217,10 +217,19 @@ extern gdcmGlobal gdcmGlob; //////////////////////////////////////////////////////////////////////////// // Deals with function returning a C++ string. %typemap(python, in) (gdcmMethod *,void * =NULL,gdcmMethod * =NULL) { - Py_INCREF($input); - $1=vtkPythonVoidFunc; - $2=$input; - $3=vtkPythonVoidFuncArgDelete; + if($input!=Py_None) + { + Py_INCREF($input); + $1=vtkPythonVoidFunc; + $2=$input; + $3=vtkPythonVoidFuncArgDelete; + } + else + { + $1=NULL; + $2=NULL; + $3=NULL; + } }