Commit 5ab43b67d1050cdd48711e13e674305470fa25a7

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