Handle unicode, utf8, and windows-1252

(cherry picked from commit 0d4f24a)
This commit is contained in:
Ebag333
2016-11-26 22:57:53 -08:00
parent 38bf143704
commit 08b5abc7ad
6 changed files with 104 additions and 27 deletions

View File

@@ -31,7 +31,7 @@ except ImportError:
class BitmapLoader(object):
try:
archive = zipfile.ZipFile(os.path.join(config.pyfaPath, 'imgs.zip'), 'r')
archive = zipfile.ZipFile(config.getPyfaPath('imgs.zip'), 'r')
except IOError:
archive = None
@@ -85,7 +85,7 @@ class BitmapLoader(object):
except KeyError:
print("Missing icon file from zip: {0}".format(path))
else:
path = os.path.join(config.pyfaPath, 'imgs', location, filename)
path = config.getPyfaPath('imgs\\' + location + "\\" + filename)
if os.path.exists(path):
return wx.Image(path)

View File

@@ -48,9 +48,20 @@ class GraphFrame(wx.Frame):
try:
cache_dir = mpl._get_cachedir()
except:
cache_dir = unicode(os.path.expanduser(os.path.join("~", ".matplotlib")))
cache_dir = os.path.expanduser(os.path.join("~", ".matplotlib"))
if type(cache_dir) == str: # leave unicode ones alone
try:
cache_dir = cache_dir.decode('utf8')
except UnicodeDecodeError:
cache_dir = cache_dir.decode('windows-1252')
cache_file = os.path.join(cache_dir, 'fontList.cache')
if type(cache_file) == str: # leave unicode ones alone
try:
cache_file = cache_file.decode('utf8')
except UnicodeDecodeError:
cache_file = cache_file.decode('windows-1252')
if os.access(cache_dir, os.W_OK | os.X_OK) and os.path.isfile(cache_file):
# remove matplotlib font cache, see #234
os.remove(cache_file)
@@ -174,7 +185,7 @@ class GraphFrame(wx.Frame):
if not isinstance(defaultVal, basestring):
defaultVal = ("%f" % defaultVal).rstrip("0")
if defaultVal[-1:] == ".":
defaultVal = defaultVal + "0"
defaultVal += "0"
textBox.ChangeValue(defaultVal)

View File

@@ -40,7 +40,14 @@ from gui.contextMenu import ContextMenu
class ItemStatsDialog(wx.Dialog):
counter = 0
def __init__(self, victim, fullContext=None, pos=wx.DefaultPosition, size=wx.DefaultSize, maximized=False):
def __init__(
self,
victim,
fullContext=None,
pos=wx.DefaultPosition,
size=wx.DefaultSize,
maximized=False
):
wx.Dialog.__init__(
self,
@@ -827,7 +834,7 @@ class ItemEffects(wx.Panel):
If effect file does not exist, create it
"""
file_ = os.path.join(config.pyfaPath, "eos", "effects", "%s.py" % event.GetText().lower())
file_ = config.getPyfaPath("eos\\effects\\%s.py" % event.GetText().lower())
if not os.path.isfile(file_):
open(file_, 'a').close()