]> Creatis software - gdcm.git/blobdiff - gdcmPython/demo/PrintFile.py.in
BUG: Apparently python2.5 do not like extension to have a .dll extension, we need...
[gdcm.git] / gdcmPython / demo / PrintFile.py.in
index a0539c7f322e2499cc575362d27432810e709565..7506aef0150dee2f552a7859aca1a5a165f3aef5 100644 (file)
@@ -1,20 +1,30 @@
 import sys
-import os
+import os.path
+from gdcmConfigDemo import *
+from gdcmPython.core import *
 
-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')
+def PrintUse():
+   print ""
+   print "Use :"
+   print "-----"
+   print "%s <fileName>" % sys.argv[0]
+   print "   fileName : path to the DICOM file to parse"
+   print ""
+   print ""
 
-from gdcmPython.core import *
+try:
+   print gdcm.DataEntry
+   print gdcm.DataEntryPtr
+except:
+   pass
 
 ### 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 +32,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."
@@ -39,3 +52,12 @@ while(val):
    val=file.GetNextEntry()
 val=None
 
+print "##############################################################"
+val=file.GetFirstEntry()
+while(val):
+   if(isinstance(val,gdcm.DataEntry)):
+      print "Data %s [%s] [%s] : %s" % (val.GetKey().str(),val.GetVR().str(),
+                                        val.GetName(),val.GetString())
+   val=file.GetNextEntry()
+val=None
+