StartWB: Remove python2 support
* removed six module * removed encode() function
This commit is contained in:
@@ -24,10 +24,7 @@ import sys
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
from urllib import unquote
|
||||
else:
|
||||
from urllib.parse import unquote
|
||||
from urllib.parse import unquote
|
||||
|
||||
|
||||
# filename will be given before this script is run
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
# contains the html code of the start page.
|
||||
# Note: It is built only once per FreeCAD session for now...
|
||||
|
||||
import six
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
@@ -46,16 +45,6 @@ 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 six.PY2:
|
||||
if not isinstance(text,six.text_type):
|
||||
return text.decode("utf8")
|
||||
return text
|
||||
|
||||
|
||||
def gethexcolor(color):
|
||||
|
||||
"returns a color hex value #000000"
|
||||
@@ -245,9 +234,9 @@ def buildCard(filename,method,arg=None):
|
||||
"""builds an html <li> element representing a file.
|
||||
method is a script + a keyword, for ex. url.py?key="""
|
||||
|
||||
result = encode("")
|
||||
result = ("")
|
||||
if os.path.exists(filename) and isOpenableByFreeCAD(filename):
|
||||
basename = encode(os.path.basename(filename))
|
||||
basename = os.path.basename(filename)
|
||||
if not arg:
|
||||
arg = basename
|
||||
finfo = getInfo(filename)
|
||||
@@ -255,17 +244,17 @@ def buildCard(filename,method,arg=None):
|
||||
image = finfo[0]
|
||||
size = finfo[1]
|
||||
author = finfo[2]
|
||||
infostring = encode(TranslationTexts.T_CREATIONDATE+": "+finfo[3]+"\n")
|
||||
infostring += encode(TranslationTexts.T_LASTMODIFIED+": "+finfo[4])
|
||||
infostring = TranslationTexts.T_CREATIONDATE+": "+finfo[3] + "\n"
|
||||
infostring += TranslationTexts.T_LASTMODIFIED+": "+finfo[4]
|
||||
if finfo[5]:
|
||||
infostring += "\n\n" + encode(finfo[5])
|
||||
infostring += "\n\n" + finfo[5]
|
||||
if size:
|
||||
result += '<li class="icon">'
|
||||
result += '<a href="'+method+urllib.parse.quote(arg)+'" title="'+infostring+'">'
|
||||
result += '<img src="file:///'+image.replace('\\','/')+'" alt="'+encode(basename)+'">'
|
||||
result += '<img src="file:///'+image.replace('\\','/')+'" alt="'+basename+'">'
|
||||
result += '<div class="caption">'
|
||||
result += '<h4>'+encode(basename)+'</h4>'
|
||||
result += '<p>'+encode(author)+'</p>'
|
||||
result += '<h4>'+basename+'</h4>'
|
||||
result += '<p>'+author+'</p>'
|
||||
result += '<p>'+size+'</p>'
|
||||
result += '</div>'
|
||||
result += '</a>'
|
||||
@@ -309,7 +298,6 @@ def handle():
|
||||
CSS = f.read()
|
||||
HTML = HTML.replace("JS",JS)
|
||||
HTML = HTML.replace("CSS",CSS)
|
||||
HTML = encode(HTML)
|
||||
|
||||
# set the language
|
||||
|
||||
@@ -340,11 +328,11 @@ def handle():
|
||||
if res:
|
||||
f = QtCore.QFile(path)
|
||||
if f.open(QtCore.QIODevice.ReadOnly | QtCore.QFile.Text):
|
||||
ALTCSS = encode(QtCore.QTextStream(f).readAll())
|
||||
ALTCSS = QtCore.QTextStream(f).readAll()
|
||||
HTML = HTML.replace("<!--QSS-->","<style type=\"text/css\">"+ALTCSS+"</style>")
|
||||
else:
|
||||
with open(path, 'r') as f:
|
||||
ALTCSS = encode(f.read())
|
||||
ALTCSS = f.read()
|
||||
HTML = HTML.replace("<!--QSS-->","<style type=\"text/css\">"+ALTCSS+"</style>")
|
||||
|
||||
# turn tips off if needed
|
||||
@@ -355,14 +343,14 @@ def handle():
|
||||
# get FreeCAD version
|
||||
|
||||
v = FreeCAD.Version()
|
||||
VERSIONSTRING = encode(TranslationTexts.T_VERSION + " " + v[0] + "." + v[1] + " " + TranslationTexts.T_BUILD + " " + v[2])
|
||||
VERSIONSTRING = 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:
|
||||
HTML = HTML.replace(text,encode(getattr(TranslationTexts,text)))
|
||||
HTML = HTML.replace(text,getattr(TranslationTexts,text))
|
||||
|
||||
# build a "create new" icon with the FreeCAD background color gradient
|
||||
|
||||
@@ -385,43 +373,43 @@ def handle():
|
||||
|
||||
rf = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles")
|
||||
rfcount = rf.GetInt("RecentFiles",0)
|
||||
SECTION_RECENTFILES = encode("<h2>"+TranslationTexts.T_RECENTFILES+"</h2>")
|
||||
SECTION_RECENTFILES = "<h2>"+TranslationTexts.T_RECENTFILES+"</h2>"
|
||||
SECTION_RECENTFILES += "<ul>"
|
||||
SECTION_RECENTFILES += '<li class="icon">'
|
||||
SECTION_RECENTFILES += '<a href="LoadNew.py" title="'+encode(TranslationTexts.T_CREATENEW)+'">'
|
||||
SECTION_RECENTFILES += '<a href="LoadNew.py" title="'+TranslationTexts.T_CREATENEW+'">'
|
||||
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("NewFileGradient",False):
|
||||
SECTION_RECENTFILES += '<img src="file:///'+encode(iconbank["createimg"]).replace('\\','/')+'" alt="'+encode(TranslationTexts.T_CREATENEW)+'">'
|
||||
SECTION_RECENTFILES += '<img src="file:///'+iconbank["createimg"].replace('\\','/')+'" alt="'+TranslationTexts.T_CREATENEW+'">'
|
||||
else:
|
||||
SECTION_RECENTFILES += '<img src="file:///'+os.path.join(resources_dir, "images/new_file_thumbnail.svg").replace('\\','/')+'" alt="'+encode(TranslationTexts.T_CREATENEW)+'">'
|
||||
SECTION_RECENTFILES += '<img src="file:///'+os.path.join(resources_dir, "images/new_file_thumbnail.svg").replace('\\','/')+'" alt="'+TranslationTexts.T_CREATENEW+'">'
|
||||
SECTION_RECENTFILES += '<div class="caption">'
|
||||
SECTION_RECENTFILES += '<h4>'+encode(TranslationTexts.T_CREATENEW)+'</h4>'
|
||||
SECTION_RECENTFILES += '<h4>'+TranslationTexts.T_CREATENEW+'</h4>'
|
||||
SECTION_RECENTFILES += '</div>'
|
||||
SECTION_RECENTFILES += '</a>'
|
||||
SECTION_RECENTFILES += '</li>'
|
||||
for i in range(rfcount):
|
||||
filename = rf.GetString("MRU%d" % (i))
|
||||
SECTION_RECENTFILES += encode(buildCard(filename,method="LoadMRU.py?MRU=",arg=str(i)))
|
||||
SECTION_RECENTFILES += buildCard(filename,method="LoadMRU.py?MRU=",arg=str(i))
|
||||
SECTION_RECENTFILES += '</ul>'
|
||||
HTML = HTML.replace("SECTION_RECENTFILES",SECTION_RECENTFILES)
|
||||
|
||||
# build SECTION_EXAMPLES
|
||||
|
||||
SECTION_EXAMPLES = encode("")
|
||||
SECTION_EXAMPLES = ""
|
||||
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("ShowExamples",True):
|
||||
SECTION_EXAMPLES = encode("<h2>"+TranslationTexts.T_EXAMPLES+"</h2>")
|
||||
SECTION_EXAMPLES = "<h2>"+TranslationTexts.T_EXAMPLES+"</h2>"
|
||||
SECTION_EXAMPLES += "<ul>"
|
||||
examples_path = FreeCAD.getResourceDir()+"examples"
|
||||
if os.path.exists(examples_path):
|
||||
examples = os.listdir(examples_path)
|
||||
for basename in examples:
|
||||
filename = FreeCAD.getResourceDir()+"examples"+os.sep+basename
|
||||
SECTION_EXAMPLES += encode(buildCard(filename,method="LoadExample.py?filename="))
|
||||
SECTION_EXAMPLES += buildCard(filename,method="LoadExample.py?filename=")
|
||||
SECTION_EXAMPLES += "</ul>"
|
||||
HTML = HTML.replace("SECTION_EXAMPLES",SECTION_EXAMPLES)
|
||||
|
||||
# build SECTION_CUSTOM
|
||||
|
||||
SECTION_CUSTOM = encode("")
|
||||
SECTION_CUSTOM = ""
|
||||
cfolders = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("ShowCustomFolder","")
|
||||
if cfolders:
|
||||
dn = 0
|
||||
@@ -431,11 +419,11 @@ def handle():
|
||||
if not os.path.exists(cfolder):
|
||||
FreeCAD.Console.PrintWarning("Custom folder not found: %s" % cfolder)
|
||||
else:
|
||||
SECTION_CUSTOM += encode("<h2>"+os.path.basename(os.path.normpath(cfolder))+"</h2>")
|
||||
SECTION_CUSTOM += "<h2>"+os.path.basename(os.path.normpath(cfolder))+"</h2>"
|
||||
SECTION_CUSTOM += "<ul>"
|
||||
for basename in os.listdir(cfolder):
|
||||
filename = os.path.join(cfolder,basename)
|
||||
SECTION_CUSTOM += encode(buildCard(filename,method="LoadCustom.py?filename="+str(dn)+"_"))
|
||||
SECTION_CUSTOM += buildCard(filename,method="LoadCustom.py?filename="+str(dn)+"_")
|
||||
SECTION_CUSTOM += "</ul>"
|
||||
# hide the custom section tooltip if custom section is set (users know about it if they enabled it)
|
||||
HTML = HTML.replace("id=\"customtip\" class","id=\"customtip\" style=\"display:none;\" class")
|
||||
@@ -514,7 +502,6 @@ def handle():
|
||||
UL_WORKBENCHES += '<a href="https://www.freecadweb.org/wiki/'+wn+'_Workbench">'+wn.replace("ReverseEngineering","ReverseEng")+'</a>'
|
||||
UL_WORKBENCHES += '</li>'
|
||||
UL_WORKBENCHES += '</ul>'
|
||||
HTML = HTML.replace("UL_WORKBENCHES",encode(UL_WORKBENCHES))
|
||||
|
||||
# Detect additional addons that are not a workbench
|
||||
|
||||
@@ -554,7 +541,7 @@ def handle():
|
||||
SHADOW = "#888888"
|
||||
if QtGui.QColor(BASECOLOR).valueF() < 0.5: # dark page - we need to make darker shadows
|
||||
SHADOW = "#000000"
|
||||
FONTFAMILY = encode(p.GetString("FontFamily","Arial,Helvetica,sans"))
|
||||
FONTFAMILY = p.GetString("FontFamily","Arial,Helvetica,sans")
|
||||
if not FONTFAMILY:
|
||||
FONTFAMILY = "Arial,Helvetica,sans"
|
||||
FONTSIZE = p.GetInt("FontSize",13)
|
||||
|
||||
@@ -33,9 +33,6 @@ def translate(context,text):
|
||||
except AttributeError:
|
||||
u = QtGui.QApplication.translate(context, text, None)
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
u = u.encode("utf8")
|
||||
|
||||
return u.replace(chr(39), "’")
|
||||
|
||||
T_TITLE = translate("StartPage", "Start")
|
||||
|
||||
Reference in New Issue
Block a user