From 30840beb4b40ca4470ede2fa7027c8db3ce4d33c Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Fri, 13 Nov 2009 12:53:31 +0000 Subject: [PATCH] ADD: A method to open a inv3 project (under development) --- invesalius/control.py | 9 +++++---- invesalius/gui/task_importer.py | 2 +- invesalius/project.py | 37 ++++++++++++++++++++++++++----------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index 634ccb6..ad8cebe 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -60,6 +60,7 @@ class Controller(): ps.Publisher().subscribe(self.OnLoadImportPanel, "End dicom load") ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') ps.Publisher().subscribe(self.OnSaveProject, 'Save Project') + ps.Publisher().subscribe(self.OnOpenProject, 'Open Project') def OnCancelImport(self, pubsub_evt): @@ -256,7 +257,7 @@ class Controller(): filename = prj.Project().name dir_ = tempfile.mkdtemp(filename) prj.Project().SavePlistProject(dir_, filename) - - - - + + def OnOpenProject(self, pubsub_evt): + filename = pubsub_evt.data + prj.Project().OpenPlistProject(filename) diff --git a/invesalius/gui/task_importer.py b/invesalius/gui/task_importer.py index 5b1476e..1af9bec 100644 --- a/invesalius/gui/task_importer.py +++ b/invesalius/gui/task_importer.py @@ -185,7 +185,7 @@ class InnerTaskPanel(wx.Panel): # This returns a Python list of files that were selected. proj_path = dlg.GetPath() proj_name = dlg.GetFilename() - print "TODO: Send Signal - Open project "+ proj_path + ps.Publisher().sendMessage('Open Project', proj_path) print "TODO: Send Signal - Change frame title "+ proj_name # Destroy the dialog. Don't do this until you are done with it! diff --git a/invesalius/project.py b/invesalius/project.py index 611a69a..14b4c59 100755 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -20,7 +20,9 @@ import glob import os import plistlib +import shutil import tarfile +import tempfile import wx import wx.lib.pubsub as ps @@ -159,21 +161,32 @@ class Project(object): plistlib.writePlist(project, filename + '.plist') Compress(dir_, "teste.inv3")#os.path.join("~/Desktop/","teste.inv3")) + shutil.rmtree(dir_) def OpenPlistProject(self, filename): - project = plistlib.readPlist(filename) - masks = project['masks'] - for index in masks: - self.mask_dict[index] = masks[index] + filelist = Extract(filename, tempfile.gettempdir()) + main_plist = min(filelist, key=lambda x: len(x)) + print main_plist + project = plistlib.readPlist(main_plist) - surfaces = project['surfaces'] - for index in surfaces: - self.surface_dict[index] = surfaces[index] + print "antes", self.__dict__ - self.min_threshold = project['min threshold'] - self.max_threshold = project['max threshold'] - self.window = project['window'] - self.level = project['level'] + for key in project: + setattr(self, key, project[key]) + + print "depois", self.__dict__ + #masks = project['masks'] + #for index in masks: + # self.mask_dict[index] = masks[index] + + #surfaces = project['surfaces'] + #for index in surfaces: + # self.surface_dict[index] = surfaces[index] + + #self.min_threshold = project['min threshold'] + #self.max_threshold = project['max threshold'] + #self.window = project['window'] + #self.level = project['level'] def Compress(folder, filename): file_list = glob.glob(os.path.join(folder,"*")) @@ -186,4 +199,6 @@ def Extract(filename, folder): tar = tarfile.open(filename, "r:gz") tar.list(verbose=True) tar.extractall(folder) + filelist = [os.path.join(folder, i) for i in tar.getnames()] tar.close() + return filelist -- libgit2 0.21.2