Commit 9e2fd40e4ed2d9a005d5241fbf039ce77bbbf35f
1 parent
0673940c
Exists in
master
Returning plugins
Showing
1 changed file
with
56 additions
and
4 deletions
Show diff stats
invesalius/control.py
| ... | ... | @@ -58,6 +58,7 @@ class Controller(): |
| 58 | 58 | def __init__(self, frame): |
| 59 | 59 | self.surface_manager = srf.SurfaceManager() |
| 60 | 60 | self.volume = volume.Volume() |
| 61 | + self.plugin_manager = plugins.PluginManager() | |
| 61 | 62 | self.__bind_events() |
| 62 | 63 | self.frame = frame |
| 63 | 64 | self.progress_dialog = None |
| ... | ... | @@ -76,9 +77,12 @@ class Controller(): |
| 76 | 77 | |
| 77 | 78 | Publisher.sendMessage('Load Preferences') |
| 78 | 79 | |
| 80 | + self.plugin_manager.find_plugins() | |
| 81 | + | |
| 79 | 82 | def __bind_events(self): |
| 80 | 83 | Publisher.subscribe(self.OnImportMedicalImages, 'Import directory') |
| 81 | 84 | Publisher.subscribe(self.OnImportGroup, 'Import group') |
| 85 | + Publisher.subscribe(self.OnImportFolder, 'Import folder') | |
| 82 | 86 | Publisher.subscribe(self.OnShowDialogImportDirectory, |
| 83 | 87 | 'Show import directory dialog') |
| 84 | 88 | Publisher.subscribe(self.OnShowDialogImportOtherFiles, |
| ... | ... | @@ -120,6 +124,8 @@ class Controller(): |
| 120 | 124 | |
| 121 | 125 | Publisher.subscribe(self.Send_affine, 'Get affine matrix') |
| 122 | 126 | |
| 127 | + Publisher.subscribe(self.create_project_from_matrix, 'Create project from matrix') | |
| 128 | + | |
| 123 | 129 | def SetBitmapSpacing(self, spacing): |
| 124 | 130 | proj = prj.Project() |
| 125 | 131 | proj.spacing = spacing |
| ... | ... | @@ -503,6 +509,33 @@ class Controller(): |
| 503 | 509 | self.LoadProject() |
| 504 | 510 | Publisher.sendMessage("Enable state project", state=True) |
| 505 | 511 | |
| 512 | + def OnImportFolder(self, folder): | |
| 513 | + Publisher.sendMessage('Begin busy cursor') | |
| 514 | + folder = os.path.abspath(folder) | |
| 515 | + | |
| 516 | + proj = prj.Project() | |
| 517 | + proj.load_from_folder(folder) | |
| 518 | + | |
| 519 | + self.Slice = sl.Slice() | |
| 520 | + self.Slice._open_image_matrix(proj.matrix_filename, | |
| 521 | + tuple(proj.matrix_shape), | |
| 522 | + proj.matrix_dtype) | |
| 523 | + | |
| 524 | + self.Slice.window_level = proj.level | |
| 525 | + self.Slice.window_width = proj.window | |
| 526 | + | |
| 527 | + Publisher.sendMessage('Update threshold limits list', | |
| 528 | + threshold_range=proj.threshold_range) | |
| 529 | + | |
| 530 | + session = ses.Session() | |
| 531 | + filename = proj.name+".inv3" | |
| 532 | + filename = filename.replace("/", "") #Fix problem case other/Skull_DICOM | |
| 533 | + dirpath = session.CreateProject(filename) | |
| 534 | + self.LoadProject() | |
| 535 | + Publisher.sendMessage("Enable state project", state=True) | |
| 536 | + | |
| 537 | + Publisher.sendMessage('End busy cursor') | |
| 538 | + | |
| 506 | 539 | #------------------------------------------------------------------------------------- |
| 507 | 540 | |
| 508 | 541 | def LoadProject(self): |
| ... | ... | @@ -848,13 +881,11 @@ class Controller(): |
| 848 | 881 | def OnOpenOtherFiles(self, filepath): |
| 849 | 882 | filepath = utils.decode(filepath, const.FS_ENCODE) |
| 850 | 883 | if not(filepath) == None: |
| 851 | - name = filepath.rpartition('\\')[-1].split('.') | |
| 852 | - | |
| 884 | + name = os.path.basename(filepath).split(".")[0] | |
| 853 | 885 | group = oth.ReadOthers(filepath) |
| 854 | - | |
| 855 | 886 | if group: |
| 856 | 887 | matrix, matrix_filename = self.OpenOtherFiles(group) |
| 857 | - self.CreateOtherProject(str(name[0]), matrix, matrix_filename) | |
| 888 | + self.CreateOtherProject(name, matrix, matrix_filename) | |
| 858 | 889 | self.LoadProject() |
| 859 | 890 | Publisher.sendMessage("Enable state project", state=True) |
| 860 | 891 | else: |
| ... | ... | @@ -1056,3 +1087,24 @@ class Controller(): |
| 1056 | 1087 | |
| 1057 | 1088 | def ApplyReorientation(self): |
| 1058 | 1089 | self.Slice.apply_reorientation() |
| 1090 | + | |
| 1091 | + def start_new_inv_instance(self, image, name, spacing, modality, orientation, window_width, window_level): | |
| 1092 | + p = prj.Project() | |
| 1093 | + project_folder = tempfile.mkdtemp() | |
| 1094 | + p.create_project_file(name, spacing, modality, orientation, window_width, window_level, image, folder=project_folder) | |
| 1095 | + err_msg = '' | |
| 1096 | + try: | |
| 1097 | + sp = subprocess.Popen([sys.executable, sys.argv[0], '--import-folder', project_folder], | |
| 1098 | + stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=os.getcwd()) | |
| 1099 | + except Exception as err: | |
| 1100 | + err_msg = str(err) | |
| 1101 | + else: | |
| 1102 | + try: | |
| 1103 | + if sp.wait(2): | |
| 1104 | + err_msg = sp.stderr.read().decode('utf8') | |
| 1105 | + sp.terminate() | |
| 1106 | + except subprocess.TimeoutExpired: | |
| 1107 | + pass | |
| 1108 | + | |
| 1109 | + if err_msg: | |
| 1110 | + dialog.MessageBox(None, "It was not possible to launch new instance of InVesalius3 dsfa dfdsfa sdfas fdsaf asdfasf dsaa", err_msg) | ... | ... |