X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=gdcmPython%2Fdemo%2FPrintFile.py.in;h=a6d6bfbb2bdc4d5fc9d202046ab43e826551c8d7;hb=7d0479304b904f27272d0464952c54d2bf4a3809;hp=77b1058c973ad20b40e4fd7b1a69f28b7c50dc13;hpb=33ea6274972a853d1214fc5e6ea31309ec7e2ad8;p=gdcm.git diff --git a/gdcmPython/demo/PrintFile.py.in b/gdcmPython/demo/PrintFile.py.in index 77b1058c..a6d6bfbb 100644 --- a/gdcmPython/demo/PrintFile.py.in +++ b/gdcmPython/demo/PrintFile.py.in @@ -1,20 +1,24 @@ import sys -import os - -sys.path.append('${GDCM_BINARY_DIR}') -if os.name == 'posix': - sys.path.append('${GDCM_BINARY_DIR}/bin') -else: - sys.path.append('${GDCM_BINARY_DIR}/bin/Release') - sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') - +import os.path +from gdcmConfigDemo import * from gdcmPython.core import * +def PrintUse(): + print "" + print "Use :" + print "-----" + print "%s " % sys.argv[0] + print " fileName : path to the DICOM file to parse" + print "" + print "" + ### Get filename from command line or default it try: fileName = sys.argv[1] except IndexError: fileName = os.path.join(GDCM_DATA_ROOT, "test.acr") + if( not os.path.isfile(fileName) ): + fileName=os.path.join(os.path.split(sys.argv[0])[0],"test.acr") try: printLevel = int(sys.argv[2]) @@ -22,11 +26,14 @@ except IndexError: printLevel = 1 ### Build the file element list -print fileName, type(fileName) -file = gdcm.File(fileName) +file = gdcm.File.New() +file.SetFileName(fileName) +file.Load() if not file.IsReadable(): + PrintUse() raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName +print "File -->",fileName print "##############################################################" print "### Display all the elements and their respective values" print "## found in the ", fileName, " file." @@ -42,12 +49,9 @@ val=None print "##############################################################" val=file.GetFirstEntry() while(val): - if(isinstance(val,gdcm.ValEntryPtr)): - print "Val %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(), - val.GetName(),val.GetValue()) - else: - print "Bin %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(), - val.GetName(),val.GetValue()) + if(isinstance(val,gdcm.DataEntryPtr)): + print "Data %s [%s] [%s] : %s" % (val.GetKey().str(),val.GetVR().str(), + val.GetName(),val.GetString()) val=file.GetNextEntry() val=None