Commit b1aaf9c9282c5c87545f909ea6a09bedfec71c6f

Authored by Paulo Henrique Junqueira Amorim
1 parent a2e1a20e

ENH: Changed wx.Event to pubsub

invesalius/control.py
@@ -35,9 +35,9 @@ class Controller(): @@ -35,9 +35,9 @@ class Controller():
35 'Save raycasting preset') 35 'Save raycasting preset')
36 ps.Publisher().subscribe(self.OnOpenDicomGroup, 36 ps.Publisher().subscribe(self.OnOpenDicomGroup,
37 'Open DICOM group') 37 'Open DICOM group')
38 - #ps.Publisher().subscribe(self.CancelDicomLoad,  
39 - # "Cancel DICOM load in the control")  
40 - 38 + ps.Publisher().subscribe(self.Progress, "Update dicom load")
  39 + ps.Publisher().subscribe(self.LoadPanel, "End dicom load")
  40 +
41 def StartImportPanel(self, pubsub_evt): 41 def StartImportPanel(self, pubsub_evt):
42 # path to directory 42 # path to directory
43 path = pubsub_evt.data 43 path = pubsub_evt.data
@@ -47,16 +47,20 @@ class Controller(): @@ -47,16 +47,20 @@ class Controller():
47 reader.SetWindowEvent(self.frame) 47 reader.SetWindowEvent(self.frame)
48 reader.SetDirectoryPath(path) 48 reader.SetDirectoryPath(path)
49 49
50 - self.frame.Bind(reader.evt_update_progress, self.Progress)  
51 - self.frame.Bind(reader.evt_end_load_file, self.LoadPanel) 50 + #self.frame.Bind(reader.evt_update_progress, self.Progress)
  51 + #self.frame.Bind(reader.evt_end_load_file, self.LoadPanel)
52 52
53 def Progress(self, evt): 53 def Progress(self, evt):
54 - if (evt.progress): 54 + print evt
  55 + data = evt.data
  56 +
  57 + if (data):
55 if not(self.progress_dialog): 58 if not(self.progress_dialog):
56 self.progress_dialog = dialog.ProgressDialog( 59 self.progress_dialog = dialog.ProgressDialog(
57 - maximum = evt.progress[1]) 60 + maximum = data[1])
58 else: 61 else:
59 - if not(self.progress_dialog.Update(evt.progress[0])): 62 + print data[0]
  63 + if not(self.progress_dialog.Update(data[0])):
60 self.progress_dialog.Close() 64 self.progress_dialog.Close()
61 self.progress_dialog = None 65 self.progress_dialog = None
62 else: 66 else:
@@ -66,7 +70,7 @@ class Controller(): @@ -66,7 +70,7 @@ class Controller():
66 70
67 71
68 def LoadPanel(self,evt): 72 def LoadPanel(self,evt):
69 - patient_series = evt.value 73 + patient_series = evt.data
70 if patient_series: 74 if patient_series:
71 ps.Publisher().sendMessage("Load import panel", patient_series) 75 ps.Publisher().sendMessage("Load import panel", patient_series)
72 first_patient = patient_series[0] 76 first_patient = patient_series[0]
invesalius/gui/dialogs.py
@@ -83,8 +83,11 @@ class ProgressDialog(object): @@ -83,8 +83,11 @@ class ProgressDialog(object):
83 ps.Publisher().sendMessage("Cancel DICOM load") 83 ps.Publisher().sendMessage("Cancel DICOM load")
84 84
85 def Update(self, value): 85 def Update(self, value):
86 - if(value != self.maximum):  
87 - self.dlg.Update(value) 86 + if(value != self.maximum):
  87 + try:
  88 + self.dlg.Update(value)
  89 + except(wx._core.PyAssertionError):
  90 + pass
88 return True 91 return True
89 else: 92 else:
90 return False 93 return False
invesalius/reader/dicom_reader.py
@@ -85,7 +85,7 @@ def yGetDicomGroups(directory, recursive=True, gui=True): @@ -85,7 +85,7 @@ def yGetDicomGroups(directory, recursive=True, gui=True):
85 nfiles = len(filenames) 85 nfiles = len(filenames)
86 86
87 print "TOTAL FILES:", nfiles 87 print "TOTAL FILES:", nfiles
88 - counter = 0.0 88 + counter = 0
89 grouper = dicom_grouper.DicomPatientGrouper() 89 grouper = dicom_grouper.DicomPatientGrouper()
90 # Retrieve only DICOM files, splited into groups 90 # Retrieve only DICOM files, splited into groups
91 if recursive: 91 if recursive:
@@ -123,11 +123,11 @@ def GetDicomGroups(directory, recursive=True): @@ -123,11 +123,11 @@ def GetDicomGroups(directory, recursive=True):
123 class ProgressDicomReader: 123 class ProgressDicomReader:
124 124
125 def __init__(self): 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() 126 + #(self.LoadFilesProgress, EVT_LOAD_FILE_PROGRESS) = wx.lib.newevent.NewEvent()
  127 + #(self.EndLoadFiles, EVT_END_LOAD_FILE) = wx.lib.newevent.NewEvent()
128 128
129 - self.evt_update_progress = EVT_LOAD_FILE_PROGRESS  
130 - self.evt_end_load_file = EVT_END_LOAD_FILE 129 + #self.evt_update_progress = EVT_LOAD_FILE_PROGRESS
  130 + #self.evt_end_load_file = EVT_END_LOAD_FILE
131 131
132 ps.Publisher().subscribe(self.CancelLoad, "Cancel DICOM load") 132 ps.Publisher().subscribe(self.CancelLoad, "Cancel DICOM load")
133 133
@@ -144,12 +144,14 @@ class ProgressDicomReader: @@ -144,12 +144,14 @@ class ProgressDicomReader:
144 thread.start_new_thread(self.GetDicomGroups,(path,recursive)) 144 thread.start_new_thread(self.GetDicomGroups,(path,recursive))
145 145
146 def UpdateLoadFileProgress(self,cont_progress): 146 def UpdateLoadFileProgress(self,cont_progress):
147 - evt = self.LoadFilesProgress(progress = cont_progress)  
148 - wx.PostEvent(self.frame, evt) 147 + ps.Publisher().sendMessage("Update dicom load", cont_progress)
  148 + #evt = self.LoadFilesProgress(progress = cont_progress)
  149 + #wx.PostEvent(self.frame, evt)
149 150
150 def EndLoadFile(self, grouper): 151 def EndLoadFile(self, grouper):
151 - evt = self.EndLoadFiles(value = grouper)  
152 - wx.PostEvent(self.frame, evt) 152 + ps.Publisher().sendMessage("End dicom load", grouper)
  153 + #evt = self.EndLoadFiles(value = grouper)
  154 + #wx.PostEvent(self.frame, evt)
153 155
154 def GetDicomGroups(self, path, recursive): 156 def GetDicomGroups(self, path, recursive):
155 y = yGetDicomGroups(path, recursive) 157 y = yGetDicomGroups(path, recursive)