def OnLinkClicked(self, linkInfo): global lastLookupWord lastLookupWord = linkInfo.GetHref() wx.BeginBusyCursor() parent = self.GetParent().GetParent().GetParent() word = enc.fromWX(lastLookupWord) try: word = word.encode(parent.activeDictionary.getEncoding()) except Exception as e: # FIXME: Code duplicates traceback.print_exc() parent.buttonStop.Disable() parent.entry.Enable(True) parent.timerSearch.Stop() parent.SetStatusText(_('Stopped')) wx.EndBusyCursor() systemLog(ERROR, "Unable to decode '%s': %s" % (word.encode('UTF-8'), e)) title = _("Encode Failed") msg = _("Unable to encode text \"%s\" in %s for \"%s\".") \ % (enc.toWX(word), parent.activeDictionary.getEncoding(), parent.activeDictionary.getName()) errorwin.showErrorMessage(title, msg) return parent.SetStatusText(_("Searching...")) parent.entry.SetValue(word) parent.timerSearch.Start(parent.delay) parent.search = Process(parent.activeDictionary.search, word)
def __init__(self, parent, id, title, msg, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE): wx.Dialog.__init__(self, parent, id, title, pos, size, style) vbox = wx.BoxSizer(wx.VERTICAL) vboxButtons = wx.BoxSizer(wx.HORIZONTAL) htmlWin = wx.html.HtmlWindow(self, -1, style=wx.SUNKEN_BORDER) htmlWin.SetFonts('Helvetica', 'Fixed', [10] * 5) error = False try: encodedText = enc.toWX(unicode(msg, 'UTF-8')) htmlWin.SetPage(encodedText) except Exception, e: systemLog(ERROR, "Unable to encode/show licence text: %s" % e) htmlWin.SetPage(_("Error: <i>unable to show licence text</i>")) error = True
def onInstallFile(self, event): """Install dictionary from file""" inst = installer.Installer(self.mainWin, self.app.config) inst.showGUI() dictNames = [] for name in self.app.dictionaries.keys(): dictNames.append(enc.toWX(name)) self.setInstalledDicts(dictNames)
def getText(): do = wx.TextDataObject() text = None wx.TheClipboard.Open() if wx.TheClipboard.GetData(do): try: text = do.GetText().strip() except Exception as e: print(e) wx.TheClipboard.Close() return enc.toWX(text)
def showInfo(self, dictInstance): """Show information about dictionary""" self.stName.Enable(1) self.stVersion.Enable(1) self.stAuthor.Enable(1) if dictInstance.getName(): dictName = enc.toWX(dictInstance.getName()) else: dictName = '--' self.labelName.SetLabel(dictName) if dictInstance.getVersion(): dictVersion = enc.toWX(dictInstance.getVersion()) else: dictVersion = '--' self.labelVersion.SetLabel(dictVersion) if dictInstance.getAuthors(): authors = [] for author in dictInstance.getAuthors(): if author: authors.append("%s <%s>" % (author.get('name'), author.get('email'))) dictAuthors = enc.toWX(', '.join(authors)) else: dictAuthors = '--' self.labelAuthor.SetLabel(dictAuthors) if dictInstance.getDescription(): description = enc.toWX(dictInstance.getDescription().strip()) else: description = '' self.textAbout.Clear() self.textAbout.WriteText(description)
def __init__(self, parent, id, title, msg, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE): wx.Dialog.__init__(self, parent, id, title, pos, size, style) vbox = wx.BoxSizer(wx.VERTICAL) vboxButtons = wx.BoxSizer(wx.HORIZONTAL) htmlWin = wx.html.HtmlWindow(self, -1, style=wx.SUNKEN_BORDER) htmlWin.SetFonts('Helvetica', 'Fixed', [10]*5) error = False try: encodedText = enc.toWX(unicode(msg, 'UTF-8')) htmlWin.SetPage(encodedText) except Exception, e: systemLog(ERROR, "Unable to encode/show licence text: %s" % e) htmlWin.SetPage(_("Error: <i>unable to show licence text</i>")) error = True
def __init__(self, parent, id, title, msg, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE): wx.Dialog.__init__(self, parent, id, title, pos, size, style) vbox = wx.BoxSizer(wx.VERTICAL) vboxButtons = wx.BoxSizer(wx.HORIZONTAL) htmlWin = wx.html.HtmlWindow(self, -1, style=wx.SUNKEN_BORDER) htmlWin.SetFonts('Helvetica', 'Fixed', [10] * 5) error = False try: encodedText = enc.toWX(str(msg, 'UTF-8')) htmlWin.SetPage(encodedText) except Exception as e: systemLog(ERROR, "Unable to encode/show licence text: %s" % e) htmlWin.SetPage(_("Error: <i>unable to show licence text</i>")) error = True vbox.Add(htmlWin, 1, wx.ALL | wx.EXPAND, 5) if not error: self.buttonNo = wx.Button(self, wx.ID_CANCEL, _("Do not accept")) vboxButtons.Add(self.buttonNo, 0, wx.ALL, 2) self.buttonYes = wx.Button(self, wx.ID_OK, _("Accept")) vboxButtons.Add(self.buttonYes, 0, wx.ALL, 2) else: self.buttonNo = wx.Button(self, wx.ID_CANCEL, _("Close")) vboxButtons.Add(self.buttonNo, 0, wx.ALL, 2) vbox.Add(vboxButtons, 0, wx.ALL | wx.ALIGN_RIGHT, 5) self.SetSizer(vbox)
def open(self): wildCard = "Slowo dictionaries (*.dwa)|*.dwa" dialog = wx.FileDialog(self, message=_("Choose dictionary file"), wildcard=wildCard, style=wx.FD_OPEN | wx.FD_MULTIPLE) if dialog.ShowModal() == wx.ID_OK: name = os.path.split(dialog.GetPaths()[0])[1] self.filePath = dialog.GetPaths()[0] self.name = os.path.split(self.filePath)[1] wx.BeginBusyCursor() try: self.editor.load(self.filePath) except Exception as e: wx.EndBusyCursor() traceback.print_exc() title = _("Open Failed") msg = _("Unable to open dictionary (got message: %s)") % e errorwin.showErrorMessage(title, msg) return self.SetTitle("%s - %s" % (self.priTitle, self.name)) self.list.Clear() words = [] for unit in self.editor.getUnits(): words.append(enc.toWX(unit.getWord())) words.sort() self.list.InsertItems(words, 0) self.checkAllButtons() self.SetStatusText(_("Dictionary loaded")) wx.EndBusyCursor()
def onSave(self, event): """Apply changes""" parent = self.GetParent() word = enc.fromWX(self.entryWord.GetValue()) translations = [] for label in self.textEntries.values(): translations.append(enc.fromWX(label.GetValue())) transcomm = {} for translation in translations: if not len(translation.strip()): continue chunks = translation.split('//', 1) if len(chunks) == 2: t = chunks[0] c = chunks[1] else: t = chunks[0] c = None transcomm[t] = c unit = dicteditor.Translation() unit.setWord(word) unit.setTranslations(transcomm) parent.editor.addUnit(unit) parent.list.Append(enc.toWX(word)) parent.setChanged(True) parent.checkAllButtons() self.Destroy()
def open(self): wildCard = "Slowo dictionaries (*.dwa)|*.dwa" dialog = wx.FileDialog(self, message=_("Choose dictionary file"), wildcard=wildCard, style=wx.OPEN|wx.MULTIPLE) if dialog.ShowModal() == wx.ID_OK: name = os.path.split(dialog.GetPaths()[0])[1] self.filePath = dialog.GetPaths()[0] self.name = os.path.split(self.filePath)[1] wx.BeginBusyCursor() try: self.editor.load(self.filePath) except Exception, e: wx.EndBusyCursor() traceback.print_exc() title = _("Open Failed") msg = _("Unable to open dictionary (got message: %s)") % e errorwin.showErrorMessage(title, msg) return self.SetTitle("%s - %s" % (self.priTitle, self.name)) self.list.Clear() words = [] for unit in self.editor.getUnits(): words.append(enc.toWX(unit.getWord())) words.sort() self.list.InsertItems(words, 0) self.checkAllButtons() self.SetStatusText(_("Dictionary loaded")) wx.EndBusyCursor()
def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style) self.app = wx.GetApp() self.printer = wx.html.HtmlEasyPrinting() self.history = History() self.htmlCode = "" self.dictName = "" self.activeDictionary = None self.words = [] self.delay = 10 # miliseconds self.lastInstalledDictName = None # This var is used by onTimerSearch to recognize search method. # If search was done by selecting a word in a list, then word list # is not updated, otherwise is. self.__searchedBySelecting = 0 # Box sizers vboxMain = wx.BoxSizer(wx.VERTICAL) self.hboxToolbar = wx.BoxSizer(wx.HORIZONTAL) # # Menu Bar # self.menuBar = wx.MenuBar() # # File menu # menuFile = wx.Menu() idPrint = wx.NewId() #menuFile.Append(idPrint, _("Print Translation"), "") idPreview = wx.NewId() #menuFile.Append(idPreview, _("Print Preview"), "") idFind = wx.NewId() menuFile.Append(idFind, _("Look Up\tCtrl-U"), _("Lookup up word in the dictionary")) menuFile.AppendSeparator() idCloseDict = wx.NewId() menuFile.Append(idCloseDict, _("&Close Dictionary\tCtrl-W"), _("Close opened dicitonary")) idExit = wx.NewId() menuFile.Append(idExit, _("E&xit\tCtrl-Q"), _("Exit program")) self.menuBar.Append(menuFile, _("&File")) menuEdit = wx.Menu() # # Clear functions # idClearEntry = wx.NewId() menuEdit.Append(idClearEntry, _("&Clear Search Entry\tCtrl-L")) idClearHistory = wx.NewId() menuEdit.Append(idClearHistory, _("Clear History")) menuEdit.AppendSeparator() # # Clipboard functions # idCopy = wx.NewId() menuEdit.Append(idCopy, _("Copy\tCtrl-C"), _("Copy selected translation text")) idPaste = wx.NewId() menuEdit.Append(idPaste, _("Paste\tCtrl-V"), _("Paste clipboard text into the search entry")) menuEdit.AppendSeparator() idPrefs = wx.NewId() menuEdit.Append(idPrefs, _("Preferences...\tCtrl-P"), _("Edit preferences")) self.menuBar.Append(menuEdit, _("&Edit")) # # View menu # menuView = wx.Menu() # Font size self.menuFontSize = wx.Menu() self.menuFontSize.Append(2007, _("Increase\tCtrl-="), _("Increase text size")) self.menuFontSize.Append(2008, _("Decrease\tCtrl--"), _("Decrease text size")) self.menuFontSize.AppendSeparator() self.menuFontSize.Append(2009, _("Normal\tCtrl-0"), _("Set normal text size")) menuView.Append(2002, _("Font Size"), self.menuFontSize) # Font face self.menuFontFace = wx.Menu() i = 0 keys = list(misc.fontFaces.keys()) keys.sort() for face in keys: self.menuFontFace.AppendRadioItem(2500 + i, face, "") self.Bind(wx.EVT_MENU, self.onDefault, id=2500 + i) if self.app.config.get('fontFace') == misc.fontFaces[face]: self.menuFontFace.FindItemById(2500 + i).Check(1) i += 1 menuView.Append(2001, _("Font Face"), self.menuFontFace) # Font encoding self.menuEncodings = wx.Menu() i = 0 keys = list(misc.encodings.keys()) keys.sort() for encoding in keys: self.menuEncodings.AppendRadioItem(2100 + i, encoding, "") self.Bind(wx.EVT_MENU, self.onDefault, id=2100 + i) if self.app.config.get('encoding') == misc.encodings[encoding]: self.menuEncodings.FindItemById(2100 + i).Check(1) i += 1 menuView.Append(2000, _("Character Encoding"), self.menuEncodings) menuView.AppendSeparator() idShowHide = wx.NewId() menuView.Append(idShowHide, _("Show/Hide Word List...\tCtrl-H"), _("Show or hide word list")) self.menuBar.Append(menuView, _("&View")) # # Dictionaries menu # self.menuDict = wx.Menu() dicts = [] for dictionary in list(self.app.dictionaries.values()): dicts.append([dictionary.getName(), dictionary.getActive()]) dicts.sort() for name, active in dicts: #if not self.app.config.activedict.enabled(name): # continue if not active: continue encoded = enc.toWX(name) itemID = list(self.app.config.ids.keys())[\ list(self.app.config.ids.values()).index(name)] try: # item = wx.MenuItem(self.menuDict, # itemID, # encoded) # self.menuDict.AppendItem(item) self.menuDict.AppendRadioItem(itemID, encoded, "") self.Bind(wx.EVT_MENU, self.onDefault, id=itemID) if self.app.config.get('defaultDict') == name: self.menuDict.FindItemById(itemID).Check(1) except Exception as e: systemLog(ERROR, "Unable to create menu item for '%s' (%s)" \ % (name, e)) self.menuDict.AppendSeparator() idAddDict = wx.NewId() self.menuDict.Append(idAddDict, _("&Install Dictionary From File...")) self.menuBar.Append(self.menuDict, _("&Dictionaries")) # # Tools menu # menuTools = wx.Menu() idManageDict = wx.NewId() 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() item = wx.MenuItem(menuTools, idUseScan, _("Take Words From Clipboard"), _("Scan the clipboard for text to translate"), wx.ITEM_CHECK) menuTools.Append(item) menuTools.Check(idUseScan, self.app.config.get('useClipboard') == 'True') menuTools.AppendSeparator() idDictServer = wx.NewId() menuTools.Append(idDictServer, _("Connect to DICT Server..."), _("Open connection to DICT server")) menuTools.AppendSeparator() idPron = wx.NewId() menuTools.Append(idPron, _("Pronounce\tCtrl-E"), _("Pronounce word")) self.menuBar.Append(menuTools, _("Tools")) # # Help menu # menuHelp = wx.Menu() idAbout = wx.NewId() menuHelp.Append(idAbout, _("&About\tCtrl-A")) self.menuBar.Append(menuHelp, _("&Help")) self.SetMenuBar(self.menuBar) # Search Bar labelWord = wx.StaticText(self, -1, _("Word:")) self.hboxToolbar.Add(labelWord, 0, wx.ALL | wx.CENTER, 5) self.entry = wx.ComboBox(self, 153, "", wx.Point(-1, -1), wx.Size(-1, -1), [], wx.CB_DROPDOWN) self.entry.SetToolTip(_("Enter some text and press " \ "\"Look Up\" button or " "[ENTER] key on your keyboard")) self.hboxToolbar.Add(self.entry, 1, wx.ALL | wx.CENTER, 1) #self.buttonSearch = wx.Button(self, wx.ID_FIND) self.buttonSearch = wx.Button(self, idFind, _("Look Up")) self.buttonSearch.SetToolTip(_("Click this button to look " \ "up word in " \ "the dictionary")) self.hboxToolbar.Add(self.buttonSearch, 0, wx.ALL | wx.CENTER, 1) # Back button bmp = wx.Bitmap(os.path.join(info.GLOBAL_HOME, "pixmaps", "left.png"), wx.BITMAP_TYPE_PNG) self.buttonBack = wx.BitmapButton(self, 2010, bmp, (24, 24), style=wx.NO_BORDER) self.buttonBack.SetToolTip(_("History Back")) self.buttonBack.Disable() self.hboxToolbar.Add(self.buttonBack, 0, wx.ALL | wx.CENTER, 1) # Forward button bmp = wx.Bitmap(os.path.join(info.GLOBAL_HOME, "pixmaps", "right.png"), wx.BITMAP_TYPE_PNG) self.buttonForward = wx.BitmapButton(self, 2011, bmp, (24, 24), style=wx.NO_BORDER) self.buttonForward.SetToolTip(_("History Forward")) self.buttonForward.Disable() self.hboxToolbar.Add(self.buttonForward, 0, wx.ALL | wx.CENTER, 1) # Stop threads # TODO: how thread can be killed? bmp = wx.Bitmap(os.path.join(info.GLOBAL_HOME, "pixmaps", "stop.png"), wx.BITMAP_TYPE_PNG) self.buttonStop = wx.BitmapButton(self, 155, bmp, (16, 16), style=wx.NO_BORDER) self.buttonStop.SetToolTip(_("Stop searching")) self.buttonStop.Disable() self.hboxToolbar.Add(self.buttonStop, 0, wx.ALL | wx.CENTER, 1) # Word list is hidden by default self.wlHidden = True bmp = wx.Bitmap(os.path.join(info.GLOBAL_HOME, "pixmaps", "hide.png"), wx.BITMAP_TYPE_PNG) self.buttonHide = wx.BitmapButton(self, 152, bmp, (24, 24), style=wx.NO_BORDER) self.hboxToolbar.Add(self.buttonHide, 0, wx.ALL | wx.CENTER, 1) vboxMain.Add(self.hboxToolbar, 0, wx.ALL | wx.EXPAND | wx.GROW, 0) # Splitter Window self.splitter = wx.SplitterWindow(self, -1) # List panel self.createListPanel() # Html window panel self.panelHtml = wx.Panel(self.splitter, -1) sbSizerHtml = wx.StaticBoxSizer( wx.StaticBox(self.panelHtml, -1, _("Translation")), wx.VERTICAL) self.htmlWin = HtmlWindow(self.panelHtml, -1, style=wx.SUNKEN_BORDER) sbSizerHtml.Add(self.htmlWin, 1, wx.ALL | wx.EXPAND, 0) self.panelHtml.SetSizer(sbSizerHtml) self.panelHtml.SetAutoLayout(True) sbSizerHtml.Fit(self.panelHtml) self.splitter.SplitVertically(self.panelList, self.panelHtml, int(self.app.config.get('sashPos'))) self.splitter.SetMinimumPaneSize(90) if not self.activeDictionary: self.hideWordList() vboxMain.Add(self.splitter, 1, wx.ALL | wx.GROW | wx.EXPAND, 0) # Status bar self.CreateStatusBar() # Main sizer self.SetSizer(vboxMain) self.timerSearch = wx.Timer(self, 5000) self.timerLoad = wx.Timer(self, 5001) idClipboard = wx.NewId() self.timerClipboard = wx.Timer(self, idClipboard) self.scanTimeout = 2000 self.search = None self.load = None self.SetIcon( wx.Icon( os.path.join(info.GLOBAL_HOME, "pixmaps", "icon-32x32.png"), wx.BITMAP_TYPE_PNG)) # # Loading default dictionary # if self.app.config.get('defaultDict'): self.loadDictionary(self.app.dictionaries.get(\ self.app.config.get('defaultDict'))) self.SetMinSize((320, 160)) # # Events # # TODO: New-style event definition # File menu events self.Bind(wx.EVT_MENU, self.onPrint, id=idPrint) self.Bind(wx.EVT_MENU, self.onPreview, id=idPreview) self.Bind(wx.EVT_MENU, self.onCloseDict, id=idCloseDict) self.Bind(wx.EVT_MENU, self.onExit, id=idExit) # Edit menu events self.Bind(wx.EVT_MENU, self.onClearHistory, id=idClearHistory) self.Bind(wx.EVT_MENU, self.onCopy, id=idCopy) self.Bind(wx.EVT_MENU, self.onPaste, id=idPaste) self.Bind(wx.EVT_MENU, self.onClean, id=idClearEntry) # View menu events self.Bind( wx.EVT_MENU, self.onIncreaseFontSize, id=2007, ) self.Bind(wx.EVT_MENU, self.onDecreaseFontSize, id=2008) self.Bind(wx.EVT_MENU, self.onNormalFontSize, id=2009) self.Bind(wx.EVT_MENU, self.onHideUnhide, id=idShowHide) # Dictionaries menu events self.Bind(wx.EVT_MENU, self.onAddDict, id=idAddDict) # Tools menu events self.Bind(wx.EVT_MENU, self.onOpenDictConn, id=idDictServer) self.Bind(wx.EVT_MENU, self.onUseScanClipboard, id=idUseScan) self.Bind(wx.EVT_MENU, self.onShowPluginManager, id=idManageDict) self.Bind(wx.EVT_MENU, self.onShowDictEditor, id=5002) self.Bind(wx.EVT_MENU, self.onShowPrefsWindow, id=idPrefs) self.Bind(wx.EVT_MENU, self.onPronounce, id=idPron) # Help menu events self.Bind(wx.EVT_MENU, self.onAbout, id=idAbout) # Other events self.Bind(wx.EVT_BUTTON, self.onSearch, self.buttonSearch) self.Bind(wx.EVT_MENU, self.onSearch, id=idFind) self.Bind(wx.EVT_BUTTON, self.onBack, id=2010) self.Bind(wx.EVT_BUTTON, self.onForward, id=2011) self.Bind(wx.EVT_BUTTON, self.onStop, id=155) self.Bind(wx.EVT_BUTTON, self.onClean, id=151) self.Bind(wx.EVT_BUTTON, self.onHideUnhide, id=152) self.Bind(wx.EVT_TEXT_ENTER, self.onSearch, id=153) self.Bind(wx.EVT_LISTBOX, self.onWordSelected, id=154) self.Bind(wx.EVT_TIMER, self.onTimerSearch, id=5000) self.Bind(wx.EVT_TIMER, self.onTimerClipboard, id=idClipboard) self.Bind(wx.EVT_CLOSE, self.onCloseWindow) self.entry.Bind(wx.EVT_KEY_DOWN, self.onKeyDown) # Prepare help message self.htmlCode = _(""" <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"> </head> <body> <h3>Welcome to OpenDict</h3> <p><b>Short usage information:</b></p> <ul> <li>To start using dictionary, select one from <i><b>Dictionaries</b></i> menu. </li> <li>To install new dictionary from the Internet, select <i><b>Manage Dictionaries</b></i> from <i><b>Tools</b></i> menu and choose <i><b>Available</b></i> tab.</li> <li>To install new dictionary from file, select <i><b>Install Dictionary From File...</b></i> from <i><b>Dictionaries</b></i> menu. </li> </ul> </body> </html> """) if self.activeDictionary: self.htmlCode = "" self.updateHtmlScreen() if self.app.invalidDictionaries: miscwin.showInvalidDicts(self, self.app.invalidDictionaries) if self.app.config.get('useClipboard') == 'True': self.timerClipboard.Start(self.scanTimeout)
def __init__(self, word, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style) vboxMain = wx.BoxSizer(wx.VERTICAL) hboxButtons = wx.BoxSizer(wx.HORIZONTAL) self.boxInfo = RowColSizer() self.boxInfo.Add(wx.StaticText(self, -1, _("Word: "), pos=(-1, -1)), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, row=0, col=0, border=1) self.entryWord = wx.TextCtrl(self, -1, word) self.entryWord.Disable() self.boxInfo.Add(self.entryWord, flag=wx.EXPAND, row=0, col=1, border=1) self.transLabels = {} self.textEntries = {} unit = parent.editor.getUnit(word) if unit: translations = unit.getTranslations() for trans in translations: comment = translations[trans] if comment: transcomm = u"%s // %s" % (trans, comment) else: transcomm = trans transcomm = enc.toWX(transcomm) self.onAddEmptyField(None) entry = self.textEntries.get(max(self.textEntries.keys())) if entry: entry.SetValue(transcomm) self.boxInfo.AddGrowableCol(1) vboxMain.Add(self.boxInfo, 1, wx.ALL | wx.EXPAND, 2) idAdd = wx.NewId() self.buttonAdd = wx.Button(self, idAdd, _("Add translation field")) vboxMain.Add(self.buttonAdd, 0, wx.ALL | wx.ALIGN_RIGHT, 2) self.buttonOK = wx.Button(self, 6050, _("OK")) hboxButtons.Add(self.buttonOK, 0, wx.ALL, 1) self.buttonCancel = wx.Button(self, 6051, _("Cancel")) hboxButtons.Add(self.buttonCancel, 0, wx.ALL, 1) vboxMain.Add(hboxButtons, 0, wx.ALL | wx.ALIGN_RIGHT, 2) self.SetSizer(vboxMain) self.Fit() self.SetSize((500, -1)) self.Bind(wx.EVT_BUTTON, self.onAddEmptyField, self.buttonAdd) self.Bind(wx.EVT_BUTTON, self.onSave, self.buttonOK) self.Bind(wx.EVT_BUTTON, self.onClose, self.buttonCancel)
def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize): wx.Dialog.__init__(self, parent, id, title, pos, size) vbox = wx.BoxSizer(wx.VERTICAL) nb = wx.Notebook(self, -1) # "Written by" panel writePanel = wx.Panel(nb, -1) vboxWrite = wx.BoxSizer(wx.VERTICAL) writtenString = unicode( "Martynas Jocius <*****@*****.**>\n" "Nerijus Baliūnas <*****@*****.**>\n" "Mantas Kriaučiūnas <*****@*****.**>", "UTF-8") written = enc.toWX(writtenString) labelWrite = wx.StaticText(writePanel, -1, written) vboxWrite.Add(labelWrite, 0, wx.ALL, 10) writePanel.SetSizer(vboxWrite) writePanel.SetFocus() nb.AddPage(writePanel, _("Written By")) # "Translations" panel tPanel = wx.Panel(nb, -1) vboxTP = wx.BoxSizer(wx.VERTICAL) transString = unicode("Martynas Jocius <*****@*****.**>", "UTF-8") trans = enc.toWX(transString) labelTP = wx.StaticText(tPanel, -1, trans) vboxTP.Add(labelTP, 0, wx.ALL, 10) tPanel.SetSizer(vboxTP) nb.AddPage(tPanel, _("Translated By")) # "Thanks" panel thPanel = wx.Panel(nb, -1) vboxThP = wx.BoxSizer(wx.VERTICAL) thanksString = _( "Ports:\n\n" ) + u"Debian/Ubuntu:\n Kęstutis Biliūnas <*****@*****.**>\n\nMacOS X:\n Linas Valiukas <*****@*****.**>" thanks = enc.toWX(thanksString) labelThP = wx.StaticText(thPanel, -1, thanks) vboxThP.Add(labelThP, 0, wx.ALL, 10) thPanel.SetSizer(vboxThP) nb.AddPage(thPanel, _("Thanks To")) # "Sponsor" panel sponsorPanel = wx.Panel(nb, -1) vboxSP = wx.BoxSizer(wx.VERTICAL) sponsorString = _("OpenDict project was sponsored by IDILES.\n" "Visit company's website at http://www.idiles.com.") sponsor = enc.toWX(sponsorString) labelSP = wx.StaticText(sponsorPanel, -1, sponsor) vboxSP.Add(labelSP, 0, wx.ALL, 10) sponsorPanel.SetSizer(vboxSP) nb.AddPage(sponsorPanel, _("Sponsors")) vbox.Add(nb, 1, wx.ALL | wx.EXPAND, 3) buttonClose = wx.Button(self, 2005, _("&Close")) vbox.Add(buttonClose, 0, wx.ALL | wx.ALIGN_RIGHT, 5) self.SetSizer(vbox) wx.EVT_BUTTON(self, 2005, self.onClose)
def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): """Initialize preferences dialog window""" wx.Dialog.__init__(self, parent, id, title, pos, size, style) self.app = wx.GetApp() vboxMain = wx.BoxSizer(wx.VERTICAL) hboxButtons = wx.BoxSizer(wx.HORIZONTAL) grid = wx.FlexGridSizer(4, 2, 1, 1) grid.Add(wx.StaticText(self, -1, _("Default dictionary: ")), 0, wx.ALIGN_CENTER_VERTICAL) dictNames = [] for name, d in list(self.app.dictionaries.items()): if d.getActive(): dictNames.append(name) dictNames.sort() dictNames.insert(0, "") try: list(map(enc.toWX, dictNames)) except Exception as e: systemLog(ERROR, "Unable to decode titles to UTF-8 (%s)" % e) self.dictChooser = wx.ComboBox( self, 1100, enc.toWX(self.app.config.get('defaultDict')), wx.Point(-1, -1), wx.Size(-1, -1), dictNames, wx.TE_READONLY) grid.Add(self.dictChooser, 0, wx.EXPAND) grid.Add(wx.StaticText(self, -1, _("Default encoding: ")), 0, wx.ALIGN_CENTER_VERTICAL) self.encChooser = wx.ComboBox( self, 1108, list(encodings.keys())[list(encodings.values()).index( self.app.config.get('encoding'))], wx.Point(-1, -1), wx.Size(-1, -1), list(encodings.keys()), wx.TE_READONLY) grid.Add(self.encChooser, 0, wx.EXPAND | wx.ALIGN_RIGHT) grid.AddGrowableCol(1) grid.Add(wx.StaticText(self, -1, _("Default DICT server: ")), 0, wx.ALIGN_CENTER_VERTICAL) self.serverEntry = wx.TextCtrl(self, -1, self.app.config.get('dictServer')) grid.Add(self.serverEntry, 0, wx.EXPAND) grid.Add(wx.StaticText(self, -1, _("Default DICT server port: ")), 0, wx.ALIGN_CENTER_VERTICAL) self.portEntry = wx.TextCtrl(self, -1, self.app.config.get('dictServerPort')) grid.Add(self.portEntry, 0, wx.EXPAND) vboxMain.Add(grid, 0, wx.ALL | wx.EXPAND, 4) # # Pronunciation # panelPron = wx.Panel(self, -1) sbSizerPron = wx.StaticBoxSizer( wx.StaticBox(panelPron, -1, _("Pronunciation")), wx.VERTICAL) panelPron.SetSizer(sbSizerPron) panelPron.SetAutoLayout(True) sbSizerPron.Fit(panelPron) vboxMain.Add(panelPron, 0, wx.ALL | wx.EXPAND, 5) hboxPronCmd = wx.BoxSizer(wx.HORIZONTAL) hboxPronCmd.Add(wx.StaticText(panelPron, -1, _("System Command: ")), 0, wx.ALIGN_CENTER_VERTICAL) self.entryPron = wx.TextCtrl(panelPron, -1, self.app.config.get('pronunciationCommand') or \ PRON_COMMAND) hboxPronCmd.Add(self.entryPron, 1, wx.EXPAND, 0) self.buttonDefaultPron = wx.Button(panelPron, 1106, _("Default")) hboxPronCmd.Add(self.buttonDefaultPron, 0, wx.ALL | wx.EXPAND) sbSizerPron.Add(hboxPronCmd, 0, wx.ALL | wx.EXPAND, 4) hboxPronWhat = wx.BoxSizer(wx.HORIZONTAL) self.rbPronOrig = wx.RadioButton(panelPron, -1, _("Pronounce original word")) hboxPronWhat.Add(self.rbPronOrig, 0, wx.ALL | wx.EXPAND, 3) self.rbPronTrans = wx.RadioButton(panelPron, -1, _("Pronounce translation")) if self.app.config.get('pronounceTrans') == 'True': self.rbPronTrans.SetValue(True) hboxPronWhat.Add(self.rbPronTrans, 0, wx.ALL | wx.EXPAND, 3) sbSizerPron.Add(hboxPronWhat, 0, wx.ALL | wx.EXPAND, 0) self.winSize = wx.CheckBox(self, 1101, _("Save window size on exit")) self.winSize.SetValue(self.app.config.get('saveWindowSize') == 'True') vboxMain.Add(self.winSize, 0, wx.ALL, 3) self.winPos = wx.CheckBox(self, 1102, _("Save window position on exit")) self.winPos.SetValue(self.app.config.get('saveWindowPos') == 'True') vboxMain.Add(self.winPos, 0, wx.ALL, 3) self.sashPos = wx.CheckBox(self, 1103, _("Save sash position on exit")) self.sashPos.SetValue(self.app.config.get('saveSashPos') == 'True') vboxMain.Add(self.sashPos, 0, wx.ALL, 3) self.clipboard = wx.CheckBox( self, 1103, _("Take words from the clipboard by default")) self.clipboard.SetValue(self.app.config.get('useClipboard') == 'True') vboxMain.Add(self.clipboard, 0, wx.ALL, 3) vboxMain.Add(wx.StaticLine(self, -1), 0, wx.ALL | wx.EXPAND, 5) self.buttonOK = wx.Button(self, 1104, _("OK")) hboxButtons.Add(self.buttonOK, 0, wx.ALL | wx.EXPAND, 1) self.buttonCancel = wx.Button(self, 1105, _("Cancel")) hboxButtons.Add(self.buttonCancel, 0, wx.ALL | wx.EXPAND, 1) vboxMain.Add(hboxButtons, 0, wx.ALL | wx.ALIGN_RIGHT, 4) self.SetSizer(vboxMain) self.Fit() self.SetSize((400, -1)) self.Bind(wx.EVT_CHECKBOX, self.onSaveWinSizeClicked, id=1101) self.Bind(wx.EVT_CHECKBOX, self.onSaveWinPosClicked, id=1102) self.Bind(wx.EVT_CHECKBOX, self.onSaveSashPosClicked, id=1103) self.Bind(wx.EVT_BUTTON, self.onDefaultPron, id=1106) self.Bind(wx.EVT_BUTTON, self.onOK, id=1104) self.Bind(wx.EVT_BUTTON, self.onCancel, id=1105)
def onSearch(self, event): if self.activeDictionary == None: if len(self.app.dictionaries): title = _("No dictionary activated") msg = _("No dictionary activated. Please select one from "\ "\"Dictionaries\" menu and try again.") else: title = _("No dictionaries installed") msg = _("There is no dictionaries installed. You can " \ "install one by selecting Tools > Manage " \ "Dictionaries > Available") errorwin.showErrorMessage(title, msg) return if self.search and not self.search.isDone(): self.onStop(None) word = self.entry.GetValue().strip() if word == "": self.SetStatusText(_("Please enter some text and try again")) self.entry.SetFocus() return global lastLookupWord lastLookupWord = word wx.BeginBusyCursor() self.__searchedBySelecting = 0 self.SetStatusText(_("Searching...")) self.timerSearch.Stop() self.search = None self.buttonStop.Enable(1) self.entry.Disable() self.timerSearch.Start(self.delay) word = enc.fromWX(word) try: word = word.encode(self.activeDictionary.getEncoding()) except Exception as e: # FIXME: Code duplicates self.buttonStop.Disable() self.entry.Enable(True) self.timerSearch.Stop() self.SetStatusText(_('Stopped')) wx.EndBusyCursor() systemLog(ERROR, "Unable to decode '%s': %s" % (word.encode('UTF-8'), e)) title = _("Encode Failed") msg = _("Unable to encode text \"%s\" in %s for \"%s\". " "That logically means the word " "definition does not exist in the dictionary.") \ % (enc.toWX(word), self.activeDictionary.getEncoding(), self.activeDictionary.getName()) errorwin.showErrorMessage(title, msg) return self.search = Process(self.activeDictionary.search, word)
def loadDictionary(self, dictInstance): """Prepares main window for using dictionary""" if not dictInstance: systemLog(ERROR, "loadDictionary: dictInstance is False") return # # Check licence agreement # licence = dictInstance.getLicence() if licence \ and not self.app.agreements.getAccepted(dictInstance.getPath()): if not miscwin.showLicenceAgreement(None, licence): from lib.gui import errorwin title = _("Licence Agreement Rejected") msg = _("You cannot use dictionary \"%s\" without accepting "\ "licence agreement") % dictInstance.getName() errorwin.showErrorMessage(title, msg) return else: self.app.agreements.addAgreement(dictInstance.getPath()) self.onCloseDict(None) self.activeDictionary = dictInstance if dictInstance.getType() in dicttype.indexableTypes: if plaindict.indexShouldBeMade(dictInstance): # Notify about indexing from lib.gui import errorwin title = _("Dictionary Index") msg = _("This is the first time you use this dictionary or it " \ "has been changed on disk since last indexing. " \ "Indexing is used to make search more efficient. " \ "The dictionary will be indexed now. It can take a few " \ "or more seconds.\n\n" \ "Press OK to continue...") errorwin.showInfoMessage(title, msg) # Make index try: wx.BeginBusyCursor() plaindict.makeIndex(dictInstance, self.app.config.get('encoding')) wx.EndBusyCursor() except Exception as e: wx.EndBusyCursor() traceback.print_exc() title = _("Index Creation Error") msg = _("Error occured while indexing file. " \ "This may be because of currently selected " \ "character encoding %s is not correct for this " \ "dictionary. Try selecting " \ "another encoding from View > Character Encoding " \ "menu") % self.app.config.get('encoding') from lib.gui import errorwin errorwin.showErrorMessage(title, msg) return # Load index try: wx.BeginBusyCursor() index = plaindict.loadIndex(dictInstance) self.activeDictionary.setIndex(index) wx.EndBusyCursor() except Exception as e: wx.EndBusyCursor() traceback.print_exc() title = _("Error") msg = _("Unable to load dictionary index table. " "Got error: %s") % e from lib.gui import errorwin errorwin.showErrorMessage(title, msg) return wx.BeginBusyCursor() self.activeDictionary.start() self.checkIfNeedsList() self.SetTitle(titleTemplate % dictInstance.getName()) self.SetStatusText(enc.toWX(_("Dictionary \"%s\" loaded") \ % dictInstance.getName())) self.entry.SetFocus() try: self.checkEncMenuItem(self.activeDictionary.getEncoding()) except Exception as e: systemLog(ERROR, "Unable to select encoding menu item: %s" % e) wx.EndBusyCursor()
def onTimerSearch(self, event): """Search timer. When finished, sets search results""" if self.search != None and self.search.isDone(): self.timerSearch.Stop() self.search.stop() # # Turn back active interface elements state wx.EndBusyCursor() self.SetStatusText("") self.entry.Enable(1) self.buttonStop.Disable() global lastLookupWord word = lastLookupWord if self.entry.FindString(word) == -1: self.entry.Append(word) result = self.search() # Check if search result is SerachResult object. # SearchResult class is used by new-type plugins. try: assert result.__class__ == meta.SearchResult except: self.SetStatusText(errortype.INTERNAL_ERROR.getMessage()) if self.activeDictionary.getType() == dicttype.PLUGIN: title = errortype.INTERNAL_ERROR.getMessage() message = errortype.INTERNAL_ERROR.getLongMessage() else: title = errortype.OPENDICT_BUG.getMessage() message = errortype.OPENDICT_BUG.getLongMessage() systemLog(ERROR, "%s: %s" % (message, misc.getTraceback())) errorwin.showErrorMessage(title, message) return # Check status code if result.getError() != errortype.OK: systemLog(ERROR, result.getError()) self.htmlWin.SetPage("") self.wordList.Clear() if result.getError() in \ [errortype.INTERNAL_ERROR, errortype.INVALID_ENCODING]: errorwin.showErrorMessage( result.getError().getMessage(), result.getError().getLongMessage()) else: self.SetStatusText(result.getError().getMessage()) return # # If dictionary (plugin) does not use NOT_FOUND notification, # check for translation and show it manually # if not result.getTranslation(): self.SetStatusText(errortype.NOT_FOUND.getMessage()) try: transUnicode = str(result.translation, self.activeDictionary.getEncoding()) except Exception as e: systemLog(ERROR, "Unable to decode translation in %s (%s)" \ % (self.activeDictionary.getEncoding(), e)) title = errortype.INVALID_ENCODING.getMessage() msg = _("Translation cannot be displayed using selected " \ "encoding %s. Please try another encoding from " \ "View > Character Encoding menu.") \ % self.activeDictionary.getEncoding() self.SetStatusText(title) errorwin.showErrorMessage(title, msg) return transPreparedForWX = enc.toWX(transUnicode) self.htmlWin.SetPage(transPreparedForWX) self.history.add(transPreparedForWX) # FIXME: Nasty names # Where it is used? htmlWin.GetPage self.htmlCode = transPreparedForWX if not self.wordListHidden(): if not self.__searchedBySelecting: self.wordList.Clear() toUnicode = lambda s: str( s, self.activeDictionary.getEncoding()) wordsInUnicode = list(map(toUnicode, result.words)) wordsPreparedForWX = list(map(enc.toWX, wordsInUnicode)) self.wordList.InsertItems(wordsPreparedForWX, 0) self.words = wordsPreparedForWX if not self.__searchedBySelecting: matches = self.wordList.GetCount() if matches == 1: self.SetStatusText(_("1 word matches")) elif matches > 1: self.SetStatusText(_("%d words match") % matches) else: self.SetStatusText(_("Done")) if self.history.canBack(): self.buttonBack.Enable(1) self.search = None
def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize): wx.Dialog.__init__(self, parent, id, title, pos, size) vbox = wx.BoxSizer(wx.VERTICAL) nb = wx.Notebook(self, -1) # "Written by" panel writePanel = wx.Panel(nb, -1) vboxWrite = wx.BoxSizer(wx.VERTICAL) writtenString = unicode("Martynas Jocius <*****@*****.**>\n" "Nerijus Baliūnas <*****@*****.**>\n" "Mantas Kriaučiūnas <*****@*****.**>", "UTF-8") written = enc.toWX(writtenString) labelWrite = wx.StaticText(writePanel, -1, written) vboxWrite.Add(labelWrite, 0, wx.ALL, 10) writePanel.SetSizer(vboxWrite) nb.AddPage(writePanel, _("Written By")) # "Translations" panel tPanel = wx.Panel(nb, -1) vboxTP = wx.BoxSizer(wx.VERTICAL) transString = unicode("Martynas Jocius <*****@*****.**>", "UTF-8") trans = enc.toWX(transString) labelTP = wx.StaticText(tPanel, -1, trans) vboxTP.Add(labelTP, 0, wx.ALL, 10) tPanel.SetSizer(vboxTP) nb.AddPage(tPanel, _("Translated By")) # "Thanks" panel thPanel = wx.Panel(nb, -1) vboxThP = wx.BoxSizer(wx.VERTICAL) thanksString = _("Ports:\n\n") + u"Debian/Ubuntu:\n Kęstutis Biliūnas <*****@*****.**>\n\nMacOS X:\n Linas Valiukas <*****@*****.**>" thanks = enc.toWX(thanksString) labelThP = wx.StaticText(thPanel, -1, thanks) vboxThP.Add(labelThP, 0, wx.ALL, 10) thPanel.SetSizer(vboxThP) nb.AddPage(thPanel, _("Thanks To")) # "Sponsor" panel sponsorPanel = wx.Panel(nb, -1) vboxSP = wx.BoxSizer(wx.VERTICAL) sponsorString = _("OpenDict project is sponsored by IDILES.\n" "Visit company's website at http://www.idiles.com.\n\n" "Report problems by email address [email protected].") sponsor = enc.toWX(sponsorString) labelSP = wx.StaticText(sponsorPanel, -1, sponsor) vboxSP.Add(labelSP, 0, wx.ALL, 10) sponsorPanel.SetSizer(vboxSP) nb.AddPage(sponsorPanel, _("Sponsors")) vbox.Add(nb, 1, wx.ALL | wx.EXPAND, 3) buttonClose = wx.Button(self, 2005, _("Close")) vbox.Add(buttonClose, 0, wx.ALL | wx.ALIGN_RIGHT, 5) self.SetSizer(vbox) wx.EVT_BUTTON(self, 2005, self.onClose)