From a2e1a20e45abab4490e26b325c478c488c0f5fc7 Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Sun, 18 Oct 2009 00:12:31 +0000 Subject: [PATCH] ADD: Added cancel in the button from ProgressDialog --- invesalius/control.py | 21 +++++++++++++++------ invesalius/gui/dialogs.py | 22 +++++++++++++++------- invesalius/reader/dicom_reader.py | 15 ++++++++++++++- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index 6467f58..619d3b1 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -35,7 +35,9 @@ class Controller(): 'Save raycasting preset') ps.Publisher().subscribe(self.OnOpenDicomGroup, 'Open DICOM group') - + #ps.Publisher().subscribe(self.CancelDicomLoad, + # "Cancel DICOM load in the control") + def StartImportPanel(self, pubsub_evt): # path to directory path = pubsub_evt.data @@ -47,13 +49,20 @@ class Controller(): self.frame.Bind(reader.evt_update_progress, self.Progress) self.frame.Bind(reader.evt_end_load_file, self.LoadPanel) - + def Progress(self, evt): - if not(self.progress_dialog): - self.progress_dialog = dialog.ProgressDialog(maximum = evt.progress[1]) + if (evt.progress): + if not(self.progress_dialog): + self.progress_dialog = dialog.ProgressDialog( + maximum = evt.progress[1]) + else: + if not(self.progress_dialog.Update(evt.progress[0])): + self.progress_dialog.Close() + self.progress_dialog = None else: - if not(self.progress_dialog.Update(evt.progress[0])): - self.progress_dialog = None + #Is None if user canceled the load + self.progress_dialog.Close() + self.progress_dialog = None def LoadPanel(self,evt): diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 8dab2cb..3629f20 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -1,5 +1,6 @@ import wx from wx.lib import masked +import wx.lib.pubsub as ps class NumberDialog(wx.Dialog): def __init__(self, message, value=0): @@ -75,12 +76,19 @@ class ProgressDialog(object): #| wx.PD_ESTIMATED_TIME #| wx.PD_REMAINING_TIME ) - - def Update(self, value): - if (value == self.maximum): - self.dlg.Destroy() - return False - else: + + self.dlg.Bind(wx.EVT_BUTTON, self.Cancel) + + def Cancel(self, evt): + ps.Publisher().sendMessage("Cancel DICOM load") + + def Update(self, value): + if(value != self.maximum): self.dlg.Update(value) return True - + else: + return False + + def Close(self): + self.dlg.Destroy() + diff --git a/invesalius/reader/dicom_reader.py b/invesalius/reader/dicom_reader.py index 56b695d..8b222c3 100644 --- a/invesalius/reader/dicom_reader.py +++ b/invesalius/reader/dicom_reader.py @@ -128,12 +128,19 @@ class ProgressDicomReader: self.evt_update_progress = EVT_LOAD_FILE_PROGRESS self.evt_end_load_file = EVT_END_LOAD_FILE + + ps.Publisher().subscribe(self.CancelLoad, "Cancel DICOM load") + def CancelLoad(self, evt_pubsub): + self.running = False + self.stoped = True + def SetWindowEvent(self, frame): self.frame = frame - + def SetDirectoryPath(self, path,recursive=True): self.running = True + self.stoped = False thread.start_new_thread(self.GetDicomGroups,(path,recursive)) def UpdateLoadFileProgress(self,cont_progress): @@ -153,4 +160,10 @@ class ProgressDicomReader: else: self.EndLoadFile(value_progress) self.running = False + + #Is necessary in the case user cancel + #the load, ensure that dicomdialog is closed + if(self.stoped): + self.UpdateLoadFileProgress(None) + self.stoped = False \ No newline at end of file -- libgit2 0.21.2