InitScript.h
Go to the documentation of this file.00001 const char FreeCADInit[] ="# FreeCAD init module\n"
00002 "# (c) 2001 Jürgen Riegel\n"
00003 "#\n"
00004 "# Gathering all the information to start FreeCAD\n"
00005 "# This is the second one of three init scripts, the third one\n"
00006 "# runs when the gui is up\n"
00007 "\n"
00008 "#***************************************************************************\n"
00009 "#* (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *\n"
00010 "#* *\n"
00011 "#* This file is part of the FreeCAD CAx development system. *\n"
00012 "#* *\n"
00013 "#* This program is free software; you can redistribute it and/or modify *\n"
00014 "#* it under the terms of the GNU General Public License (GPL) *\n"
00015 "#* as published by the Free Software Foundation; either version 2 of *\n"
00016 "#* the License, or (at your option) any later version. *\n"
00017 "#* for detail see the LICENCE text file. *\n"
00018 "#* *\n"
00019 "#* FreeCAD is distributed in the hope that it will be useful, *\n"
00020 "#* but WITHOUT ANY WARRANTY; without even the implied warranty of *\n"
00021 "#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *\n"
00022 "#* GNU Library General Public License for more details. *\n"
00023 "#* *\n"
00024 "#* You should have received a copy of the GNU Library General Public *\n"
00025 "#* License along with FreeCAD; if not, write to the Free Software *\n"
00026 "#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *\n"
00027 "#* USA *\n"
00028 "#* *\n"
00029 "#* Juergen Riegel 2002 *\n"
00030 "#***************************************************************************/\n"
00031 "\n"
00032 "\n"
00033 "# imports the one and only\n"
00034 "import FreeCAD\n"
00035 "\n"
00036 "\n"
00037 "def InitApplications():\n"
00038 " try:\n"
00039 " import sys,os\n"
00040 " except:\n"
00041 " FreeCAD.PrintError(\"\\n\\nSeems the python standard libs are not installed, bailing out!\\n\\n\")\n"
00042 " raise\n"
00043 " # Checking on FreeCAD module path ++++++++++++++++++++++++++++++++++++++++++\n"
00044 " ModDir = FreeCAD.getHomePath()+\'Mod\'\n"
00045 " ModDir = os.path.realpath(ModDir)\n"
00046 " BinDir = FreeCAD.getHomePath()+\'bin\'\n"
00047 " BinDir = os.path.realpath(BinDir)\n"
00048 " LibDir = FreeCAD.getHomePath()+\'lib\'\n"
00049 " LibDir = os.path.realpath(LibDir)\n"
00050 " AddPath = FreeCAD.ConfigGet(\"AdditionalModulePaths\").split(\";\")\n"
00051 " HomeMod = FreeCAD.ConfigGet(\"UserAppData\")+\"Mod\"\n"
00052 " HomeMod = os.path.realpath(HomeMod)\n"
00053 " MacroMod = FreeCAD.ParamGet(\"User parameter:BaseApp/Preferences/Macro\").GetString(\"MacroPath\")+\"/Mod\"\n"
00054 " MacroMod = os.path.realpath(MacroMod)\n"
00055 " ModPar = FreeCAD.ParamGet(\"System parameter:Modules\")\n"
00056 "\n"
00057 " #print FreeCAD.getHomePath()\n"
00058 " if os.path.isdir(FreeCAD.getHomePath()+\'src\\\\Tools\'):\n"
00059 " sys.path.append(FreeCAD.getHomePath()+\'src\\\\Tools\')\n"
00060 " # Searching for module dirs +++++++++++++++++++++++++++++++++++++++++++++++++++\n"
00061 " # Use dict to handle duplicated module names\n"
00062 " ModDict = {}\n"
00063 " if os.path.isdir(ModDir):\n"
00064 " ModDirs = os.listdir(ModDir)\n"
00065 " for i in ModDirs: ModDict[i.lower()] = os.path.join(ModDir,i)\n"
00066 " else:\n"
00067 " Wrn (\"No modules found in \" + ModDir + \"\\n\")\n"
00068 " # Search for additional modules in the home directory\n"
00069 " if os.path.isdir(HomeMod):\n"
00070 " HomeMods = os.listdir(HomeMod)\n"
00071 " for i in HomeMods: ModDict[i.lower()] = os.path.join(HomeMod,i)\n"
00072 " # Search for additional modules in the macro directory\n"
00073 " if os.path.isdir(MacroMod):\n"
00074 " MacroMods = os.listdir(MacroMod)\n"
00075 " for i in MacroMods: ModDict[i.lower()] = os.path.join(MacroMod,i)\n"
00076 " # Search for additional modules in command line\n"
00077 " for i in AddPath:\n"
00078 " if os.path.isdir(i): ModDict[i] = i\n"
00079 " #AddModPaths = App.ParamGet(\"System parameter:AdditionalModulePaths\")\n"
00080 " #Err( AddModPaths)\n"
00081 " # add also this path so that all modules search for libraries\n"
00082 " # they depend on first here\n"
00083 " PathExtension = BinDir + os.pathsep\n"
00084 " # prepend all module paths to Python search path\n"
00085 " Log(\'Init: Searching for modules...\\n\')\n"
00086 " FreeCAD.__path__ = ModDict.values()\n"
00087 " for Dir in ModDict.values():\n"
00088 " if ((Dir != \'\') & (Dir != \'CVS\') & (Dir != \'__init__.py\')):\n"
00089 " ModGrp = ModPar.GetGroup(Dir)\n"
00090 " sys.path.insert(0,Dir)\n"
00091 " PathExtension += Dir + os.pathsep\n"
00092 " InstallFile = os.path.join(Dir,\"Init.py\")\n"
00093 " if (os.path.exists(InstallFile)):\n"
00094 " try:\n"
00095 " execfile(InstallFile)\n"
00096 " except Exception, inst:\n"
00097 " Log(\'Init: Initializing \' + Dir + \'... failed\\n\')\n"
00098 " Err(\'During initialization the error \' + str(inst) + \' occurred in \' + InstallFile + \'\\n\')\n"
00099 " else:\n"
00100 " Log(\'Init: Initializing \' + Dir + \'... done\\n\')\n"
00101 " else:\n"
00102 " Log(\'Init: Initializing \' + Dir + \'(Init.py not found)... ignore\\n\')\n"
00103 " sys.path.insert(0,LibDir)\n"
00104 " sys.path.insert(0,ModDir)\n"
00105 " Log(\"Using \"+ModDir+\" as module path!\\n\")\n"
00106 " # new paths must be prepended to avoid to load a wrong version of a library\n"
00107 " os.environ[\"PATH\"] = PathExtension + os.environ[\"PATH\"]\n"
00108 " path = os.environ[\"PATH\"].split(os.pathsep)\n"
00109 " Log(\"System path after init:\\n\")\n"
00110 " for i in path:\n"
00111 " Log(\" \" + i + \"\\n\")\n"
00112 " # add special path for MacOSX (bug #0000307)\n"
00113 " import platform\n"
00114 " if len(platform.mac_ver()[0]) > 0:\n"
00115 " sys.path.append(os.path.expanduser(\'~/Library/Application Support/FreeCAD/Mod\'))\n"
00116 "\n"
00117 "# some often used shortcuts (for lazy people like me ;-)\n"
00118 "App = FreeCAD\n"
00119 "Log = FreeCAD.Console.PrintLog\n"
00120 "Msg = FreeCAD.Console.PrintMessage\n"
00121 "Err = FreeCAD.Console.PrintError\n"
00122 "Wrn = FreeCAD.Console.PrintWarning\n"
00123 "\n"
00124 "Log (\'Init: starting App::FreeCADInit.py\\n\')\n"
00125 "\n"
00126 "# init every application by importing Init.py\n"
00127 "InitApplications()\n"
00128 "\n"
00129 "FreeCAD.EndingAdd(\"FreeCAD document (*.FCStd)\",\"FreeCAD\")\n"
00130 "\n"
00131 "# set to no gui, is overwritten by InitGui\n"
00132 "App.GuiUp = 0\n"
00133 "\n"
00134 "# clean up namespace\n"
00135 "del(InitApplications)\n"
00136 "\n"
00137 "Log (\'Init: App::FreeCADInit.py done\\n\')\n"
00138 "\n"
00139 "\n"
00140 "\n"
00141 "\n"
00142 ;
00143
00144