Commit 26370a907c387121bbaa4b9f0d76ae458d6d5621
1 parent
8057fbed
Exists in
master
and in
6 other branches
ADD: Last projects (fix #57)
Showing
2 changed files
with
84 additions
and
39 deletions
Show diff stats
invesalius/control.py
@@ -70,6 +70,7 @@ class Controller(): | @@ -70,6 +70,7 @@ class Controller(): | ||
70 | ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') | 70 | ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') |
71 | ps.Publisher().subscribe(self.OnShowDialogCloseProject, 'Close Project') | 71 | ps.Publisher().subscribe(self.OnShowDialogCloseProject, 'Close Project') |
72 | ps.Publisher().subscribe(self.OnOpenProject, 'Open project') | 72 | ps.Publisher().subscribe(self.OnOpenProject, 'Open project') |
73 | + ps.Publisher().subscribe(self.OnOpenRecentProject, 'Open recent project') | ||
73 | 74 | ||
74 | def OnCancelImport(self, pubsub_evt): | 75 | def OnCancelImport(self, pubsub_evt): |
75 | #self.cancel_import = True | 76 | #self.cancel_import = True |
@@ -177,6 +178,23 @@ class Controller(): | @@ -177,6 +178,23 @@ class Controller(): | ||
177 | path = pubsub_evt.data | 178 | path = pubsub_evt.data |
178 | self.OpenProject(path) | 179 | self.OpenProject(path) |
179 | 180 | ||
181 | + def OnOpenRecentProject(self, pubsub_evt): | ||
182 | + filepath = pubsub_evt.data | ||
183 | + | ||
184 | + session = ses.Session() | ||
185 | + st = session.project_status | ||
186 | + if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): | ||
187 | + filename = session.project_path[1] | ||
188 | + answer = dialog.SaveChangesDialog2(filename) | ||
189 | + if answer: | ||
190 | + self.ShowDialogSaveProject() | ||
191 | + print "1" | ||
192 | + self.CloseProject() | ||
193 | + print "2" | ||
194 | + self.OpenProject(filepath) | ||
195 | + print "3" | ||
196 | + | ||
197 | + | ||
180 | 198 | ||
181 | def OpenProject(self, filepath): | 199 | def OpenProject(self, filepath): |
182 | ps.Publisher().sendMessage('Begin busy cursor') | 200 | ps.Publisher().sendMessage('Begin busy cursor') |
invesalius/gui/task_importer.py
@@ -131,11 +131,72 @@ class InnerTaskPanel(wx.Panel): | @@ -131,11 +131,72 @@ class InnerTaskPanel(wx.Panel): | ||
131 | 131 | ||
132 | # Update main sizer and panel layout | 132 | # Update main sizer and panel layout |
133 | self.SetSizer(main_sizer) | 133 | self.SetSizer(main_sizer) |
134 | - self.Fit() | 134 | + self.Update() |
135 | + self.SetAutoLayout(1) | ||
135 | self.sizer = main_sizer | 136 | self.sizer = main_sizer |
136 | 137 | ||
137 | # Test load and unload specific projects' links | 138 | # Test load and unload specific projects' links |
138 | - #self.TestLoadProjects() | 139 | + self.TestLoadProjects2() |
140 | + #self.__bind_events() | ||
141 | + | ||
142 | + #def __bind_events(self): | ||
143 | + # ps.Publisher().subscribe(self.OnLoadRecentProjects, "Load recent projects") | ||
144 | + | ||
145 | + #def OnLoadRecentProjects(self, pubsub_evt): | ||
146 | + # projects = pubsub_evt.data | ||
147 | + # for tuple in projects: | ||
148 | + # filename = tuple[1] | ||
149 | + # path = tuple[0] | ||
150 | + # self.LoadProject(filename, path) | ||
151 | + | ||
152 | + def TestLoadProjects2(self): | ||
153 | + import session as ses | ||
154 | + session = ses.Session() | ||
155 | + projects = session.recent_projects | ||
156 | + for tuple in projects: | ||
157 | + filename = tuple[1] | ||
158 | + path = tuple[0] | ||
159 | + self.LoadProject(filename, path) | ||
160 | + | ||
161 | + | ||
162 | + def TestLoadProjects(self): | ||
163 | + self.LoadProject("test1.inv3", "/Volumes/file/inv3") | ||
164 | + self.LoadProject("test2.inv3", "/Volumes/file/inv3") | ||
165 | + self.LoadProject("test3.inv3", "/Volumes/file/inv3") | ||
166 | + | ||
167 | + def LoadProject(self, proj_name="Unnamed", proj_dir=""): | ||
168 | + """ | ||
169 | + Load into user interface name of project into import task panel. | ||
170 | + Can be called 3 times in sequence. | ||
171 | + Call UnloadProjects to empty it. | ||
172 | + """ | ||
173 | + # TODO: What todo when it is called more than 3 times? | ||
174 | + # TODO: Load from config file last 3 recent projects | ||
175 | + | ||
176 | + proj_path = os.path.join(proj_dir, proj_name) | ||
177 | + | ||
178 | + if (self.proj_count < 3): | ||
179 | + self.proj_count += 1 | ||
180 | + | ||
181 | + # Create name to be plot on GUI | ||
182 | + label = " "+str(self.proj_count)+". "+proj_name | ||
183 | + | ||
184 | + # Create corresponding hyperlink | ||
185 | + proj_link = hl.HyperLinkCtrl(self, -1, label) | ||
186 | + proj_link.SetUnderlines(False, False, False) | ||
187 | + proj_link.SetColours("BLACK", "BLACK", "BLACK") | ||
188 | + proj_link.AutoBrowse(False) | ||
189 | + proj_link.UpdateLink() | ||
190 | + proj_link.Bind(hl.EVT_HYPERLINK_LEFT, | ||
191 | + lambda e: self.OpenProject(proj_path)) | ||
192 | + | ||
193 | + # Add to existing frame | ||
194 | + self.sizer.Add(proj_link, 1, wx.GROW | wx.EXPAND | wx.ALL, 2) | ||
195 | + self.Update() | ||
196 | + | ||
197 | + # Add hyperlink to floating hyperlinks list | ||
198 | + self.float_hyper_list.append(proj_link) | ||
199 | + | ||
139 | 200 | ||
140 | def OnLinkImport(self, event): | 201 | def OnLinkImport(self, event): |
141 | self.ImportDicom() | 202 | self.ImportDicom() |
@@ -158,9 +219,9 @@ class InnerTaskPanel(wx.Panel): | @@ -158,9 +219,9 @@ class InnerTaskPanel(wx.Panel): | ||
158 | def ImportDicom(self): | 219 | def ImportDicom(self): |
159 | ps.Publisher().sendMessage('Show import directory dialog') | 220 | ps.Publisher().sendMessage('Show import directory dialog') |
160 | 221 | ||
161 | - def OpenProject(self, filename=None): | ||
162 | - if filename: | ||
163 | - print "TODO: Send Signal - Open "+filename | 222 | + def OpenProject(self, path=None): |
223 | + if path: | ||
224 | + ps.Publisher().sendMessage('Open recent project', path) | ||
164 | else: | 225 | else: |
165 | ps.Publisher().sendMessage('Show open project dialog') | 226 | ps.Publisher().sendMessage('Show open project dialog') |
166 | 227 | ||
@@ -184,41 +245,7 @@ class InnerTaskPanel(wx.Panel): | @@ -184,41 +245,7 @@ class InnerTaskPanel(wx.Panel): | ||
184 | else: #elif id == BTN_OPEN_PROJECT: | 245 | else: #elif id == BTN_OPEN_PROJECT: |
185 | self.OpenProject() | 246 | self.OpenProject() |
186 | 247 | ||
187 | - def TestLoadProjects(self): | ||
188 | - self.LoadProject("test1.inv3") | ||
189 | - self.LoadProject("test2.inv3") | ||
190 | - self.LoadProject("test3.inv3") | ||
191 | - | ||
192 | - def LoadProject(self, proj_name="Unnamed"): | ||
193 | - """ | ||
194 | - Load into user interface name of project into import task panel. | ||
195 | - Can be called 3 times in sequence. | ||
196 | - Call UnloadProjects to empty it. | ||
197 | - """ | ||
198 | - # TODO: What todo when it is called more than 3 times? | ||
199 | - # TODO: Load from config file last 3 recent projects | ||
200 | - | ||
201 | - if (self.proj_count < 3): | ||
202 | - self.proj_count += 1 | ||
203 | - | ||
204 | - # Create name to be plot on GUI | ||
205 | - label = " "+str(self.proj_count)+". "+proj_name | ||
206 | 248 | ||
207 | - # Create corresponding hyperlink | ||
208 | - proj_link = hl.HyperLinkCtrl(self, -1, label) | ||
209 | - proj_link.SetUnderlines(False, False, False) | ||
210 | - proj_link.SetColours("BLACK", "BLACK", "BLACK") | ||
211 | - proj_link.AutoBrowse(False) | ||
212 | - proj_link.UpdateLink() | ||
213 | - proj_link.Bind(hl.EVT_HYPERLINK_LEFT, | ||
214 | - lambda e: self.LinkOpenProject(proj_name)) | ||
215 | - | ||
216 | - # Add to existing frame | ||
217 | - self.sizer.Add(proj_link, 1, wx.GROW | wx.EXPAND | wx.ALL, 2) | ||
218 | - self.Update() | ||
219 | - | ||
220 | - # Add hyperlink to floating hyperlinks list | ||
221 | - self.float_hyper_list.append(proj_link) | ||
222 | 249 | ||
223 | def UnloadProjects(self): | 250 | def UnloadProjects(self): |
224 | """ | 251 | """ |