Commit d8d664c6fbbdbfbcc28cb97e1d06c80034426402
1 parent
6d8a0c4e
Exists in
master
and in
6 other branches
ENH: Last selected directory when importing dicom, win and linux FIX #71
Showing
2 changed files
with
61 additions
and
33 deletions
Show diff stats
invesalius/gui/dialogs.py
@@ -27,6 +27,7 @@ import wx.lib.pubsub as ps | @@ -27,6 +27,7 @@ import wx.lib.pubsub as ps | ||
27 | 27 | ||
28 | 28 | ||
29 | import project | 29 | import project |
30 | +import session as ses | ||
30 | 31 | ||
31 | class NumberDialog(wx.Dialog): | 32 | class NumberDialog(wx.Dialog): |
32 | def __init__(self, message, value=0): | 33 | def __init__(self, message, value=0): |
@@ -157,7 +158,18 @@ def ShowOpenProjectDialog(): | @@ -157,7 +158,18 @@ def ShowOpenProjectDialog(): | ||
157 | 158 | ||
158 | def ShowImportDirDialog(): | 159 | def ShowImportDirDialog(): |
159 | current_dir = os.path.abspath(".") | 160 | current_dir = os.path.abspath(".") |
160 | - dlg = wx.DirDialog(None, _("Choose a DICOM folder:"), "", | 161 | + |
162 | + #defaultPath = sys.platform" | ||
163 | + | ||
164 | + if (sys.platform == 'win32') or (sys.platform == 'linux2'): | ||
165 | + session = ses.Session() | ||
166 | + | ||
167 | + if (session.GetLastDicomFolder()): | ||
168 | + folder = session.GetLastDicomFolder() | ||
169 | + else: | ||
170 | + folder = '' | ||
171 | + | ||
172 | + dlg = wx.DirDialog(None, _("Choose a DICOM folder:"), folder, | ||
161 | style=wx.DD_DEFAULT_STYLE | 173 | style=wx.DD_DEFAULT_STYLE |
162 | | wx.DD_DIR_MUST_EXIST | 174 | | wx.DD_DIR_MUST_EXIST |
163 | | wx.DD_CHANGE_DIR) | 175 | | wx.DD_CHANGE_DIR) |
@@ -169,8 +181,11 @@ def ShowImportDirDialog(): | @@ -169,8 +181,11 @@ def ShowImportDirDialog(): | ||
169 | # UnicodeEncodeError is raised. To avoid this, path is encoded in utf-8 | 181 | # UnicodeEncodeError is raised. To avoid this, path is encoded in utf-8 |
170 | if sys.platform == "win32": | 182 | if sys.platform == "win32": |
171 | path = dlg.GetPath() | 183 | path = dlg.GetPath() |
184 | + session.SetLastDicomFolder(path) | ||
172 | else: | 185 | else: |
173 | path = dlg.GetPath().encode('utf-8') | 186 | path = dlg.GetPath().encode('utf-8') |
187 | + session.SetLastDicomFolder(path) | ||
188 | + | ||
174 | except(wx._core.PyAssertionError): #TODO: error win64 | 189 | except(wx._core.PyAssertionError): #TODO: error win64 |
175 | path = dlg.GetPath() | 190 | path = dlg.GetPath() |
176 | 191 |
invesalius/session.py
@@ -16,12 +16,12 @@ class Session(object): | @@ -16,12 +16,12 @@ class Session(object): | ||
16 | def __init__(self): | 16 | def __init__(self): |
17 | # ? | 17 | # ? |
18 | self.temp_item = False | 18 | self.temp_item = False |
19 | - | 19 | + |
20 | ws = self.ws = WriteSession(self) | 20 | ws = self.ws = WriteSession(self) |
21 | ws.start() | 21 | ws.start() |
22 | - | 22 | + |
23 | ps.Publisher().subscribe(self.StopRecording, "Stop Config Recording") | 23 | ps.Publisher().subscribe(self.StopRecording, "Stop Config Recording") |
24 | - | 24 | + |
25 | def CreateItens(self): | 25 | def CreateItens(self): |
26 | import constants as const | 26 | import constants as const |
27 | self.project_path = () | 27 | self.project_path = () |
@@ -34,22 +34,24 @@ class Session(object): | @@ -34,22 +34,24 @@ class Session(object): | ||
34 | self.mode = const.MODE_RP | 34 | self.mode = const.MODE_RP |
35 | # const.MODE_RP, const.MODE_NAVIGATOR, const.MODE_RADIOLOGY, | 35 | # const.MODE_RP, const.MODE_NAVIGATOR, const.MODE_RADIOLOGY, |
36 | # const.MODE_ODONTOLOGY | 36 | # const.MODE_ODONTOLOGY |
37 | - | 37 | + |
38 | # InVesalius default projects' directory | 38 | # InVesalius default projects' directory |
39 | homedir = self.homedir = os.path.expanduser('~') | 39 | homedir = self.homedir = os.path.expanduser('~') |
40 | tempdir = os.path.join(homedir, ".invesalius", "temp") | 40 | tempdir = os.path.join(homedir, ".invesalius", "temp") |
41 | if not os.path.isdir(tempdir): | 41 | if not os.path.isdir(tempdir): |
42 | os.makedirs(tempdir) | 42 | os.makedirs(tempdir) |
43 | self.tempdir = tempdir | 43 | self.tempdir = tempdir |
44 | - | 44 | + |
45 | # GUI language | 45 | # GUI language |
46 | self.language = "" # "pt_BR", "es" | 46 | self.language = "" # "pt_BR", "es" |
47 | - | 47 | + |
48 | # Recent projects list | 48 | # Recent projects list |
49 | self.recent_projects = [] | 49 | self.recent_projects = [] |
50 | - | 50 | + |
51 | + self.last_dicom_folder = '' | ||
52 | + | ||
51 | self.CreateSessionFile() | 53 | self.CreateSessionFile() |
52 | - | 54 | + |
53 | def StopRecording(self, pubsub_evt): | 55 | def StopRecording(self, pubsub_evt): |
54 | self.ws.Stop() | 56 | self.ws.Stop() |
55 | 57 | ||
@@ -103,23 +105,24 @@ class Session(object): | @@ -103,23 +105,24 @@ class Session(object): | ||
103 | path = os.path.join(dirpath, file) | 105 | path = os.path.join(dirpath, file) |
104 | os.remove(path) | 106 | os.remove(path) |
105 | self.temp_item = False | 107 | self.temp_item = False |
106 | - | 108 | + |
107 | def CreateSessionFile(self): | 109 | def CreateSessionFile(self): |
108 | - | 110 | + |
109 | config = ConfigParser.RawConfigParser() | 111 | config = ConfigParser.RawConfigParser() |
110 | - | 112 | + |
111 | config.add_section('session') | 113 | config.add_section('session') |
112 | config.set('session', 'mode', self.mode) | 114 | config.set('session', 'mode', self.mode) |
113 | config.set('session', 'status', self.project_status) | 115 | config.set('session', 'status', self.project_status) |
114 | config.set('session','debug', self.debug) | 116 | config.set('session','debug', self.debug) |
115 | config.set('session', 'language', self.language) | 117 | config.set('session', 'language', self.language) |
116 | - | 118 | + |
117 | config.add_section('project') | 119 | config.add_section('project') |
118 | config.set('project', 'recent_projects', self.recent_projects) | 120 | config.set('project', 'recent_projects', self.recent_projects) |
119 | - | 121 | + |
120 | config.add_section('paths') | 122 | config.add_section('paths') |
121 | config.set('paths','homedir',self.homedir) | 123 | config.set('paths','homedir',self.homedir) |
122 | config.set('paths','tempdir',self.tempdir) | 124 | config.set('paths','tempdir',self.tempdir) |
125 | + config.set('paths','last_dicom_folder',self.last_dicom_folder) | ||
123 | path = os.path.join(self.homedir , | 126 | path = os.path.join(self.homedir , |
124 | '.invesalius', 'config.cfg') | 127 | '.invesalius', 'config.cfg') |
125 | configfile = open(path, 'wb') | 128 | configfile = open(path, 'wb') |
@@ -138,7 +141,7 @@ class Session(object): | @@ -138,7 +141,7 @@ class Session(object): | ||
138 | 141 | ||
139 | # Add new item | 142 | # Add new item |
140 | l.insert(0, item) | 143 | l.insert(0, item) |
141 | - | 144 | + |
142 | # Remove oldest projects from list | 145 | # Remove oldest projects from list |
143 | if len(l)>const.PROJ_MAX: | 146 | if len(l)>const.PROJ_MAX: |
144 | for i in xrange(len(l)-const.PROJ_MAX): | 147 | for i in xrange(len(l)-const.PROJ_MAX): |
@@ -156,13 +159,20 @@ class Session(object): | @@ -156,13 +159,20 @@ class Session(object): | ||
156 | dict = plistlib.readPlist(main_plist) | 159 | dict = plistlib.readPlist(main_plist) |
157 | for key in dict: | 160 | for key in dict: |
158 | setattr(self, key, dict[key]) | 161 | setattr(self, key, dict[key]) |
159 | - | 162 | + |
160 | def GetLanguage(self): | 163 | def GetLanguage(self): |
161 | return self.language | 164 | return self.language |
162 | - | 165 | + |
163 | def SetLanguage(self, language): | 166 | def SetLanguage(self, language): |
164 | self.language = language | 167 | self.language = language |
165 | - | 168 | + |
169 | + def GetLastDicomFolder(self): | ||
170 | + return self.last_dicom_folder | ||
171 | + | ||
172 | + def SetLastDicomFolder(self, folder): | ||
173 | + self.last_dicom_folder = folder | ||
174 | + self.CreateSessionFile() | ||
175 | + | ||
166 | def ReadLanguage(self): | 176 | def ReadLanguage(self): |
167 | config = ConfigParser.ConfigParser() | 177 | config = ConfigParser.ConfigParser() |
168 | home_path = os.path.expanduser('~') | 178 | home_path = os.path.expanduser('~') |
@@ -173,9 +183,9 @@ class Session(object): | @@ -173,9 +183,9 @@ class Session(object): | ||
173 | return self.language | 183 | return self.language |
174 | except(ConfigParser.NoSectionError, ConfigParser.NoOptionError): | 184 | except(ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
175 | return False | 185 | return False |
176 | - | 186 | + |
177 | def ReadSession(self): | 187 | def ReadSession(self): |
178 | - | 188 | + |
179 | config = ConfigParser.ConfigParser() | 189 | config = ConfigParser.ConfigParser() |
180 | home_path = os.path.expanduser('~') | 190 | home_path = os.path.expanduser('~') |
181 | path = os.path.join(home_path ,'.invesalius', 'config.cfg') | 191 | path = os.path.join(home_path ,'.invesalius', 'config.cfg') |
@@ -188,48 +198,51 @@ class Session(object): | @@ -188,48 +198,51 @@ class Session(object): | ||
188 | self.recent_projects = eval(config.get('project','recent_projects')) | 198 | self.recent_projects = eval(config.get('project','recent_projects')) |
189 | self.homedir = config.get('paths','homedir') | 199 | self.homedir = config.get('paths','homedir') |
190 | self.tempdir = config.get('paths','tempdir') | 200 | self.tempdir = config.get('paths','tempdir') |
201 | + self.last_dicom_folder = config.get('paths','last_dicom_folder') | ||
191 | return True | 202 | return True |
192 | except(ConfigParser.NoSectionError, ConfigParser.NoOptionError): | 203 | except(ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
193 | return False | 204 | return False |
194 | - | ||
195 | - | 205 | + |
206 | + | ||
196 | class WriteSession(Thread): | 207 | class WriteSession(Thread): |
197 | - | 208 | + |
198 | def __init__ (self, session): | 209 | def __init__ (self, session): |
199 | Thread.__init__(self) | 210 | Thread.__init__(self) |
200 | self.session = session | 211 | self.session = session |
201 | self.runing = 1 | 212 | self.runing = 1 |
202 | - | 213 | + |
203 | def run(self): | 214 | def run(self): |
204 | while self.runing: | 215 | while self.runing: |
205 | time.sleep(10) | 216 | time.sleep(10) |
206 | self.Write() | 217 | self.Write() |
207 | - | ||
208 | - def Stop(self): | 218 | + |
219 | + def Stop(self): | ||
209 | self.runing = 0 | 220 | self.runing = 0 |
210 | - | 221 | + |
211 | def Write(self): | 222 | def Write(self): |
212 | - | 223 | + |
213 | config = ConfigParser.RawConfigParser() | 224 | config = ConfigParser.RawConfigParser() |
214 | - | 225 | + |
215 | config.add_section('session') | 226 | config.add_section('session') |
216 | config.set('session', 'mode', self.session.mode) | 227 | config.set('session', 'mode', self.session.mode) |
217 | config.set('session', 'status', self.session.project_status) | 228 | config.set('session', 'status', self.session.project_status) |
218 | config.set('session','debug', self.session.debug) | 229 | config.set('session','debug', self.session.debug) |
219 | config.set('session', 'language', self.session.language) | 230 | config.set('session', 'language', self.session.language) |
220 | - | 231 | + |
221 | config.add_section('project') | 232 | config.add_section('project') |
222 | config.set('project', 'recent_projects', self.session.recent_projects) | 233 | config.set('project', 'recent_projects', self.session.recent_projects) |
223 | - | 234 | + |
224 | config.add_section('paths') | 235 | config.add_section('paths') |
225 | config.set('paths','homedir',self.session.homedir) | 236 | config.set('paths','homedir',self.session.homedir) |
226 | config.set('paths','tempdir',self.session.tempdir) | 237 | config.set('paths','tempdir',self.session.tempdir) |
238 | + config.set('paths','last_dicom_folder', self.session.last_dicom_folder) | ||
239 | + | ||
227 | path = os.path.join(self.session.homedir , | 240 | path = os.path.join(self.session.homedir , |
228 | '.invesalius', 'config.cfg') | 241 | '.invesalius', 'config.cfg') |
229 | configfile = open(path, 'wb') | 242 | configfile = open(path, 'wb') |
230 | config.write(configfile) | 243 | config.write(configfile) |
231 | configfile.close() | 244 | configfile.close() |
232 | - | ||
233 | 245 | ||
234 | 246 | ||
235 | - | 247 | + |
248 | + |