diff --git a/Code/Mantid/Build/CMake/MantidUtils.cmake b/Code/Mantid/Build/CMake/MantidUtils.cmake index 25b7540e4d616a32c01eb68a479715e745cd1722..5ad44cda151cebbdff62f1c733fcb01a1f0623f7 100644 --- a/Code/Mantid/Build/CMake/MantidUtils.cmake +++ b/Code/Mantid/Build/CMake/MantidUtils.cmake @@ -61,29 +61,29 @@ endfunction( SET_TARGET_OUTPUT_DIRECTORY ) ####################################################################### # -# NAME: COPY_PYTHON_FILES_TO_DIR -# Adds a set of custom commands for each python file to copy +# NAME: COPY_FILES_TO_DIR +# Adds a set of custom commands for each file to copy # the given file to the destination directory -# - PY_FILES :: A list of python files to copy. Note you will have +# - FILES :: A list of files to copy. Note you will have # to quote an expanded list # - SRC_DIR :: The src directory of the files to be copied # - DEST_DIR :: The final directory for the copied files # - INSTALLED_FILES :: An output variable containing the list of copied # files including their full paths -function( COPY_PYTHON_FILES_TO_DIR PY_FILES SRC_DIR DEST_DIR INSTALLED_FILES ) +function( COPY_FILES_TO_DIR FILES SRC_DIR DEST_DIR INSTALLED_FILES ) set ( COPIED_FILES ${${INSTALLED_FILES}} ) - foreach ( PYFILE ${PY_FILES} ) - get_filename_component( _basefilename ${PYFILE} NAME_WE ) - set( _py_src ${SRC_DIR}/${PYFILE} ) - set( _py_bin ${DEST_DIR}/${PYFILE} ) - add_custom_command ( OUTPUT ${_py_bin} - DEPENDS ${_py_src} + foreach ( _FILE ${FILES} ) + get_filename_component( _basefilename ${_FILE} NAME_WE ) + set( _src ${SRC_DIR}/${_FILE} ) + set( _bin ${DEST_DIR}/${_FILE} ) + add_custom_command ( OUTPUT ${_bin} + DEPENDS ${_src} COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different - ${_py_src} ${_py_bin} ) - set ( COPIED_FILES ${COPIED_FILES} ${_py_bin} ) - endforeach ( PYFILE ) + ${_src} ${_bin} ) + set ( COPIED_FILES ${COPIED_FILES} ${_bin} ) + endforeach ( _FILE ) set ( ${INSTALLED_FILES} ${COPIED_FILES} PARENT_SCOPE ) -endfunction( COPY_PYTHON_FILES_TO_DIR ) +endfunction( COPY_FILES_TO_DIR ) ####################################################################### diff --git a/Code/Mantid/Framework/PythonInterface/mantid/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/CMakeLists.txt index b09ae5d1644d90545b1739959dd312aaf8d7c40d..be9210d92556882ab17e9b3d8857727a7c45f5ab 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/CMakeLists.txt @@ -17,15 +17,15 @@ set ( PY_FILES simpleapi.py ) -copy_python_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} - PYTHON_PKGROOT_INSTALL_FILES ) +copy_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} + PYTHON_PKGROOT_INSTALL_FILES ) # Generate the version module set ( VERSION_PY pyversion ) # Build version configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/${VERSION_PY}.py.in ${CMAKE_CURRENT_BINARY_DIR}/${VERSION_PY}.py ) # Copy py to build directory, taking care of multi-config (MSVC) builds -copy_python_files_to_dir ( ${VERSION_PY}.py ${CMAKE_CURRENT_BINARY_DIR} ${OUTPUT_DIR} - PYTHON_PKGROOT_INSTALL_FILES ) +copy_files_to_dir ( ${VERSION_PY}.py ${CMAKE_CURRENT_BINARY_DIR} ${OUTPUT_DIR} + PYTHON_PKGROOT_INSTALL_FILES ) # Package version configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/${VERSION_PY}.py.in ${CMAKE_CURRENT_BINARY_DIR}/${VERSION_PY}.install.py ) diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt index 1ec1239798419506c1106abcc2a692932a544ebd..cc0ebaa5c9e18d4195458adb7c20f07788a96ea8 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt @@ -115,8 +115,8 @@ if(CMAKE_GENERATOR STREQUAL Xcode) set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PKG_ROOT}/api ) endif() -copy_python_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} - PYTHON_INSTALL_FILES ) +copy_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} + PYTHON_INSTALL_FILES ) ############################################################################################# # Create the target for this directory diff --git a/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt index 7c79f4f4afa814550d10fb1030e58cb487c7bd06..91479c6c25df720aac2ccc00fb21844be42ed781 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt @@ -59,8 +59,8 @@ if(CMAKE_GENERATOR STREQUAL Xcode) set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PKG_ROOT}/geometry ) endif() -copy_python_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} - PYTHON_INSTALL_FILES ) +copy_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} + PYTHON_INSTALL_FILES ) ############################################################################################# # Create the target for this directory diff --git a/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt index 4b2b707442e9af828a62590837c204608e2dc3d2..5786eecaf1dda0970fe285b9b6b3d2bb9583ab1c 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt @@ -124,8 +124,8 @@ if(CMAKE_GENERATOR STREQUAL Xcode) set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PKG_ROOT}/kernel ) endif() -copy_python_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} - PYTHON_INSTALL_FILES ) +copy_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} + PYTHON_INSTALL_FILES ) ############################################################################################# # Generate the packagesetup module for the build & install package @@ -139,8 +139,8 @@ endif() # Build version configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGESETUP_PY}.py.in ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGESETUP_PY}.py ) # Copy py to build directory, taking care of multi-config (MSVC) builds -copy_python_files_to_dir ( ${PACKAGESETUP_PY}.py ${CMAKE_CURRENT_BINARY_DIR} ${OUTPUT_DIR} - PYTHON_INSTALL_FILES ) +copy_files_to_dir ( ${PACKAGESETUP_PY}.py ${CMAKE_CURRENT_BINARY_DIR} ${OUTPUT_DIR} + PYTHON_INSTALL_FILES ) # Package version if ( WIN32 OR APPLE ) diff --git a/Code/Mantid/Framework/PythonInterface/test/testhelpers/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/test/testhelpers/CMakeLists.txt index 487f06eda1dce18305184dfd8ed90bb44b02e86a..8c15b65d9ee05111c20374bcfb153a78f187dbdc 100644 --- a/Code/Mantid/Framework/PythonInterface/test/testhelpers/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/test/testhelpers/CMakeLists.txt @@ -9,8 +9,8 @@ set ( PY_FILES # Copy python files to output directory set ( OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/testhelpers ) -copy_python_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} - PYTHON_INSTALL_FILES ) +copy_files_to_dir ( "${PY_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIR} + PYTHON_INSTALL_FILES ) ############################################################################################# # Create the targets for this directory diff --git a/Code/Mantid/MantidPlot/CMakeLists.txt b/Code/Mantid/MantidPlot/CMakeLists.txt index 7020a98b3bf66918c0ef6c23725998b9c2a315bf..e3a0adb7606078ce3d4374afe23152a119609bea 100644 --- a/Code/Mantid/MantidPlot/CMakeLists.txt +++ b/Code/Mantid/MantidPlot/CMakeLists.txt @@ -821,35 +821,50 @@ if ( APPLE ) set_source_files_properties(MANTID_RC_FILE PROPERTIES MACOSX_PACKAGE_LOCATION Resources) endif () +########################################################################### +# Config reset scripts +########################################################################### + +if ( WIN32 ) + set ( CONFIG_RESET_SCRIPT mantid_reset_settings.bat ) +else () + set ( CONFIG_RESET_SCRIPT mantid_reset_settings.sh ) +endif () + +copy_files_to_dir ( "${CONFIG_RESET_SCRIPT}" + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} + CONFIG_RESET_SCRIPT_FILE ) + ########################################################################### # Required Python config files ########################################################################### # Top-level python scripts -set( PY_FILES mantidplotrc.py mantidplot.py ) -copy_python_files_to_dir ( "${PY_FILES}" - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} - PYTHON_INSTALL_FILES ) +set( PY_FILES mantidplotrc.py mantidplot.py mantid_qt_settings_editor.py ) +copy_files_to_dir ( "${PY_FILES}" + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} + PYTHON_INSTALL_FILES ) # mantidplot.py package set( MTDPLOTPY_FILES __init__.py proxies.py ) -copy_python_files_to_dir ( "${MTDPLOTPY_FILES}" - ${CMAKE_CURRENT_SOURCE_DIR}/mantidplotpy - ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/mantidplotpy - MTDPLOT_INSTALL_FILES ) +copy_files_to_dir ( "${MTDPLOTPY_FILES}" + ${CMAKE_CURRENT_SOURCE_DIR}/mantidplotpy + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/mantidplotpy + MTDPLOT_INSTALL_FILES ) # IPython scripts set( IPY_FILES __init__.py mantid_ipython_widget.py ) -copy_python_files_to_dir ( "${IPY_FILES}" - ${CMAKE_CURRENT_SOURCE_DIR}/ipython_widget - ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/ipython_widget - IPYTHON_INSTALL_FILES ) +copy_files_to_dir ( "${IPY_FILES}" + ${CMAKE_CURRENT_SOURCE_DIR}/ipython_widget + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/ipython_widget + IPYTHON_INSTALL_FILES ) ########################################################################### # MantidPlot executable @@ -858,7 +873,7 @@ copy_python_files_to_dir ( "${IPY_FILES}" add_executable ( MantidPlot ${WIN_CONSOLE} MACOSX_BUNDLE ${ALL_SRC} src/main.cpp ${INC_FILES} ${QTIPLOT_C_SRC} ${UI_HDRS} ${RES_FILES} ${MANTID_RC_FILE} - ${PYTHON_INSTALL_FILES} ${MTDPLOT_INSTALL_FILES} ${IPYTHON_INSTALL_FILES} + ${PYTHON_INSTALL_FILES} ${MTDPLOT_INSTALL_FILES} ${IPYTHON_INSTALL_FILES} ${CONFIG_RESET_SCRIPT_FILE} ) # Library dependencies @@ -996,6 +1011,7 @@ endforeach() foreach(PY_FILE ${IPY_FILES} ) install ( FILES ipython_widget/${PY_FILE} DESTINATION ${BIN_DIR}/ipython_widget ) endforeach() +install ( FILES ${CONFIG_RESET_SCRIPT} DESTINATION ${BIN_DIR} ) if ( APPLE ) configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/FixBundle.cmake.in @@ -1005,3 +1021,4 @@ if ( APPLE ) install ( SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/FixBundle.cmake ) endif () + diff --git a/Code/Mantid/MantidPlot/mantid_qt_settings_editor.py b/Code/Mantid/MantidPlot/mantid_qt_settings_editor.py new file mode 100755 index 0000000000000000000000000000000000000000..025f05001943c9388e030180974ee58cdcba891b --- /dev/null +++ b/Code/Mantid/MantidPlot/mantid_qt_settings_editor.py @@ -0,0 +1,169 @@ +#!/usr/bin/python + +# Copyright © 2007-2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + +# This file is part of Mantid. + +# Mantid is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# Mantid 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 General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# File change history is stored at: <https://github.com/mantidproject/mantid>. +# Code Documentation is available at: <http://doxygen.mantidproject.org> + +import sys +from PyQt4.QtCore import QSettings + +try: + from argparse import ArgumentParser as Parser + have_argparse = True +except ImportError: + from optparse import OptionParser as Parser + have_argparse = False + +def print_all_keys(settings): + keys = settings.allKeys() + + if len(keys) == 0: + sys.stdout.write("No properties\n") + + for k in keys: + value = settings.value(k).toString() + if value == "": + value = "[obj]" + sys.stdout.write("%s = %s\n" % (k, value)) + +def get_verification(notify_string): + sys.stdout.write("%s\nAre you sure (y/N): " % (notify_string)) + response = raw_input(); + + if len(response) == 0: + return False + return response.upper()[0] == "Y" + +def run(props): + # Create a new Qt settings object using supplied application + # and organisation name + settings = QSettings(props.org, props.app) + + # Have the clear preferences parameter + if props.clear: + # Check if we can clear by force + ok_to_clear = props.force + # If not ask the user if we can + if not ok_to_clear: + ok_to_clear = get_verification( + "This will clear all Qt preferences for %s (by %s)" % (props.app, props.org)) + + # If so clear all Qt preferences in the selected application + # and report back unless quiet is enabled + if ok_to_clear: + settings.clear() + if not props.quiet: + sys.stdout.write("Qt preferences cleared\n") + else: + if not props.quiet: + sys.stdout.write("Qt preferences not cleared\n") + + # Have the set preference parameter + if props.set != None: + # Input data is in the form k=v, split this into a list of k and v + data = props.set.split("=") + + # Check if we can set by force + ok_to_set = props["force"] + # If not ask the user if we can + if not ok_to_set: + ok_to_set = get_verification( + "This will set Qt preference %s to %s for %s (by %s)" % + (data[0], data[1], props.app, props.org)) + + if ok_to_set: + settings.setValue(data[0], data[1]) + if not props.quiet: + sys.stdout.write("Set preference %s to %s\n" % (data[0], data[1])) + else: + if not props.quiet: + sys.stdout.write("Preference not set\n") + + # Have the list all preferences parameter + if props.list and not props.quiet: + sys.stdout.write("All Keys:\n") + print_all_keys(settings) + +if __name__ == "__main__": + parser = Parser( + description="Tool to modify Qt preferences for MantidPlot (or any other Qt application)" + ) + + if have_argparse: + add_arg = parser.add_argument + else: + add_arg = parser.add_option + + add_arg( + '-c', '--clear', + action='store_true', + help="Clears all Qt settings" + ) + + add_arg( + '-s', '--set', + action='store', + metavar='PROPERTY=VALUE', + help="Sets a Qt property" + ) + + add_arg( + '-l', '--list', + action='store_true', + help="Lists all Qt properties and their values" + ) + + add_arg( + '-f', '--force', + action='store_true', + help="Will not ask for permission to do destructive tasks" + ) + + add_arg( + '-q', '--quiet', + action='store_true', + help="Will not print to stdout" + ) + + add_arg( + '-o', '--org', + action='store', + default='Mantid', + metavar='ORGANISATION', + help='Organisation name to pass to QSettings' + ) + + add_arg( + '-a', '--app', + action='store', + default='MantidPlot', + metavar='APPLICATION', + help='Application name to pass to QSettings' + ) + + if have_argparse: + props = parser.parse_args() + else: + (props, extra_args) = parser.parse_args() + + # Check not run with no command parameters + if props.set == None and not props.clear and not props.list: + parser.print_usage() + else: + run(props) diff --git a/Code/Mantid/MantidPlot/mantid_reset_settings.bat b/Code/Mantid/MantidPlot/mantid_reset_settings.bat new file mode 100755 index 0000000000000000000000000000000000000000..78784fc89a0f57804c57e51a0ea521441c9157f7 --- /dev/null +++ b/Code/Mantid/MantidPlot/mantid_reset_settings.bat @@ -0,0 +1,27 @@ +:: Copyright © 2007-2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + +:: This file is part of Mantid. + +:: Mantid is free software; you can redistribute it and/or modify +:: it under the terms of the GNU General Public License as published by +:: the Free Software Foundation; either version 3 of the License, or +:: (at your option) any later version. + +:: Mantid 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 General Public License for more details. + +:: You should have received a copy of the GNU General Public License +:: along with this program. If not, see <http://www.gnu.org/licenses/>. + +:: File change history is stored at: <https://github.com/mantidproject/mantid>. +:: Code Documentation is available at: <http://doxygen.mantidproject.org> + +@echo off + +set pref_file=Mantid.user.properties + +if exist %pref_file%. del %pref_file%. else echo %pref_file% not found + +python.exe mantid_qt_settings_editor.py -fc diff --git a/Code/Mantid/MantidPlot/mantid_reset_settings.sh b/Code/Mantid/MantidPlot/mantid_reset_settings.sh new file mode 100755 index 0000000000000000000000000000000000000000..3fb6e2f60181de6eec80603e84862c43ac32e675 --- /dev/null +++ b/Code/Mantid/MantidPlot/mantid_reset_settings.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright © 2007-2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + +# This file is part of Mantid. + +# Mantid is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# Mantid 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 General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# File change history is stored at: <https://github.com/mantidproject/mantid>. +# Code Documentation is available at: <http://doxygen.mantidproject.org> + +pref_file=~/.mantid/Mantid.user.properties + +# If the user properties file exists then remove it +if [ -f $pref_file ] +then + echo "Removing "$pref_file + rm $pref_file +else + echo $pref_file" not found" +fi + +# Remove all Qt preferences for MantidPlot +python ./mantid_qt_settings_editor.py -fc