예제 #1
0
  def __init__(self):
    print 'starting %s' % handlepaths.APP_NAME
    self.espeak = EspeakFrontend()
    # Create temporary filename
    self.tempFilename = tempfile.mkstemp(prefix=handlepaths.APP_NAME)[1]
    self.timeoutCheck = None
    self.recordToFile = None
    self.recordToFileRequested = False
    self.variants = ((), ())
    gladeUI = handlepaths.getPath('ui', 'gespeaker.glade')
    print 'loading interface from %s' % gladeUI
    self.gladeFile = gtk.glade.XML(fname=gladeUI, domain=handlepaths.APP_NAME)
    # Proxy maps
    self.proxy = {
      'text.set': self.set_text,
      'text.cut': self.on_imgmenuEditCut_activate,
      'text.copy': self.on_imgmenuEditCopy_activate,
      'text.paste': self.on_imgmenuEditPaste_activate,
      'ui.new':  self.on_imgmenuFileNew_activate,
      'ui.open': self.on_imgmenuFileOpen_activate,
      'ui.save': self.on_imgmenuFileSaveAs_activate,
      'ui.record': self.on_imgmenuFileRec_activate,
      'ui.unrecord': self.disable_record,
      'ui.reset': self.on_imgmenuEditResetSettings_activate,
      'ui.quit': self.on_imgmenuFileQuit_activate,
      'ui.set_size': self.set_size,
      'ui.set_position': self.set_position,
      'ui.set_window': self.set_window,
      'espeak.play': self.on_imgmenuEditPlay_activate,
      'espeak.stop': self.on_imgmenuEditStop_activate,
      'espeak.pause': self.on_imgmenuEditPause_activate,
      'espeak.is_playing': self.checkIfPlaying,
    }
    # Signals handler
    signals = {
      'on_imgmenuFileQuit_activate': self.on_imgmenuFileQuit_activate,
      'on_imgmenuEditPlay_activate': self.on_imgmenuEditPlay_activate,
      'on_imgmenuFileNew_activate': self.on_imgmenuFileNew_activate,
      'on_imgmenuFileOpen_activate': self.on_imgmenuFileOpen_activate,
      'on_imgmenuFileSaveAs_activate': self.on_imgmenuFileSaveAs_activate,
      'on_imgmenuEditStop_activate': self.on_imgmenuEditStop_activate,
      'on_btnPlayStop_toggled': self.on_btnPlayStop_toggled,
      'on_btnPause_toggled': self.on_btnPause_toggled,
      'on_tlbRecord_toggled': self.on_tlbRecord_toggled,
      'on_imgmenuEditPause_activate': self.on_imgmenuEditPause_activate,
      'on_imgmenuFileRec_activate': self.on_imgmenuFileRec_activate,
      'on_imgmenuEditResetSettings_activate': self.on_imgmenuEditResetSettings_activate,
      'on_imgmenuEditCut_activate': self.on_imgmenuEditCut_activate,
      'on_imgmenuEditCopy_activate': self.on_imgmenuEditCopy_activate,
      'on_imgmenuEditPaste_activate': self.on_imgmenuEditPaste_activate,
      'on_imgmenuHelpAbout_activate': self.on_imgmenuHelpAbout_activate,
      'on_imgmenuEditPreferences_activate': self.on_imgmenuEditPreferences_activate,
      'on_radioVoice_toggled': self.on_radioVoice_toggled,
      'on_cboLanguages_changed': self.on_cboLanguages_changed
    }
    self.gladeFile.signal_autoconnect(signals)
    # Set clipboard
    display = gtk.gdk.display_manager_get().get_default_display()
    self.clipboard = gtk.Clipboard(display, "CLIPBOARD")

    # Load window and controls
    self.loadControls()
    self.loadSettings(True)
