def populate_filter_table(self): """Populates the table with save files transcriptions.""" self.converter.data.transcriptions = list() self.converter.components.filter_table.clear_table() LOG_SESSION.info(f"Populating table from Project: {self.project_name}") for i, word in enumerate(self.save_data['words']): self.converter.data.transcriptions.append( Transcription( index=i, transcription=word['transcription'], translation=word['translation'][0], image=word.get('image')[0] if word.get('image') else '', media=word.get('audio')[0] if word.get('audio') else '')) if word.get('audio'): # An audio file exists, add it. self.converter.data.transcriptions[i].set_blank_sample() self.converter.data.transcriptions[i].sample.set_sample( word.get('audio')[0]) # Populate table with data for n in range(len(self.save_data['words'])): self.converter.components.filter_table.add_blank_row() self.converter.components.filter_table.populate_table( self.converter.data.transcriptions) # Update user on save success in status bar. self.converter.components.status_bar.clearMessage() self.converter.components.status_bar.showMessage( f"Project loaded: {self.project_name}", 10000) LOG_SESSION.info( f"Table populated with {len(self.save_data['words'])} transcriptions." )
def extract_transcriptions(transcription_tier: str, components: ConverterComponents, data: ConverterData, audio_file) -> List[Transcription]: completed_count = 0 elan_transcriptions = data.eaf_object.get_annotation_data_for_tier(transcription_tier) components.status_bar.showMessage('Processing transcriptions...') transcription_count = len(elan_transcriptions) transcriptions = [] for index in range(transcription_count): components.progress_bar.update_progress(completed_count / transcription_count) transcription = Transcription(index=index, transcription=elan_transcriptions[index][2], start=int(elan_transcriptions[index][0]), end=int(elan_transcriptions[index][1]), media=audio_file) transcription.translation = match_translations(transcription, data.translations) transcriptions.append(transcription) completed_count += 1 components.progress_bar.hide() return transcriptions
def exec_open(self): """Execs open functionality. Assumes that a file has been successfully found by user.""" if self.template_type: with open(self.template_name, 'r') as f: loaded_data = json.loads(f.read()) self.session_log.info(f"Data loaded: {loaded_data}") else: with open(self.session_filename, 'r') as f: loaded_data = json.loads(f.read()) self.session_log.info(f"Data loaded: {loaded_data}") # Populate manifest in converter data self.populate_initial_lmf_fields(loaded_data) # Add transcriptions self.converter.data.transcriptions = list() self.converter.components.filter_table.clear_table() for i, word in enumerate(loaded_data['words']): self.converter.data.transcriptions.append( Transcription( index=i, transcription=word['transcription'], translation=word['translation'][0], image=word.get('image')[0] if word.get('image') else '', media=word.get('audio')[0] if word.get('audio') else '')) if word.get('audio'): # An audio file exists, add it. self.converter.data.transcriptions[i].set_blank_sample() self.converter.data.transcriptions[i].sample.set_sample( word.get('audio')[0]) self.session_log.info( f"Transcription loaded: {self.converter.data.transcriptions[i]}" ) # Populate table, add an extra blank row for convenience at end. for n in range(len(loaded_data['words']) + 1): self.converter.components.filter_table.add_blank_row() self.converter.components.filter_table.populate_table( self.converter.data.transcriptions) # Clear Export Location for a fresh session self.converter.data.export_location = None # Update user on save success in status bar. self.converter.components.status_bar.clearMessage() if self.template_type: self.converter.components.status_bar.showMessage( f"Data opened from: {self.template_name}", 5000) else: self.converter.components.status_bar.showMessage( f"Data opened from: {self.session_filename}", 5000)
def match_translations(transcription: Transcription, translations: List[Translation]) -> Union[None, str]: for translation in translations: if transcription.time_matches_translation(translation): return translation.translation return None
def add_blank_row(self): new_row_index = self.table.rowCount() self.table.insertRow(new_row_index) self.data.transcriptions.append( Transcription(index=new_row_index, transcription="")) self.populate_table_row(self.table.rowCount() - 1)
def load_third_stage_widgets(self, components: ConverterComponents, data: ConverterData) -> None: """Third stage widgets constructs main filter table for user input, image upload, audio recording. Export Button will be disabled until export location is set for export. At this stage, main menu functionality is fully activated, and the autosave thread starts. Starting from scratch loads this section as a first step. """ if self.data.mode == OperationMode.ELAN: data.audio_file = get_audio_file(self.data) transcription_tier = components.tier_selector.get_transcription_tier( ) translation_tier = components.tier_selector.get_translation_tier() extract_elan_data(transcription_tier, translation_tier, self.data, components) else: self.components.mode_select.hide() self.data.transcriptions.append( Transcription(index=0, transcription="")) # Sixth Row (Filter & Selector) self.components.filter_table = FilterTable(self.data, self.components.status_bar, self.settings) self.layout.addWidget(self.components.filter_table, 2, 0, 1, 8) self.components.table = self.components.filter_table.table # Eighth Row Frame, will be set behind grid widgets. export_separator = QFrame() export_separator.setFrameShape(QFrame.StyledPanel) export_separator.setFrameShadow(QFrame.Sunken) export_separator.setLineWidth(1) export_separator.setContentsMargins(BASE_MARGIN, 1, BASE_MARGIN, 1) self.layout.addWidget(export_separator, 3, 0, 5, 8) # Eighth Row Components, Margins follow (left, top, right, bottom) # Header export_heading = QLabel("Export") header_font = QFont() header_font.setFamily('SansSerif') header_font.setPointSize(10) header_font.setBold(True) export_heading.setFont(header_font) export_heading.setContentsMargins(BASE_MARGIN + 10, BASE_MARGIN, 0, 0) self.layout.addWidget(export_heading, 4, 0, 1, 8) # Export Field self.components.export_location_field = ExportLocationField(self) self.components.export_location_field.setContentsMargins( BASE_MARGIN, 0, BASE_MARGIN, 0) self.layout.addWidget(self.components.export_location_field, 5, 0, 1, 8) self.components.status_bar.showMessage( 'Select words to include and choose an export location') # Export Button self.components.export_button = ExportButton(self) self.components.export_button.setContentsMargins( BASE_MARGIN, 0, BASE_MARGIN, BASE_MARGIN) self.layout.addWidget(self.components.export_button, 6, 0, 1, 8) self.components.export_button.setEnabled(False) # Re-init menu to allow for Open/Save functionality now that table widget exists. self.parent.init_menu(True) self.parent.session.start_autosave()
def load_main_hermes_app(self, components: ConverterComponents, data: ConverterData) -> None: """Main hermes app once a file is loaded or a new project has begun is initialised. Main app contains the table widget allowing for user input, image uploading, audio recording, and the final export process. At this stage, main menu functionality is fully activated, and the autosave thread starts. """ if self.data.mode == OperationMode.ELAN: data.audio_file = get_audio_file(self.data) transcription_tier = components.tier_selector.get_transcription_tier( ) translation_tier = components.tier_selector.get_translation_tier() extract_elan_data(transcription_tier, translation_tier, self.data, components) else: if self.components.project_mode_select: self.components.project_mode_select.hide() elif self.components.main_project_select: self.components.main_project_select.hide() self.data.transcriptions.append( Transcription(index=0, transcription="")) # Filter Table Rows self.components.filter_table = FilterTable(self.data, self.components.status_bar, self.settings) self.layout.addWidget(self.components.filter_table, 2, 0, 1, 8) self.components.table = self.components.filter_table.table # Export Frame export_separator = QFrame() export_separator.setFrameShape(QFrame.StyledPanel) export_separator.setFrameShadow(QFrame.Sunken) export_separator.setLineWidth(1) export_separator.setContentsMargins(BASE_MARGIN, 1, BASE_MARGIN, 1) self.layout.addWidget(export_separator, 3, 0, 5, 8) # Export Components, Margins follow (left, top, right, bottom) # Header export_heading = QLabel("Export") header_font = QFont() header_font.setFamily('SansSerif') header_font.setPointSize(10) header_font.setBold(True) export_heading.setFont(header_font) export_heading.setContentsMargins(BASE_MARGIN + 10, BASE_MARGIN, 0, 0) self.layout.addWidget(export_heading, 4, 0, 1, 8) # Export Field self.components.export_location_field = ExportLocationField(self) self.components.export_location_field.setContentsMargins( BASE_MARGIN, 0, BASE_MARGIN, 0) self.layout.addWidget(self.components.export_location_field, 5, 0, 1, 8) self.components.status_bar.showMessage( 'Select words to include and choose an export location') # Set export location self.data.export_location = self.parent.session.export_path self.components.export_location_field.set_export_field_text( self.data.export_location) # Export Button self.components.export_button = ExportButton(self) self.components.export_button.setContentsMargins( BASE_MARGIN, 0, BASE_MARGIN, BASE_MARGIN) self.layout.addWidget(self.components.export_button, 6, 0, 1, 8) # self.components.export_button.setEnabled(False) self.enable_export_button() # Re-init menu to allow for Open/Save functionality now that table widget exists. self.parent.init_menu(True) self.parent.session.start_autosave()