Commit a2e1a20e45abab4490e26b325c478c488c0f5fc7

Authored by Paulo Henrique Junqueira Amorim
1 parent 6c57dc4a

ADD: Added cancel in the button from ProgressDialog

invesalius/control.py
... ... @@ -35,7 +35,9 @@ class Controller():
35 35 'Save raycasting preset')
36 36 ps.Publisher().subscribe(self.OnOpenDicomGroup,
37 37 'Open DICOM group')
38   -
  38 + #ps.Publisher().subscribe(self.CancelDicomLoad,
  39 + # "Cancel DICOM load in the control")
  40 +
39 41 def StartImportPanel(self, pubsub_evt):
40 42 # path to directory
41 43 path = pubsub_evt.data
... ... @@ -47,13 +49,20 @@ class Controller():
47 49  
48 50 self.frame.Bind(reader.evt_update_progress, self.Progress)
49 51 self.frame.Bind(reader.evt_end_load_file, self.LoadPanel)
50   -
  52 +
51 53 def Progress(self, evt):
52   - if not(self.progress_dialog):
53   - self.progress_dialog = dialog.ProgressDialog(maximum = evt.progress[1])
  54 + if (evt.progress):
  55 + if not(self.progress_dialog):
  56 + self.progress_dialog = dialog.ProgressDialog(
  57 + maximum = evt.progress[1])
  58 + else:
  59 + if not(self.progress_dialog.Update(evt.progress[0])):
  60 + self.progress_dialog.Close()
  61 + self.progress_dialog = None
54 62 else:
55   - if not(self.progress_dialog.Update(evt.progress[0])):
56   - self.progress_dialog = None
  63 + #Is None if user canceled the load
  64 + self.progress_dialog.Close()
  65 + self.progress_dialog = None
57 66  
58 67  
59 68 def LoadPanel(self,evt):
... ...
invesalius/gui/dialogs.py
1 1 import wx
2 2 from wx.lib import masked
  3 +import wx.lib.pubsub as ps
3 4  
4 5 class NumberDialog(wx.Dialog):
5 6 def __init__(self, message, value=0):
... ... @@ -75,12 +76,19 @@ class ProgressDialog(object):
75 76 #| wx.PD_ESTIMATED_TIME
76 77 #| wx.PD_REMAINING_TIME
77 78 )
78   -
79   - def Update(self, value):
80   - if (value == self.maximum):
81   - self.dlg.Destroy()
82   - return False
83   - else:
  79 +
  80 + self.dlg.Bind(wx.EVT_BUTTON, self.Cancel)
  81 +
  82 + def Cancel(self, evt):
  83 + ps.Publisher().sendMessage("Cancel DICOM load")
  84 +
  85 + def Update(self, value):
  86 + if(value != self.maximum):
84 87 self.dlg.Update(value)
85 88 return True
86   -
  89 + else:
  90 + return False
  91 +
  92 + def Close(self):
  93 + self.dlg.Destroy()
  94 +
... ...
invesalius/reader/dicom_reader.py
... ... @@ -128,12 +128,19 @@ class ProgressDicomReader:
128 128  
129 129 self.evt_update_progress = EVT_LOAD_FILE_PROGRESS
130 130 self.evt_end_load_file = EVT_END_LOAD_FILE
  131 +
  132 + ps.Publisher().subscribe(self.CancelLoad, "Cancel DICOM load")
131 133  
  134 + def CancelLoad(self, evt_pubsub):
  135 + self.running = False
  136 + self.stoped = True
  137 +
132 138 def SetWindowEvent(self, frame):
133 139 self.frame = frame
134   -
  140 +
135 141 def SetDirectoryPath(self, path,recursive=True):
136 142 self.running = True
  143 + self.stoped = False
137 144 thread.start_new_thread(self.GetDicomGroups,(path,recursive))
138 145  
139 146 def UpdateLoadFileProgress(self,cont_progress):
... ... @@ -153,4 +160,10 @@ class ProgressDicomReader:
153 160 else:
154 161 self.EndLoadFile(value_progress)
155 162 self.running = False
  163 +
  164 + #Is necessary in the case user cancel
  165 + #the load, ensure that dicomdialog is closed
  166 + if(self.stoped):
  167 + self.UpdateLoadFileProgress(None)
  168 + self.stoped = False
156 169  
157 170 \ No newline at end of file
... ...