mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
missing files
This commit is contained in:
parent
38c1f71d5d
commit
e6db07b74a
5 changed files with 80 additions and 36 deletions
|
@ -8,6 +8,8 @@ import re, os, sys
|
|||
from anki.utils import parseTags, stripHTML, tidyHTML
|
||||
import anki.sound
|
||||
from ankiqt import ui
|
||||
import ankiqt
|
||||
from ankiqt.ui.utils import mungeQA, saveGeom, restoreGeom
|
||||
|
||||
class FactEditor(object):
|
||||
"""An editor for new/existing facts.
|
||||
|
@ -120,26 +122,37 @@ class FactEditor(object):
|
|||
self.foreground.setLayout(hbox)
|
||||
self.iconsBox.addWidget(self.foreground)
|
||||
self.foreground.setStyle(self.plastiqueStyle)
|
||||
# preview
|
||||
self.preview = QPushButton(self.widget)
|
||||
self.preview.connect(self.preview, SIGNAL("clicked()"),
|
||||
self.onPreview)
|
||||
self.preview.setToolTip(_("Preview (F2)"))
|
||||
self.preview.setShortcut(_("F2"))
|
||||
self.preview.setIcon(QIcon(":/icons/document-preview.png"))
|
||||
self.preview.setFocusPolicy(Qt.NoFocus)
|
||||
self.preview.setEnabled(False)
|
||||
self.iconsBox.addWidget(self.preview)
|
||||
self.preview.setStyle(self.plastiqueStyle)
|
||||
# pictures
|
||||
spc = QSpacerItem(10,10)
|
||||
self.iconsBox.addItem(spc)
|
||||
self.addPicture = QPushButton(self.widget)
|
||||
self.addPicture.connect(self.addPicture, SIGNAL("clicked()"), self.onAddPicture)
|
||||
self.addPicture.setFocusPolicy(Qt.NoFocus)
|
||||
self.addPicture.setShortcut(_("F2"))
|
||||
self.addPicture.setShortcut(_("F3"))
|
||||
self.addPicture.setIcon(QIcon(":/icons/colors.png"))
|
||||
self.addPicture.setEnabled(False)
|
||||
self.addPicture.setToolTip(_("Add a picture (F2)"))
|
||||
self.addPicture.setToolTip(_("Add a picture (F3)"))
|
||||
self.iconsBox.addWidget(self.addPicture)
|
||||
self.addPicture.setStyle(self.plastiqueStyle)
|
||||
# sounds
|
||||
self.addSound = QPushButton(self.widget)
|
||||
self.addSound.connect(self.addSound, SIGNAL("clicked()"), self.onAddSound)
|
||||
self.addSound.setFocusPolicy(Qt.NoFocus)
|
||||
self.addSound.setShortcut(_("F3"))
|
||||
self.addSound.setShortcut(_("F4"))
|
||||
self.addSound.setEnabled(False)
|
||||
self.addSound.setIcon(QIcon(":/icons/text-speak.png"))
|
||||
self.addSound.setToolTip(_("Add audio (F3)"))
|
||||
self.addSound.setToolTip(_("Add audio (F4)"))
|
||||
self.iconsBox.addWidget(self.addSound)
|
||||
self.addSound.setStyle(self.plastiqueStyle)
|
||||
# latex
|
||||
|
@ -175,17 +188,6 @@ class FactEditor(object):
|
|||
self.latexMathEnv.setEnabled(False)
|
||||
self.iconsBox.addWidget(self.latexMathEnv)
|
||||
self.latexMathEnv.setStyle(self.plastiqueStyle)
|
||||
# preview
|
||||
self.preview = QPushButton(self.widget)
|
||||
self.preview.connect(self.preview, SIGNAL("clicked()"),
|
||||
self.onPreview)
|
||||
self.preview.setToolTip(_("Preview (F5)"))
|
||||
self.preview.setShortcut(_("F5"))
|
||||
#self.preview.setIcon(QIcon(":/icons/math_matrix.png"))
|
||||
self.preview.setFocusPolicy(Qt.NoFocus)
|
||||
self.preview.setEnabled(False)
|
||||
self.iconsBox.addWidget(self.preview)
|
||||
self.preview.setStyle(self.plastiqueStyle)
|
||||
|
||||
self.fieldsFrame = None
|
||||
self.widget.setLayout(self.fieldsBox)
|
||||
|
@ -454,8 +456,7 @@ class FactEditor(object):
|
|||
w.moveCursor(QTextCursor.PreviousCharacter)
|
||||
|
||||
def onPreview(self):
|
||||
print self.deck.previewFact(self.fact)
|
||||
print "preview"
|
||||
PreviewDialog(self.parent, self.deck, self.fact).exec_()
|
||||
|
||||
def fieldsAreBlank(self):
|
||||
for (field, widget) in self.fields.values():
|
||||
|
@ -568,3 +569,40 @@ class FactEdit(QTextEdit):
|
|||
QTextEdit.focusInEvent(self, evt)
|
||||
self.parent.formatChanged(None)
|
||||
self.parent.enableButtons()
|
||||
|
||||
class PreviewDialog(QDialog):
|
||||
|
||||
def __init__(self, parent, deck, fact, *args):
|
||||
QDialog.__init__(self, parent, *args)
|
||||
self.deck = deck
|
||||
self.fact = fact
|
||||
cards = self.deck.previewFact(self.fact)
|
||||
if not cards:
|
||||
ui.utils.showInfo(_("No cards to preview."),
|
||||
parent=self.parent)
|
||||
return
|
||||
self.cards = cards
|
||||
self.currentCard = 0
|
||||
self.dialog = ankiqt.forms.previewcards.Ui_Dialog()
|
||||
self.dialog.setupUi(self)
|
||||
self.dialog.comboBox.addItems(QStringList(
|
||||
[c.cardModel.name for c in self.cards]))
|
||||
self.connect(self.dialog.comboBox, SIGNAL("activated(int)"),
|
||||
self.onChange)
|
||||
self.updateCard()
|
||||
restoreGeom(self, "preview")
|
||||
|
||||
def updateCard(self):
|
||||
c = self.cards[self.currentCard]
|
||||
self.dialog.webView.setHtml(
|
||||
"<style>" + self.deck.css + "</style>" +
|
||||
mungeQA(self.deck, c.htmlQuestion()) +
|
||||
mungeQA(self.deck, c.htmlAnswer()))
|
||||
|
||||
def onChange(self, idx):
|
||||
self.currentCard = idx
|
||||
self.updateCard()
|
||||
|
||||
def reject(self):
|
||||
saveGeom(self, "preview")
|
||||
QDialog.reject(self)
|
||||
|
|
|
@ -52,6 +52,7 @@ class AnkiQt(QMainWindow):
|
|||
self.restoreGeometry(self.config['mainWindowGeom'])
|
||||
self.bodyView = ui.view.View(self, self.mainWin.mainText,
|
||||
self.mainWin.mainTextFrame)
|
||||
self.mainWin.mainText.pageAction(QWebPage.Reload).setVisible(False)
|
||||
self.addView(self.bodyView)
|
||||
self.statusView = ui.status.StatusView(self)
|
||||
self.addView(self.statusView)
|
||||
|
@ -812,7 +813,7 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
|
|||
def showSaveEditorButton(self):
|
||||
if self.lastState == self.state:
|
||||
return
|
||||
self.editFactButton = QPushButton(_("Return"))
|
||||
self.editFactButton = QPushButton(_("Close"))
|
||||
self.editFactButton.setToolTip("Hit Esc to return to review.")
|
||||
self.editFactButton.setFixedHeight(self.easeButtonHeight)
|
||||
self.editFactButton.setShortcut(_("Esc"))
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
import re, os
|
||||
from anki.sound import playFromText, stripSounds
|
||||
from anki.latex import renderLatex, stripLatex
|
||||
|
||||
import re, os, sys
|
||||
import ankiqt
|
||||
|
||||
def openLink(link):
|
||||
|
@ -88,3 +91,17 @@ def restoreGeom(widget, key):
|
|||
key += "Geom"
|
||||
if ankiqt.mw.config.get(key):
|
||||
widget.restoreGeometry(ankiqt.mw.config[key])
|
||||
|
||||
def mungeQA(deck, txt):
|
||||
txt = renderLatex(deck, txt)
|
||||
txt = stripSounds(txt)
|
||||
def quote(match):
|
||||
if sys.platform.startswith("win32"):
|
||||
prefix = "file:///"
|
||||
else:
|
||||
prefix = "file://"
|
||||
return 'img src="%s%s"' % (
|
||||
prefix, os.path.join(deck.mediaDir(),
|
||||
unicode(match.group(1))))
|
||||
txt = re.sub('img src="(.*?)"', quote, txt)
|
||||
return txt
|
||||
|
|
|
@ -10,6 +10,7 @@ from anki.latex import renderLatex, stripLatex
|
|||
from anki.utils import stripHTML
|
||||
import types, time, re, os, urllib, sys
|
||||
from ankiqt import ui
|
||||
from ankiqt.ui.utils import mungeQA
|
||||
|
||||
# Views - define the way a user is prompted for questions, etc
|
||||
##########################################################################
|
||||
|
@ -68,7 +69,6 @@ class View(object):
|
|||
def addStyles(self):
|
||||
# card styles
|
||||
s = "<style>\n"
|
||||
t = time.time()
|
||||
if self.main.deck:
|
||||
s += self.main.deck.css
|
||||
# last card
|
||||
|
@ -109,31 +109,17 @@ class View(object):
|
|||
# Question and answer
|
||||
##########################################################################
|
||||
|
||||
def munge(self, txt):
|
||||
txt = renderLatex(self.main.deck, txt)
|
||||
txt = stripSounds(txt)
|
||||
def quote(match):
|
||||
if sys.platform.startswith("win32"):
|
||||
prefix = "file:///"
|
||||
else:
|
||||
prefix = "file://"
|
||||
return 'img src="%s%s"' % (
|
||||
prefix, os.path.join(self.main.deck.mediaDir(),
|
||||
unicode(match.group(1))))
|
||||
txt = re.sub('img src="(.*?)"', quote, txt)
|
||||
return txt
|
||||
|
||||
def drawQuestion(self, nosound=False):
|
||||
"Show the question."
|
||||
q = self.main.currentCard.htmlQuestion()
|
||||
self.write(self.munge(q))
|
||||
self.write(mungeQA(self.main.deck, q))
|
||||
if self.state != self.oldState and not nosound:
|
||||
playFromText(q)
|
||||
|
||||
def drawAnswer(self):
|
||||
"Show the answer."
|
||||
a = self.main.currentCard.htmlAnswer()
|
||||
self.write('<span id=answer />' + self.munge(a))
|
||||
self.write('<span id=answer />' + mungeQA(self.main.deck, a))
|
||||
if self.state != self.oldState:
|
||||
playFromText(a)
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<RCC>
|
||||
<qresource prefix="/" >
|
||||
<file>icons/document-preview.png</file>
|
||||
<file>icons/media-record.png</file>
|
||||
<file>icons/edit-rename.png</file>
|
||||
<file>icons/kblogger.png</file>
|
||||
<file>icons/chronometer.png</file>
|
||||
|
|
Loading…
Reference in a new issue