Commit cd7f4721c6d1ab9a3838a070ece6b10263a4af71
1 parent
0586bd4a
Exists in
master
and in
68 other branches
ENH: Now it's possible to cancel a import
Showing
1 changed file
with
8 additions
and
18 deletions
Show diff stats
invesalius/reader/dicom_reader.py
... | ... | @@ -120,17 +120,11 @@ def yGetDicomGroups(directory, recursive=True, gui=True): |
120 | 120 | def GetDicomGroups(directory, recursive=True): |
121 | 121 | return yGetDicomGroups(directory, recursive, gui=False).next() |
122 | 122 | |
123 | + | |
123 | 124 | class ProgressDicomReader: |
124 | - | |
125 | 125 | def __init__(self): |
126 | - #(self.LoadFilesProgress, EVT_LOAD_FILE_PROGRESS) = wx.lib.newevent.NewEvent() | |
127 | - #(self.EndLoadFiles, EVT_END_LOAD_FILE) = wx.lib.newevent.NewEvent() | |
128 | - | |
129 | - #self.evt_update_progress = EVT_LOAD_FILE_PROGRESS | |
130 | - #self.evt_end_load_file = EVT_END_LOAD_FILE | |
131 | - | |
132 | 126 | ps.Publisher().subscribe(self.CancelLoad, "Cancel DICOM load") |
133 | - | |
127 | + | |
134 | 128 | def CancelLoad(self, evt_pubsub): |
135 | 129 | self.running = False |
136 | 130 | self.stoped = True |
... | ... | @@ -142,29 +136,25 @@ class ProgressDicomReader: |
142 | 136 | self.running = True |
143 | 137 | self.stoped = False |
144 | 138 | self.GetDicomGroups(path,recursive) |
145 | - | |
139 | + | |
146 | 140 | def UpdateLoadFileProgress(self,cont_progress): |
147 | 141 | ps.Publisher().sendMessage("Update dicom load", cont_progress) |
148 | - #evt = self.LoadFilesProgress(progress = cont_progress) | |
149 | - #wx.PostEvent(self.frame, evt) | |
150 | - | |
142 | + | |
151 | 143 | def EndLoadFile(self, grouper): |
152 | 144 | ps.Publisher().sendMessage("End dicom load", grouper) |
153 | - #evt = self.EndLoadFiles(value = grouper) | |
154 | - #wx.PostEvent(self.frame, evt) | |
155 | - | |
145 | + | |
156 | 146 | def GetDicomGroups(self, path, recursive): |
157 | 147 | y = yGetDicomGroups(path, recursive) |
158 | - #while self.running: | |
159 | 148 | for value_progress in y: |
149 | + if not self.running: | |
150 | + break | |
160 | 151 | if isinstance(value_progress, tuple): |
161 | 152 | self.UpdateLoadFileProgress(value_progress) |
162 | 153 | else: |
163 | 154 | self.EndLoadFile(value_progress) |
164 | - | |
155 | + | |
165 | 156 | #Is necessary in the case user cancel |
166 | 157 | #the load, ensure that dicomdialog is closed |
167 | 158 | if(self.stoped): |
168 | 159 | self.UpdateLoadFileProgress(None) |
169 | 160 | self.stoped = False |
170 | - | ... | ... |