]> Creatis software - gdcm.git/blob - gdcmPython/demo/DicomDirProgressMethod.py
* src/gdcmDicomDit.h the Method typedef is now local to DicomDir class.
[gdcm.git] / gdcmPython / demo / DicomDirProgressMethod.py
1 ### This simple code illustrates how the behavior of the parsing of
2 ### directory in order to build a DicomDir can be controlled by
3 ### the caller. By caller control we mean two things:
4 ###  1/ watch the advancement of the parsing
5 ###  2/ abort it on caller demand
6 ### In this example we arbitrarily stop the parsing (see progessMethod() )
7 ### when the parsing reaches 20% of it's duty. A typical GUI usage of
8 ### this mecanism would be to offer a "Cancel" button to the user...
9 from gdcmPython import *
10 import sys
11
12 ### Get the pathname from command line or default it to .
13 try:
14    DirPathName = sys.argv[1]
15 except IndexError:
16    DirPathName = "."
17
18 ### The python defined methods that we wan't to call back
19 def startMethod():
20    print "Start"
21 def progressMethod():
22    print "Progress", dicomDir.GetProgress()
23    if( dicomDir.GetProgress() > 0.2 ):
24       dicomDir.AbortProgress()
25 def endMethod():
26    print "End"
27
28 dicomDir=gdcm.DicomDir( DirPathName )
29 print dicomDir.IsReadable()
30 ### Set up the call backs:
31 dicomDir.SetStartMethod(startMethod)
32 dicomDir.SetProgressMethod(progressMethod)
33 dicomDir.SetEndMethod(endMethod)
34 ### Launch the parsing of the directory
35 dicomDir.ParseDirectory()