예제 #2
0
  def __init__(self):
    print 'starting %s' % handlepaths.APP_NAME
    self.espeak = EspeakFrontend()
    # Create temporary filename
    self.tempFilename = tempfile.mkstemp(prefix=handlepaths.APP_NAME)[1]
    self.timeoutCheck = None
    self.recordToFile = None
    self.recordToFileRequested = False
    self.variants = ((), ())
    gladeUI = handlepaths.getPath('ui', 'gespeaker.glade')
    print 'loading interface from %s' % gladeUI
    self.gladeFile = gtk.glade.XML(fname=gladeUI, domain=handlepaths.APP_NAME)
    # Proxy maps
    self.proxy = {
      'text.set': self.set_text,
      'text.cut': self.on_imgmenuEditCut_activate,
      'text.copy': self.on_imgmenuEditCopy_activate,
      'text.paste': self.on_imgmenuEditPaste_activate,
      'ui.new':  self.on_imgmenuFileNew_activate,
      'ui.open': self.on_imgmenuFileOpen_activate,
      'ui.save': self.on_imgmenuFileSaveAs_activate,
      'ui.record': self.on_imgmenuFileRec_activate,
      'ui.unrecord': self.disable_record,
      'ui.reset': self.on_imgmenuEditResetSettings_activate,
      'ui.quit': self.on_imgmenuFileQuit_activate,
      'ui.set_size': self.set_size,
      'ui.set_position': self.set_position,
      'ui.set_window': self.set_window,
      'espeak.play': self.on_imgmenuEditPlay_activate,
      'espeak.stop': self.on_imgmenuEditStop_activate,
      'espeak.pause': self.on_imgmenuEditPause_activate,
      'espeak.is_playing': self.checkIfPlaying,
    }
    # Signals handler
    signals = {
      'on_imgmenuFileQuit_activate': self.on_imgmenuFileQuit_activate,
      'on_imgmenuEditPlay_activate': self.on_imgmenuEditPlay_activate,
      'on_imgmenuFileNew_activate': self.on_imgmenuFileNew_activate,
      'on_imgmenuFileOpen_activate': self.on_imgmenuFileOpen_activate,
      'on_imgmenuFileSaveAs_activate': self.on_imgmenuFileSaveAs_activate,
      'on_imgmenuEditStop_activate': self.on_imgmenuEditStop_activate,
      'on_btnPlayStop_toggled': self.on_btnPlayStop_toggled,
      'on_btnPause_toggled': self.on_btnPause_toggled,
      'on_tlbRecord_toggled': self.on_tlbRecord_toggled,
      'on_imgmenuEditPause_activate': self.on_imgmenuEditPause_activate,
      'on_imgmenuFileRec_activate': self.on_imgmenuFileRec_activate,
      'on_imgmenuEditResetSettings_activate': self.on_imgmenuEditResetSettings_activate,
      'on_imgmenuEditCut_activate': self.on_imgmenuEditCut_activate,
      'on_imgmenuEditCopy_activate': self.on_imgmenuEditCopy_activate,
      'on_imgmenuEditPaste_activate': self.on_imgmenuEditPaste_activate,
      'on_imgmenuHelpAbout_activate': self.on_imgmenuHelpAbout_activate,
      'on_imgmenuEditPreferences_activate': self.on_imgmenuEditPreferences_activate,
      'on_radioVoice_toggled': self.on_radioVoice_toggled,
      'on_cboLanguages_changed': self.on_cboLanguages_changed
    }
    self.gladeFile.signal_autoconnect(signals)
    # Set clipboard
    display = gtk.gdk.display_manager_get().get_default_display()
    self.clipboard = gtk.Clipboard(display, "CLIPBOARD")

    # Load window and controls
    self.loadControls()
    self.loadSettings(True)
