mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
custom templates for browser display, move clayout buttons into dropdown
This commit is contained in:
parent
3705cedf33
commit
646116604c
3 changed files with 150 additions and 19 deletions
|
@ -237,9 +237,14 @@ class DataModel(QAbstractTableModel):
|
||||||
return self.browser.mw.col.decks.name(c.did)
|
return self.browser.mw.col.decks.name(c.did)
|
||||||
|
|
||||||
def question(self, c):
|
def question(self, c):
|
||||||
return self.formatQA(c.q())
|
return self.formatQA(c.q(browser=True))
|
||||||
|
|
||||||
def answer(self, c):
|
def answer(self, c):
|
||||||
|
if c.template().get('bafmt'):
|
||||||
|
# they have provided a template, use it verbatim
|
||||||
|
c.q(browser=True)
|
||||||
|
return self.formatQA(c.a())
|
||||||
|
# need to strip question from answer
|
||||||
q = self.question(c)
|
q = self.question(c)
|
||||||
a = self.formatQA(c.a())
|
a = self.formatQA(c.a())
|
||||||
if a.startswith(q):
|
if a.startswith(q):
|
||||||
|
|
|
@ -145,19 +145,10 @@ Please create a new card type first."""))
|
||||||
flip.setAutoDefault(False)
|
flip.setAutoDefault(False)
|
||||||
l.addWidget(flip)
|
l.addWidget(flip)
|
||||||
c(flip, SIGNAL("clicked()"), self.onFlip)
|
c(flip, SIGNAL("clicked()"), self.onFlip)
|
||||||
rename = QPushButton(_("Rename..."))
|
more = QPushButton(_("More") + u" ▾")
|
||||||
rename.setAutoDefault(False)
|
more.setAutoDefault(False)
|
||||||
l.addWidget(rename)
|
l.addWidget(more)
|
||||||
c(rename, SIGNAL("clicked()"), self.onRename)
|
c(more, SIGNAL("clicked()"), lambda: self.onMore(more))
|
||||||
if self.model['type'] != MODEL_CLOZE:
|
|
||||||
repos = QPushButton(_("Reposition..."))
|
|
||||||
repos.setAutoDefault(False)
|
|
||||||
l.addWidget(repos)
|
|
||||||
c(repos, SIGNAL("clicked()"), self.onReorder)
|
|
||||||
self.deckButton = tgt = QPushButton(_("Deck..."))
|
|
||||||
tgt.setAutoDefault(False)
|
|
||||||
l.addWidget(tgt)
|
|
||||||
c(tgt, SIGNAL("clicked()"), self.onTargetDeck)
|
|
||||||
l.addStretch()
|
l.addStretch()
|
||||||
close = QPushButton(_("Close"))
|
close = QPushButton(_("Close"))
|
||||||
close.setAutoDefault(False)
|
close.setAutoDefault(False)
|
||||||
|
@ -186,11 +177,6 @@ Please create a new card type first."""))
|
||||||
self.tab['tform'].front.setPlainText(t['qfmt'])
|
self.tab['tform'].front.setPlainText(t['qfmt'])
|
||||||
self.tab['tform'].css.setPlainText(self.model['css'])
|
self.tab['tform'].css.setPlainText(self.model['css'])
|
||||||
self.tab['tform'].back.setPlainText(t['afmt'])
|
self.tab['tform'].back.setPlainText(t['afmt'])
|
||||||
if self.model['type'] != MODEL_CLOZE:
|
|
||||||
if t['did']:
|
|
||||||
self.deckButton.setText(_("Specific Deck..."))
|
|
||||||
else:
|
|
||||||
self.deckButton.setText(_("Default Deck..."))
|
|
||||||
self.redrawing = False
|
self.redrawing = False
|
||||||
|
|
||||||
def saveCard(self):
|
def saveCard(self):
|
||||||
|
@ -305,6 +291,44 @@ adjust the template manually to switch the question and answer."""))
|
||||||
m.group(1).strip())
|
m.group(1).strip())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def onMore(self, button):
|
||||||
|
m = QMenu(self)
|
||||||
|
a = m.addAction(_("Rename"))
|
||||||
|
a.connect(a, SIGNAL("triggered()"),
|
||||||
|
self.onRename)
|
||||||
|
if self.model['type'] != MODEL_CLOZE:
|
||||||
|
a = m.addAction(_("Reposition"))
|
||||||
|
a.connect(a, SIGNAL("triggered()"),
|
||||||
|
self.onReorder)
|
||||||
|
t = self.card.template()
|
||||||
|
if t['did']:
|
||||||
|
s = _(" (on)")
|
||||||
|
else:
|
||||||
|
s = _(" (off)")
|
||||||
|
a = m.addAction(_("Deck Override") + s)
|
||||||
|
a.connect(a, SIGNAL("triggered()"),
|
||||||
|
self.onTargetDeck)
|
||||||
|
a = m.addAction(_("Column Templates"))
|
||||||
|
a.connect(a, SIGNAL("triggered()"),
|
||||||
|
self.onBrowserDisplay)
|
||||||
|
m.exec_(button.mapToGlobal(QPoint(0,0)))
|
||||||
|
|
||||||
|
def onBrowserDisplay(self):
|
||||||
|
d = QDialog()
|
||||||
|
f = aqt.forms.browserdisp.Ui_Dialog()
|
||||||
|
f.setupUi(d)
|
||||||
|
t = self.card.template()
|
||||||
|
f.qfmt.setText(t.get('bqfmt', ""))
|
||||||
|
f.afmt.setText(t.get('bafmt', ""))
|
||||||
|
d.connect(f.buttonBox, SIGNAL("accepted()"),
|
||||||
|
lambda: self.onBrowserDisplayOk(f))
|
||||||
|
d.exec_()
|
||||||
|
|
||||||
|
def onBrowserDisplayOk(self, f):
|
||||||
|
t = self.card.template()
|
||||||
|
t['bqfmt'] = f.qfmt.text().strip()
|
||||||
|
t['bafmt'] = f.afmt.text().strip()
|
||||||
|
|
||||||
def onTargetDeck(self):
|
def onTargetDeck(self):
|
||||||
from aqt.tagedit import TagEdit
|
from aqt.tagedit import TagEdit
|
||||||
t = self.card.template()
|
t = self.card.template()
|
||||||
|
|
102
designer/browserdisp.ui
Normal file
102
designer/browserdisp.ui
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>412</width>
|
||||||
|
<height>204</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Column Templates</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Template for front column in browser:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="qfmt"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Template for back column in browser</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="afmt"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>qfmt</tabstop>
|
||||||
|
<tabstop>afmt</tabstop>
|
||||||
|
<tabstop>buttonBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
Reference in a new issue