]> Creatis software - gdcm.git/blob - gdcmPython/demo/MakeDicomDir.py.in
* Add the CommandPy and CommandManager to the python wrapping
[gdcm.git] / gdcmPython / demo / MakeDicomDir.py.in
1 import sys
2 import os.path
3 from gdcmConfigDemo import *
4 from gdcmPython.core import *
5
6 def PrintUse():
7    print ""
8    print "Use :"
9    print "-----"
10    print "%s" % sys.argv[0]
11    print "   Create the DicomDir from the GDCM_DATA_ROOT path"
12    print ""
13    print ""
14
15 ### Progress methods
16 def startMethod():
17    print "Start"
18 def progressMethod():
19    print "Progress",dicomdir.GetProgress()
20 def endMethod():
21    print "End"
22
23 ### Get filename from command line or default it
24 try:
25    fileName = sys.argv[1]
26 except IndexError:
27    fileName = os.path.join(GDCM_DATA_ROOT, "DICOMDIR")
28    if( not os.path.isfile(fileName) ):
29       fileName=os.path.join(os.path.split(sys.argv[0])[0],"DICOMDIR")
30
31 try:
32    printLevel = int(sys.argv[2])
33 except IndexError:
34    printLevel = 1
35
36 ### Build the DicomDir element list
37 dicomdir = gdcm.DicomDir.New()
38
39 cmd=gdcm.CommandPy.New()
40 cmd.SetCallback(startMethod)
41 gdcm.CommandManager.SetCommand(dicomdir,gdcm.CMD_STARTPROGRESS,cmd)
42 cmd=gdcm.CommandPy.New()
43 cmd.SetCallback(endMethod)
44 gdcm.CommandManager.SetCommand(dicomdir,gdcm.CMD_ENDPROGRESS,cmd)
45 cmd=gdcm.CommandPy.New()
46 cmd.SetCallback(progressMethod)
47 gdcm.CommandManager.SetCommand(dicomdir,gdcm.CMD_PROGRESS,cmd)
48
49 dicomdir.SetDirectoryName(GDCM_DATA_ROOT)
50 dicomdir.Load()
51 if not dicomdir.IsReadable():
52    PrintUse()
53    raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName
54
55 print "DICOMDIR -->",fileName
56 print "##############################################################"
57 print "## Display all the elements and their respective values"
58 print "## found in the ", fileName, " file."
59 print "##############################################################"
60 dicomdir.SetPrintLevel(-1)
61 dicomdir.Print()
62