Commit 50e3d457db14ae0eea05fedbcd022b5a60964e7a
1 parent
81a37add
Exists in
master
and in
6 other branches
ENH: Structure of project management (moved all to control)
Showing
4 changed files
with
186 additions
and
124 deletions
Show diff stats
invesalius/control.py
@@ -51,7 +51,14 @@ class Controller(): | @@ -51,7 +51,14 @@ class Controller(): | ||
51 | 51 | ||
52 | def __bind_events(self): | 52 | def __bind_events(self): |
53 | ps.Publisher().subscribe(self.OnImportMedicalImages, 'Import directory') | 53 | ps.Publisher().subscribe(self.OnImportMedicalImages, 'Import directory') |
54 | - ps.Publisher().subscribe(self.StartImportPanel, "Load data to import panel") | 54 | + #ps.Publisher().subscribe(self.StartImportPanel, "Load data to import panel") |
55 | + ps.Publisher().subscribe(self.OnShowDialogImportDirectory, | ||
56 | + 'Show import directory dialog') | ||
57 | + ps.Publisher().subscribe(self.OnShowDialogOpenProject, | ||
58 | + 'Show open project dialog') | ||
59 | + | ||
60 | + ps.Publisher().subscribe(self.OnShowDialogSaveProject, 'Show save dialog') | ||
61 | + | ||
55 | ps.Publisher().subscribe(self.LoadRaycastingPreset, | 62 | ps.Publisher().subscribe(self.LoadRaycastingPreset, |
56 | 'Load raycasting preset') | 63 | 'Load raycasting preset') |
57 | ps.Publisher().subscribe(self.SaveRaycastingPreset, | 64 | ps.Publisher().subscribe(self.SaveRaycastingPreset, |
@@ -61,18 +68,82 @@ class Controller(): | @@ -61,18 +68,82 @@ class Controller(): | ||
61 | ps.Publisher().subscribe(self.Progress, "Update dicom load") | 68 | ps.Publisher().subscribe(self.Progress, "Update dicom load") |
62 | ps.Publisher().subscribe(self.OnLoadImportPanel, "End dicom load") | 69 | ps.Publisher().subscribe(self.OnLoadImportPanel, "End dicom load") |
63 | ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') | 70 | ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') |
64 | - ps.Publisher().subscribe(self.OnSaveProject, 'Save Project') | ||
65 | - ps.Publisher().subscribe(self.OnOpenProject, 'Open Project') | 71 | + #ps.Publisher().subscribe(self.OnSaveProject, 'Save Project') |
72 | + #ps.Publisher().subscribe(self.OnOpenProject, 'Open Project') | ||
66 | ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | 73 | ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') |
67 | 74 | ||
68 | 75 | ||
69 | def OnCancelImport(self, pubsub_evt): | 76 | def OnCancelImport(self, pubsub_evt): |
70 | #self.cancel_import = True | 77 | #self.cancel_import = True |
71 | ps.Publisher().sendMessage('Hide import panel') | 78 | ps.Publisher().sendMessage('Hide import panel') |
79 | + | ||
80 | + def OnShowDialogImportDirectory(self, pubsub_evt): | ||
81 | + self.ShowDialogImportDirectory() | ||
82 | + | ||
83 | + def OnShowDialogOpenProject(self, pubsub_evt): | ||
84 | + self.ShowDialogOpenProject() | ||
85 | + | ||
86 | + def OnShowDialogSaveProject(self, pubsub_evt): | ||
87 | + saveas = pubsub_evt.data | ||
88 | + self.ShowDialogSaveProject(saveas) | ||
89 | + | ||
90 | +########################### | ||
91 | + | ||
92 | + def ShowDialogImportDirectory(self): | ||
93 | + dirpath = dialog.ShowImportDirDialog() | ||
94 | + if dirpath: | ||
95 | + self.StartImportPanel(dirpath) | ||
96 | + ps.Publisher().sendMessage("Load data to import panel", dirpath) | ||
97 | + | ||
98 | + def ShowDialogOpenProject(self): | ||
99 | + filepath = dialog.ShowOpenProjectDialog() | ||
100 | + if filepath: | ||
101 | + self.OpenProject(filepath) | ||
102 | + | ||
103 | + def OpenProject(self, filepath): | ||
104 | + path = os.path.abspath(filepath) | ||
105 | + | ||
106 | + proj = prj.Project() | ||
107 | + proj.OpenPlistProject(path) | ||
108 | + proj.SetAcquisitionModality(proj.modality) | ||
109 | + | ||
110 | + session = ses.Session() | ||
111 | + session.OpenProject(path) | ||
112 | + | ||
113 | + self.LoadProject() | ||
114 | + | ||
115 | + def ShowDialogSaveProject(self, saveas=False): | ||
116 | + session = ses.Session() | ||
117 | + if saveas: | ||
118 | + proj = prj.Project() | ||
119 | + filepath = dialog.ShowSaveAsProjectDialog(proj.name) | ||
120 | + if filepath: | ||
121 | + session.RemoveTemp() | ||
122 | + session.OpenProject(filepath) | ||
123 | + else: | ||
124 | + return | ||
125 | + else: | ||
126 | + dirpath, filename = session.project_path | ||
127 | + filepath = os.path.join(dirpath, filename) | ||
72 | 128 | ||
73 | - def StartImportPanel(self, pubsub_evt): | ||
74 | - # path to directory | ||
75 | - path = pubsub_evt.data | 129 | + self.SaveProject(filepath) |
130 | + | ||
131 | + def SaveProject(self, path=None): | ||
132 | + session = ses.Session() | ||
133 | + if path: | ||
134 | + dirpath, filename = os.path.split(path) | ||
135 | + session.SaveProject((dirpath, filename)) | ||
136 | + else: | ||
137 | + dirpath, filename = session.project_path | ||
138 | + | ||
139 | + proj = prj.Project() | ||
140 | + prj.Project().SavePlistProject(dirpath, filename) | ||
141 | + | ||
142 | +################################## | ||
143 | + | ||
144 | + | ||
145 | + | ||
146 | + def StartImportPanel(self, path): | ||
76 | 147 | ||
77 | # retrieve DICOM files splited into groups | 148 | # retrieve DICOM files splited into groups |
78 | reader = dcm.ProgressDicomReader() | 149 | reader = dcm.ProgressDicomReader() |
@@ -265,59 +336,8 @@ class Controller(): | @@ -265,59 +336,8 @@ class Controller(): | ||
265 | preset_dir = os.path.join(const.USER_RAYCASTING_PRESETS_DIRECTORY, preset_name) | 336 | preset_dir = os.path.join(const.USER_RAYCASTING_PRESETS_DIRECTORY, preset_name) |
266 | plistlib.writePlist(preset, preset_dir) | 337 | plistlib.writePlist(preset, preset_dir) |
267 | 338 | ||
268 | - def OnSaveProject(self, pubsub_evt): | ||
269 | - session = ses.Session() | ||
270 | - | ||
271 | - path = pubsub_evt.data | ||
272 | - if path: | ||
273 | - print "----- FILENAME" | ||
274 | - dirpath, filename = os.path.split(path) | ||
275 | - session.SaveProject((dirpath, filename)) | ||
276 | - else: | ||
277 | - dirpath, filename = session.project_path | ||
278 | - | ||
279 | - print "$$$$$$$$$$$$$$$$$$$$$$$$$$" | ||
280 | - print "filename: ", filename | ||
281 | - print "dirpath: ", dirpath | ||
282 | - | ||
283 | - proj = prj.Project() | ||
284 | - prj.Project().SavePlistProject(dirpath, filename) | ||
285 | - | ||
286 | - | ||
287 | - | ||
288 | - | ||
289 | - #if not(pubsub_evt.data): | ||
290 | - # filename = prj.Project().path | ||
291 | - #else: | ||
292 | - # filename = pubsub_evt.data | ||
293 | - #dir_,filename = os.path.split(filename) | ||
294 | - | ||
295 | - #if not (filename): | ||
296 | - # filename = prj.Project().name | ||
297 | - #else: | ||
298 | - # filename = filename.replace(' ','_') | ||
299 | - # prj.Project().name = filename | ||
300 | - #prj.Project().path = filename | ||
301 | - #print prj.Project().path | ||
302 | - | ||
303 | - #prj.Project().SavePlistProject(dirpath, filename) | ||
304 | - | ||
305 | - #session.project_status = const.PROJ_OPEN | ||
306 | - #session.project_path = (dirpath, filename) | ||
307 | - | ||
308 | - def OnOpenProject(self, pubsub_evt): | ||
309 | - path = os.path.abspath(pubsub_evt.data) | ||
310 | - | ||
311 | - proj = prj.Project() | ||
312 | - proj.OpenPlistProject(path) | ||
313 | - proj.SetAcquisitionModality(proj.modality) | ||
314 | - ###proj.path = filename | ||
315 | - ###proj.save_as = False | ||
316 | 339 | ||
317 | - session = ses.Session() | ||
318 | - session.OpenProject(path) | ||
319 | 340 | ||
320 | - self.LoadProject() | ||
321 | 341 | ||
322 | def OnCloseProject(self, pubsub_evt): | 342 | def OnCloseProject(self, pubsub_evt): |
323 | print "OnCloseProject" | 343 | print "OnCloseProject" |
@@ -327,7 +347,12 @@ class Controller(): | @@ -327,7 +347,12 @@ class Controller(): | ||
327 | if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): | 347 | if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): |
328 | answer = dialog.SaveChangesDialog(filename) | 348 | answer = dialog.SaveChangesDialog(filename) |
329 | if not answer: | 349 | if not answer: |
330 | - print "Delete all" | ||
331 | - elif answer > 1: | ||
332 | - print "Save" | 350 | + print "Close without changes" |
351 | + elif answer == 1: | ||
352 | + print "Save changes and close" | ||
353 | + #else: | ||
354 | + # print "Cancel" | ||
355 | + else: | ||
356 | + print ":) Close without changes" | ||
357 | + | ||
333 | 358 |
invesalius/gui/dialogs.py
@@ -47,7 +47,7 @@ class NumberDialog(wx.Dialog): | @@ -47,7 +47,7 @@ class NumberDialog(wx.Dialog): | ||
47 | btn_ok.SetDefault() | 47 | btn_ok.SetDefault() |
48 | 48 | ||
49 | btn_cancel = wx.Button(self, wx.ID_CANCEL) | 49 | btn_cancel = wx.Button(self, wx.ID_CANCEL) |
50 | - btn_cancel.SetHelpText("Value will not be applied.)") | 50 | + btn_cancel.SetHelpText("Value will not be applied.") |
51 | 51 | ||
52 | btnsizer = wx.StdDialogButtonSizer() | 52 | btnsizer = wx.StdDialogButtonSizer() |
53 | btnsizer.AddButton(btn_ok) | 53 | btnsizer.AddButton(btn_ok) |
@@ -192,16 +192,80 @@ def ShowSaveAsProjectDialog(default_filename=None): | @@ -192,16 +192,80 @@ def ShowSaveAsProjectDialog(default_filename=None): | ||
192 | filename = filename + "." + extension | 192 | filename = filename + "." + extension |
193 | return filename | 193 | return filename |
194 | 194 | ||
195 | + | ||
196 | + | ||
197 | + | ||
198 | + | ||
199 | + | ||
200 | + | ||
201 | + | ||
202 | + | ||
203 | + | ||
204 | + | ||
205 | +class MessageDialog(wx.Dialog): | ||
206 | + def __init__(self, message): | ||
207 | + pre = wx.PreDialog() | ||
208 | + pre.Create(None, -1, "InVesalius 3", size=(360, 370), pos=wx.DefaultPosition, | ||
209 | + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | ||
210 | + self.PostCreate(pre) | ||
211 | + | ||
212 | + # Static text which contains message to user | ||
213 | + label = wx.StaticText(self, -1, message) | ||
214 | + | ||
215 | + # Buttons | ||
216 | + btn_yes = wx.Button(self, wx.ID_YES) | ||
217 | + btn_yes.SetHelpText("") | ||
218 | + btn_yes.SetDefault() | ||
219 | + | ||
220 | + btn_no = wx.Button(self, wx.ID_NO) | ||
221 | + btn_no.SetHelpText("") | ||
222 | + | ||
223 | + btn_cancel = wx.Button(self, wx.ID_CANCEL) | ||
224 | + btn_cancel.SetHelpText("") | ||
225 | + | ||
226 | + btnsizer = wx.StdDialogButtonSizer() | ||
227 | + btnsizer.AddButton(btn_yes) | ||
228 | + btnsizer.AddButton(btn_cancel) | ||
229 | + btnsizer.AddButton(btn_no) | ||
230 | + btnsizer.Realize() | ||
231 | + | ||
232 | + | ||
233 | + sizer = wx.BoxSizer(wx.VERTICAL) | ||
234 | + sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) | ||
235 | + sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL| | ||
236 | + wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5) | ||
237 | + self.SetSizer(sizer) | ||
238 | + sizer.Fit(self) | ||
239 | + | ||
240 | + self.Centre() | ||
241 | + | ||
242 | +def SaveChangesDialog__Old(filename): | ||
243 | + message = "Save changes to "+filename+"?" | ||
244 | + dlg = MessageDialog(message) | ||
245 | + | ||
246 | + answer = dlg.ShowModal() | ||
247 | + dlg.Destroy() | ||
248 | + if answer == wx.ID_YES: | ||
249 | + return 1 | ||
250 | + elif answer == wx.ID_NO: | ||
251 | + return 0 | ||
252 | + else: | ||
253 | + return -1 | ||
254 | + | ||
255 | + | ||
195 | def SaveChangesDialog(filename): | 256 | def SaveChangesDialog(filename): |
196 | - dlg = wx.MessageDialog(None, | ||
197 | - "InVesalius 3", | ||
198 | - "Save changes to "+filename+"?", | ||
199 | - wx.YES | wx.NO | wx.CANCEL | wx.ICON_INFORMATION) | ||
200 | 257 | ||
201 | - if dlg.ShowModal() == wx.ID_YES: | 258 | + dlg = wx.MessageDialog(None, "", |
259 | + "Save changes to "+filename+"?", | ||
260 | + wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL) | ||
261 | + answer = dlg.ShowModal() | ||
262 | + dlg.Destroy() | ||
263 | + | ||
264 | + if answer == wx.ID_YES: | ||
202 | return 1 | 265 | return 1 |
203 | - elif dlg.ShowModal() == wx.ID_NO: | 266 | + elif answer == wx.ID_NO: |
204 | return 0 | 267 | return 0 |
205 | else: | 268 | else: |
206 | return -1 | 269 | return -1 |
207 | 270 | ||
271 | + |
invesalius/gui/frame.py
@@ -214,10 +214,7 @@ class Frame(wx.Frame): | @@ -214,10 +214,7 @@ class Frame(wx.Frame): | ||
214 | evt.Skip() | 214 | evt.Skip() |
215 | 215 | ||
216 | def OnMenuClick(self, evt): | 216 | def OnMenuClick(self, evt): |
217 | - #ps.Publisher().sendMessage(("Event from GUI", | ||
218 | - # evt.GetId())) | ||
219 | id = evt.GetId() | 217 | id = evt.GetId() |
220 | - #proj = prj.Project() | ||
221 | session = ses.Session() | 218 | session = ses.Session() |
222 | if id == const.ID_DICOM_IMPORT: | 219 | if id == const.ID_DICOM_IMPORT: |
223 | self.ImportDicom() | 220 | self.ImportDicom() |
@@ -237,49 +234,16 @@ class Frame(wx.Frame): | @@ -237,49 +234,16 @@ class Frame(wx.Frame): | ||
237 | self.Exit() | 234 | self.Exit() |
238 | 235 | ||
239 | def ImportDicom(self): | 236 | def ImportDicom(self): |
240 | - dirpath = dlg.ShowImportDirDialog() | ||
241 | - if dirpath: | ||
242 | - ps.Publisher().sendMessage("Load data to import panel", dirpath) | 237 | + ps.Publisher().sendMessage('Show import directory dialog') |
243 | 238 | ||
244 | def OpenProject(self): | 239 | def OpenProject(self): |
245 | - filepath = dlg.ShowOpenProjectDialog() | ||
246 | - if filepath: | ||
247 | - ps.Publisher().sendMessage('Open Project', filepath) | 240 | + ps.Publisher().sendMessage('Show open project dialog') |
248 | 241 | ||
249 | def SaveAsProject(self): | 242 | def SaveAsProject(self): |
250 | - self.SaveProject(True) | 243 | + ps.Publisher().sendMessage('Show save dialog', True) |
251 | 244 | ||
252 | - def SaveProject(self, saveas=False): | ||
253 | - | ||
254 | - session = ses.Session() | ||
255 | - if saveas: | ||
256 | - proj = prj.Project() | ||
257 | - filepath = dlg.ShowSaveAsProjectDialog(proj.name) | ||
258 | - if filepath: | ||
259 | - session.RemoveTemp() | ||
260 | - session.OpenProject(filepath) | ||
261 | - else: | ||
262 | - return | ||
263 | - else: | ||
264 | - dirpath, filename = session.project_path | ||
265 | - filepath = os.path.join(dirpath, filename) | ||
266 | - ps.Publisher().sendMessage('Save Project',filepath) | ||
267 | - | ||
268 | - | ||
269 | - def SaveAsOld(self): | ||
270 | - | ||
271 | - filename = (Project().name).replace(' ','_') | ||
272 | - filename = dlg.ShowSaveAsProjectDialog(filename) | ||
273 | - if filename: | ||
274 | - Project().save_as = False | ||
275 | - else: | ||
276 | - return | ||
277 | - self.SaveProject(filename) | ||
278 | - | ||
279 | - def SaveProjectOld(self, filename=None): | ||
280 | - if not filename: | ||
281 | - filename = Project().name | ||
282 | - ps.Publisher().sendMessage('Save Project',filename) | 245 | + def SaveProject(self): |
246 | + ps.Publisher().sendMessage('Show save dialog', False) | ||
283 | 247 | ||
284 | def CloseProject(self): | 248 | def CloseProject(self): |
285 | ps.Publisher().sendMessage('Close Project') | 249 | ps.Publisher().sendMessage('Close Project') |
invesalius/gui/task_importer.py
@@ -138,42 +138,51 @@ class InnerTaskPanel(wx.Panel): | @@ -138,42 +138,51 @@ class InnerTaskPanel(wx.Panel): | ||
138 | #self.TestLoadProjects() | 138 | #self.TestLoadProjects() |
139 | 139 | ||
140 | def OnLinkImport(self, event): | 140 | def OnLinkImport(self, event): |
141 | - self.LinkImport() | 141 | + self.ImportDicom() |
142 | event.Skip() | 142 | event.Skip() |
143 | 143 | ||
144 | def OnLinkImportPACS(self, event): | 144 | def OnLinkImportPACS(self, event): |
145 | - self.LinkImportPACS() | 145 | + self.ImportPACS() |
146 | event.Skip() | 146 | event.Skip() |
147 | 147 | ||
148 | def OnLinkOpenProject(self, event): | 148 | def OnLinkOpenProject(self, event): |
149 | - self.LinkOpenProject() | 149 | + self.OpenProject() |
150 | event.Skip() | 150 | event.Skip() |
151 | 151 | ||
152 | - def LinkImport(self): | ||
153 | - dirpath = dlg.ShowImportDirDialog() | ||
154 | - if dirpath: | ||
155 | - ps.Publisher().sendMessage("Load data to import panel", dirpath) | ||
156 | 152 | ||
157 | - def LinkImportPACS(self): | 153 | + def ImportPACS(self): |
158 | print "TODO: Send Signal - Import DICOM files from PACS" | 154 | print "TODO: Send Signal - Import DICOM files from PACS" |
159 | 155 | ||
160 | - def LinkOpenProject(self, filename=None): | 156 | + |
157 | +####### | ||
158 | + def ImportDicom(self): | ||
159 | + ps.Publisher().sendMessage('Show import directory dialog') | ||
160 | + | ||
161 | + def OpenProject(self, filename=None): | ||
161 | if filename: | 162 | if filename: |
162 | - print "TODO: Send Signal - Open inv3 last project" | 163 | + print "TODO: Send Signal - Open "+filename |
163 | else: | 164 | else: |
164 | - filepath = dlg.ShowOpenProjectDialog() | ||
165 | - if filepath: | ||
166 | - ps.Publisher().sendMessage('Open Project', filepath) | 165 | + ps.Publisher().sendMessage('Show open project dialog') |
166 | + | ||
167 | + def SaveAsProject(self): | ||
168 | + ps.Publisher().sendMessage('Show save dialog', True) | ||
169 | + | ||
170 | + def SaveProject(self): | ||
171 | + ps.Publisher().sendMessage('Show save dialog', False) | ||
172 | + | ||
173 | + def CloseProject(self): | ||
174 | + ps.Publisher().sendMessage('Close Project') | ||
175 | +####### | ||
167 | 176 | ||
168 | def OnButton(self, evt): | 177 | def OnButton(self, evt): |
169 | id = evt.GetId() | 178 | id = evt.GetId() |
170 | 179 | ||
171 | if id == BTN_IMPORT_LOCAL: | 180 | if id == BTN_IMPORT_LOCAL: |
172 | - self.LinkImport() | 181 | + self.ImportDicom() |
173 | elif id == BTN_IMPORT_PACS: | 182 | elif id == BTN_IMPORT_PACS: |
174 | - self.LinkImportPACS() | 183 | + self.ImportPACS() |
175 | else: #elif id == BTN_OPEN_PROJECT: | 184 | else: #elif id == BTN_OPEN_PROJECT: |
176 | - self.LinkOpenProject() | 185 | + self.OpenProject() |
177 | 186 | ||
178 | def TestLoadProjects(self): | 187 | def TestLoadProjects(self): |
179 | self.LoadProject("test1.inv3") | 188 | self.LoadProject("test1.inv3") |