def request_config_file_name(self, open_flag=True): _caption = 'Select or Define a Configuration File Name' _current_folder = self.parent.configuration_folder if open_flag: _file = QFileDialog.getOpenFileName(parent=self.parent, filter='config (*.cfg)', caption=_caption, directory=_current_folder) if isinstance(_file, tuple): _file = _file[0] else: _file, _ = get_save_file(parent=self.parent, filter={'config (*.cfg)':'cfg'}, caption=_caption, directory=_current_folder) if not _file: self.filename = '' return _new_path = os.path.dirname(_file) self.parent.configuration_folder = _new_path o_file_handler = FileHandler(filename=_file) o_file_handler.check_file_extension(ext_requested='cfg') self.filename = o_file_handler.filename
def save_as_clicked(self): _current_folder = self.parent.current_folder _python_file, _ = get_save_file(parent=self.parent, caption='Output File Name', directory=_current_folder, filter={'python (*.py)':'py', 'All Files (*.*)':''}) if not _python_file: return _script = str(self.ui.preview_mantid_script_textedit.toPlainText()) o_file_handler = FileHandler(filename=_python_file) o_file_handler.create_ascii(contain=_script, carriage_return=False)
def run_calibration_button_clicked(self): # make dictionary of all infos o_dict = MakeCalibrationDictionary(parent=self) _file, _ = get_save_file( parent=self, caption="Select where and name of json file to create...", # directory = '/SNS/users/ntm/', filter={'json (*.json)': 'json'}) if _file: with open(_file, 'w') as fp: simplejson.dump(o_dict.dictionary, fp, indent=2, ignore_nan=True)
def _export(self): _current_folder = self.main_window.current_folder _table_file, _ = get_save_file(parent=self.main_window, caption="Select File", directory=_current_folder, filter={'text (*.txt)':'txt', 'All Files (*.*)':''}) if not _table_file: return if isinstance(_table_file, tuple): _table_file = _table_file[0] _file_handler = FileHandler(filename=_table_file) _file_handler.check_file_extension(ext_requested='txt') _table_file = _file_handler.filename _export_handler = ExportTable(parent=self.main_window, filename=_table_file) _export_handler.run()
def do_save_gr(main_window): """ Save the selected the G(r) from menu to ASCII file """ # read the selected item from the tree gr_list = main_window.calculategr_ui.treeWidget_grWsList gr_name_list = gr_list.get_selected_items_of_level(2, excluded_parent='SofQ', return_item_text=True) if len(gr_name_list) != 1: err_msg = 'ERROR: Only 1 workspace of G(r) can be selected.' err_msg += '{0} are selected.\n Selection: {1}' err_msg = err_msg.format(len(gr_name_list), str(gr_name_list)) QMessageBox.warning(main_window, 'Error', err_msg) return else: gr_ws_name = gr_name_list[0] # pop-up a dialog for the file to save default_dir = os.getcwd() caption = 'Save G(r)' FILE_FILTERS = { 'PDFgui (*.gr)': 'gr', 'XYE (*.xye)': 'xye', 'CSV XYE (*.csv)': 'csv', 'RMCProfile (*.dat)': 'dat' } filename, filetype = get_save_file(parent=main_window, directory=default_dir, caption=caption, filter=FILE_FILTERS) if not filename: # user pressed cancel return if filetype == 'dat': filetype = 'rmcprofile' # save! main_window._myController.save_ascii(gr_ws_name, filename, filetype)
def do_merge_to_gss(self): """ Merge a selected GSAS workspace (with split workspaces) to a new GSAS file """ # check prerequisite assert self._main_window is not None, 'Main window is not set up.' # get the selected GSAS node's name status, ret_obj = self.get_current_main_nodes() if not status: print('[Error] Get current main nodes: %s.' % str(ret_obj)) return gss_node_list = ret_obj if len(gss_node_list) == 0: return elif len(gss_node_list) > 1: msg = '[Error] Only 1 GSS node can be selected.' msg += 'Current selected nodes are {}.' print(msg.format(gss_node_list)) return # pop-out a file dialog for GSAS file's name file_ext = {'GSAS File (*.gsa)': 'gsa', 'Any File (*.*)': ''} new_gss_file_name, _ = get_save_file( self, caption='New GSAS file name', directory=self._main_window.get_default_data_dir(), filter=file_ext) if not new_gss_file_name: # user pressed cancel return # emit the signal to the main window selected_node = self.get_selected_items()[0] bank_ws_list = self.get_child_nodes(selected_node, output_str=True) # write all the banks to a GSAS file self._main_window.get_workflow().write_gss_file( ws_name_list=bank_ws_list, gss_file_name=new_gss_file_name)
def _export(self): _current_folder = self.parent.current_folder _table_file, _ = get_save_file(parent=self.parent, caption="Select File", directory=_current_folder, filter={ 'text (*.txt)': 'txt', 'All Files (*.*)': '' }) if not _table_file: return if isinstance(_table_file, tuple): _table_file = _table_file[0] _file_handler = FileHandler(filename=_table_file) _file_handler.check_file_extension(ext_requested='txt') _table_file = _file_handler.filename _export_handler = ExportTable(parent=self.parent, filename=_table_file) _export_handler.run()
def do_merge_to_gss(self): """ Merge a selected GSAS workspace (with split workspaces) to a new GSAS file Returns: """ # check prerequisite assert self._mainWindow is not None, 'Main window is not set up.' # get the selected GSAS node's name status, ret_obj = self.get_current_main_nodes() if not status: print('[Error] Get current main nodes: %s.' % str(ret_obj)) return gss_node_list = ret_obj if len(gss_node_list) == 0: return elif len(gss_node_list) > 1: print('[Error] Only 1 GSS node can be selected. Current selected nodes are %s.' % str(gss_node_list)) return # pop-out a file dialog for GSAS file's name file_ext = {'GSAS File (*.gsa)':'gsa', 'Any File (*.*)':''} new_gss_file_name, _ = get_save_file(parent=self, caption='New GSAS file name', directory=self._mainWindow.get_default_data_dir(), filter=file_ext) if not new_gss_file_name: # user pressed cancel return # emit the signal to the main window selected_node = self.get_selected_items()[0] bank_ws_list = self.get_child_nodes(selected_node, output_str=True) #out_gss_ws = os.path.basename(new_gss_file_name).split('.')[0] # write all the banks to a GSAS file self._mainWindow.get_workflow().write_gss_file(ws_name_list=bank_ws_list, gss_file_name=new_gss_file_name) return
def do_save_sq(main_window): """Save the selected the G(r) from menu to ASCII file :return: """ # TEST/ISSUE/NOW - Test! # read the selected item from the tree... return if nothing is selected gr_list = main_window.calculategr_ui.treeWidget_grWsList sq_name_list = gr_list.get_selected_items_of_level(2, excluded_parent='GofR', return_item_text=True) if len(sq_name_list) == 0: # show dialog message here. o_dialog = SaveSqDialogMessageDialog(main_window=main_window) o_dialog.show() FILE_FILTERS = { 'XYE (*.xye)': 'xye', 'CSV XYE (*.csv)': 'csv', 'SofQ (*.sq)': 'sq' } # used to support .dat extension, but save_ascii assumes rmcprofile file # loop the SofQ name to save for sq_name in sq_name_list: # get the output file name first filename, filetype = get_save_file( parent=main_window, directory=main_window._currWorkDir, caption='Input File Name to Save S(Q) {0}'.format(sq_name), filter=FILE_FILTERS) if not filename: # skip if the user cancel the operation on this S(Q) continue # save file main_window._myController.save_ascii(sq_name, filename, filetype)