Back to index

salome-gui  6.5.0
dlgfactory.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 
00021 import sys, os
00022 
00023 __descr_str = ""
00024 __descr_str += "This script generates a set of files to initiate a dialog Qt window "
00025 __descr_str += "(i.e. MyDialog.ui, MyDialog.hxx and MyDialog.cxx files). "
00026 __descr_str += "The dialog window can be a self-consistent class (i.e. depends only "
00027 __descr_str += "on Qt classes) or a class that inherits class GenericDialog "
00028 __descr_str += "which implementation is provided in this package and "
00029 __descr_str += "which design is defined by the GenericDialog.ui file (editable using "
00030 __descr_str += "the Qt designer). "
00031 __descr_str += "The -t option let you choose between the two possibilities (specify "
00032 __descr_str += "\"-t qdialog\" for the first case, \"-t gdialog\" otherwise)."
00033 
00034 __msg_str = """
00035 #
00036 # ---------------------------------------------------------
00037 # Generation rules to create moc files from QObject headers
00038 # and form source files from ui files
00039 # ---------------------------------------------------------
00040 
00041 %_moc.cxx: %.hxx
00042        $(MOC) $< -o $@
00043 
00044 ui_%.hxx: %.ui
00045        $(UIC) -o $@ $<
00046 
00047 
00048 # ---------------------------------------------------------
00049 # Declaration of form files generated by UIC and MOC files
00050 # as BUILT_SOURCES to be used in the building process.
00051 # ---------------------------------------------------------
00052 #
00053 UIC_FILES = \
00054        ui___CLASSNAME__.hxx
00055 #
00056 MOC_FILES = \
00057        __CLASSNAME___moc.cxx
00058 
00059 BUILT_SOURCES = $(UIC_FILES)
00060 
00061 #
00062 # ---------------------------------------------------------
00063 # Declaration of sources files to the building process
00064 # ---------------------------------------------------------
00065 # MOC files and UIC files should be added to the list of undistributed
00066 # source files with something like (where <MyLibrary> should be
00067 # replaced by the name of the product declared by the directive
00068 # lib_LTLIBRARIES):
00069 #
00070 nodist_<MyLibrary>_la_SOURCES += $(MOC_FILES) $(UIC_FILES)
00071 
00072 dist_<MyLibrary>_la_SOURCES += __CLASSNAME__.cxx
00073 salomeinclude_HEADERS       += __CLASSNAME__.hxx
00074 
00075 <MyLibrary>_la_CPPFLAGS = \\
00076        $(QT_CXXFLAGS)
00077 
00078 <MyLibrary>_la_LDFLAGS = \\
00079         $(QT_LIBS)
00080 """ 
00081 
00082 if __name__ == "__main__":
00083   from optparse import OptionParser
00084   import shutil, fileinput
00085 
00086   tool_path = os.path.dirname( os.path.abspath( sys.argv[0] ) )
00087 
00088   parser = OptionParser( description = __descr_str )
00089   parser.add_option( "-n", action="store", default="TestDialog", dest="className", metavar="className",
00090                      help="specify the name of the class (default is TestDialog)" )
00091   parser.add_option( "-t", action="store", default="qdialog", dest="classType",
00092                      choices=["qdialog", "gdialog"], metavar="classType",
00093                      help="specify the type of the class (default is qdialog)" )
00094   parser.add_option( "-v", "--verbose", action="store_true", default=True, dest="verbose",
00095                      help="verbose mode" )
00096   parser.add_option( "-s", "--silent", action="store_false", dest="verbose",
00097                      help="silent mode" )
00098 
00099   (options, args) = parser.parse_args()
00100   className = options.className
00101   classType = options.classType
00102 
00103   for ext in [".cxx", ".hxx", ".ui"]:
00104     file_dest = className + ext 
00105     if classType == "qdialog":
00106       file_src = os.path.join( tool_path, "__QDIALOG__" + ext )
00107       pass
00108     else:
00109       file_src = os.path.join( tool_path, "__GDIALOG__" + ext )
00110       pass
00111     shutil.copyfile( file_src, file_dest )
00112     finput = fileinput.FileInput( file_dest, inplace=1 )
00113     for line in finput:
00114       line = line[:-1] 
00115       line = line.replace( "__CLASSNAME__", className )
00116       print line
00117       pass
00118 
00119     if options.verbose:
00120       print "Note that the following directives should be present in your Makefile.am (or something like that): \n"
00121       print __msg_str.replace( "__CLASSNAME__", className )
00122       pass
00123   pass
00124