FreeCADGuiInit.py

Go to the documentation of this file.
00001 # FreeCAD gui init module
00002 # (c) 2003 Jürgen Riegel
00003 #
00004 # Gathering all the information to start FreeCAD
00005 # This is the second one of three init scripts, the third one
00006 # runs when the gui is up
00007 
00008 #***************************************************************************
00009 #*   (c) Jürgen Riegel (juergen.riegel@web.de) 2002                        *
00010 #*                                                                         *
00011 #*   This file is part of the FreeCAD CAx development system.              *
00012 #*                                                                         *
00013 #*   This program is free software; you can redistribute it and/or modify  *
00014 #*   it under the terms of the GNU General Public License (GPL)            *
00015 #*   as published by the Free Software Foundation; either version 2 of     *
00016 #*   the License, or (at your option) any later version.                   *
00017 #*   for detail see the LICENCE text file.                                 *
00018 #*                                                                         *
00019 #*   FreeCAD is distributed in the hope that it will be useful,            *
00020 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022 #*   GNU Library General Public License for more details.                  *
00023 #*                                                                         *
00024 #*   You should have received a copy of the GNU Library General Public     *
00025 #*   License along with FreeCAD; if not, write to the Free Software        *
00026 #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00027 #*   USA                                                                   *
00028 #*                                                                         *
00029 #*   Juergen Riegel 2002                                                   *
00030 #***************************************************************************/
00031 
00032 
00033 # imports the one and only
00034 import FreeCAD, FreeCADGui
00035 
00036 # shortcuts
00037 Gui = FreeCADGui
00038 
00039 # Important definitions
00040 class Workbench:
00041         """The workbench base class."""
00042         Icon = """
00043                         /* XPM */
00044                         static const char *FCIcon[]={
00045                         "16 16 4 1",
00046                         ". c None",
00047                         "# c #000000",
00048                         "a c #848284",
00049                         "b c #ff0000",
00050                         "........#.......",
00051                         ".......##aaaaaa.",
00052                         "........#.....a.",
00053                         ".#######......a.",
00054                         ".##...........a.",
00055                         ".##...bbbb....a.",
00056                         ".##..bb..bb...a.",
00057                         ".###bb#...b..###",
00058                         ".##.bb........#.",
00059                         ".##.bb..........",
00060                         ".##.bb..........",
00061                         ".##.bb..........",
00062                         ".##.bb....b.....",
00063                         ".....bb..bb.....",
00064                         "......bbbb......",
00065                         "................"};
00066                         """
00067         MenuText = ""
00068         ToolTip = ""
00069         
00070         def Initialize(self):
00071                 """Initializes this workbench."""
00072                 App.PrintWarning(str(self) + ": Workbench.Initialize() not implemented in subclass!")
00073         def ContextMenu(self, recipient):
00074                 pass
00075         def appendToolbar(self,name,cmds):
00076                 self.__Workbench__.appendToolbar(name, cmds)
00077         def removeToolbar(self,name):
00078                 self.__Workbench__.removeToolbar(name)
00079         def appendCommandbar(self,name,cmds):
00080                 self.__Workbench__.appendCommandbar(name, cmds)
00081         def removeCommandbar(self,name):
00082                 self.__Workbench__.removeCommandbar(name)
00083         def appendMenu(self,name,cmds):
00084                 self.__Workbench__.appendMenu(name, cmds)
00085         def removeMenu(self,name):
00086                 self.__Workbench__.removeMenu(name)
00087         def listMenus(self):
00088                 return self.__Workbench__.listMenus()
00089         def appendContextMenu(self,name,cmds):
00090                 self.__Workbench__.appendContextMenu(name, cmds)
00091         def removeContextMenu(self,name):
00092                 self.__Workbench__.removeContextMenu(name)
00093         def name(self):
00094                 return self.__Workbench__.name()
00095         def GetClassName(self):
00096                 """Return the name of the associated C++ class."""
00097                 # as default use this to simplify writing workbenches in Python 
00098                 return "Gui::PythonWorkbench"
00099 
00100 
00101 class StandardWorkbench ( Workbench ):
00102         """A workbench defines the tool bars, command bars, menus, 
00103 context menu and dockable windows of the main window.
00104         """
00105         def Initialize(self):
00106                 """Initialize this workbench."""
00107                 # load the module
00108                 Log ('Init: Loading FreeCAD GUI\n')
00109         def GetClassName(self):
00110                 """Return the name of the associated C++ class."""
00111                 return "Gui::StdWorkbench"
00112 
00113 class NoneWorkbench ( Workbench ):
00114         """An empty workbench."""
00115         MenuText = "<none>"
00116         ToolTip = "The default empty workbench"
00117         def Initialize(self):
00118                 """Initialize this workbench."""
00119                 # load the module
00120                 Log ('Init: Loading FreeCAD GUI\n')
00121         def GetClassName(self):
00122                 """Return the name of the associated C++ class."""
00123                 return "Gui::NoneWorkbench"
00124 
00125 def InitApplications():
00126         import sys,os
00127         # Searching modules dirs +++++++++++++++++++++++++++++++++++++++++++++++++++
00128         # (additional module paths are already cached)
00129         ModDirs = FreeCAD.__path__
00130         #print ModDirs
00131         Log('Init:   Searching modules...\n')
00132         ModPar = FreeCAD.ParamGet("System parameter:Modules")
00133         for Dir in ModDirs:
00134                 if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')):
00135                         InstallFile = os.path.join(Dir,"InitGui.py")
00136                         if (os.path.exists(InstallFile)):
00137                                 try:
00138                                         execfile(InstallFile)
00139                                 except Exception, inst:
00140                                         Log('Init:      Initializing ' + Dir + '... failed\n')
00141                                         Err('During initialization the error ' + str(inst) + ' occurred in ' + InstallFile + '\n')
00142                                 else:
00143                                         Log('Init:      Initializing ' + Dir + '... done\n')
00144                         else:
00145                                 Log('Init:      Initializing ' + Dir + '(InitGui.py not found)... ignore\n')
00146 
00147 
00148 Log ('Init: Running FreeCADGuiInit.py start script...\n')
00149 
00150 # init the gui
00151 
00152 # signal that the gui is up
00153 App.GuiUp = 1
00154 App.Gui = FreeCADGui
00155 
00156 Gui.addWorkbench(NoneWorkbench())
00157 
00158 # init modules
00159 InitApplications()
00160 
00161 # set standard workbench (needed as fallback)
00162 Gui.activateWorkbench("NoneWorkbench")
00163 
00164 # Register .py, .FCScript and .FCMacro
00165 FreeCAD.addImportType("Inventor V2.1 (*.iv)","FreeCADGui")
00166 FreeCAD.addImportType("VRML V2.0 (*.wrl *.vrml *.wrz *.wrl.gz)","FreeCADGui")
00167 FreeCAD.addImportType("Python (*.py *.FCMacro *.FCScript)","FreeCADGui")
00168 FreeCAD.addExportType("Inventor V2.1 (*.iv)","FreeCADGui")
00169 FreeCAD.addExportType("VRML V2.0 (*.wrl *.vrml *.wrz *.wrl.gz)","FreeCADGui")
00170 #FreeCAD.addExportType("IDTF (for 3D PDF) (*.idtf)","FreeCADGui")
00171 FreeCAD.addExportType("3D View (*.svg)","FreeCADGui")
00172 
00173 del(InitApplications)
00174 del(NoneWorkbench)
00175 del(StandardWorkbench)
00176 
00177 
00178 Log ('Init: Running FreeCADGuiInit.py start script... done\n')

Generated on Wed Nov 23 19:00:15 2011 for FreeCAD by  doxygen 1.6.1