예제 #3
0
class gespeakerUI(object):
  def __init__(self):
    print 'starting %s' % handlepaths.APP_NAME
    self.espeak = EspeakFrontend()
    # Create temporary filename
    self.tempFilename = tempfile.mkstemp(prefix=handlepaths.APP_NAME)[1]
    self.timeoutCheck = None
    self.recordToFile = None
    self.recordToFileRequested = False
    self.variants = ((), ())
    gladeUI = handlepaths.getPath('ui', 'gespeaker.glade')
    print 'loading interface from %s' % gladeUI
    self.gladeFile = gtk.glade.XML(fname=gladeUI, domain=handlepaths.APP_NAME)
    # Proxy maps
    self.proxy = {
      'text.set': self.set_text,
      'text.cut': self.on_imgmenuEditCut_activate,
      'text.copy': self.on_imgmenuEditCopy_activate,
      'text.paste': self.on_imgmenuEditPaste_activate,
      'ui.new':  self.on_imgmenuFileNew_activate,
      'ui.open': self.on_imgmenuFileOpen_activate,
      'ui.save': self.on_imgmenuFileSaveAs_activate,
      'ui.record': self.on_imgmenuFileRec_activate,
      'ui.unrecord': self.disable_record,
      'ui.reset': self.on_imgmenuEditResetSettings_activate,
      'ui.quit': self.on_imgmenuFileQuit_activate,
      'ui.set_size': self.set_size,
      'ui.set_position': self.set_position,
      'ui.set_window': self.set_window,
      'espeak.play': self.on_imgmenuEditPlay_activate,
      'espeak.stop': self.on_imgmenuEditStop_activate,
      'espeak.pause': self.on_imgmenuEditPause_activate,
      'espeak.is_playing': self.checkIfPlaying,
    }
    # Signals handler
    signals = {
      'on_imgmenuFileQuit_activate': self.on_imgmenuFileQuit_activate,
      'on_imgmenuEditPlay_activate': self.on_imgmenuEditPlay_activate,
      'on_imgmenuFileNew_activate': self.on_imgmenuFileNew_activate,
      'on_imgmenuFileOpen_activate': self.on_imgmenuFileOpen_activate,
      'on_imgmenuFileSaveAs_activate': self.on_imgmenuFileSaveAs_activate,
      'on_imgmenuEditStop_activate': self.on_imgmenuEditStop_activate,
      'on_btnPlayStop_toggled': self.on_btnPlayStop_toggled,
      'on_btnPause_toggled': self.on_btnPause_toggled,
      'on_tlbRecord_toggled': self.on_tlbRecord_toggled,
      'on_imgmenuEditPause_activate': self.on_imgmenuEditPause_activate,
      'on_imgmenuFileRec_activate': self.on_imgmenuFileRec_activate,
      'on_imgmenuEditResetSettings_activate': self.on_imgmenuEditResetSettings_activate,
      'on_imgmenuEditCut_activate': self.on_imgmenuEditCut_activate,
      'on_imgmenuEditCopy_activate': self.on_imgmenuEditCopy_activate,
      'on_imgmenuEditPaste_activate': self.on_imgmenuEditPaste_activate,
      'on_imgmenuHelpAbout_activate': self.on_imgmenuHelpAbout_activate,
      'on_imgmenuEditPreferences_activate': self.on_imgmenuEditPreferences_activate,
      'on_radioVoice_toggled': self.on_radioVoice_toggled,
      'on_cboLanguages_changed': self.on_cboLanguages_changed
    }
    self.gladeFile.signal_autoconnect(signals)
    # Set clipboard
    display = gtk.gdk.display_manager_get().get_default_display()
    self.clipboard = gtk.Clipboard(display, "CLIPBOARD")

    # Load window and controls
    self.loadControls()
    self.loadSettings(True)
  
  def run(self):
    "Start main loop"
    self.proxy['ui.set_window']('show')
    gtk.main()
  
  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'))

  def loadSettings(self, loadEverything):
    if loadEverything:
      # Restore voice settings
      self.hscVolume.set_value(Settings.get('VoiceVolume'))
      self.hscPitch.set_value(Settings.get('VoicePitch'))
      self.hscSpeed.set_value(Settings.get('VoiceSpeed'))
      self.hscDelay.set_value(Settings.get('VoiceDelay'))
      if Settings.get('VoiceTypeMale'):
        self.radioVoiceMale.set_active(True)
      else:
        self.radioVoiceFemale.set_active(True)
      # Sets default language
      language = Settings.get('VoiceLanguage')
      languageIndex = TreeModel_find_text(self.listLanguages, COL_LANGUAGE, language)
      if not ComboBox_set_item_from_text(self.cboLanguages, 0, language):
        self.cboLanguages.set_active(self.defaultLanguageIndex)
      Settings.set('VoiceLanguage', self.listLanguages[self.cboLanguages.get_active()][COL_NAME])
    # Load standard settings
    self.txvText.set_wrap_mode(
      Settings.get('WordWrap') and gtk.WRAP_WORD or gtk.WRAP_NONE)
    players = ('aplay', 'paplay', '', Settings.get('PlayCommand'))
    self.cmdPlayer = players[Settings.get('PlayMethod')]
    # Load voice variants
    if Settings.get('LoadVariants'):
      self.variants = self.espeak.loadVariants(Settings.cmdEspeak)
      self.lblVariants.show()
      self.cboVariants.show()
    else:
      self.variants = ((), ())
      self.lblVariants.hide()
      self.cboVariants.hide()
    # Reload list
    voicebutton = Radio_get_active(self.radioVoiceMale.get_group())
    self.on_radioVoice_toggled(voicebutton, None)

  def on_imgmenuFileQuit_activate(self, widget, data=None):
    "Close the program"
    plugins.signal_proxy('on_closing')
    if self.tempFilename and os.path.exists(self.tempFilename):
      os.remove(self.tempFilename)
    gtk.main_quit()
    return 0
  
  def on_imgmenuEditPlay_activate(self, widget, data=None):
    "Press button to start play, indirect cause button style"
    self.btnPlayStop.set_active(True)
  
  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_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:
