def open_data_files(self, file_names=None): """ Analyzes the files for correctness, then adds them to the list widget. :param ListType<StringType> file_names: The file names to be included in the list widget. If not included, this function will use a QtGui.QFileDialog.getOpenFileNames to open files. :returns: BooleanType -- **True** if files were opened, **False** otherwise. """ if file_names is None: file_names = QtGui.QFileDialog.getOpenFileNames( self, 'Open data file', '.', "All types(*.h5 *.hkd *.log *.mat);;" "Pypore data files *.h5(*.h5);;" "Heka files *.hkd(*.hkd);;" "Chimera files *.log(*.log);;Gabys files *.mat(*.mat)")[0] if len(file_names) > 0: self.file_list_widget.clear() else: return are_files_opened = False open_dir = None for w in file_names: reader = get_reader_from_filename(w) # if 'error' in params: # TODO implement error handling in readers # pass # else: reader.close() are_files_opened = True item = FileListItem(w) open_dir = item.get_directory() self.file_list_widget.addItem(item) return are_files_opened
class TestFileListItem(unittest.TestCase): def setUp(self): self.filename = os.path.abspath('hi.txt') self._set_item() def _set_item(self): self.item = FileListItem(self.filename) def tearDown(self): pass def test_file_list_item_simple_name(self): simple_name = self.item.get_simple_name() self.assertEqual(simple_name, 'hi.txt') def test_file_list_item_directory(self): directory = self.item.get_directory() self.assertEqual(directory, os.path.dirname(self.filename)) def test_file_list_item_filename(self): check = self.item.get_file_name() self.assertEqual(check, self.filename)
def open_data_files(self, file_names=None): """ Analyzes the files for correctness, then adds them to the list widget. :param ListType<StringType> file_names: The file names to be included in the list widget. If not included, this function will use a QtGui.QFileDialog.getOpenFileNames to open files. :returns: BooleanType -- **True** if files were opened, **False** otherwise. """ if file_names is None: file_names = QtGui.QFileDialog.getOpenFileNames(self, 'Open data file', '.', "All types(*.h5 *.hkd *.log *.mat);;" "Pypore data files *.h5(*.h5);;" "Heka files *.hkd(*.hkd);;" "Chimera files *.log(*.log);;Gabys files *.mat(*.mat)")[0] if len(file_names) > 0: self.file_list_widget.clear() else: return are_files_opened = False open_dir = None for w in file_names: reader = get_reader_from_filename(w) # if 'error' in params: # TODO implement error handling in readers # pass # else: reader.close() are_files_opened = True item = FileListItem(w) open_dir = item.get_directory() self.file_list_widget.addItem(item) return are_files_opened
def open_event_databases(self, file_names=None): """ Adds the files to the list widget. :param ListType<StringType> file_names: (Optional) List of file names to be added to the list widget. If not included, then a QtGui.QFileDialog will be opened to select files. """ if file_names is None: file_names = QtGui.QFileDialog.getOpenFileNames( self, 'Open event database', '.', '*.h5')[0] if len(file_names) > 0: self.eventview_list_widget.clear() else: return for w in file_names: item = FileListItem(w) self.eventview_list_widget.addItem(item)
def _set_item(self): self.item = FileListItem(self.filename)