def OnApply(self, event): """ A plugin was clicked: Apply it on a set of files. :param event: (PluginApplyEvent) Event indicating the identifier of the plugin to apply. """ # Get the list of files (from the main frame). trs_files = self.GetTopLevelParent().GetTrsSelection() audio_files = self.GetTopLevelParent().GetAudioSelection() file_names = trs_files + audio_files if len(file_names) == 0: ShowInformation(self, self._preferences, "No file(s) selected to apply a plugin!", style=wx.ICON_WARNING) return # Set the options of the plugin plugin_id = event.pid logging.debug("Apply plugin %s on %d files." % (plugin_id, len(file_names))) dlg = spPluginConfig(self, self._preferences, self._manager.get_plugin(plugin_id)) res = dlg.ShowModal() # OK... now execute the plugin. if res == wx.ID_OK: log_text = "" style = wx.ICON_INFORMATION try: wx.BeginBusyCursor() p = ProcessProgressDialog( self, self._preferences, "Plugin %s is processing..." % plugin_id) self._manager.set_progress(p) log_text = self._manager.run_plugin(plugin_id, file_names) p.close() wx.EndBusyCursor() if len(log_text) == 0: log_text = "Done." except Exception as e: import traceback traceback.print_exc() logging.info('%s' % str(e)) log_text = str(e) style = wx.ICON_ERROR # Show the output message ShowInformation(self, self._preferences, log_text, style=style) dlg.Destroy() # Update the filetree of the main frame evt = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, ID_FILES) evt.SetEventObject(self) wx.PostEvent(self.GetTopLevelParent(), evt)
def Import(self): """ Import and install a plugin. """ filename = OpenSpecificFiles("Plugin archive", ['zip', "*.zip", "*.[zZ][iI][pP]"]) if len(filename) > 0: try: # fix a name for the plugin directory plugin_folder = os.path.splitext(os.path.basename(filename))[0] plugin_folder.replace(' ', "_") # install the plugin. plugin_id = self._manager.install(filename, plugin_folder) ShowInformation( self, self._preferences, "Plugin %s successfully installed in %s folder." % (plugin_id, plugin_folder), style=wx.ICON_INFORMATION) self._plugins_panel.Append(self._manager.get_plugin(plugin_id)) self._plugins_panel.Layout() self._plugins_panel.Refresh() except Exception as e: logging.info('%s' % str(e)) ShowInformation(self, self._preferences, "%s" % str(e), style=wx.ICON_ERROR)
def MoveUp(self): """ Move up the selected tier (except for the first one). """ if self._transcription.GetSize() == 0: return # Get the selected tier in the list sellist = self.tier_list.GetFirstSelected() if sellist == -1: return # Too many selected items if self.tier_list.GetSelectedItemCount() > 1: ShowInformation(self, self._prefs, "One tier must be checked", style=wx.ICON_INFORMATION) return # tier = self._transcription[sellist] if tier in self._protected: ShowInformation(self, self._prefs, "Attempt to move a protected tier: forbidden!", style=wx.ICON_INFORMATION) return #Impossible to move up the first tier. if sellist == 0: return # Pop selected tier from transcription. try: self._transcription._hierarchy.remove_tier( self._transcription[sellist] ) # waiting a better way to work with hierarchy... except Exception: pass self._transcription.Pop(sellist) # Delete old tier of the list self.tier_list.DeleteItem(sellist) # Add tier to the transcription tierindex = self._transcription.Add(tier, sellist - 1) # Add tier to the list self.SetTierProperties(tierindex) # Update tier number self.tier_list.SetStringItem(sellist, 0, str(sellist + 1)) # Let the item selected self.tier_list.Select(sellist - 1, on=True) self._dirty = True self._boxtitle.SetForegroundColour(FG_FILE_DIRTY_COLOUR) self.Refresh()
def onTierCheck(self, event): """Fix the list of tiers to Show/Hide.""" if self._trsctrl is None: return # Get the list of tiers' names lst = self._trsctrl.GetTierNames() if len(lst) == 0: return # hum... just to be sure dlg = wx.MultiChoiceDialog(self, "Check the tiers to show:", "Tiers to show/hide", lst) dlg.SetSelections(self._trsctrl.GetTierIdxChecked()) if dlg.ShowModal() == wx.ID_OK: # get the list of tiers' names that are checked selections = dlg.GetSelections() checked = [lst[x] for x in selections] if len(checked) == 0: ShowInformation(self, self._prefsIO, "At least one tier must be checked!", wx.ICON_INFORMATION) else: # send the list to the trsctrl instance, then redraw self._trsctrl.SetTierChecked(checked) dlg.Destroy()
def _copy(self): """ Export selected files. """ # Some files to save??? files = self.GetSelected() if not files: return for filename in files: default_dir = os.path.dirname(filename) default_file = os.path.basename(filename) # Show the dialog and retrieve the user response. newfilename = SaveAsAnnotationFile(default_dir, default_file) # If it is the OK response, process the data. if newfilename: try: trs = sppas.src.annotationdata.aio.read(filename) sppas.src.annotationdata.aio.write(newfilename, trs) except Exception as e: ShowInformation(self, self._prefsIO, "Copy/Export failed: %s" % e, style=wx.ICON_ERROR) else: self._append_file(newfilename)
def FileSelected(self, filename): """Add files.""" got = False name = os.path.splitext(filename)[0] for ext in anndata.aio.extensions: if ext in ['.pitchtier', '.hz', '.txt']: continue f = self.exists(name+ext) if got is False and f is not None: # create the object r = self._trsPanel.SetData(filename, f) if r is True: self._txtinfo.SetLabel("Transcription file: " + f) self._current_page = self._trsPanel.LoadPage(1) # show the current page and the total amount of pages at # the bottom of the window self.__set_footer() self.Layout() got = True else: self._trsPanel.UnsetData() self._sndname = filename if got is False: ShowInformation(self, self._prefsIO, "Missing IPUs: A file with an IPUs segmentation is required.", wx.ICON_ERROR) self.FileDeSelected() return
def Rename(self): """Rename the selected tier. Dialog with the user to get the new name.""" sel_list = self._check_selected_tier() if sel_list == -1: return tier = self._transcription[sel_list] if tier in self._protected: ShowInformation(self, self._prefs, "Attempt to rename a protected tier: forbidden!", style=wx.ICON_INFORMATION) return # Ask the user to enter a new name (set current as default) dlg = wx.TextEntryDialog(self, 'Indicate the new tier name', 'Data Roamer', 'Rename a tier.') dlg.SetValue(tier.get_name()) if dlg.ShowModal() == wx.ID_OK: new_name = dlg.GetValue() else: new_name = tier.get_name() dlg.Destroy() if new_name != tier.get_name(): # Update tier name of the transcription tier.set_name(new_name) # Update tier name of the list self.tier_list.SetStringItem(sel_list, 1, dlg.GetValue()) self._dirty = True self._box_title.SetForegroundColour(FG_FILE_DIRTY_COLOUR) self.Refresh()
def SetData(self, filename): """Add a file.""" # Do not add an already loaded file if self._filetrs.Exists(filename): return False # create the object new_trs = TrsList(self._trspanel, filename) new_trs.SetPreferences(self._prefsIO) if new_trs.GetTranscriptionName() == "IO-Error": ShowInformation(self, self._prefsIO, 'Error loading: ' + filename, style=wx.ICON_ERROR) # put the new trs in a sizer (required to enable sizer.Remove()) s = wx.BoxSizer(wx.HORIZONTAL) s.Add(new_trs, proportion=1, flag=wx.EXPAND, border=0) self._trssizer.Add(s, proportion=1, flag=wx.EXPAND | wx.TOP, border=4) # add in the list of files self._filetrs.Append(filename, new_trs) self.Layout() self._trspanel.Refresh() return True
def onPlay(self, event): """ Plays the music. """ if self._mediaplayer is None: logging.debug('onPlay. Unable to play: No media player.') return if self._mediaplayer.GetState() == wx.media.MEDIASTATE_PLAYING: logging.debug('onPlay. Unable to play: already playing!') return # save current position offset = self._mediaplayer.Tell() omin, omax = self._offsets if self._playbackSlider is not None: offset = self._playbackSlider.GetValue() elif (offset < omin or offset > omax): offset = omin if not self._mediaplayer.Play(): logging.debug('onPlay. Unable to play. offset=%d'%offset) ShowInformation(self, self._prefs, "Unable to Play. Offset=%d"%offset, style=wx.ICON_ERROR) return # force to play at the good position self._mediaplayer.Seek(offset, mode=wx.FromStart) # required! if self._knob is not None: self._mediaplayer.SetVolume(float(self._knob.GetValue())/100.0) if 'play' in self._buttons.keys(): self._buttons['play'].SetBitmapLabel(self._dict_buttons_enable[self._buttons['play']]) if 'pause' in self._buttons.keys(): self._buttons['pause'].SetBitmapLabel(self._dict_buttons_enable[self._buttons['pause']]) self.Refresh()
def MoveUp(self): """Move up the selected tier (except for the first one).""" sel_list = self._check_selected_tier() # Impossible to move up the first tier. if sel_list <= 0: return # tier = self._transcription[sel_list] if tier in self._protected: ShowInformation(self, self._prefs, "Attempt to move a protected tier: forbidden!", style=wx.ICON_INFORMATION) return # move up into the transcription self._transcription.set_tier_index(tier.get_name(), sel_list - 1) # Delete old tier of the list self.tier_list.DeleteItem(sel_list) # Add moved tier to the list self.AddTierProperties(tier) # Update tier number self.tier_list.SetStringItem(sel_list, 0, " -- {:d} --".format(sel_list + 1)) # Let the item selected self.tier_list.Select(sel_list - 1, on=True) self._dirty = True self._box_title.SetForegroundColour(FG_FILE_DIRTY_COLOUR) self.Refresh()
def Delete(self): """Delete the selected tier. Dialog with the user to confirm. """ sel_list = self._check_selected_tier(multiple=True) # Get Indexes of tiers to remove indexes = list() while sel_list != -1: indexes.append(sel_list) sel_list = self.tier_list.GetNextSelected(sel_list) # how many tiers to delete??? d = 0 for sel_list in indexes: tier = self._transcription[sel_list] if tier not in self._protected: d += 1 if d == 0: message = 'None of the selected tiers can be deleted.' \ ''.format(d, self._filename) ShowInformation(self, self._prefs, message, style=wx.ICON_INFORMATION) return # Ask the user to confirm before deleting delete = 0 message = 'Are you sure you want to definitively delete:\n' \ '{:d} tiers in {:s}?'.format(d, self._filename) dlg = ShowYesNoQuestion(self, self._prefs, message) if dlg == wx.ID_YES: for sel_list in reversed(sorted(indexes)): tier = self._transcription[sel_list] if tier in self._protected: logging.info('Attempted to delete the protected tier {:s}' ''.format(tier.get_name())) else: # Delete tier of the transcription self._transcription.pop(sel_list) # Delete tier of the list self.tier_list.DeleteItem(sel_list) delete = delete + 1 # Update tier numbers of next items in the list. for i in range(sel_list, self.tier_list.GetItemCount()): self.tier_list.SetStringItem( i, 0, " -- {:d} --".format(i + 1)) self._dirty = True self._box_title.SetForegroundColour(FG_FILE_DIRTY_COLOUR) self.Refresh() self._checksize() return delete
def SaveAs(self): """Save as... the selected file.""" if self._selection is None: ShowInformation(self, self._prefsIO, "No file selected!\n" "Click on a tier to select a file...", style=wx.ICON_INFORMATION) return found = -1 for i in range(self._filetrs.GetSize()): p = self._filetrs.GetObject(i) if p == self._selection: found = i break if found > -1: f = self._filetrs.GetFilename(i) p = self._filetrs.GetObject(i) # Ask for the new file name filename = filedialogs.SaveAsAnnotationFile() if filename is None: return # do not erase the file if it is already existing! if os.path.exists(filename) and f != filename: ShowInformation( self, self._prefsIO, "File not saved: this file name is already existing!", style=wx.ICON_INFORMATION) elif f == filename: p.Save() else: p.SaveAs(filename) # Add the newly created file in the file manager evt = FileWanderEvent(filename=filename, status=True) evt.SetEventObject(self) wx.PostEvent(self.GetTopLevelParent(), evt) evt = FileWanderEvent(filename=filename, status=True) evt.SetEventObject(self) wx.PostEvent(self.GetParent().GetParent().GetParent(), evt)
def SetData(self, wavname, trsname): """ Open a transcription file with a wav file. @param wav: Wav file name @param trsname: Transcription file name """ # What to do with the current opened transcription if len(self._ipupanels) > 0: if self.dirty is True: pass # TODO: a dialog box asking to save, or not! # userChoice = ShowYesNoQuestion(None, self._prefsIO, # "Do you want to save changes on the transcription of\n%s?"%f) # if userChoice == wx.ID_YES: # fix o object!!! # o.Save() self.UnsetData() # Transcription retrieval (tieridx, trs) = self.__TierSelection(trsname) if trs is None or trs[tieridx].is_empty(): ShowInformation(self, self._prefsIO, 'Error loading: ' + trsname, style=wx.ICON_ERROR) return False # Gauge... to be patient! #progressMax = trs[tieridx].GetSize() #gauge = wx.ProgressDialog("IPUScribe", # "Loading data...", progressMax, # style=wx.STAY_ON_TOP|wx.PD_AUTO_HIDE|wx.PD_ELAPSED_TIME|wx.PD_APP_MODAL) wx.BeginBusyCursor() b = wx.BusyInfo("Please wait while loading data...") # Store IPU data color = co.PickRandomColour(155, 255) i = 0 # interval index k = 1 # ipu number for a in trs[tieridx]: # if it is not a silence if a.get_best_tag().is_silence() is False: ipu = IPUData(trs, tieridx, i, color, k) self._ipudata.insert(k, ipu) k += 1 i += 1 #gauge.Update(i) self._trsname = trsname self._trsinput = trs #gauge.Destroy() b.Destroy() b = None wx.EndBusyCursor() return True
def Cut(self): """ Cut the selected tier. Return the clipboard. """ if self._transcription.GetSize() == 0: return # Get the selected tier in the list sellist = self.tier_list.GetFirstSelected() # No tier selected if sellist == -1: return # Too many selected items if self.tier_list.GetSelectedItemCount() > 1: ShowInformation(self, self._prefs, 'One tier must be checked.', style=wx.ICON_INFORMATION) return # Copy the tier to the clipboard tier = self._transcription[sellist] if tier in self._protected: ShowInformation(self, self._prefs, "Attempt to cut a protected tier: forbidden!", style=wx.ICON_INFORMATION) return clipboard = tier.Copy() # Delete tier of the transcription self._transcription.Remove(sellist) # Delete tier of the list self.tier_list.DeleteItem(sellist) # Update tier numbers of next items in the list. for i in range(sellist, self.tier_list.GetItemCount()): self.tier_list.SetStringItem(i, 0, "Tier " + str(i + 1)) self.Deselect() self._checksize() self._dirty = True self._boxtitle.SetForegroundColour(FG_FILE_DIRTY_COLOUR) self.Refresh() return clipboard
def _export(self): """ Export multiple files, i.e. propose to change the extension. Nothing else. """ # Some selection? files = self.GetSelected() if not files: return # Ask for the expected file format errors = False extensions = sppas.src.annotationdata.aio.extensions_out dlg = Choice(self, self._prefsIO, "Select the file extension to export to:", extensions) dlg.SetSelection(0) # default choice (=xra) if dlg.ShowModal() == wx.ID_OK: # get the index of the extension checked = dlg.GetSelection() # Convert all files for filename in files: try: oldextension = os.path.splitext(filename)[1][1:] newfilename = filename.replace("." + oldextension, extensions[checked]) trs = sppas.src.annotationdata.aio.read(filename) sppas.src.annotationdata.aio.write(newfilename, trs) except Exception as e: ShowInformation(self, self._prefsIO, "Export failed for file %s: %s" % (filename, e), style=wx.ICON_ERROR) errors = True else: self._append_file(newfilename) else: errors = None dlg.Destroy() if errors is False: ShowInformation(self, self._prefsIO, "Export with success.", style=wx.ICON_INFORMATION)
def ShowInfo(self): """Estimate all values then display the information.""" # we never estimated values. we have to do it! if self._cv is None: try: self.SetChannel(self._channel) except Exception as e: ShowInformation(self, self._prefs, "Error: %s" % str(e)) return # Amplitude self._wxobj["nframes"][1].ChangeValue( " " + str(self._channel.get_nframes()) + " ") self._wxobj["minmax"][1].ChangeValue(" " + str(self._ca.minmax()) + " ") self._wxobj["cross"][1].ChangeValue(" " + str(self._ca.cross()) + " ") # Modifiable fm = str(self._channel.get_framerate()) if not fm in AudioRoamerPanel.FRAMERATES: self._wxobj["framerate"][1].Append(fm) self._wxobj["framerate"][1].SetStringSelection(fm) self.MODIFIABLES["framerate"] = fm sp = str(self._channel.get_sampwidth() * 8) if not sp in AudioRoamerPanel.SAMPWIDTH: self._wxobj["sampwidth"][1].Append(sp) self._wxobj["sampwidth"][1].SetStringSelection(sp) self.MODIFIABLES["sampwidth"] = sp # Clipping for i in range(1, 10): cr = self._ca.clipping_rate(float(i) / 10.) * 100. self._wxobj["clip" + str(i)][1].ChangeValue(" " + str(round(cr, 2)) + "% ") # Volumes / Silences vmin = self._cv.get_volstats().min() vmax = self._cv.get_volstats().max() vavg = self._cv.get_volstats().mean() vmin_db = sppasAudioConverter().amp2db(vmin) vmax_db = sppasAudioConverter().amp2db(vmax) vavg_db = sppasAudioConverter().amp2db(vavg) self._wxobj["volmin"][1].ChangeValue(" " + str(vmin) + " (" + str(vmin_db) + " dB) ") self._wxobj["volmax"][1].ChangeValue(" " + str(vmax) + " (" + str(vmax_db) + " dB) ") self._wxobj["volavg"][1].ChangeValue(" " + str(int(vavg)) + " (" + str(vavg_db) + " dB) ") self._wxobj["volsil"][1].ChangeValue( " " + str(self._cv.search_threshold_vol()) + " ") self._wxobj["nbipus"][1].ChangeValue(" " + str(len(self._tracks)) + " ") d = sum([(e - s) for (s, e) in self._tracks]) self._wxobj["duripus"][1].ChangeValue(" " + str(d) + " ")
def Radius(self): """Fix a new radius value to all TimePoint instances of the selected tier.""" if len(self._transcription) == 0: return # Get the selected tier in the list sel_list = self.tier_list.GetFirstSelected() if sel_list == -1: return # tier = self._transcription[sel_list] if tier in self._protected: ShowInformation(self, self._prefs, "Attempt to modify a protected tier: forbidden!", style=wx.ICON_INFORMATION) return # Open a dialog to ask the new radius value radius = 0.005 dlg = RadiusChooser(self, self._prefs, radius) if dlg.ShowModal() == wx.ID_OK: # Get the value r = dlg.GetValue() try: r = float(r) if r > 1.0 or r < 0.: raise ValueError('Radius must range 0-1.') except Exception as e: ShowInformation(self, self._prefs, "Error: {:s}".format(str(e)), style=wx.ICON_ERROR) return # Set the value while sel_list != -1: tier.set_radius(r) sel_list = self.tier_list.GetNextSelected(sel_list) dlg.Destroy()
def onInfo(self, event): """ Display information about the selected Wave. """ if self._mediaplayer is None: return try: ShowAudioInfo(self, self._prefs, self._filename) except Exception as e: ShowInformation(self, self._prefs, 'No information available: %s'%str(e), style=wx.ICON_ERROR)
def Remove(self): """ Remove and delete a plugin. """ try: plugin_id = self._plugins_panel.Remove() if plugin_id is not None: self._manager.delete(plugin_id) ShowInformation(self, self._preferences, "Plugin %s was successfully deleted." % plugin_id, style=wx.ICON_INFORMATION) except Exception as e: logging.info('%s' % str(e)) ShowInformation(self, self._preferences, "%s" % str(e), style=wx.ICON_ERROR)
def UserAgreement(self): """ User agreement .""" nb = self._get_nbselectedtiers(inselection=False) if nb == 2: dlg = UserAgreementDialog(self, self._prefsIO, self._get_selectedtiers()) dlg.ShowModal() dlg.Destroy() else: ShowInformation(self, self._prefsIO, "Two tiers must be checked!", wx.ICON_WARNING)
def _on_save(self, evt): """ Save the content in a text file. """ filesel = None wildcard = "SPPAS log files (*-sppas.log)|*-sppas.log" defaultDir = os.path.dirname(self.filename) defaultFile = os.path.basename("Annotations-sppas.log") dlg = wx.FileDialog(self, message="Save as...", defaultDir=defaultDir, defaultFile=defaultFile, wildcard=wildcard, style=wx.FD_SAVE | wx.CHANGE_DIR) # Show the dialog and retrieve the user response. # If it is the OK response, process the data. if dlg.ShowModal() == wx.ID_OK: filesel = dlg.GetPath() dlg.Destroy() if filesel: # OK. We have a filename... # but if this is the default, don't do anything! if self.filename == filesel: return # or copy the file! try: shutil.copy(self.filename, filesel) # eg. src and dest are the same file except shutil.Error as e: ShowInformation(self, self.preferences, "Error while saving: %s" % str(e), wx.ICON_ERROR) # eg. source or destination doesn't exist except IOError as e: ShowInformation(self, self.preferences, "Error while saving: %s" % str(e), wx.ICON_ERROR)
def Rename(self): """ Rename the selected tier. Dialog with the user to get the new name. """ if self._transcription.GetSize() == 0: return # Get the selected tier in the list sellist = self.tier_list.GetFirstSelected() # Nothing selected if sellist == -1: return # Too many selected items if self.tier_list.GetSelectedItemCount() > 1: ShowInformation(self, self._prefs, 'Only one tier has to be checked to be renamed...', style=wx.ICON_INFORMATION) return tier = self._transcription[sellist] if tier in self._protected: ShowInformation(self, self._prefs, "Attempt to rename a protected tier: forbidden!", style=wx.ICON_INFORMATION) return # Ask the user to enter a new name dlg = wx.TextEntryDialog(self, 'Indicate the new tier name', 'Data Roamer', 'Rename a tier.') dlg.SetValue(self._transcription[sellist].GetName()) if dlg.ShowModal() == wx.ID_OK: # Update tier name of the transcription tier.SetName(dlg.GetValue()) # Update tier name of the list self.tier_list.SetStringItem(sellist, 1, dlg.GetValue()) self._dirty = True self._boxtitle.SetForegroundColour(FG_FILE_DIRTY_COLOUR) self.Refresh() dlg.Destroy()
def DescriptivesStats(self): """ Descriptives Statistics .""" nb = self._get_nbselectedtiers(inselection=False) if nb > 0: dlg = DescriptivesStatsDialog(self, self._prefsIO, self._get_selectedtiers()) dlg.ShowModal() dlg.Destroy() else: ShowInformation(self, self._prefsIO, "At least one tier must be checked!", wx.ICON_INFORMATION)
def SaveAs(self, filename): """ Save the current page content with another file name. Keep everything un-changed in self. """ try: sppas.src.annotationdata.aio.write(filename, self._transcription) except Exception as e: # give information ShowInformation(self, self._prefs, 'File not saved: %s' % str(e), style=wx.ICON_ERROR)
def _check_selected_tier(self, multiple=False): if len(self._transcription) == 0: return -1 # Too many selected items if multiple is False and self.tier_list.GetSelectedItemCount() > 1: ShowInformation(self, self._prefs, "Only one tier must be checked", style=wx.ICON_INFORMATION) return -1 # Get the selected tier in the list return self.tier_list.GetFirstSelected()
def Save(self): """Save the selected file.""" if self._selection is None: ShowInformation(self, self._prefsIO, "No file selected!\n" "Click on a tier to select a file...", style=wx.ICON_INFORMATION) return for i in range(self._filetrs.GetSize()): p = self._filetrs.GetObject(i) if p == self._selection: p.Save()
def Preview(self): """ Open a frame to view a tier. """ # Show the tier which is checked in the selected files nb = self._get_nbselectedtiers(inselection=True) if nb == 1: self._selection.Preview() else: # show the tier which is checked... even if it's not in a selected file nb = self._get_nbselectedtiers(inselection=False) if nb == 0: ShowInformation(self, self._prefsIO, "One tier must be checked.", wx.ICON_INFORMATION) elif nb == 1: for i in range(self._filetrs.GetSize()): p = self._filetrs.GetObject(i) if p.tier_list.GetSelectedItemCount() == 1: p.Preview() else: ShowInformation(self, self._prefsIO, "Only one tier must be checked.", wx.ICON_INFORMATION)
def __TierSelection(self, trsname): """ Return the tier containing the orthographic transcription. It is then supposed that only one tier concerns orthographic transcription... which is a serious limitation of this tool. """ transtier = -1 try: parser = anndata.sppasRW(trsname) trsinput = parser.read() except: ShowInformation(self, self._prefsIO, "Transcription {:s} not loaded" "".format(self._trsname), style=wx.ICON_ERROR) return None if len(trsinput) == 0: return None try: transcribed_tier = sppasFindTier().transcription(trsinput) for i, tier in enumerate(trsinput): if tier == transcribed_tier: transtier = i break except: # poor IPUScribe.... no tier is available to transcribe! lst = [] for tier in trsinput: lst.append(tier.get_name()) # show a dialog dlg = wx.MultiChoiceDialog(self, "Select transcription tiers of file {:s}" "".format(os.path.basename(trsname)), "Select the tiers to view/edit", lst) if dlg.ShowModal() == wx.ID_OK: transtiername = dlg.GetSelections() for i, tier in enumerate(trsinput): if tier.get_name() == transtiername: transtier = i else: return dlg.Destroy() return transtier, trsinput
def on_sppas_run(self, evt): """ Execute the automatic annotations. """ # The procedure outcome report file. self.parameters.set_report_filename(self.log_report.get_filename()) self.log_report.increment() # The list of files and folders selected by the user file_list = self.GetTopLevelParent().GetAudioSelection() file_list.extend(self.GetTopLevelParent().GetTrsSelection()) # The annotation annprocess = AnnotateProcess(self._prefsIO) message = annprocess.Run(self.GetParent(), file_list, self.activated, self.parameters) if message: ShowInformation(None, self._prefsIO, message)
def SaveAs(self, filename): """Save the current page content with another file name. Keep everything un-changed in self. """ try: parser = sppasRW(filename) parser.write(self._transcription) except Exception as e: # give information ShowInformation( self, self._prefs, 'File not saved due to the following error: {:s}'.format(e), style=wx.ICON_ERROR)