diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py index 26a573ba3d..4ae0511e11 100644 --- a/src/Mod/Start/StartPage/StartPage.py +++ b/src/Mod/Start/StartPage/StartPage.py @@ -1,4 +1,4 @@ -import os,FreeCAD,FreeCADGui,tempfile,time,zipfile,urllib,re +import os,FreeCAD,FreeCADGui,tempfile,time,zipfile,urllib,re,cStringIO from PyQt4 import QtGui from xml.etree.ElementTree import parse @@ -6,8 +6,19 @@ FreeCADGui.addLanguagePath(":/translations") FreeCADGui.updateLocale() def translate(context,text): - "convenience function for the Qt translator" - return str(QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8).toUtf8()) + "convenience function for the Qt translator" + # return str(QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8).toUtf8()) + u = QtGui.QApplication.translate(context, text, None, + QtGui.QApplication.UnicodeUTF8).toUtf8() + s = cStringIO.StringIO() + for i in u: + if ord(i) == 39: + s.write("\\'") + else: + s.write(i) + t = s.getvalue() + s.close() + return t # texts to be translated @@ -66,144 +77,164 @@ page = """ FreeCAD - Start page + + + @@ -269,204 +300,202 @@ page = """ """ def getWebExamples(): - return """ - """ + return """ + """ def getExamples(): - return """ - """ + return """ + """ def getLinks(): - return """ - """ + return """ + """ def getWorkbenches(): - return """ - -""" + return """ + """ def getInfo(filename): - "returns available file information" + "returns available file information" - def getLocalTime(timestamp): - "returns a local time from a timestamp" - - return time.strftime("%m/%d/%Y %H:%M:%S",time.localtime(timestamp)) + def getLocalTime(timestamp): + "returns a local time from a timestamp" + return time.strftime("%m/%d/%Y %H:%M:%S",time.localtime(timestamp)) - def getSize(size): - "returns a human-readable size" - - if size > 1024*1024: - hsize = str(size/(1024*1024)) + "Mb" - elif size > 1024: - hsize = str(size/1024) + "Kb" - else: - hsize = str(size) + "b" - return hsize - - html = '

'+os.path.basename(filename)+'

' - - if os.path.exists(filename): - # get normal file info - s = os.stat(filename) - html += "

" + text33 + " " + getSize(s.st_size) + "
" - html += text34 + " " + getLocalTime(s.st_ctime) + "
" - html += text35 + " " + getLocalTime(s.st_mtime) + "
" - html += "" + text36 + " " + filename + "

" - # get additional info from fcstd files - if os.path.splitext(filename)[1] in [".fcstd",".FcStd"]: - zfile=zipfile.ZipFile(filename) - files=zfile.namelist() - # check for meta-file if it's really a FreeCAD document - if files[0] == "Document.xml": - html += "

FreeCAD Standard File

" - image="thumbnails/Thumbnail.png" - if image in files: - image=zfile.read(image) - thumbfile = tempfile.mkstemp(suffix='.png')[1] - thumb = open(thumbfile,"wb") - thumb.write(image) - thumb.close() - html += '
' + def getSize(size): + "returns a human-readable size" + if size > 1024*1024: + hsize = str(size/(1024*1024)) + "Mb" + elif size > 1024: + hsize = str(size/1024) + "Kb" else: - html += "

" + text41 + "

" - - return html + hsize = str(size) + "b" + return hsize + + html = '

'+os.path.basename(filename)+'

' + + if os.path.exists(filename): + # get normal file info + s = os.stat(filename) + html += "

" + text33 + " " + getSize(s.st_size) + "
" + html += text34 + " " + getLocalTime(s.st_ctime) + "
" + html += text35 + " " + getLocalTime(s.st_mtime) + "
" + html += "" + text36 + " " + filename + "

" + # get additional info from fcstd files + if os.path.splitext(filename)[1] in [".fcstd",".FcStd"]: + zfile=zipfile.ZipFile(filename) + files=zfile.namelist() + # check for meta-file if it's really a FreeCAD document + if files[0] == "Document.xml": + html += "

FreeCAD Standard File

" + image="thumbnails/Thumbnail.png" + if image in files: + image=zfile.read(image) + thumbfile = tempfile.mkstemp(suffix='.png')[1] + thumb = open(thumbfile,"wb") + thumb.write(image) + thumb.close() + html += '
' + else: + html += "

" + text41 + "

" + + return html def getRecentFiles(): - "returns a list of 3 latest recent files" - - rf=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles") - ct=rf.GetInt("RecentFiles") - html = '' - return html + "returns a list of 3 latest recent files" + rf = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles") + ct = rf.GetInt("RecentFiles") + html = '' + return html def getFeed(url,numitems=3): - "returns a html list with links from the given RSS feed url" - xml = parse(urllib.urlopen(url)).getroot() - items = [] - channel = xml.find('channel') - for element in channel.findall('item'): - items.append({ - 'title': element.find('title').text, - 'description': element.find('description').text, - 'link': element.find('link').text, - }) - if len(items) > numitems: - items = items[:numitems] - resp = '' - print resp - return resp + "returns a html list with links from the given RSS feed url" + xml = parse(urllib.urlopen(url)).getroot() + items = [] + channel = xml.find('channel') + for element in channel.findall('item'): + items.append({'title': element.find('title').text, + 'description': element.find('description').text, + 'link': element.find('link').text}) + if len(items) > numitems: + items = items[:numitems] + resp = '' + print resp + return resp def getCustomBlocks(): - "fetches custom html files in FreeCAD user dir" - output = "" - return output + "fetches custom html files in FreeCAD user dir" + output = "" + return output def handle(): - "returns the complete html startpage" - - # add recent files - recentfiles = getRecentFiles() - html = page.replace("recentfiles",recentfiles) + "returns the complete html startpage" + + # add recent files + recentfiles = getRecentFiles() + html = page.replace("recentfiles",recentfiles) - # add default workbenches - html = html.replace("defaultworkbenches",getWorkbenches()) + # add default workbenches + html = html.replace("defaultworkbenches",getWorkbenches()) - # add default web links - html = html.replace("defaultlinks",getLinks()) + # add default web links + html = html.replace("defaultlinks",getLinks()) - # add default examples - html = html.replace("defaultexamples",getExamples()) + # add default examples + html = html.replace("defaultexamples",getExamples()) - # add web examples - #html = html.replace("webexamples",getWebExamples()) + # add web examples + #html = html.replace("webexamples",getWebExamples()) + + # add custom blocks + html = html.replace("customblocks",getCustomBlocks()) + + return html - # add custom blocks - html = html.replace("customblocks",getCustomBlocks()) - - return html -