Commit 7afb7ef626eabeb825e856e13e83742f2fdf880f
1 parent
ad70187d
Exists in
master
and in
5 other branches
ENH: Added session with volume rendering and surface interpolation option
Showing
4 changed files
with
57 additions
and
24 deletions
Show diff stats
invesalius/constants.py
invesalius/gui/frame.py
... | ... | @@ -74,6 +74,7 @@ class Frame(wx.Frame): |
74 | 74 | # Create aui manager and insert content in it |
75 | 75 | self.__init_aui() |
76 | 76 | |
77 | + self.preferences = preferences.Preferences(self) | |
77 | 78 | # Initialize bind to pubsub events |
78 | 79 | self.__bind_events() |
79 | 80 | self.__bind_events_wx() |
... | ... | @@ -324,9 +325,9 @@ class Frame(wx.Frame): |
324 | 325 | evt.Skip() |
325 | 326 | |
326 | 327 | def ShowPreferences(self): |
327 | - prf = preferences.Preferences(self) | |
328 | - prf.ShowModal() | |
329 | - #print "Show Preferences" | |
328 | + if self.preferences.ShowModal(): | |
329 | + self.preferences.GetPreferences() | |
330 | + self.preferences.Close() | |
330 | 331 | |
331 | 332 | def ShowAbout(self): |
332 | 333 | """ | ... | ... |
invesalius/gui/preferences.py
1 | 1 | import wx |
2 | +import constants as const | |
2 | 3 | |
3 | 4 | ID = wx.NewId() |
4 | 5 | |
... | ... | @@ -10,7 +11,7 @@ except ImportError: # if it's not there locally, try the wxPython lib. |
10 | 11 | |
11 | 12 | class Preferences(wx.Dialog): |
12 | 13 | |
13 | - def __init__( self, parent, id = ID, title = "Preferences", size=wx.DefaultSize,\ | |
14 | + def __init__( self, parent, id = ID, title = _("Preferences"), size=wx.DefaultSize,\ | |
14 | 15 | pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE): |
15 | 16 | |
16 | 17 | pre = wx.PreDialog() |
... | ... | @@ -25,21 +26,21 @@ class Preferences(wx.Dialog): |
25 | 26 | self.book = fnb.FlatNotebook(self, wx.ID_ANY, agwStyle=bookStyle) |
26 | 27 | sizer.Add(self.book, 80, wx.EXPAND|wx.ALL) |
27 | 28 | |
28 | - self.pnl_volume_rendering = Viewer3D(self) | |
29 | + self.pnl_viewer3d = Viewer3D(self) | |
29 | 30 | self.pnl_language = Language(self) |
30 | 31 | |
31 | - self.book.AddPage(self.pnl_volume_rendering, "Visualization") | |
32 | - self.book.AddPage(self.pnl_language, "Language") | |
32 | + self.book.AddPage(self.pnl_viewer3d, _("Visualization")) | |
33 | + self.book.AddPage(self.pnl_language, _("Language")) | |
33 | 34 | |
34 | 35 | line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) |
35 | 36 | sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) |
36 | 37 | |
37 | 38 | btnsizer = wx.StdDialogButtonSizer() |
38 | 39 | |
39 | - btn = wx.Button(self, wx.ID_OK, "Apply") | |
40 | + btn = wx.Button(self, wx.ID_OK) | |
40 | 41 | btnsizer.AddButton(btn) |
41 | 42 | |
42 | - btn = wx.Button(self, wx.ID_CANCEL, "Cancel") | |
43 | + btn = wx.Button(self, wx.ID_CANCEL) | |
43 | 44 | btnsizer.AddButton(btn) |
44 | 45 | |
45 | 46 | btnsizer.Realize() |
... | ... | @@ -48,6 +49,10 @@ class Preferences(wx.Dialog): |
48 | 49 | |
49 | 50 | self.SetSizer(sizer) |
50 | 51 | sizer.Fit(self) |
52 | + | |
53 | + def GetPreferences(self): | |
54 | + | |
55 | + print ">>>>>>>>>", self.pnl_viewer3d.GetSelection() | |
51 | 56 | |
52 | 57 | |
53 | 58 | |
... | ... | @@ -58,28 +63,27 @@ class Viewer3D(wx.Panel): |
58 | 63 | wx.Panel.__init__(self, parent, size = wx.Size(800,600)) |
59 | 64 | |
60 | 65 | |
61 | - box_visualization = wx.StaticBox(self, -1, "Surface") | |
66 | + box_visualization = wx.StaticBox(self, -1, _("Surface")) | |
62 | 67 | bsizer = wx.StaticBoxSizer(box_visualization, wx.VERTICAL) |
63 | 68 | |
64 | - lbl_inter = wx.StaticText(self, -1, "Interpolation ") | |
69 | + lbl_inter = wx.StaticText(self, -1, _("Interpolation ")) | |
65 | 70 | bsizer.Add(lbl_inter, 0, wx.TOP|wx.LEFT, 10) |
66 | 71 | |
67 | - rb_inter = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize, | |
72 | + rb_inter = self.rb_inter = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize, | |
68 | 73 | ['Flat','Gouraud','Phong'], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER) |
69 | 74 | |
70 | 75 | bsizer.Add(rb_inter, 0, wx.TOP|wx.LEFT, 0) |
71 | 76 | |
72 | - box_rendering = wx.StaticBox(self, -1, "Volume Rendering") | |
77 | + box_rendering = wx.StaticBox(self, -1, _("Volume Rendering")) | |
73 | 78 | bsizer_ren = wx.StaticBoxSizer(box_rendering, wx.VERTICAL) |
74 | 79 | |
75 | - lbl_rendering = wx.StaticText(self, -1, "Rendering") | |
80 | + lbl_rendering = wx.StaticText(self, -1, _("Rendering")) | |
76 | 81 | bsizer_ren.Add(lbl_rendering, 0, wx.TOP | wx.LEFT, 10) |
77 | 82 | |
78 | - rb_rendering = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize, | |
83 | + rb_rendering = self.rb_rendering = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize, | |
79 | 84 | ['CPU', 'GPU (Only NVidia video card)'], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER) |
80 | 85 | |
81 | 86 | bsizer_ren.Add(rb_rendering, 0, wx.TOP | wx.LEFT, 0) |
82 | - | |
83 | 87 | border = wx.BoxSizer(wx.VERTICAL) |
84 | 88 | border.Add(bsizer, 50, wx.EXPAND|wx.ALL, 10) |
85 | 89 | border.Add(bsizer_ren, 50, wx.EXPAND|wx.ALL, 10) |
... | ... | @@ -87,6 +91,14 @@ class Viewer3D(wx.Panel): |
87 | 91 | |
88 | 92 | border.Fit(self) |
89 | 93 | |
94 | + | |
95 | + def GetSelection(self): | |
96 | + | |
97 | + options = {const.RENDERING:self.rb_rendering.GetSelection(), | |
98 | + const.SURFACE_INTERPOLATION:self.rb_inter.GetSelection()} | |
99 | + | |
100 | + return options | |
101 | + | |
90 | 102 | class Language(wx.Panel): |
91 | 103 | |
92 | 104 | def __init__(self, parent): | ... | ... |
invesalius/session.py
... | ... | @@ -25,7 +25,6 @@ class Session(object): |
25 | 25 | import constants as const |
26 | 26 | self.project_path = () |
27 | 27 | self.debug = False |
28 | - | |
29 | 28 | self.project_status = const.PROJ_CLOSE |
30 | 29 | # const.PROJ_NEW*, const.PROJ_OPEN, const.PROJ_CHANGE*, |
31 | 30 | # const.PROJ_CLOSE |
... | ... | @@ -47,7 +46,8 @@ class Session(object): |
47 | 46 | # Recent projects list |
48 | 47 | self.recent_projects = [(const.SAMPLE_DIR, "Cranium.inv3")] |
49 | 48 | self.last_dicom_folder = '' |
50 | - | |
49 | + self.surface_interpolation = 0 | |
50 | + self.rendering = 0 | |
51 | 51 | self.CreateSessionFile() |
52 | 52 | |
53 | 53 | def StopRecording(self, pubsub_evt): |
... | ... | @@ -64,13 +64,13 @@ class Session(object): |
64 | 64 | homedir = self.homedir = os.path.expanduser('~') |
65 | 65 | try: |
66 | 66 | path = os.path.join(self.homedir , |
67 | - '.invesalius', 'config.backup') | |
67 | + '.invesalius', 'config.backup') | |
68 | 68 | path_dst = os.path.join(self.homedir , |
69 | - '.invesalius', 'config.cfg') | |
69 | + '.invesalius', 'config.cfg') | |
70 | 70 | shutil.copy(path, path_dst) |
71 | 71 | return True |
72 | 72 | except(IOError): |
73 | - return False | |
73 | + return False | |
74 | 74 | |
75 | 75 | |
76 | 76 | def CloseProject(self): |
... | ... | @@ -132,6 +132,8 @@ class Session(object): |
132 | 132 | config.set('session', 'status', self.project_status) |
133 | 133 | config.set('session','debug', self.debug) |
134 | 134 | config.set('session', 'language', self.language) |
135 | + config.set('session', 'surface_interpolation', self.surface_interpolation) | |
136 | + config.set('session', 'rendering', self.rendering) | |
135 | 137 | |
136 | 138 | config.add_section('project') |
137 | 139 | config.set('project', 'recent_projects', self.recent_projects) |
... | ... | @@ -204,15 +206,19 @@ class Session(object): |
204 | 206 | self.project_status = config.get('session', 'status') |
205 | 207 | self.debug = config.get('session','debug') |
206 | 208 | self.language = config.get('session','language') |
209 | + | |
207 | 210 | self.recent_projects = eval(config.get('project','recent_projects')) |
208 | 211 | self.homedir = config.get('paths','homedir') |
209 | 212 | self.tempdir = config.get('paths','tempdir') |
210 | 213 | self.last_dicom_folder = config.get('paths','last_dicom_folder') |
211 | 214 | self.last_dicom_folder = self.last_dicom_folder.decode('utf-8') |
212 | - return True | |
213 | 215 | |
214 | - except(ConfigParser.NoSectionError, ConfigParser.NoOptionError, | |
215 | - ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError): | |
216 | + self.surface_interpolation = config.get('session', 'surface_interpolation') | |
217 | + self.rendering = config.get('session', 'rendering') | |
218 | + #return True | |
219 | + | |
220 | + except(ConfigParser.NoSectionError, ConfigParser.MissingSectionHeaderError, | |
221 | + ConfigParser.ParsingError): | |
216 | 222 | |
217 | 223 | if (self.RecoveryConfigFile()): |
218 | 224 | self.ReadSession() |
... | ... | @@ -220,6 +226,14 @@ class Session(object): |
220 | 226 | else: |
221 | 227 | return False |
222 | 228 | |
229 | + except(ConfigParser.NoOptionError): | |
230 | + #Added to fix new version compatibility | |
231 | + self.surface_interpolation = 0 | |
232 | + self.rendering = 0 | |
233 | + | |
234 | + self.CreateSessionFile() | |
235 | + return True | |
236 | + | |
223 | 237 | |
224 | 238 | class WriteSession(Thread): |
225 | 239 | |
... | ... | @@ -249,6 +263,8 @@ class WriteSession(Thread): |
249 | 263 | config.set('session', 'status', self.session.project_status) |
250 | 264 | config.set('session','debug', self.session.debug) |
251 | 265 | config.set('session', 'language', self.session.language) |
266 | + config.set('session', 'surface_interpolation', self.session.surface_interpolation) | |
267 | + config.set('session', 'rendering', self.session.rendering) | |
252 | 268 | |
253 | 269 | config.add_section('project') |
254 | 270 | config.set('project', 'recent_projects', self.session.recent_projects) | ... | ... |