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