recording support, various changes

- progress bars refactored to use title 'anki' in most cases
- added 'record noise profile' option
- make sure to display 100% on progress
This commit is contained in:
Damien Elmes 2009-01-17 01:04:13 +09:00
parent 6de11197ff
commit e3e70488ef
7 changed files with 54 additions and 14 deletions

View file

@ -7,6 +7,7 @@ from PyQt4.QtCore import *
import re, os, sys, tempfile, urllib2
from anki.utils import stripHTML, tidyHTML, canonifyTags
from anki.sound import playFromText
from ankiqt.ui.sound import getAudio
import anki.sound
from ankiqt import ui
import ankiqt
@ -172,6 +173,16 @@ class FactEditor(object):
self.addSound.setToolTip(_("Add audio (F4)"))
self.iconsBox.addWidget(self.addSound)
self.addSound.setStyle(self.plastiqueStyle)
# sounds
self.recSound = QPushButton(self.widget)
self.recSound.connect(self.recSound, SIGNAL("clicked()"), self.onRecSound)
self.recSound.setFocusPolicy(Qt.NoFocus)
self.recSound.setShortcut(_("F5"))
self.recSound.setEnabled(False)
self.recSound.setIcon(QIcon(":/icons/media-record.png"))
self.recSound.setToolTip(_("Record audio (F5)"))
self.iconsBox.addWidget(self.recSound)
self.recSound.setStyle(self.plastiqueStyle)
# latex
spc = QSpacerItem(10,10)
self.iconsBox.addItem(spc)
@ -450,6 +461,7 @@ class FactEditor(object):
self.latexMathEnv.setEnabled(val)
self.preview.setEnabled(val)
self.htmlEdit.setEnabled(val)
self.recSound.setEnabled(val)
def disableButtons(self):
self.enableButtons(False)
@ -587,6 +599,12 @@ class FactEditor(object):
anki.sound.play(path)
w.insertHtml('[sound:%s]' % path)
def onRecSound(self):
w = self.focusedEdit()
file = getAudio(self.parent)
if file:
self._addSound(file, widget=w)
class FactEdit(QTextEdit):
def __init__(self, parent, *args):

View file

@ -210,9 +210,9 @@ def intervalGraph(parent, deck):
hbox = QHBoxLayout()
def showHideAll():
deck.startProgress(_("Graphs"), 0, len(widgets))
deck.startProgress(len(widgets))
for w in widgets:
deck.updateProgress(_("Preparing..."))
deck.updateProgress(_("Processing..."))
w.showHide()
frame.adjustSize()
deck.finishProgress()
@ -250,10 +250,10 @@ def intervalGraph(parent, deck):
QDesktopServices.openUrl(QUrl(ankiqt.appWiki + "Graphs"))
def onRefresh():
deck.startProgress(_("Graphs"), 0, len(widgets))
deck.startProgress(len(widgets))
dg.stats = None
for w in widgets:
deck.updateProgress(_("Preparing..."))
deck.updateProgress(_("Processing..."))
w.updateFigure()
deck.finishProgress()

View file

@ -43,6 +43,7 @@ class AnkiQt(QMainWindow):
self.setLang()
self.setupDocumentDir()
self.setupFonts()
self.setupSound()
self.setupBackupDir()
self.setupMainWindow()
self.alterShortcuts()
@ -1360,12 +1361,6 @@ day = :d""", d=yesterday)
s = unicode(s)
self.deck.save()
# open tmp deck
if self.config['randomizeOnCram']:
n = 5
else:
n = 3
p = ui.utils.ProgressWin(self, _("Cram"), 0, n)
p.update(_("Copying cards..."))
ndir = tempfile.mkdtemp(prefix="anki-cram")
path = os.path.join(ndir, "cram.anki")
from anki.exporting import AnkiExporter
@ -1378,6 +1373,11 @@ day = :d""", d=yesterday)
ui.utils.showInfo(_("No cards matched the provided tags."))
p.finish()
return
if self.config['randomizeOnCram']:
n = 4
else:
n = 2
p = ui.utils.ProgressWin(self, n, 0, _("Cram"))
p.update(_("Loading deck..."))
self.deck.close()
self.deck = None
@ -1677,6 +1677,7 @@ day = :d""", d=yesterday)
self.connect(m.actionUncacheLatex, s, self.onUncacheLatex)
self.connect(m.actionStudyOptions, s, self.onStudyOptions)
self.connect(m.actionDonate, s, self.onDonate)
self.connect(m.actionRecordNoiseProfile, s, self.onRecordNoiseProfile)
def enableDeckMenuItems(self, enabled=True):
"setEnabled deck-related items."
@ -1830,7 +1831,6 @@ day = :d""", d=yesterday)
def pluginsFolder(self):
dir = self.config.configPath
file = os.path.join(dir, "custom.py")
return os.path.join(dir, "plugins")
def loadPlugins(self):
@ -1924,11 +1924,20 @@ day = :d""", d=yesterday)
# Sounds
##########################################################################
def setupSound(self):
anki.sound.noiseProfile = os.path.join(
self.config.configPath, "noise.profile")
anki.sound.checkForNoiseProfile()
def onRepeatAudio(self):
playFromText(self.currentCard.question)
if self.state != "showQuestion":
playFromText(self.currentCard.answer)
def onRecordNoiseProfile(self):
from ui.sound import recordNoiseProfile
recordNoiseProfile(self)
# Progress info
##########################################################################
@ -1937,9 +1946,9 @@ day = :d""", d=yesterday)
addHook("updateProgress", self.onUpdateProgress)
addHook("finishProgress", self.onFinishProgress)
def onStartProgress(self, title, min, max):
def onStartProgress(self, max=100, min=0, title=None):
self.progressWin = ui.utils.ProgressWin(self.app.activeWindow() or self,
title, min, max)
max, min, title)
def onUpdateProgress(self, label=None, value=None):
if self.progressWin:

1
ankiqt/ui/sound.py Symbolic link
View file

@ -0,0 +1 @@
resolve@twitch.ichi2.net.12462:1231199561

View file

@ -188,7 +188,10 @@ def mungeQA(deck, txt):
class ProgressWin(object):
def __init__(self, parent, title, min, max):
def __init__(self, parent, max=100, min=0, title=None):
if not title:
title = "Anki"
print parent, max, min, title
self.diag = QProgressDialog("", "", min, max, parent)
self.diag.setWindowTitle(title)
self.diag.setCancelButton(None)
@ -220,4 +223,5 @@ class ProgressWin(object):
def finish(self):
self.diag.setValue(self.max)
self.app.processEvents()
time.sleep(0.1)
self.diag.cancel()

View file

@ -1217,6 +1217,7 @@
<addaction name="separator" />
<addaction name="actionMergeModels" />
<addaction name="separator" />
<addaction name="actionRecordNoiseProfile" />
</widget>
<addaction name="actionGraphs" />
<addaction name="actionDstats" />
@ -1863,6 +1864,11 @@
<string>&amp;Donate...</string>
</property>
</action>
<action name="actionRecordNoiseProfile" >
<property name="text" >
<string>&amp;Record Noise Profile...</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>newPerDay</tabstop>

View file

@ -1,5 +1,7 @@
<RCC>
<qresource prefix="/" >
<file>icons/media-playback-stop.png</file>
<file>icons/media-record.png</file>
<file>icons/view-calendar-tasks.png</file>
<file>icons/help-hint.png</file>
<file>icons/go-first.png</file>