Commit 5ab43b67d1050cdd48711e13e674305470fa25a7
1 parent
c6a22019
Exists in
master
Fix: homepath with non ascii chars
Showing
2 changed files
with
32 additions
and
8 deletions
Show diff stats
app.py
... | ... | @@ -100,6 +100,8 @@ class SplashScreen(wx.SplashScreen): |
100 | 100 | # Splash screen image will depend on currently language |
101 | 101 | lang = False |
102 | 102 | |
103 | + self.locale = wx.Locale(wx.LANGUAGE_DEFAULT) | |
104 | + | |
103 | 105 | # Language information is available in session configuration |
104 | 106 | # file. First we need to check if this file exist, if now, it |
105 | 107 | # should be created |
... | ... | @@ -155,6 +157,9 @@ class SplashScreen(wx.SplashScreen): |
155 | 157 | # Only after language was defined, splash screen will be |
156 | 158 | # shown |
157 | 159 | if lang: |
160 | + print "LANG", lang, _, wx.Locale(), wx.GetLocale() | |
161 | + import locale | |
162 | + locale.setlocale(locale.LC_ALL, '') | |
158 | 163 | # For pt_BR, splash_pt.png should be used |
159 | 164 | if (lang.startswith('pt')): |
160 | 165 | icon_file = "splash_pt.png" |
... | ... | @@ -166,7 +171,6 @@ class SplashScreen(wx.SplashScreen): |
166 | 171 | abs_file_path = os.path.abspath(".." + os.sep) |
167 | 172 | path = abs_file_path |
168 | 173 | |
169 | - path = os.path.join(path, "icons", icon_file) | |
170 | 174 | else: |
171 | 175 | |
172 | 176 | path = os.path.join(".","icons", icon_file) | ... | ... |
invesalius/session.py
... | ... | @@ -31,10 +31,13 @@ import codecs |
31 | 31 | |
32 | 32 | #import wx.lib.pubsub as ps |
33 | 33 | from wx.lib.pubsub import pub as Publisher |
34 | +import wx | |
34 | 35 | |
35 | 36 | from invesalius.utils import Singleton, debug |
36 | 37 | from random import randint |
37 | 38 | |
39 | +ENCODE=wx.GetDefaultPyEncoding() | |
40 | + | |
38 | 41 | class Session(object): |
39 | 42 | # Only one session will be initialized per time. Therefore, we use |
40 | 43 | # Singleton design pattern for implementing it |
... | ... | @@ -59,8 +62,8 @@ class Session(object): |
59 | 62 | # const.MODE_ODONTOLOGY |
60 | 63 | |
61 | 64 | # InVesalius default projects' directory |
62 | - homedir = self.homedir = os.path.expanduser('~') | |
63 | - tempdir = os.path.join(homedir, ".invesalius", "temp") | |
65 | + homedir = self.homedir = os.path.expanduser('~').decode(ENCODE) | |
66 | + tempdir = os.path.join(homedir, u".invesalius", u"temp") | |
64 | 67 | if not os.path.isdir(tempdir): |
65 | 68 | os.makedirs(tempdir) |
66 | 69 | self.tempdir = tempdir |
... | ... | @@ -160,6 +163,10 @@ class Session(object): |
160 | 163 | def WriteSessionFile(self): |
161 | 164 | config = ConfigParser.RawConfigParser() |
162 | 165 | |
166 | + print ">>>", type(self.homedir), self.homedir, repr(self.homedir) | |
167 | + print ">>>", type(self.tempdir), self.tempdir, repr(self.tempdir) | |
168 | + print ">>>", type(self.language), self.language, repr(self.language) | |
169 | + | |
163 | 170 | config.add_section('session') |
164 | 171 | config.set('session', 'mode', self.mode) |
165 | 172 | config.set('session', 'status', self.project_status) |
... | ... | @@ -178,11 +185,15 @@ class Session(object): |
178 | 185 | config.set('paths','tempdir',self.tempdir) |
179 | 186 | config.set('paths','last_dicom_folder',self.last_dicom_folder) |
180 | 187 | |
188 | + print config.items('session') | |
189 | + print config.items('project') | |
190 | + print config.items('paths') | |
191 | + | |
181 | 192 | path = os.path.join(self.homedir , |
182 | 193 | '.invesalius', 'config.cfg') |
183 | 194 | |
184 | 195 | if sys.platform == 'win32': |
185 | - configfile = codecs.open(path, 'wb', 'utf-8') | |
196 | + configfile = codecs.open(path, 'wb', 'utf8') | |
186 | 197 | else: |
187 | 198 | configfile = open(path, 'wb') |
188 | 199 | |
... | ... | @@ -253,10 +264,10 @@ class Session(object): |
253 | 264 | |
254 | 265 | def ReadSession(self): |
255 | 266 | config = ConfigParser.ConfigParser() |
256 | - home_path = os.path.expanduser('~') | |
267 | + home_path = os.path.expanduser('~').decode(ENCODE) | |
257 | 268 | path = os.path.join(home_path ,'.invesalius', 'config.cfg') |
258 | 269 | try: |
259 | - config.read(path) | |
270 | + config.readfp(codecs.open(path, 'rb', 'utf8')) | |
260 | 271 | self.mode = config.get('session', 'mode') |
261 | 272 | # Do not reading project status from the config file, since there |
262 | 273 | # isn't a recover sessession tool in InVesalius |
... | ... | @@ -267,7 +278,7 @@ class Session(object): |
267 | 278 | self.homedir = config.get('paths','homedir') |
268 | 279 | self.tempdir = config.get('paths','tempdir') |
269 | 280 | self.last_dicom_folder = config.get('paths','last_dicom_folder') |
270 | - | |
281 | + | |
271 | 282 | #if not(sys.platform == 'win32'): |
272 | 283 | # self.last_dicom_folder = self.last_dicom_folder.decode('utf-8') |
273 | 284 | |
... | ... | @@ -278,9 +289,13 @@ class Session(object): |
278 | 289 | self.random_id = config.get('session','random_id') |
279 | 290 | return True |
280 | 291 | |
292 | + except IOError: | |
293 | + return False | |
294 | + | |
281 | 295 | except(ConfigParser.NoSectionError, ConfigParser.MissingSectionHeaderError, |
282 | 296 | ConfigParser.ParsingError): |
283 | 297 | |
298 | + print 'Error 1' | |
284 | 299 | if (self.RecoveryConfigFile()): |
285 | 300 | self.ReadSession() |
286 | 301 | return True |
... | ... | @@ -288,10 +303,15 @@ class Session(object): |
288 | 303 | return False |
289 | 304 | |
290 | 305 | except(ConfigParser.NoOptionError): |
306 | + print 'Error 2' | |
291 | 307 | #Added to fix new version compatibility |
292 | 308 | self.surface_interpolation = 0 |
293 | 309 | self.slice_interpolation = 0 |
294 | 310 | self.rendering = 0 |
295 | 311 | self.random_id = randint(0,pow(10,16)) |
296 | - self.WriteSessionFile() | |
312 | + try: | |
313 | + self.WriteSessionFile() | |
314 | + except AttributeError: | |
315 | + print 'Error 3' | |
316 | + return False | |
297 | 317 | return True | ... | ... |