#*************************************************************************** #* * #* Copyright (c) 2012 * #* Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * #* it under the terms of the GNU Lesser General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * #* * #* This program is distributed in the hope that it will be useful, * #* but WITHOUT ANY WARRANTY; without even the implied warranty of * #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * #* GNU Library General Public License for more details. * #* * #* You should have received a copy of the GNU Library General Public * #* License along with this program; if not, write to the Free Software * #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * #* USA * #* * #*************************************************************************** # This is the start page template import os,FreeCAD,FreeCADGui,tempfile,time,zipfile,urllib,re,cStringIO from PySide 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).encode("utf8") 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 commits") 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","Architectural 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://www.freecadweb.org/wiki/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 dedicated to python scripting, with examples, explanations, and API commands.") text48 = translate("StartPage","A blog dedicated to teaching FreeCAD, maintained by members of the FreeCAD community") text49 = translate("StartPage","Getting started") text50 = translate("StartPage","The FreeCAD interface is divided in workbenches, which are sets of tools suited for a specific task. You can start with one of the workbenches in this list, or with the complete workbench, which presents you with some of the most used tools gathered from other workbenches. Click to read more about workbenches on the FreeCAD website.") text51 = translate("StartPage","http://www.freecadweb.org/wiki/index.php?title=Workbenches") text52 = translate("StartPage","Ship Design") text53 = translate("StartPage","Designing and calculating ships") text54 = translate("StartPage","The Ship Design module offers several tools to help ship designers to view, model and calculate profiles and other specific properties of ship hulls.") text55 = translate("StartPage","Load an Architectural example model") text56 = translate("StartPage","http://www.freecadweb.org/wiki/index.php?title=Tutorials") text57 = translate("StartPage","http://www.freecadweb.org/wiki/index.php?title=Power_users_hub") text58 = translate("StartPage","Your version of FreeCAD is up to date.") text59 = translate("StartPage","There is a new release of FreeCAD available.") text60 = translate("StartPage","Load an FEM 3D example analysis") text61 = translate("StartPage","Obtain a development version") text62 = translate("StartPage","Development versions are made available by community members from time to time and usually contain the latest changes, but are more likely to contain bugs.") text63 = translate("StartPage","See all commits") text64 = translate("StartPage","Load an FEM 2D example analysis") # get FreeCAD version v = FreeCAD.Version() vmajor = v[0] vminor = v[1] vbuild = v[2].split(" ")[0] # here is the html page skeleton page = """ FreeCAD - Start page

 """ + text01 + """
 

 

""" + text02 + """

defaultworkbenches

""" + text03 + """

recentfiles

""" + text05 + """

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 setColors(html): "gets theme colors from the system, and sets appropriate styles" defaults = {"#basecolor":"#191B26", "#linkcolor":"#0092E8", "#textcolor":"#FFFFFF", "#windowcolor":"#FFFFFF", "#windowtextcolor":"#000000"} try: palette = QtGui.qApp.palette() except: pass else: #defaults["#basecolor"] = palette.base().color().name() defaults["#basecolor"] = "#171A2B url(Background.jpg)" #defaults["#linkcolor"] = palette.link().color().name() # UGLY!! defaults["#textcolor"] = palette.text().color().name() defaults["#windowcolor"] = palette.window().color().name() defaults["#windowtextcolor"] = palette.windowText().color().name() for k,v in defaults.iteritems(): html = html.replace(k,str(v)) return html 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()) # fetches system colors html = setColors(html) return html def exportTestFile(): f = open(os.path.expanduser("~")+os.sep+"freecad-startpage.html","wb") f.write(handle()) f.close()