def open_file(self): filename = UIUtils.open_file('Select trs file', [UIUtils.TRS_FILE_FILTER, UIUtils.ALL_FILE_FILTER]) if filename: progress_dialog = ProgressDialog('Processing File...', ['Parsing trs file...', 'Validating data...', 'Building UI...']) progress_dialog.show() VerificationWindow(filename, progress_dialog)
def open_file(self): filename = UIUtils.open_file( 'Select trs file', [UIUtils.TRS_FILE_FILTER, UIUtils.ALL_FILE_FILTER]) if filename: progress_dialog = ProgressDialog('Processing File...', ['Parsing trs file...']) progress_dialog.show() FreqWindow(filename, progress_dialog)
def _get_wav_filename(self): wav_filename = None #try to find a wav file with the same name as the csv file if self.csv_filename.lower().endswith('.csv'): default_filename = self.csv_filename[:-3] + 'wav' if os.path.exists(default_filename): wav_filename = default_filename #if the above didn't succeed, prompt the user for a filename if not wav_filename: wav_filename = UIUtils.open_file(title='Select wav file', filters=[UIUtils.WAV_FILE_FILTER, UIUtils.ALL_FILE_FILTER]) return wav_filename
def __init__(self): self.window = gtk.Window(gtk.WindowType.TOPLEVEL) self.window.set_title('Data Viewer') self.window.connect('destroy', lambda w: self._clean_up()) self.window.set_border_width(10) self.window.set_default_size(800, 600) self.logger = logging.getLogger(__name__) self.csv_filename = UIUtils.open_file('Select csv file', filters=[UIUtils.CSV_FILE_FILTER, UIUtils.ALL_FILE_FILTER]) self.window.set_title('%s - %s' % (self.window.get_title(), os.path.basename(self.csv_filename))) if not self.csv_filename: exit(0) self.wav_filename = self._get_wav_filename() self.wav_parser = None if self.wav_filename: self.wav_parser = WavParser(self.wav_filename) # if not self.wav_filename: # exit(0) self.sound_col_fcns = None col_datatypes, col_headers = self._get_col_info() db = self._build_db(col_datatypes, col_headers) model = self._get_model(col_datatypes) treeview = self._get_treeview(model, col_headers, db) self.filters = [] self.where_cond = None self.where_params = [] self.sort_order = None self.sort_col = None self._populate_model(db, model) toolbar = self._build_toolbar(db, treeview, col_headers) scrolled_win = gtk.ScrolledWindow() scrolled_win.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC) scrolled_win.add(treeview) vbox = gtk.VBox() vbox.pack_start(toolbar, False, False, 0) vbox.pack_start(scrolled_win, True, True, 0) self.window.add(vbox) self.window.show_all()
def split_file(self): filename = UIUtils.open_file( 'Select trs file', [UIUtils.TRS_FILE_FILTER, UIUtils.ALL_FILE_FILTER]) dest_folder = None if filename: dialog = gtk.FileChooserDialog( title='Select Folder for Split Files', action=gtk.FileChooserAction.SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, gtk.STOCK_OPEN, gtk.ResponseType.OK)) dialog.set_default_response(gtk.ResponseType.OK) response = dialog.run() if response == gtk.ResponseType.OK: dest_folder = dialog.get_filename() OptionsWindow(filename, dest_folder) dialog.destroy()
def open_file(self): self.filename = UIUtils.open_file('Select its file', [UIUtils.ITS_FILE_FILTER, UIUtils.ALL_FILE_FILTER]) self.xmlParser = XMLParser2(self.filename)
def run(self): csv_path = self.csv_entry.get_text() wav_path = self.wav_entry.get_text() blocks_per_activity = self.blocks_spinner.get_value_as_int() activities = [] if self.acts_treeview and self.acts_treeview.get_selection(): model, sel_paths = self.acts_treeview.get_selection( ).get_selected_rows() for path in sel_paths: it = model.get_iter(path) activities.append(model.get_value(it, 0)) environments = [] if self.envs_treeview and self.envs_treeview.get_selection(): model, sel_paths = self.envs_treeview.get_selection( ).get_selected_rows() for path in sel_paths: it = model.get_iter(path) environments.append(model.get_value(it, 0)) is_valid = csv_path and wav_path and blocks_per_activity and len( activities) and len(environments) if is_valid: check2 = Check2( csv_path, wav_path, activities, environments, blocks_per_activity, ) sel_test2s = None enough_blocks, counts_str = self.parser.have_enough_blocks( check2, False) if enough_blocks: print counts_str sel_test2s = self.parser.pick_rows( check2, lambda filename: UIUtils.open_file( 'Please locate %s' % (filename), filters=[UIUtils.WAV_FILE_FILTER], save_last_location=True, cur_location=wav_path), False) else: enough_blocks, counts_str = self.parser.have_enough_blocks( check2, True) if enough_blocks: print counts_str if UIUtils.show_confirm_dialog( 'There are not enough unused rows left for some activities (see command window for row counts). If you proceed, the same row will be selected twice. Ok to continue?' ): sel_test2s = self.parser.pick_rows( check2, lambda filename: UIUtils.open_file( 'Please locate %s' % (filename), filters=[UIUtils.WAV_FILE_FILTER], save_last_location=True, cur_location=wav_path), True) else: print counts_str UIUtils.show_message_dialog( 'The input file does not contain enough blocks of the specified types. Please refer to the command window for a printout of the activity counts.' ) if sel_test2s: progress_dialog = ProgressDialog(title='Setting up...', phases=['']) progress_dialog.show() db = BLLDatabase() check2.db_insert(db) check2.test2s = sel_test2s for i in range(len(check2.test2s)): test2 = check2.test2s[i] test2.check2_id = check2.db_id test2.db_insert(db) progress_dialog.set_fraction( float(i + 1) / float(len(check2.test2s))) db.close() progress_dialog.ensure_finish() TestWindow(check2) if self.parser: self.parser.close() self.window.destroy() else: UIUtils.show_empty_form_dialog()
def main(): filename = UIUtils.open_file( title='Select _all.txt File', filters=[UIUtils.build_file_filter('_all.txt', '_all.txt')]) if not filename: exit() try: input_file = open(filename) except Exception as e: print 'Unable to open _all.txt file, exiting.' print 'Exception info: %s' % (e) reader = csv.reader(input_file, delimiter='\t') try: headers = reader.next() line = reader.next() except StopIteration: input_file.close() exit() filename_col = -1 i = 0 while i < len(headers) and filename_col < 0: if headers[i].lower() == 'file_name': filename_col = i i += 1 if filename_col < 0: print 'Unable to locate "File_Name" column in _all.txt, exiting.' input_file.close() exit() absent_wavs = [] script_dir = re.match(r'^(.+\\)_all\.txt$', filename).groups()[0] present_files = glob.glob(script_dir + '*.wav') #note: this is case insensitive present_dict = dict(zip(present_files, [True] * len(present_files))) while line: wav_name = script_dir + line[filename_col][:-3] + 'wav' if not wav_name in present_dict: absent_wavs.append(wav_name) present_dict[wav_name] = True try: line = reader.next() except StopIteration: line = None if absent_wavs: print 'The following wav files are needed to run the praat script on _all.txt:' i = 0 while i < len(absent_wavs): short_name = re.match(r'^.+\\([^\\]+\.wav)$', absent_wavs[i]).groups()[0] print '%d: %s' % (i + 1, short_name) i += 1 print '' else: print 'All of the required wav files are present.' input_file.close()