예제 #4
0
class gespeakerUI(object):
  def __init__(self):
    print 'starting %s' % handlepaths.APP_NAME
    self.espeak = EspeakFrontend()
    # Create temporary filename
    self.tempFilename = tempfile.mkstemp(prefix=handlepaths.APP_NAME)[1]
    self.timeoutCheck = None
    self.recordToFile = None
    self.recordToFileRequested = False
    self.variants = ((), ())
    gladeUI = handlepaths.getPath('ui', 'gespeaker.glade')
    print 'loading interface from %s' % gladeUI
    self.gladeFile = gtk.glade.XML(fname=gladeUI, domain=handlepaths.APP_NAME)
    # Proxy maps
    self.proxy = {
      'text.set': self.set_text,
      'text.cut': self.on_imgmenuEditCut_activate,
      'text.copy': self.on_imgmenuEditCopy_activate,
      'text.paste': self.on_imgmenuEditPaste_activate,
      'ui.new':  self.on_imgmenuFileNew_activate,
      'ui.open': self.on_imgmenuFileOpen_activate,
      'ui.save': self.on_imgmenuFileSaveAs_activate,
      'ui.record': self.on_imgmenuFileRec_activate,
      'ui.unrecord': self.disable_record,
      'ui.reset': self.on_imgmenuEditResetSettings_activate,
      'ui.quit': self.on_imgmenuFileQuit_activate,
      'ui.set_size': self.set_size,
      'ui.set_position': self.set_position,
      'ui.set_window': self.set_window,
      'espeak.play': self.on_imgmenuEditPlay_activate,
      'espeak.stop': self.on_imgmenuEditStop_activate,
      'espeak.pause': self.on_imgmenuEditPause_activate,
      'espeak.is_playing': self.checkIfPlaying,
    }
    # Signals handler
    signals = {
      'on_imgmenuFileQuit_activate': self.on_imgmenuFileQuit_activate,
      'on_imgmenuEditPlay_activate': self.on_imgmenuEditPlay_activate,
      'on_imgmenuFileNew_activate': self.on_imgmenuFileNew_activate,
      'on_imgmenuFileOpen_activate': self.on_imgmenuFileOpen_activate,
      'on_imgmenuFileSaveAs_activate': self.on_imgmenuFileSaveAs_activate,
      'on_imgmenuEditStop_activate': self.on_imgmenuEditStop_activate,
      'on_btnPlayStop_toggled': self.on_btnPlayStop_toggled,
      'on_btnPause_toggled': self.on_btnPause_toggled,
      'on_tlbRecord_toggled': self.on_tlbRecord_toggled,
      'on_imgmenuEditPause_activate': self.on_imgmenuEditPause_activate,
      'on_imgmenuFileRec_activate': self.on_imgmenuFileRec_activate,
      'on_imgmenuEditResetSettings_activate': self.on_imgmenuEditResetSettings_activate,
      'on_imgmenuEditCut_activate': self.on_imgmenuEditCut_activate,
      'on_imgmenuEditCopy_activate': self.on_imgmenuEditCopy_activate,
      'on_imgmenuEditPaste_activate': self.on_imgmenuEditPaste_activate,
      'on_imgmenuHelpAbout_activate': self.on_imgmenuHelpAbout_activate,
      'on_imgmenuEditPreferences_activate': self.on_imgmenuEditPreferences_activate,
      'on_radioVoice_toggled': self.on_radioVoice_toggled,
      'on_cboLanguages_changed': self.on_cboLanguages_changed
    }
    self.gladeFile.signal_autoconnect(signals)
    # Set clipboard
    display = gtk.gdk.display_manager_get().get_default_display()
    self.clipboard = gtk.Clipboard(display, "CLIPBOARD")

    # Load window and controls
    self.loadControls()
    self.loadSettings(True)
  
  def run(self):
    "Start main loop"
    self.proxy['ui.set_window']('show')
    gtk.main()
  
  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'))

  def loadSettings(self, loadEverything):
    if loadEverything:
      # Restore voice settings
      self.hscVolume.set_value(Settings.get('VoiceVolume'))
      self.hscPitch.set_value(Settings.get('VoicePitch'))
      self.hscSpeed.set_value(Settings.get('VoiceSpeed'))
      self.hscDelay.set_value(Settings.get('VoiceDelay'))
      if Settings.get('VoiceTypeMale'):
        self.radioVoiceMale.set_active(True)
      else:
        self.radioVoiceFemale.set_active(True)
      # Sets default language
      language = Settings.get('VoiceLanguage')
      languageIndex = TreeModel_find_text(self.listLanguages, COL_LANGUAGE, language)
      if not ComboBox_set_item_from_text(self.cboLanguages, 0, language):
        self.cboLanguages.set_active(self.defaultLanguageIndex)
      Settings.set('VoiceLanguage', self.listLanguages[self.cboLanguages.get_active()][COL_NAME])
    # Load standard settings
    self.txvText.set_wrap_mode(
      Settings.get('WordWrap') and gtk.WRAP_WORD or gtk.WRAP_NONE)
    players = ('aplay', 'paplay', '', Settings.get('PlayCommand'))
    self.cmdPlayer = players[Settings.get('PlayMethod')]
    # Load voice variants
    if Settings.get('LoadVariants'):
      self.variants = self.espeak.loadVariants(Settings.cmdEspeak)
      self.lblVariants.show()
      self.cboVariants.show()
    else:
      self.variants = ((), ())
      self.lblVariants.hide()
      self.cboVariants.hide()
    # Reload list
    voicebutton = Radio_get_active(self.radioVoiceMale.get_group())
    self.on_radioVoice_toggled(voicebutton, None)

  def on_imgmenuFileQuit_activate(self, widget, data=None):
    "Close the program"
    plugins.signal_proxy('on_closing')
    if self.tempFilename and os.path.exists(self.tempFilename):
      os.remove(self.tempFilename)
    gtk.main_quit()
    return 0
  
  def on_imgmenuEditPlay_activate(self, widget, data=None):
    "Press button to start play, indirect cause button style"
    self.btnPlayStop.set_active(True)
  
  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_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: