def export_data(self): _filename = self.filename if _filename == '': return _output_text = self.output_text _o_file = FileHandler(filename=_filename) _o_file.create_ascii(contain=_output_text)
def display_dialog(self): try: # if extension is csv, use ascii loader if FileHandler.is_file_correct_extension( filename=self.filename, ext_requested='csv'): # ascii file o_loader = AsciiLoader(parent=self.parent, filename=self.filename) o_loader.show_dialog() # json file elif FileHandler.is_file_correct_extension(filename=self.filename, ext_requested='json'): o_loader = JsonLoader(parent=self.parent, filename=self.filename) o_loader.load() else: raise IOError("File format not supported for {}!".format( self.filename)) self.parent.check_master_table_column_highlighting() except ValueError: self.parent.ui.statusbar.setStyleSheet("color: red") self.parent.ui.statusbar.showMessage( "Unable to load configuration file {}!".format(self.filename), self.parent.statusbar_display_time) except TypeError: self.parent.ui.statusbar.setStyleSheet("color: red") self.parent.ui.statusbar.showMessage( "Error while trying to load file {}!".format(self.filename), self.parent.statusbar_display_time)
def save_settings(self): _output_filename = self.filename configuration = self.configuration o_file_handler = FileHandler(filename=_output_filename) o_file_handler.create_config_parser( section_name=self.parent.config_section_name, dictionary=configuration)
def load(self): # options selected by user options = self.parent.ascii_loader_option if options is None: return filename = self.filename o_file = FileHandler(filename=filename) o_table = o_file.csv_parser() list_runs = o_table['#Scan'] list_titles = o_table['title'] o_format = FormatAsciiList(list1=list_runs, list2=list_titles) # option 1 # keep raw title and merge lines with exact same title if options == 1: o_format.option1() # option 2 # remove temperature part of title and merge lines with exact same # title elif options == 2: o_format.option2() # option 3 # keep raw title, append run number elif options == 3: o_format.option3() # option 4 # take raw title, remove temperature part, add run number elif options == 4: o_format.option4() else: raise ValueError("Options nos implemented yet!") list_runs = o_format.new_list1 list_titles = o_format.new_list2 _table_dictionary = {} runs_titles = zip(list_runs, list_titles) _index = 0 for [_run, _title] in runs_titles: _entry = copy.deepcopy(_default_empty_row) _entry['title'] = str(_title) _entry['sample']['runs'] = str(_run) _table_dictionary[_index] = _entry _index += 1 self.table_dictionary = _table_dictionary self.parent.ascii_loader_dictionary = _table_dictionary o_table_ui_loader = FromDictionaryToTableUi(parent=self.parent) o_table_ui_loader.fill(input_dictionary=_table_dictionary) self.parent.ui.statusbar.setStyleSheet("color: blue") self.parent.ui.statusbar.showMessage( "File {} has been imported".format(self.filename), self.parent.statusbar_display_time)
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 is_sum_inp_file_not_empty(self): full_output_file_name = os.path.join(self.folder, self.output_inp_file) _o_file = FileHandler(filename=full_output_file_name) _o_file.retrieve_contain() _file_contain = _o_file.file_contain if len(_file_contain) == 12: return False return True
def open_output_file_if_writable(self, full_output_file_name): _o_file = FileHandler(filename=full_output_file_name) if _o_file.is_file_writable(): outfile = open(full_output_file_name, "w") else: title = "No write permissions!" error_msg = "Unable to write cached table. " + \ "Will not be able to write output files to this directory. " + \ "\n\nCheck file and directory for write permissions!" QMessageBox.warning(self.parent, title, error_msg) outfile = None return outfile
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 save_as_clicked(self): _current_folder = self.parent.current_folder _python_file = QFileDialog.getSaveFileName( parent=self.parent, caption="Output File Name", directory=_current_folder, filter=("python (*.py);; All Files (*.*)")) if not _python_file: return if isinstance(_python_file, tuple): _python_file = _python_file[0] _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 browse_file(self): _ascii_file = QFileDialog.getOpenFileName(parent=self.parent_no_ui, caption='Select file to display', directory=self.current_folder) if not _ascii_file: return if isinstance(_ascii_file, tuple): _ascii_file = _ascii_file[0] _ascii_file = str(_ascii_file) o_file_handler = FileHandler(filename=_ascii_file) o_file_handler.retrieve_contain() text_contain = o_file_handler.file_contain o_preview = PreviewAsciiWindow(parent=self.parent_no_ui, text=text_contain, filename=_ascii_file) o_preview.show()
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 _export(self): _current_folder = self.parent_no_ui.current_folder _table_file = QFileDialog.getSaveFileName( parent=self.parent_no_ui, caption="Select File", directory=_current_folder, filter=("text (*.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_no_ui, filename=_table_file) _export_handler.run()
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 _get_text(self, filename=None): _file_handler = FileHandler(filename=filename) _file_handler.retrieve_contain() return _file_handler.file_contain
def run(self): o_file = FileHandler(filename=self.full_file_name) o_file.retrieve_contain() _file_contrain = o_file.file_contain self.retrieve_settings(_file_contrain)
def load_ascii(self): _filename = self.filename o_file = FileHandler(filename=_filename) o_file.retrieve_contain() self.file_contain = o_file.file_contain
def save_settings(self): _output_filename = self.filename configuration = self.configuration o_file_handler = FileHandler(filename=_output_filename) o_file_handler.create_config_parser(section_name=self.parent.config_section_name, dictionary=configuration)