diff --git a/ankiqt/ui/__init__.py b/ankiqt/ui/__init__.py index 0c74141a9..0e41f8b1f 100644 --- a/ankiqt/ui/__init__.py +++ b/ankiqt/ui/__init__.py @@ -14,7 +14,6 @@ def importAll(): import exporting import facteditor import help - import lookup import modelchooser import modelproperties import preferences diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 57af844ce..dc0aba83f 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -1009,46 +1009,6 @@ class FactEdit(QTextEdit): self.parent.disableButtons() self.emit(SIGNAL("lostFocus")) - # this shouldn't be necessary if/when we move away from kakasi - def mouseDoubleClickEvent(self, evt): - t = self.parent.fact.model.tags.lower() - if (not "japanese" in t and - not "mandarin" in t and - not "cantonese" in t): - return QTextEdit.mouseDoubleClickEvent(self,evt) - r = QRegExp("\\{(.*[|,].*)\\}") - r.setMinimal(True) - - mouseposition = self.textCursor().position() - - blockoffset = 0 - result = r.indexIn(self.toPlainText(), 0) - - found = "" - - while result != -1: - if mouseposition > result and mouseposition < result + r.matchedLength(): - mouseposition -= result + 1 - frompos = 0 - topos = 0 - - string = r.cap(1) - offset = 0 - bits = re.split("[|,]", unicode(string)) - for index in range(0, len(bits)): - offset += len(bits[index]) + 1 - if mouseposition < offset: - found = bits[index] - break - break - - blockoffset= result + r.matchedLength() - result = r.indexIn(self.toPlainText(), blockoffset) - - if found == "": - return QTextEdit.mouseDoubleClickEvent(self,evt) - self.setPlainText(self.toPlainText().replace(result, r.matchedLength(), found)) - def focusInEvent(self, evt): if (self.parent.lastFocusedEdit and self.parent.lastFocusedEdit is not self): diff --git a/ankiqt/ui/lookup.py b/ankiqt/ui/lookup.py deleted file mode 100644 index 8041177a3..000000000 --- a/ankiqt/ui/lookup.py +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright: Damien Elmes -# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html - -from PyQt4.QtGui import * -from PyQt4.QtCore import * -import urllib, re -import anki -from ankiqt import ui - -# Tools - looking up words in the dictionary -########################################################################## - -class Lookup(object): - - def __init__(self, main): - self.main = main - - def selection(self, function): - "Get the selected text and look it up with FUNCTION." - text = unicode(self.main.mainWin.mainText.selectedText()) - text = text.strip() - if "\n" in text: - ui.utils.showInfo(_("Can't look up a selection with a newline.")) - return - text = text.strip() - if not text: - ui.utils.showInfo(_("Empty selection.")) - return - function(text) - - def edictKanji(self, text): - self.edict(text, True) - - def edict(self, text, kanji=False): - "Look up TEXT with edict." - if kanji: - x="M" - else: - x="U" - baseUrl="http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1M" + x - if isJapaneseText(text): - baseUrl += "J" - else: - baseUrl += "E" - url = baseUrl + urllib.quote(text.encode("utf-8")) - qurl = QUrl() - qurl.setEncodedUrl(url) - QDesktopServices.openUrl(qurl) - - def alc(self, text): - "Look up TEXT with ALC." - newText = urllib.quote(text.encode("utf-8")) - url = ( - "http://eow.alc.co.jp/" + - newText + - "/UTF-8/?ref=sa") - qurl = QUrl() - qurl.setEncodedUrl(url) - QDesktopServices.openUrl(qurl) - -def isJapaneseText(text): - "True if 70% of text is a Japanese character." - total = len(text) - if total == 0: - return True - jp = 0 - en = 0 - for c in text: - if ord(c) >= 0x2E00 and ord(c) <= 0x9FFF: - jp += 1 - if re.match("[A-Za-z]", c): - en += 1 - if not jp: - return False - return ((jp + 1) / float(en + 1)) >= 1.0 diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index caef70743..d91e89604 100755 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1552,68 +1552,9 @@ learnt today") tb = self.mainWin.toolBar self.config['showToolbar'] = tb.isVisible() - # Tools - looking up words in the dictionary - ########################################################################## - - def initLookup(self): - if not getattr(self, "lookup", None): - self.lookup = ui.lookup.Lookup(self) - - def onLookupExpression(self): - self.initLookup() - try: - self.lookup.alc(self.currentCard.fact['Expression']) - except KeyError: - ui.utils.showInfo(_("No expression in current card.")) - - def onLookupMeaning(self): - self.initLookup() - try: - self.lookup.alc(self.currentCard.fact['Meaning']) - except KeyError: - ui.utils.showInfo(_("No meaning in current card.")) - - def onLookupEdictSelection(self): - self.initLookup() - self.lookup.selection(self.lookup.edict) - - def onLookupEdictKanjiSelection(self): - self.initLookup() - self.lookup.selection(self.lookup.edictKanji) - - def onLookupAlcSelection(self): - self.initLookup() - self.lookup.selection(self.lookup.alc) - # Tools - statistics ########################################################################## - def onKanjiStats(self): - rep = anki.stats.KanjiStats(self.deck).report() - rep += _("Missing
") - rep += _("Seen
") - rep += _("Non-jouyou
") - self.help.showText(rep, py={ - "miss": self.onMissingStats, - "seen": self.onSeenKanjiStats, - "non": self.onNonJouyouKanjiStats, - }) - - def onMissingStats(self): - ks = anki.stats.KanjiStats(self.deck) - ks.genKanjiSets() - self.help.showText(ks.missingReport()) - - def onSeenKanjiStats(self): - ks = anki.stats.KanjiStats(self.deck) - ks.genKanjiSets() - self.help.showText(ks.seenReport()) - - def onNonJouyouKanjiStats(self): - ks = anki.stats.KanjiStats(self.deck) - ks.genKanjiSets() - self.help.showText(ks.nonJouyouReport()) - def onDeckStats(self): txt = anki.stats.DeckStats(self.deck).report() self.help.showText(txt) @@ -2194,13 +2135,7 @@ Couldn't contact Anki Online. Please check your internet connection.""") self.connect(m.actionEditdeck, s, self.onEditDeck) self.connect(m.actionEditCurrent, s, self.onEditCurrent) self.connect(m.actionPreferences, s, self.onPrefs) - self.connect(m.actionLookup_es, s, self.onLookupEdictSelection) - self.connect(m.actionLookup_esk, s, self.onLookupEdictKanjiSelection) - self.connect(m.actionLookup_expr, s, self.onLookupExpression) - self.connect(m.actionLookup_mean, s, self.onLookupMeaning) - self.connect(m.actionLookup_as, s, self.onLookupAlcSelection) self.connect(m.actionDstats, s, self.onDeckStats) - self.connect(m.actionKstats, s, self.onKanjiStats) self.connect(m.actionCstats, s, self.onCardStats) self.connect(m.actionGraphs, s, self.onShowGraph) self.connect(m.actionAbout, s, self.onAbout) @@ -2281,8 +2216,6 @@ Couldn't contact Anki Online. Please check your internet connection.""") def disableCardMenuItems(self): self.maybeEnableUndo() - self.maybeShowLookup(False) - self.maybeShowKanjiStats() self.mainWin.actionEditCurrent.setEnabled(False) self.mainWin.actionMarkCard.setEnabled(False) self.mainWin.actionSuspendCard.setEnabled(False) @@ -2292,8 +2225,6 @@ Couldn't contact Anki Online. Please check your internet connection.""") def enableCardMenuItems(self): self.maybeEnableUndo() - self.maybeShowLookup(True) - self.maybeShowKanjiStats() snd = (hasSound(self.currentCard.question) or (hasSound(self.currentCard.answer) and self.state != "getQuestion")) @@ -2307,34 +2238,6 @@ Couldn't contact Anki Online. Please check your internet connection.""") self.mainWin.actionEditCurrent.setEnabled(enableEdits) self.mainWin.actionEditdeck.setEnabled(enableEdits) - def maybeShowKanjiStats(self): - if not self.deck: - have = False - else: - if getattr(self.deck, "haveJapanese", None) is None: - self.deck.haveJapanese = False - if self.deck: - for m in self.deck.models: - if "Japanese" in m.tags: - self.deck.haveJapanese = True - break - have = self.deck.haveJapanese - self.mainWin.actionKstats.setVisible(have) - - def maybeShowLookup(self, enable): - if (self.currentCard and - "Japanese" in self.currentCard.fact.model.tags): - self.mainWin.menu_Lookup.menuAction().setVisible(True) - else: - self.mainWin.menu_Lookup.menuAction().setVisible(False) - enable = False - self.mainWin.menu_Lookup.setEnabled(enable) - self.mainWin.actionLookup_es.setEnabled(enable) - self.mainWin.actionLookup_esk.setEnabled(enable) - self.mainWin.actionLookup_expr.setEnabled(enable) - self.mainWin.actionLookup_mean.setEnabled(enable) - self.mainWin.actionLookup_as.setEnabled(enable) - def maybeEnableUndo(self): if self.deck and self.deck.undoAvailable(): self.mainWin.actionUndo.setText(_("Undo %s") % diff --git a/ankiqt/ui/modelproperties.py b/ankiqt/ui/modelproperties.py index fb2a4602f..70976c037 100644 --- a/ankiqt/ui/modelproperties.py +++ b/ankiqt/ui/modelproperties.py @@ -502,6 +502,5 @@ order by n""", id=card.id) self.onFinish() self.deck.setUndoEnd(self.undoName) # check again - self.deck.haveJapanese = None self.deck.finishProgress() QDialog.reject(self) diff --git a/ankiqt/ui/preferences.py b/ankiqt/ui/preferences.py index 17a8570ce..6396d1148 100644 --- a/ankiqt/ui/preferences.py +++ b/ankiqt/ui/preferences.py @@ -7,7 +7,6 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * import anki, anki.utils from anki.facts import Fact -from anki.stdmodels import JapaneseModel from ankiqt import ui import ankiqt.forms diff --git a/designer/main.ui b/designer/main.ui index e14ab22c2..90b88871c 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -1473,7 +1473,7 @@ 0 0 696 - 36 + 23 @@ -1541,21 +1541,6 @@ &Tools - - - &Lookup - - - - :/icons/edit-find.png:/icons/edit-find.png - - - - - - - - Ad&vanced @@ -1573,11 +1558,9 @@ - -