|
From: Martynas J. <mj...@us...> - 2006-04-14 11:22:46
|
Update of /cvsroot/opendict/opendict/lib/gui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1615/lib/gui Modified Files: mainwin.py prefswin.py Log Message: Pronunciation support using external command (Festival by default) added. Index: prefswin.py =================================================================== RCS file: /cvsroot/opendict/opendict/lib/gui/prefswin.py,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- prefswin.py 6 Aug 2005 20:37:06 -0000 1.17 +++ prefswin.py 14 Apr 2006 11:22:35 -0000 1.18 @@ -25,11 +25,12 @@ from lib import enc _ = wxGetTranslation - +PRON_COMMAND = "echo \"(SayText \\\"%s\\\")\" | festival" class PrefsWindow(wxDialog): """Preferences dialog class""" + def __init__(self, parent, id, title, pos=wxDefaultPosition, size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE): """Initialize preferences dialog window""" @@ -85,6 +86,42 @@ grid.Add(self.portEntry, 0, wxEXPAND) vboxMain.Add(grid, 0, wxALL | wxEXPAND, 4) + + # + # Pronunciation + # + panelPron = wxPanel(self, -1) + sbSizerPron = wxStaticBoxSizer(wxStaticBox(panelPron, -1, + _("Pronunciation")), + wxVERTICAL) + panelPron.SetSizer(sbSizerPron) + panelPron.SetAutoLayout(true) + sbSizerPron.Fit(panelPron) + vboxMain.Add(panelPron, 0, wxALL | wxEXPAND, 5) + + hboxPronCmd = wxBoxSizer(wxHORIZONTAL) + hboxPronCmd.Add(wxStaticText(panelPron, -1, _("System Command: ")), 0, + wxALIGN_CENTER_VERTICAL) + + self.entryPron = wxTextCtrl(panelPron, -1, + self.app.config.get('pronunciationCommand') or \ + PRON_COMMAND) + hboxPronCmd.Add(self.entryPron, 1, wxEXPAND, 0) + + self.buttonDefaultPron = wxButton(panelPron, 1106, _("Default")) + hboxPronCmd.Add(self.buttonDefaultPron, 0, wxALL | wxEXPAND) + + sbSizerPron.Add(hboxPronCmd, 0, wxALL | wxEXPAND, 4) + + hboxPronWhat = wxBoxSizer(wxHORIZONTAL) + self.rbPronOrig = wxRadioButton(panelPron, -1, _("Pronounce original word")) + hboxPronWhat.Add(self.rbPronOrig, 0, wxALL | wxEXPAND, 3) + self.rbPronTrans = wxRadioButton(panelPron, -1, _("Pronounce translation")) + if self.app.config.get('pronounceTrans') == 'True': + self.rbPronTrans.SetValue(True) + hboxPronWhat.Add(self.rbPronTrans, 0, wxALL | wxEXPAND, 3) + + sbSizerPron.Add(hboxPronWhat, 0, wxALL | wxEXPAND, 0) self.winSize = wxCheckBox(self, 1101, _("Save window size on exit")) self.winSize.SetValue(self.app.config.get('saveWindowSize') == 'True') @@ -120,6 +157,7 @@ EVT_CHECKBOX(self, 1101, self.onSaveWinSizeClicked) EVT_CHECKBOX(self, 1102, self.onSaveWinPosClicked) EVT_CHECKBOX(self, 1103, self.onSaveSashPosClicked) + EVT_BUTTON(self, 1106, self.onDefaultPron) EVT_BUTTON(self, 1104, self.onOK) EVT_BUTTON(self, 1105, self.onCancel) @@ -157,6 +195,12 @@ self.app.config.saveSashPos = 0 + def onDefaultPron(self, event): + """Set pronunciation command to default value""" + + self.entryPron.SetValue(PRON_COMMAND) + + def onOK(self, event): """Save configuration in the configuration object""" @@ -169,6 +213,9 @@ self.app.config.set('dictServer', self.serverEntry.GetValue()) self.app.config.set('dictServerPort', self.portEntry.GetValue()) + + self.app.config.set('pronunciationCommand', self.entryPron.GetValue()) + self.app.config.set('pronounceTrans', str(self.rbPronTrans.GetValue())) self.app.config.set('saveWindowSize', str(self.winSize.GetValue())) self.app.config.set('saveWindowPos', str(self.winPos.GetValue())) Index: mainwin.py =================================================================== RCS file: /cvsroot/opendict/opendict/lib/gui/mainwin.py,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- mainwin.py 20 Mar 2006 20:37:24 -0000 1.95 +++ mainwin.py 14 Apr 2006 11:22:35 -0000 1.96 @@ -35,6 +35,7 @@ from lib.gui.dicteditorwin import DictEditorWindow from lib.gui.dictaddwin import DictAddWindow from lib.gui.prefswin import PrefsWindow +from lib.gui import prefswin from lib.gui.helpwin import LicenseWindow, AboutWindow from lib.gui import errorwin from lib.gui import miscwin @@ -301,6 +302,9 @@ menuTools.Append(idManageDict, _("Manage Dictionaries...\tCtrl-M"), _("Install or remove dictionaries")) + menuTools.Append(5002, _("Create Dictionaries..."), + _("Create and edit dictionaries")) + menuTools.AppendSeparator() idUseScan = wx.NewId() @@ -319,10 +323,12 @@ _("Open connection to DICT server")) menuTools.AppendSeparator() - - menuTools.Append(5002, _("Create Dictionaries..."), - _("Create and edit dictionaries")) + + idPron = wx.NewId() + menuTools.Append(idPron, _("Pronounce\tCtrl-E"), + _("Pronounce word")) + self.menuBar.Append(menuTools, _("Tools")) @@ -490,6 +496,7 @@ EVT_MENU(self, idManageDict, self.onShowPluginManager) EVT_MENU(self, 5002, self.onShowDictEditor) EVT_MENU(self, idPrefs, self.onShowPrefsWindow) + EVT_MENU(self, idPron, self.onPronounce) # Help menu events EVT_MENU(self, idAbout, self.onAbout) @@ -909,6 +916,32 @@ wxTheClipboard.Close() + def onPronounce(self, event): + """Pronouce word using external software.""" + + word = self.entry.GetValue().strip() + if word: + cmd = self.app.config.get('pronunciationCommand') or prefswin.PRON_COMMAND + + if self.app.config.get('pronounceTrans') == 'True': + word = html2text(self.htmlCode) + + import locale + localeCharset = locale.getpreferredencoding() + + try: + word = word.replace('(', '').replace(')', '').replace('\n', + '').replace('\r', '').replace('"', '\\"') + cmd = (cmd % word).encode(localeCharset) + Process(os.system, cmd) + except Exception, e: + traceback.print_exc() + title = _("Error") + msg = _("Unable to decode text using your locale charset %s" \ + % localeCharset) + errorwin.showErrorMessage(title, msg) + + def onShowGroupsWindow(self, event): """This method is invoked when Groups menu item is selected""" self.groupsWindow = GroupsWindow(self, -1, |