diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py
index b394442802..23ff22a3ca 100644
--- a/src/Mod/Start/StartPage/StartPage.py
+++ b/src/Mod/Start/StartPage/StartPage.py
@@ -36,6 +36,17 @@ iconbank = {} # to store already created icons so we don't overpollute the temp
tempfolder = None # store icons inside a subfolder in temp dir
defaulticon = None # store a default icon for problematic file types
+
+def encode(text):
+
+ "make sure we are always working with unicode in python2"
+
+ if sys.version_info.major < 3:
+ if not isinstance(text,unicode):
+ return text.decode("utf8")
+ return text
+
+
def gethexcolor(color):
"returns a color hex value #000000"
@@ -187,7 +198,7 @@ def buildCard(filename,method,arg=None):
"builds a html
element representing a file. method is a script + a keyword, for ex. url.py?key="
- result = ""
+ result = encode("")
if os.path.exists(filename) and isOpenableByFreeCAD(filename):
basename = os.path.basename(filename)
if not arg:
@@ -197,10 +208,10 @@ def buildCard(filename,method,arg=None):
image = finfo[0]
size = finfo[1]
author = finfo[2]
- infostring = TranslationTexts.T_CREATIONDATE+": "+finfo[3]+"\n"
- infostring += TranslationTexts.T_LASTMODIFIED+": "+finfo[4]
+ infostring = encode(TranslationTexts.T_CREATIONDATE+": "+finfo[3]+"\n")
+ infostring += encode(TranslationTexts.T_LASTMODIFIED+": "+finfo[4])
if finfo[5]:
- infostring += "\n\n" + finfo[5]
+ infostring += "\n\n" + encode(finfo[5])
if size:
result += ''
result += ''
@@ -251,6 +262,7 @@ def handle():
CSS = f.read()
HTML = HTML.replace("JS",JS)
HTML = HTML.replace("CSS",CSS)
+ HTML = encode(HTML)
# get the stylesheet if we are using one
@@ -258,25 +270,20 @@ def handle():
qssfile = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/MainWindow").GetString("StyleSheet","")
if qssfile:
with open(qssfile, 'r') as f:
- ALTCSS = f.read()
- if sys.version_info.major < 3:
- ALTCSS = ALTCSS.decode("utf8")
+ ALTCSS = encode(f.read())
HTML = HTML.replace("","")
# get FreeCAD version
v = FreeCAD.Version()
- VERSIONSTRING = TranslationTexts.T_VERSION + " " + v[0] + "." + v[1] + " " + TranslationTexts.T_BUILD + " " + v[2]
+ VERSIONSTRING = encode(TranslationTexts.T_VERSION + " " + v[0] + "." + v[1] + " " + TranslationTexts.T_BUILD + " " + v[2])
HTML = HTML.replace("VERSIONSTRING",VERSIONSTRING)
# translate texts
texts = [t for t in dir(TranslationTexts) if t.startswith("T_")]
for text in texts:
- if sys.version_info.major < 3:
- HTML = HTML.replace(text,getattr(TranslationTexts,text).decode("utf8"))
- else:
- HTML = HTML.replace(text,getattr(TranslationTexts,text))
+ HTML = HTML.replace(text,encode(getattr(TranslationTexts,text)))
# build a "create new" icon with the FreeCAD background color gradient
@@ -297,60 +304,54 @@ def handle():
# build SECTION_RECENTFILES
- SECTION_RECENTFILES = ""
+ SECTION_RECENTFILES = encode("")
rf = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles")
rfcount = rf.GetInt("RecentFiles",0)
if rfcount:
- SECTION_RECENTFILES = ""+TranslationTexts.T_RECENTFILES+"
"
+ SECTION_RECENTFILES = encode(""+TranslationTexts.T_RECENTFILES+"
")
SECTION_RECENTFILES += "'
- if sys.version_info.major < 3:
- SECTION_RECENTFILES = SECTION_RECENTFILES.decode("utf8")
HTML = HTML.replace("SECTION_RECENTFILES",SECTION_RECENTFILES)
# build SECTION_EXAMPLES
- SECTION_EXAMPLES = ""
+ SECTION_EXAMPLES = encode("")
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("ShowExamples",True):
- SECTION_EXAMPLES = ""+TranslationTexts.T_EXAMPLES+"
"
+ SECTION_EXAMPLES = encode(""+TranslationTexts.T_EXAMPLES+"
")
SECTION_EXAMPLES += ""
for basename in os.listdir(FreeCAD.getResourceDir()+"examples"):
filename = FreeCAD.getResourceDir()+"examples"+os.sep+basename
- SECTION_EXAMPLES += buildCard(filename,method="LoadExample.py?filename=")
+ SECTION_EXAMPLES += encode(buildCard(filename,method="LoadExample.py?filename="))
SECTION_EXAMPLES += "
"
- if sys.version_info.major < 3:
- SECTION_EXAMPLES = SECTION_EXAMPLES.decode("utf8")
HTML = HTML.replace("SECTION_EXAMPLES",SECTION_EXAMPLES)
# build SECTION_CUSTOM
- SECTION_CUSTOM = ""
+ SECTION_CUSTOM = encode("")
cfolder = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("ShowCustomFolder","")
if cfolder:
if not os.path.isdir(cfolder):
cfolder = os.path.dirname(cfolder)
- SECTION_CUSTOM = ""+os.path.basename(os.path.normpath(cfolder))+"
"
+ SECTION_CUSTOM = encode(""+os.path.basename(os.path.normpath(cfolder))+"
")
SECTION_CUSTOM += ""
for basename in os.listdir(cfolder):
filename = os.path.join(cfolder,basename)
- SECTION_CUSTOM += buildCard(filename,method="LoadCustom.py?filename=")
+ SECTION_CUSTOM += encode(buildCard(filename,method="LoadCustom.py?filename="))
SECTION_CUSTOM += "
"
- if sys.version_info.major < 3:
- SECTION_CUSTOM = SECTION_CUSTOM.decode("utf8")
HTML = HTML.replace("SECTION_CUSTOM",SECTION_CUSTOM)
# build UL_WORKBENCHES
@@ -395,7 +396,7 @@ def handle():
UL_WORKBENCHES += ''+wn.replace("ReverseEngineering","ReverseEng")+''
UL_WORKBENCHES += ''
UL_WORKBENCHES += ''
- HTML = HTML.replace("UL_WORKBENCHES",UL_WORKBENCHES)
+ HTML = HTML.replace("UL_WORKBENCHES",encode(UL_WORKBENCHES))
# Detect additional addons that are not a workbench
@@ -435,7 +436,7 @@ def handle():
SHADOW = "#888888"
if QtGui.QColor(BASECOLOR).valueF() < 0.5: # dark page - we need to make darker shadows
SHADOW = "#000000"
- FONTFAMILY = p.GetString("FontFamily","Arial,Helvetica,sans")
+ FONTFAMILY = encode(p.GetString("FontFamily","Arial,Helvetica,sans"))
if not FONTFAMILY:
FONTFAMILY = "Arial,Helvetica,sans"
FONTSIZE = p.GetInt("FontSize",13)