def view_closing(self): """ Saves the mantid settings and updates updates the parent """ if not self.ask_before_close or self.view.ask_before_close(): ConfigService.saveConfig(ConfigService.getUserFilename()) self.parent.config_updated() self.view.close() return True else: #try to stop the close aation return False
def view_closing(self): """ Saves the mantid settings and updates updates the parent """ if not self.ask_before_close or self.view.ask_before_close(): ConfigService.saveConfig(ConfigService.getUserFilename()) self.parent.config_updated() self.view.close() if self.changes_that_need_restart: self.view.notify_changes_need_restart( self.changes_that_need_restart) return True else: # try to stop the close action return False
def _handle_browse(self): # Add Error handling search_directories = ConfigService.Instance().getDataSearchDirs() file_paths = self.view.show_file_picker(RunSelectorPresenter.file_extensions, search_directories) self._add_runs(self.find_from_file_path(file_path) for file_path in file_paths) self._refresh()
def save_settings_to_file(filepath, settings): with open(filepath, 'w') as file: for setting in settings: if CONF.has(setting): if setting != GeneralProperties.USER_LAYOUT.value: value = CONF.get(setting, type=str) else: value = ConfigService.getString(setting) file.write(setting + '=' + str(value) + '\n')
def load_settings_from_file(filepath, settings): with open(filepath, 'r') as file: line = file.readline() while line: setting = line.rstrip('\n').split('=', 1) prop = setting[0].strip() if prop in settings: if CONF.has(prop) or prop.find('/') != -1: if prop == GeneralProperties.USER_LAYOUT.value: pass elif prop == GeneralProperties.FONT.value and not setting[1]: # if the font setting is empty removing it will make workbench use the default CONF.remove(prop) else: try: value = ast.literal_eval(setting[1]) except (SyntaxError, ValueError): value = setting[1] CONF.set(setting[0].strip(), value) else: ConfigService.setString(prop, setting[1]) line = file.readline()
def archive_search(): DEFAULT_FACILITY = 'default.facility' DEFAULT_INSTRUMENT = 'default.instrument' SEARCH_ARCHIVE = 'datasearch.searcharchive' HFIR = 'HFIR' HB2B = 'HB2B' # get the old values config = ConfigService.Instance() old_config = {} for property_name in [ DEFAULT_FACILITY, DEFAULT_INSTRUMENT, SEARCH_ARCHIVE ]: old_config[property_name] = config[property_name] # don't update things that are already set correctly if config[DEFAULT_FACILITY] == HFIR: del old_config[DEFAULT_FACILITY] else: config[DEFAULT_FACILITY] = HFIR if config[DEFAULT_INSTRUMENT] == HB2B: del old_config[DEFAULT_INSTRUMENT] else: config[DEFAULT_INSTRUMENT] = HB2B if HFIR in config[SEARCH_ARCHIVE]: del old_config[SEARCH_ARCHIVE] else: config[SEARCH_ARCHIVE] = HFIR try: # give back context yield finally: # set properties back to original values for property_name in old_config.keys(): config[property_name] = old_config[property_name]
def runTest(self): ConfigService.Instance().setString("default.instrument", "INTER") Load(self.runs_file, OutputWorkspace=self.runs_workspace) CreateTransmissionWorkspaces(self.transmission_run_names[0], self.transmission_run_names[1], scale=False) workspaces_to_exclude_from_result = AnalysisDataService.Instance( ).getObjectNames() stitched_name = StitchedTransmissionWorkspaceName( self.transmission_run_names[0], self.transmission_run_names[1]) Stitch1D(LHSWorkspace=TransmissionWorkspaceName( self.transmission_run_names[0]), RHSWorkspace=TransmissionWorkspaceName( self.transmission_run_names[1]), StartOverlap=10, EndOverlap=12, ScaleRHSWorkspace=False, OutputWorkspace=stitched_name) AutoReduce([stitched_name, stitched_name], self.run_numbers) RemoveWorkspaces(workspaces_to_exclude_from_result) GroupWorkspaces( InputWorkspaces=AnalysisDataService.Instance().getObjectNames(), OutputWorkspace=self.result_workspace) mtd[self.result_workspace].sortByName()
def action_save_settings_to_file(self): ConfigService.saveConfig(ConfigService.getUserFilename()) filepath = self.view.get_properties_filename( accept_mode=QFileDialog.AcceptSave, file_mode=QFileDialog.AnyFile) if filepath: self.model.save_settings_to_file(filepath, self.all_properties)
def action_peak_added(self, function_name, set_global_default=False): self.peak_type_changed.emit(function_name) self.mouse_state.transition_to('add_peak') if set_global_default: ConfigService.setString('curvefitting.defaultPeak', function_name)
def action_save_settings_button(self): if not self.ask_before_close or self.view.ask_before_close(): ConfigService.saveConfig(ConfigService.getUserFilename()) self.parent.config_updated() self.view.close()
# Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI, # NScD Oak Ridge National Laboratory, European Spallation Source, # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # SPDX - License - Identifier: GPL - 3.0 + # This file is part of the mantid workbench. import functools from qtpy.QtWidgets import QMenu, QMessageBox from os.path import join, exists from mantid import ConfigService from mantidqt.utils.qt import create_action from workbench.config import CONF RECENT_SCRIPT_MAX_NUMBER = 10 CACHE_FILE_NAME = "recent_script_file" MENU_CACHE_LOCATION = join(ConfigService.getAppDataDirectory(), CACHE_FILE_NAME) RECENT_SCRIPTS_KEY = "RecentScripts" class RecentlyClosedScriptsMenu(QMenu): def __init__(self, mainwindow): super(RecentlyClosedScriptsMenu, self).__init__() self.setTitle("Open Recently Closed Scripts") self.aboutToShow.connect(self.repopulate_menu) self.mainwindow = mainwindow def repopulate_menu(self): self.clear() self.populate_menu()
import mantidplottests import os import platform import unittest import mantidplot from mantidplottests import runTests, threadsafe_call from glob import glob #from mantid.kernel import * from mantid import AnalysisDataService, ConfigService from mantid.simpleapi import CreateWorkspace from PyQt4 import QtGui import shutil import _qti path = os.path.join(ConfigService.getAppDataDirectory(), 'recovery', platform.node()) def cleanUp(): # Clean Up for cc in glob(os.path.join(path, "*", "")): shutil.rmtree(cc) AnalysisDataService.clear() class MantidPlotProjectRecovery(unittest.TestCase): def test_exec(self): CreateWorkspace(OutputWorkspace="ws", DataX=[1, 2, 3], DataY=[1, 2, 3], NSpec=1)
def setupInstrument(): configI = ConfigService.Instance() configI.setString("default.instrument", "INTER") configI.setString("default.facility", "ISIS")