mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
add importing tag support, fix audio
This commit is contained in:
parent
835b4b5969
commit
ff4cc7b0af
4 changed files with 36 additions and 12 deletions
|
@ -8,8 +8,8 @@ Importing support
|
|||
|
||||
To import, a mapping is created of the form: [FieldModel, ...]. The mapping
|
||||
may be extended by calling code if a file has more fields. To ignore a
|
||||
particular FieldModel, replace it with None. The same field model should not
|
||||
occur more than once."""
|
||||
particular FieldModel, replace it with None. A special number 0 donates a tags
|
||||
field. The same field model should not occur more than once."""
|
||||
|
||||
__docformat__ = 'restructuredtext'
|
||||
|
||||
|
@ -70,6 +70,7 @@ class Importer(object):
|
|||
m = []
|
||||
[m.append(f) for f in self.model.fieldModels if f.required]
|
||||
[m.append(f) for f in self.model.fieldModels if not f.required]
|
||||
m.append(0)
|
||||
rem = max(0, self.fields() - len(m))
|
||||
m += [None] * rem
|
||||
del m[numFields:]
|
||||
|
@ -122,6 +123,13 @@ all but one card template."""))
|
|||
|
||||
def addCards(self, cards):
|
||||
"Add facts in bulk from foreign cards."
|
||||
# map tags field to attr
|
||||
try:
|
||||
idx = self.mapping.index(0)
|
||||
for c in cards:
|
||||
c.tags = c.fields[idx]
|
||||
except ValueError:
|
||||
pass
|
||||
# add facts
|
||||
self.deck.updateProgress()
|
||||
factIds = [genID() for n in range(len(cards))]
|
||||
|
@ -238,7 +246,7 @@ from anki.importing.mnemosyne10 import Mnemosyne10Importer
|
|||
from anki.importing.wcu import WCUImporter
|
||||
|
||||
Importers = (
|
||||
(_("TAB/semicolon-separated file (*)"), TextImporter),
|
||||
(_("Text file (tab/semicolon separated) (*)"), TextImporter),
|
||||
(_("Anki 1.0 deck (*.anki)"), Anki10Importer),
|
||||
(_("Mnemosyne 1.x deck (*.mem)"), Mnemosyne10Importer),
|
||||
(_("CueCard deck (*.wcu)"), WCUImporter),
|
||||
|
|
|
@ -135,9 +135,15 @@ def clearQueueExternal():
|
|||
try:
|
||||
import pyaudio
|
||||
import wave
|
||||
|
||||
PYAU_FORMAT = pyaudio.paInt16
|
||||
PYAU_CHANNELS = 1
|
||||
PYAU_RATE = 44100
|
||||
PYAU_INPUT_INDEX = 0
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class _Recorder(object):
|
||||
|
||||
def postprocess(self):
|
||||
|
@ -161,16 +167,13 @@ class PyAudioThreadedRecorder(threading.Thread):
|
|||
|
||||
def run(self):
|
||||
chunk = 1024
|
||||
FORMAT = pyaudio.paInt16
|
||||
CHANNELS = 1
|
||||
RATE = 44100
|
||||
p = pyaudio.PyAudio()
|
||||
stream = p.open(format = FORMAT,
|
||||
channels = CHANNELS,
|
||||
rate = RATE,
|
||||
input = True,
|
||||
input_device_index = 0,
|
||||
frames_per_buffer = chunk)
|
||||
stream = p.open(format=PYAU_FORMAT,
|
||||
channels=PYAU_CHANNELS,
|
||||
rate=PYAU_RATE,
|
||||
input=True,
|
||||
input_device_index=PYAU_INPUT_INDEX,
|
||||
frames_per_buffer=chunk)
|
||||
all = []
|
||||
while not self.finish:
|
||||
data = stream.read(chunk)
|
||||
|
|
1
tests/importing/text-tags.txt
Normal file
1
tests/importing/text-tags.txt
Normal file
|
@ -0,0 +1 @@
|
|||
foo bar baz,qux
|
|
@ -7,6 +7,7 @@ from anki.errors import *
|
|||
from anki import DeckStorage
|
||||
from anki.importing import anki10, csv, mnemosyne10
|
||||
from anki.stdmodels import BasicModel
|
||||
from anki.facts import Fact
|
||||
|
||||
from anki.db import *
|
||||
|
||||
|
@ -23,6 +24,17 @@ def test_csv():
|
|||
assert i.total == 5
|
||||
deck.s.close()
|
||||
|
||||
def test_csv_tags():
|
||||
deck = DeckStorage.Deck()
|
||||
deck.addModel(BasicModel())
|
||||
file = unicode(os.path.join(testDir, "importing/text-tags.txt"))
|
||||
i = csv.TextImporter(deck, file)
|
||||
i.doImport()
|
||||
facts = deck.s.query(Fact).all()
|
||||
assert len(facts) == 1
|
||||
assert facts[0].tags == "baz, qux"
|
||||
deck.s.close()
|
||||
|
||||
def test_mnemosyne10():
|
||||
deck = DeckStorage.Deck()
|
||||
deck.addModel(BasicModel())
|
||||
|
|
Loading…
Reference in a new issue