mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
strip all japanese support out in favour of a plugin
This commit is contained in:
parent
eeede2008d
commit
102e63acf0
7 changed files with 1 additions and 233 deletions
|
@ -14,7 +14,6 @@ def importAll():
|
||||||
import exporting
|
import exporting
|
||||||
import facteditor
|
import facteditor
|
||||||
import help
|
import help
|
||||||
import lookup
|
|
||||||
import modelchooser
|
import modelchooser
|
||||||
import modelproperties
|
import modelproperties
|
||||||
import preferences
|
import preferences
|
||||||
|
|
|
@ -1009,46 +1009,6 @@ class FactEdit(QTextEdit):
|
||||||
self.parent.disableButtons()
|
self.parent.disableButtons()
|
||||||
self.emit(SIGNAL("lostFocus"))
|
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):
|
def focusInEvent(self, evt):
|
||||||
if (self.parent.lastFocusedEdit and
|
if (self.parent.lastFocusedEdit and
|
||||||
self.parent.lastFocusedEdit is not self):
|
self.parent.lastFocusedEdit is not self):
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
||||||
# 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
|
|
|
@ -1552,68 +1552,9 @@ learnt today")
|
||||||
tb = self.mainWin.toolBar
|
tb = self.mainWin.toolBar
|
||||||
self.config['showToolbar'] = tb.isVisible()
|
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
|
# Tools - statistics
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def onKanjiStats(self):
|
|
||||||
rep = anki.stats.KanjiStats(self.deck).report()
|
|
||||||
rep += _("<a href=py:miss>Missing</a><br>")
|
|
||||||
rep += _("<a href=py:seen>Seen</a><br>")
|
|
||||||
rep += _("<a href=py:non>Non-jouyou</a><br>")
|
|
||||||
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):
|
def onDeckStats(self):
|
||||||
txt = anki.stats.DeckStats(self.deck).report()
|
txt = anki.stats.DeckStats(self.deck).report()
|
||||||
self.help.showText(txt)
|
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.actionEditdeck, s, self.onEditDeck)
|
||||||
self.connect(m.actionEditCurrent, s, self.onEditCurrent)
|
self.connect(m.actionEditCurrent, s, self.onEditCurrent)
|
||||||
self.connect(m.actionPreferences, s, self.onPrefs)
|
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.actionDstats, s, self.onDeckStats)
|
||||||
self.connect(m.actionKstats, s, self.onKanjiStats)
|
|
||||||
self.connect(m.actionCstats, s, self.onCardStats)
|
self.connect(m.actionCstats, s, self.onCardStats)
|
||||||
self.connect(m.actionGraphs, s, self.onShowGraph)
|
self.connect(m.actionGraphs, s, self.onShowGraph)
|
||||||
self.connect(m.actionAbout, s, self.onAbout)
|
self.connect(m.actionAbout, s, self.onAbout)
|
||||||
|
@ -2281,8 +2216,6 @@ Couldn't contact Anki Online. Please check your internet connection.""")
|
||||||
|
|
||||||
def disableCardMenuItems(self):
|
def disableCardMenuItems(self):
|
||||||
self.maybeEnableUndo()
|
self.maybeEnableUndo()
|
||||||
self.maybeShowLookup(False)
|
|
||||||
self.maybeShowKanjiStats()
|
|
||||||
self.mainWin.actionEditCurrent.setEnabled(False)
|
self.mainWin.actionEditCurrent.setEnabled(False)
|
||||||
self.mainWin.actionMarkCard.setEnabled(False)
|
self.mainWin.actionMarkCard.setEnabled(False)
|
||||||
self.mainWin.actionSuspendCard.setEnabled(False)
|
self.mainWin.actionSuspendCard.setEnabled(False)
|
||||||
|
@ -2292,8 +2225,6 @@ Couldn't contact Anki Online. Please check your internet connection.""")
|
||||||
|
|
||||||
def enableCardMenuItems(self):
|
def enableCardMenuItems(self):
|
||||||
self.maybeEnableUndo()
|
self.maybeEnableUndo()
|
||||||
self.maybeShowLookup(True)
|
|
||||||
self.maybeShowKanjiStats()
|
|
||||||
snd = (hasSound(self.currentCard.question) or
|
snd = (hasSound(self.currentCard.question) or
|
||||||
(hasSound(self.currentCard.answer) and
|
(hasSound(self.currentCard.answer) and
|
||||||
self.state != "getQuestion"))
|
self.state != "getQuestion"))
|
||||||
|
@ -2307,34 +2238,6 @@ Couldn't contact Anki Online. Please check your internet connection.""")
|
||||||
self.mainWin.actionEditCurrent.setEnabled(enableEdits)
|
self.mainWin.actionEditCurrent.setEnabled(enableEdits)
|
||||||
self.mainWin.actionEditdeck.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):
|
def maybeEnableUndo(self):
|
||||||
if self.deck and self.deck.undoAvailable():
|
if self.deck and self.deck.undoAvailable():
|
||||||
self.mainWin.actionUndo.setText(_("Undo %s") %
|
self.mainWin.actionUndo.setText(_("Undo %s") %
|
||||||
|
|
|
@ -502,6 +502,5 @@ order by n""", id=card.id)
|
||||||
self.onFinish()
|
self.onFinish()
|
||||||
self.deck.setUndoEnd(self.undoName)
|
self.deck.setUndoEnd(self.undoName)
|
||||||
# check again
|
# check again
|
||||||
self.deck.haveJapanese = None
|
|
||||||
self.deck.finishProgress()
|
self.deck.finishProgress()
|
||||||
QDialog.reject(self)
|
QDialog.reject(self)
|
||||||
|
|
|
@ -7,7 +7,6 @@ from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
import anki, anki.utils
|
import anki, anki.utils
|
||||||
from anki.facts import Fact
|
from anki.facts import Fact
|
||||||
from anki.stdmodels import JapaneseModel
|
|
||||||
from ankiqt import ui
|
from ankiqt import ui
|
||||||
import ankiqt.forms
|
import ankiqt.forms
|
||||||
|
|
||||||
|
|
|
@ -1473,7 +1473,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>696</width>
|
<width>696</width>
|
||||||
<height>36</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuHelp">
|
<widget class="QMenu" name="menuHelp">
|
||||||
|
@ -1541,21 +1541,6 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&Tools</string>
|
<string>&Tools</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menu_Lookup">
|
|
||||||
<property name="title">
|
|
||||||
<string>&Lookup</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../icons.qrc">
|
|
||||||
<normaloff>:/icons/edit-find.png</normaloff>:/icons/edit-find.png</iconset>
|
|
||||||
</property>
|
|
||||||
<addaction name="actionLookup_expr"/>
|
|
||||||
<addaction name="actionLookup_mean"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="actionLookup_as"/>
|
|
||||||
<addaction name="actionLookup_es"/>
|
|
||||||
<addaction name="actionLookup_esk"/>
|
|
||||||
</widget>
|
|
||||||
<widget class="QMenu" name="menuAdvanced">
|
<widget class="QMenu" name="menuAdvanced">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Ad&vanced</string>
|
<string>Ad&vanced</string>
|
||||||
|
@ -1573,11 +1558,9 @@
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="actionGraphs"/>
|
<addaction name="actionGraphs"/>
|
||||||
<addaction name="actionDstats"/>
|
<addaction name="actionDstats"/>
|
||||||
<addaction name="actionKstats"/>
|
|
||||||
<addaction name="actionCstats"/>
|
<addaction name="actionCstats"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionRepeatAudio"/>
|
<addaction name="actionRepeatAudio"/>
|
||||||
<addaction name="menu_Lookup"/>
|
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="menuAdvanced"/>
|
<addaction name="menuAdvanced"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
|
Loading…
Reference in a new issue