import os,FreeCAD,FreeCADGui,tempfile,time,zipfile,urllib,re,cStringIO from PyQt4 import QtGui from xml.etree.ElementTree import parse 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()) 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 text01 = translate("StartPage","FreeCAD Start Center") text02 = translate("StartPage","Start a new project") text03 = translate("StartPage","Recent Files") text04 = translate("StartPage","Latest videos") text05 = translate("StartPage","Latest news") text06 = translate("StartPage","On the web") text07 = translate("StartPage","This is the FreeCAD Homepage. Here you will be able to find a lot of information about FreeCAD, including tutorials, examples and user documentation.") text08 = translate("StartPage","FreeCAD Homepage") text09 = translate("StartPage","Example projects") text10 = translate("StartPage","Schenkel STEP file") text11 = translate("StartPage","Load a PartDesign example") text12 = translate("StartPage","Load a Drawing extraction") text13 = translate("StartPage","Load a Robot simulation example") text14 = translate("StartPage","Projects from the Web") text15 = translate("StartPage","Schenkel STEP") text16 = translate("StartPage","Complex Part") text17 = translate("StartPage","Close this window after opening or creating a file") text18 = translate("StartPage","Don't show me this window again next time") text19 = translate("StartPage","Designing parts") text20 = translate("StartPage","The Part Design workbench is designed to create complex pieces based on constrained 2D sketches. Use it to draw 2D shapes, constrain some of their elements and extrude them to form 3D pieces.") text21 = translate("StartPage","Example workflow") text22 = translate("StartPage","Part Design") text23 = translate("StartPage","Designing architectural elements") text24 = translate("StartPage","The Architectural Design workbench is specially designed for working with architectural elements such as walls or windows. Start by drawing 2D shapes, and use them as guides to build architecutral objects.") text25 = translate("StartPage","Architectual Design") text26 = translate("StartPage","Working with Meshes") text27 = translate("StartPage","The Mesh Workbench is used to work with Mesh objects. Meshes are simpler 3D objects than Part objects, but they are often easier to import and export to/from other applications.") text28 = translate("StartPage","FreeCAD offers you several tools to convert between Mesh and Part objects.") text29 = translate("StartPage","Work with Meshes") text30 = translate("StartPage","The complete workbench") text31 = translate("StartPage","FreeCAD Complete workbench") text32 = translate("StartPage","populated with some of the most commonly used tools.") text33 = translate("StartPage","file size:") text34 = translate("StartPage","creation time:") text35 = translate("StartPage","last modified:") text36 = translate("StartPage","location:") text37 = translate("StartPage","User manual") text38 = translate("StartPage","http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Online_Help_Toc") text39 = translate("StartPage","Tutorials") text40 = translate("StartPage","Python resources") text41 = translate("StartPage","File not found") text42 = translate("StartPage","from @FreeCADNews") text43 = translate("StartPage","The FreeCAD-tutorial blog") text44 = translate("StartPage","from FreeCADNews channel") text45 = translate("StartPage","This is the official user manual of FreeCAD, built, maintained and translated by the FreeCAD community.") text46 = translate("StartPage","The tutorials section on the FreeCAD website") text47 = translate("StartPage","The section of the FreeCAd website dedicate dto python scripting, with examples, explanations, and API commands.") text48 = translate("StartPage","A blog dedicated to teaching FreeCAD, maintained by members of the FreeCAD community") # here is the html page skeleton page = """ FreeCAD - Start page

 """ + text01 + """

""" + text02 + """

defaultworkbenches

""" + text03 + """

recentfiles

""" + text04 + """ """ + text44 + """

youtube videos

""" + text05 + """ """ + text42 + """

news feed

""" + text06 + """

defaultlinks

""" + text09 + """

defaultexamples
customblocks
 
""" def getWebExamples(): return """ """ def getExamples(): return """ """ def getLinks(): return """ """ def getWorkbenches(): return """ """ def getInfo(filename): "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 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].upper() in [".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 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 def getCustomBlocks(): "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) # add default workbenches html = html.replace("defaultworkbenches",getWorkbenches()) # add default web links html = html.replace("defaultlinks",getLinks()) # add default examples html = html.replace("defaultexamples",getExamples()) # add web examples #html = html.replace("webexamples",getWebExamples()) # add custom blocks html = html.replace("customblocks",getCustomBlocks()) return html