def on_imgmenuFileOpen_activate(self, widget, filename=None): "Loads an external file" if not filename: # If filename was not provided show dialog dialog = DialogFileOpen( title=_('Please select the text file to open'), initialDir=os.path.expanduser('~')) dialog.set_icon_from_file(handlepaths.get_app_logo()) dialog.addFilter(_('Text files (*.txt)'), ['*.txt'], None) dialog.addFilter(_('All files'), ['*'], None) if dialog.show(): filename = dialog.filename dialog.destroy() # Open selected filename if filename: file = None try: file = open(filename, 'r') self.txvBuffer.set_text(file.read()) print 'loading text from %s' % filename except IOError, (errno, strerror): ShowDialogError( text=_('Error opening the file') + '\n\n%s' % strerror, showOk=True, icon=handlepaths.get_app_logo() ) print 'unable to load %s (I/O error %s: %s)' % ( filename, errno, strerror ) except:
def on_imgmenuFileSaveAs_activate(self, widget, filename=None): "Saves the whole text in the specified filename" if not filename: dialog = DialogFileSave( title=_('Please select where to save the text file'), initialDir=os.path.expanduser('~')) txtFilter = _('Text files (*.txt)') dialog.addFilter(txtFilter, ['*.txt'], None) dialog.addFilter(_('All files'), ['*'], None) dialog.set_icon_from_file(handlepaths.get_app_logo()) if dialog.show(): filename = dialog.filename if dialog.lastFilter.get_name() == txtFilter and filename[-4:] != '.txt': filename += '.txt' dialog.destroy() # Save selected filename if filename: print 'saving text in %s' % filename file = None try: file = open(filename, 'w') file.write(TextBuffer_get_text(self.txvBuffer)) print 'file %s saved' % filename except IOError, (errno, strerror): ShowDialogError( text=_('Error saving the file') + '\n\n%s' % strerror, showOk=True, icon=handlepaths.get_app_logo() ) print 'unable to save %s (I/O error %s: %s)' % ( filename, errno, strerror ) except:
def on_imgmenuHelpAbout_activate(self, widget, data=None): "Show the about dialog" print 'show about dialog' DialogAbout( name=handlepaths.APP_TITLE, version=handlepaths.APP_VERSION, comment=_('A GTK frontend for espeak'), copyright='Copyright 2009 Fabio Castelli', license=handlepaths.read_text_file('doc', 'copyright'), website='http://code.google.com/p/gespeaker/', website_label='Gespeaker', authors=['Fabio Castelli <*****@*****.**>'], translation=handlepaths.read_text_file('doc', 'translators'), logo=handlepaths.get_app_logo(), icon=handlepaths.get_app_logo() )
def on_btnPlayerTest_clicked(self, widget, data=None): "Test selected player with testing.wav" # Set waiting cursor Window_change_cursor(self.dlgPrefs.window, gtk.gdk.WATCH, True) players = ('aplay', 'paplay', '', self.txtPlayerCommand.get_text()) filename = handlepaths.getPath('data', 'testing.wav') test = SubprocessWrapper.Popen(['cat', filename], stdout=SubprocessWrapper.PIPE) play = None try: # Try to play with pipe play = SubprocessWrapper.Popen(players[self.cboPlayer.get_active()], stdin=test.stdout, stdout=SubprocessWrapper.PIPE, stderr=SubprocessWrapper.PIPE) play.communicate() except OSError, (errno, strerror): # Error during communicate" ShowDialogError( title=_('Audio testing'), showOk=True, text=_('There was an error during the test for the audio player.\n\n' 'Error %s: %s') % (errno, strerror), icon=handlepaths.get_app_logo() )
def on_imgmenuFileNew_activate(self, widget, confirm=True): "Clears the whole text" if TextBuffer_get_text(self.txvBuffer): if confirm: dialog = DialogYesNo( message=_('Do you want to delete the current text?'), default_button=gtk.RESPONSE_NO ) dialog.set_icon_from_file(handlepaths.get_app_logo()) dialog.show() # Clear if confirm was not requested or if the user gave response if not confirm or dialog.responseIsYes(): self.txvBuffer.set_text('') print 'text cleared'
def on_btnPluginInfo_clicked(self, widget, data=None): "Show information about plugin" model, iter = self.tvwPlugins.get_selection().get_selected() if model: plugin = plugins.plugins[model[iter][COL_NAME]] DialogAbout( name=model[iter][COL_NAME], version=plugin.version, comment=plugin.description, copyright='Copyright %s' % plugin.author, website=plugin.website, website_label=plugin.website, logo=model[iter][COL_ICON], icon=handlepaths.get_app_logo() )
def __init__(self, gladeFile, espeak): self.gladeFile = gladeFile self.espeak = espeak self.loadControls() self.dlgPrefs.set_icon_from_file(handlepaths.get_app_logo()) signals = { 'on_cboPlayer_changed': self.on_cboPlayer_changed, 'on_btnPlayerTest_clicked': self.on_btnPlayerTest_clicked, 'on_chkCustomWelcome_toggled': self.on_chkCustomWelcome_toggled, 'on_btnRefresh_clicked': self.on_btnRefresh_clicked, 'on_btnOk_clicked': self.on_btnOk_clicked, 'on_btnPluginInfo_clicked': self.on_btnPluginInfo_clicked, 'on_tvwPlugins_row_activated': self.on_tvwPlugins_row_activated } self.gladeFile.signal_autoconnect(signals) # Load settings self.cboPlayer.set_active(Settings.get('PlayMethod')) self.txtPlayerCommand.set_text(Settings.get('PlayCommand')) self.chkPlayWelcome.set_active(Settings.get('PlayWelcomeText') == True) self.chkCustomWelcome.set_active( Settings.get('UseCustomWelcome') == True) self.txtWelcomeText.set_text(Settings.get('WelcomeText')) self.chkSaveVoice.set_active(Settings.get('SaveVoiceSettings') == True) self.chkSaveSize.set_active(Settings.get('SaveWindowSize') == True) self.chkSingleRecord.set_active(Settings.get('SingleRecord') == True) self.chkWordWrap.set_active(Settings.get('WordWrap') == True) self.chkLoadVariants.set_active(Settings.get('LoadVariants') == True) self.chooserLanguagePath.set_current_folder( Settings.get('VoicesmbPath')) # Before to use the window property the realize method must be called self.dlgPrefs.realize() # Change WM buttons making the window only movable with the closing button self.dlgPrefs.window.set_functions(gtk.gdk.FUNC_CLOSE | gtk.gdk.FUNC_MOVE) # Reload mbrola languages list self.btnRefresh.clicked() # Load plugins list self.modelPlugins.clear() for pl in plugins.plugins.itervalues(): self.modelPlugins.append([ pl.active, pl.render_icon(), pl.name, '<b>%s</b>\n%s' % (pl.name, pl.description) ]) self.dlgPrefs.run() self.dlgPrefs.destroy()
def __playAudio(self, procFrom, cmdPlayer): "Play audio with the player piping from a process" try: procPlay = SubprocessWrapper.Popen(cmdPlayer.split(), stdin=procFrom.stdout, stdout=SubprocessWrapper.PIPE, stderr=SubprocessWrapper.PIPE) except OSError, (errno, strerror): # Error during communicate" ShowDialogError( title=_('Audio testing'), showOk=True, text= _('There was an error during the test for the audio player.\n\n' 'Error %s: %s') % (errno, strerror), icon=handlepaths.get_app_logo()) procPlay = None
def __init__(self, gladeFile, espeak): self.gladeFile = gladeFile self.espeak = espeak self.loadControls() self.dlgPrefs.set_icon_from_file(handlepaths.get_app_logo()) signals = { 'on_cboPlayer_changed': self.on_cboPlayer_changed, 'on_btnPlayerTest_clicked': self.on_btnPlayerTest_clicked, 'on_chkCustomWelcome_toggled': self.on_chkCustomWelcome_toggled, 'on_btnRefresh_clicked': self.on_btnRefresh_clicked, 'on_btnOk_clicked': self.on_btnOk_clicked, 'on_btnPluginInfo_clicked': self.on_btnPluginInfo_clicked, 'on_tvwPlugins_row_activated': self.on_tvwPlugins_row_activated } self.gladeFile.signal_autoconnect(signals) # Load settings self.cboPlayer.set_active(Settings.get('PlayMethod')) self.txtPlayerCommand.set_text(Settings.get('PlayCommand')) self.chkPlayWelcome.set_active(Settings.get('PlayWelcomeText') == True) self.chkCustomWelcome.set_active(Settings.get('UseCustomWelcome') == True) self.txtWelcomeText.set_text(Settings.get('WelcomeText')) self.chkSaveVoice.set_active(Settings.get('SaveVoiceSettings') == True) self.chkSaveSize.set_active(Settings.get('SaveWindowSize') == True) self.chkSingleRecord.set_active(Settings.get('SingleRecord') == True) self.chkWordWrap.set_active(Settings.get('WordWrap') == True) self.chkLoadVariants.set_active(Settings.get('LoadVariants') == True) self.chooserLanguagePath.set_current_folder(Settings.get('VoicesmbPath')) # Before to use the window property the realize method must be called self.dlgPrefs.realize() # Change WM buttons making the window only movable with the closing button self.dlgPrefs.window.set_functions(gtk.gdk.FUNC_CLOSE | gtk.gdk.FUNC_MOVE) # Reload mbrola languages list self.btnRefresh.clicked() # Load plugins list self.modelPlugins.clear() for pl in plugins.plugins.itervalues(): self.modelPlugins.append([ pl.active, pl.render_icon(), pl.name, '<b>%s</b>\n%s' % (pl.name, pl.description) ]) self.dlgPrefs.run() self.dlgPrefs.destroy()
def on_imgmenuEditResetSettings_activate(self, widget, confirm=True): "Restore default settings" if confirm: dialog = DialogYesNo( message=_('Do you want to reset the default settings?'), default_button=gtk.RESPONSE_NO ) dialog.set_icon_from_file(handlepaths.get_app_logo()) dialog.show() # Reset if confirm was not requested or if the user gave response if not confirm or dialog.responseIsYes(): if self.defaultLanguageIndex: self.cboLanguages.set_active(self.defaultLanguageIndex) print 'restored default settings' if os.path.exists(Settings.conffile): os.remove(Settings.conffile) print 'removed user settings file: %s' % Settings.conffile # Reload default settings Settings.load() self.loadSettings(True)
def on_tlbRecord_toggled(self, widget, data=None): # Workaround to avoid dialog show if the record was requested through dbus if self.recordToFileRequested: return self.recordToFile = None if self.tlbRecord.get_active(): dialog = DialogFileSave( title=_('Please select where to save the recorded file'), initialDir=os.path.expanduser('~')) dialog.set_icon_from_file(handlepaths.get_app_logo()) dialog.addFilter(_('Wave files (*.wav)'), ['*.wav'], None) dialog.addFilter(_('All files'), ['*'], None) if dialog.show(): filename = dialog.filename if filename[-4:] != '.wav': filename += '.wav' self.set_record(filename) else: self.tlbRecord.set_active(False) dialog.destroy() else: self.stbStatus.pop(self.statusContextId)
def loadControls(self): "Load controls and other values" # Load controls from gladeFile print 'loading controls from UI' gw = self.gladeFile.get_widget self.winMain = gw('winMain') self.winMain.set_title(handlepaths.APP_TITLE) self.winMain.set_icon_from_file(handlepaths.get_app_logo()) self.txvText = gw('txvText') self.txvBuffer = self.txvText.get_buffer() self.winMain.set_focus(self.txvText) self.expSettings = gw('expSettings') self.hscVolume = gw('hscVolume') self.hscPitch = gw('hscPitch') self.hscSpeed = gw('hscSpeed') self.hscDelay = gw('hscDelay') self.lblVoice = gw('lblVoice') self.radioVoiceMale = gw('radioVoiceMale') self.radioVoiceFemale = gw('radioVoiceFemale') self.cboLanguages = gw('cboLanguages') self.lblVariants = gw('lblVariants') self.cboVariants = gw('cboVariants') self.imgmenuEditPlay = gw('imgmenuEditPlay') self.imgmenuEditStop = gw('imgmenuEditStop') self.imgmenuFileRec = gw('imgmenuFileRec') self.tlbStop = gw('tlbStop') self.btnPlayStop = gw('btnPlayStop') self.btnPause = gw('btnPause') self.tlbRecord = gw('tlbRecord') self.stbStatus = gw('stbStatus') self.statusContextId = self.stbStatus.get_context_id(handlepaths.APP_NAME) self.imgmenuEditPause = gw('imgmenuEditPause') self.imgMbrola = gw('imgMbrola') # Create model for cboLanguages by (language, shortname, mbrola) self.listLanguages = gtk.ListStore(str, str, bool) self.cboLanguages.set_model(self.listLanguages) cell = gtk.CellRendererText() self.cboLanguages.pack_start(cell, True) self.cboLanguages.add_attribute(cell, 'text', 0) # Load languages list from espeak --voices for langs in self.espeak.loadLanguages(Settings.cmdEspeak): lang = langs[22:52].rsplit(None, 1) self.listLanguages.append(lang + [False]) # Load mbrola voices if mbrola is available if self.espeak.mbrolaExists(Settings.cmdMbrola): for lang in self.espeak.loadMbrolaVoices(Settings.get('VoicesmbPath')): if lang[2]: self.listLanguages.append(lang) self.listLanguages.set_sort_column_id(0, gtk.SORT_ASCENDING) # Select default voice self.defaultLanguageIndex = 0 defaultLanguage = _('default language') if defaultLanguage == 'default language': defaultLanguage = 'default' self.defaultLanguageIndex = TreeModel_find_text( self.listLanguages, COL_LANGUAGE, defaultLanguage) # Prepare sorted model for voice variants self.listVariants = gtk.ListStore(str, str) self.listVariants.set_sort_column_id(0, gtk.SORT_ASCENDING) self.cboVariants.set_model(self.listVariants) cell = gtk.CellRendererText() self.cboVariants.pack_start(cell, True) self.cboVariants.add_attribute(cell, 'text', 1) self.winMain.set_default_size( Settings.default('MainWindowWidth'), Settings.default('MainWindowHeight') ) self.expSettings.set_expanded(Settings.get('SettingsExpander'))
self.txvBuffer.set_text(file.read()) print 'loading text from %s' % filename except IOError, (errno, strerror): ShowDialogError( text=_('Error opening the file') + '\n\n%s' % strerror, showOk=True, icon=handlepaths.get_app_logo() ) print 'unable to load %s (I/O error %s: %s)' % ( filename, errno, strerror ) except: ShowDialogError( text=_('Error opening the file'), showOk=True, icon=handlepaths.get_app_logo() ) print 'error loading %s' % filename if file: file.close() def on_imgmenuFileSaveAs_activate(self, widget, filename=None): "Saves the whole text in the specified filename" if not filename: dialog = DialogFileSave( title=_('Please select where to save the text file'), initialDir=os.path.expanduser('~')) txtFilter = _('Text files (*.txt)') dialog.addFilter(txtFilter, ['*.txt'], None) dialog.addFilter(_('All files'), ['*'], None) dialog.set_icon_from_file(handlepaths.get_app_logo())