Commit 30840beb4b40ca4470ede2fa7027c8db3ce4d33c
1 parent
6eacca2e
Exists in
master
and in
6 other branches
ADD: A method to open a inv3 project (under development)
Showing
3 changed files
with
32 additions
and
16 deletions
Show diff stats
invesalius/control.py
... | ... | @@ -60,6 +60,7 @@ class Controller(): |
60 | 60 | ps.Publisher().subscribe(self.OnLoadImportPanel, "End dicom load") |
61 | 61 | ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') |
62 | 62 | ps.Publisher().subscribe(self.OnSaveProject, 'Save Project') |
63 | + ps.Publisher().subscribe(self.OnOpenProject, 'Open Project') | |
63 | 64 | |
64 | 65 | |
65 | 66 | def OnCancelImport(self, pubsub_evt): |
... | ... | @@ -256,7 +257,7 @@ class Controller(): |
256 | 257 | filename = prj.Project().name |
257 | 258 | dir_ = tempfile.mkdtemp(filename) |
258 | 259 | prj.Project().SavePlistProject(dir_, filename) |
259 | - | |
260 | - | |
261 | - | |
262 | - | |
260 | + | |
261 | + def OnOpenProject(self, pubsub_evt): | |
262 | + filename = pubsub_evt.data | |
263 | + prj.Project().OpenPlistProject(filename) | ... | ... |
invesalius/gui/task_importer.py
... | ... | @@ -185,7 +185,7 @@ class InnerTaskPanel(wx.Panel): |
185 | 185 | # This returns a Python list of files that were selected. |
186 | 186 | proj_path = dlg.GetPath() |
187 | 187 | proj_name = dlg.GetFilename() |
188 | - print "TODO: Send Signal - Open project "+ proj_path | |
188 | + ps.Publisher().sendMessage('Open Project', proj_path) | |
189 | 189 | print "TODO: Send Signal - Change frame title "+ proj_name |
190 | 190 | |
191 | 191 | # Destroy the dialog. Don't do this until you are done with it! | ... | ... |
invesalius/project.py
... | ... | @@ -20,7 +20,9 @@ |
20 | 20 | import glob |
21 | 21 | import os |
22 | 22 | import plistlib |
23 | +import shutil | |
23 | 24 | import tarfile |
25 | +import tempfile | |
24 | 26 | |
25 | 27 | import wx |
26 | 28 | import wx.lib.pubsub as ps |
... | ... | @@ -159,21 +161,32 @@ class Project(object): |
159 | 161 | plistlib.writePlist(project, filename + '.plist') |
160 | 162 | |
161 | 163 | Compress(dir_, "teste.inv3")#os.path.join("~/Desktop/","teste.inv3")) |
164 | + shutil.rmtree(dir_) | |
162 | 165 | |
163 | 166 | def OpenPlistProject(self, filename): |
164 | - project = plistlib.readPlist(filename) | |
165 | - masks = project['masks'] | |
166 | - for index in masks: | |
167 | - self.mask_dict[index] = masks[index] | |
167 | + filelist = Extract(filename, tempfile.gettempdir()) | |
168 | + main_plist = min(filelist, key=lambda x: len(x)) | |
169 | + print main_plist | |
170 | + project = plistlib.readPlist(main_plist) | |
168 | 171 | |
169 | - surfaces = project['surfaces'] | |
170 | - for index in surfaces: | |
171 | - self.surface_dict[index] = surfaces[index] | |
172 | + print "antes", self.__dict__ | |
172 | 173 | |
173 | - self.min_threshold = project['min threshold'] | |
174 | - self.max_threshold = project['max threshold'] | |
175 | - self.window = project['window'] | |
176 | - self.level = project['level'] | |
174 | + for key in project: | |
175 | + setattr(self, key, project[key]) | |
176 | + | |
177 | + print "depois", self.__dict__ | |
178 | + #masks = project['masks'] | |
179 | + #for index in masks: | |
180 | + # self.mask_dict[index] = masks[index] | |
181 | + | |
182 | + #surfaces = project['surfaces'] | |
183 | + #for index in surfaces: | |
184 | + # self.surface_dict[index] = surfaces[index] | |
185 | + | |
186 | + #self.min_threshold = project['min threshold'] | |
187 | + #self.max_threshold = project['max threshold'] | |
188 | + #self.window = project['window'] | |
189 | + #self.level = project['level'] | |
177 | 190 | |
178 | 191 | def Compress(folder, filename): |
179 | 192 | file_list = glob.glob(os.path.join(folder,"*")) |
... | ... | @@ -186,4 +199,6 @@ def Extract(filename, folder): |
186 | 199 | tar = tarfile.open(filename, "r:gz") |
187 | 200 | tar.list(verbose=True) |
188 | 201 | tar.extractall(folder) |
202 | + filelist = [os.path.join(folder, i) for i in tar.getnames()] | |
189 | 203 | tar.close() |
204 | + return filelist | ... | ... |