mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
work on fields dialog
This commit is contained in:
parent
3362ca06a3
commit
967dff23dd
7 changed files with 89 additions and 115 deletions
|
@ -1445,7 +1445,9 @@ class BrowserToolbar(Toolbar):
|
||||||
right += borderImg("mark", "star16", mark)
|
right += borderImg("mark", "star16", mark)
|
||||||
right += borderImg("pause", "pause16", pause)
|
right += borderImg("pause", "pause16", pause)
|
||||||
self.web.stdHtml(self._body % (
|
self.web.stdHtml(self._body % (
|
||||||
' '*20, #<a class="hitem" href="anki">Browser ▾</a>',
|
" "+
|
||||||
|
"<span style='font-weight:normal;'>%s</span>"%_("On Selected:"),
|
||||||
|
#' '*20, #<a class="hitem" href="anki">Browser ▾</a>',
|
||||||
self._centerLinks(),
|
self._centerLinks(),
|
||||||
right), self._css, focus=False)
|
right), self._css, focus=False)
|
||||||
|
|
||||||
|
|
|
@ -156,12 +156,14 @@ Please create a new card first."""))
|
||||||
def renderPreview(self):
|
def renderPreview(self):
|
||||||
c = self.card
|
c = self.card
|
||||||
styles = "\n.cloze { font-weight: bold; color: blue; }"
|
styles = "\n.cloze { font-weight: bold; color: blue; }"
|
||||||
html = '<html><body id=card><style>%s</style>%s</body></html>'
|
html = '''<html><head>%s</head><body id=card>
|
||||||
|
<style>%s</style>%s</body></html>'''
|
||||||
ti = self.maybeTextInput
|
ti = self.maybeTextInput
|
||||||
|
base = getBase(self.mw.col)
|
||||||
self.tab['pform'].front.setHtml(
|
self.tab['pform'].front.setHtml(
|
||||||
html % (styles, ti(mungeQA(c.q(reload=True)))))
|
html % (base, styles, ti(mungeQA(c.q(reload=True)))))
|
||||||
self.tab['pform'].back.setHtml(
|
self.tab['pform'].back.setHtml(
|
||||||
html % (styles, ti(mungeQA(c.a()), 'a')))
|
html % (base, styles, ti(mungeQA(c.a()), 'a')))
|
||||||
|
|
||||||
def maybeTextInput(self, txt, type='q'):
|
def maybeTextInput(self, txt, type='q'):
|
||||||
if type == 'q':
|
if type == 'q':
|
||||||
|
|
|
@ -269,8 +269,10 @@ class Editor(object):
|
||||||
# align to right
|
# align to right
|
||||||
self.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding))
|
self.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding))
|
||||||
b = self._addButton
|
b = self._addButton
|
||||||
|
b("fields", self.onFields, "Ctrl+f",
|
||||||
|
shortcut(_("Layout (Ctrl+f)")), size=False, text=_("Fields"))
|
||||||
b("layout", self.onCardLayout, "Ctrl+l",
|
b("layout", self.onCardLayout, "Ctrl+l",
|
||||||
shortcut(_("Layout (Ctrl+l)")), size=False, text=_("Layout..."))
|
shortcut(_("Layout (Ctrl+l)")), size=False, text=_("Layout"))
|
||||||
b("text_bold", self.toggleBold, "Ctrl+b", _("Bold text (Ctrl+b)"),
|
b("text_bold", self.toggleBold, "Ctrl+b", _("Bold text (Ctrl+b)"),
|
||||||
check=True)
|
check=True)
|
||||||
b("text_italic", self.toggleItalic, "Ctrl+i", _("Italic text (Ctrl+i)"),
|
b("text_italic", self.toggleItalic, "Ctrl+i", _("Italic text (Ctrl+i)"),
|
||||||
|
@ -306,6 +308,11 @@ class Editor(object):
|
||||||
def disableButtons(self):
|
def disableButtons(self):
|
||||||
self.enableButtons(False)
|
self.enableButtons(False)
|
||||||
|
|
||||||
|
def onFields(self):
|
||||||
|
from aqt.fields import FieldDialog
|
||||||
|
self.saveNow()
|
||||||
|
FieldDialog(self.mw, self.note, parent=self.widget)
|
||||||
|
|
||||||
def onCardLayout(self):
|
def onCardLayout(self):
|
||||||
from aqt.clayout import CardLayout
|
from aqt.clayout import CardLayout
|
||||||
self.saveNow()
|
self.saveNow()
|
||||||
|
|
140
aqt/fields.py
140
aqt/fields.py
|
@ -9,114 +9,78 @@ from aqt.utils import saveGeom, restoreGeom, getBase, mungeQA, \
|
||||||
saveSplitter, restoreSplitter, showInfo, askUser, getText, \
|
saveSplitter, restoreSplitter, showInfo, askUser, getText, \
|
||||||
openHelp
|
openHelp
|
||||||
from anki.utils import isMac, isWin
|
from anki.utils import isMac, isWin
|
||||||
import aqt.templates
|
|
||||||
|
|
||||||
# raise Exception("Remember to disallow media&latex refs in edit.")
|
# raise Exception("Remember to disallow media&latex refs in edit.")
|
||||||
|
|
||||||
# need to strip the field management code out of this
|
# need to strip the field management code out of this
|
||||||
|
|
||||||
# - add sort field
|
class FieldDialog(QDialog):
|
||||||
|
|
||||||
class CardLayout(QDialog):
|
|
||||||
|
|
||||||
def __init__(self, mw, note, ord=0, parent=None):
|
def __init__(self, mw, note, ord=0, parent=None):
|
||||||
QDialog.__init__(self, parent or mw, Qt.Window)
|
QDialog.__init__(self, parent or mw, Qt.Window)
|
||||||
self.mw = aqt.mw
|
self.mw = aqt.mw
|
||||||
self.parent = parent or mw
|
self.parent = parent or mw
|
||||||
self.note = note
|
self.note = note
|
||||||
self.ord = ord
|
|
||||||
self.col = self.mw.col
|
self.col = self.mw.col
|
||||||
self.mm = self.mw.col.models
|
self.mm = self.mw.col.models
|
||||||
self.model = note.model()
|
self.model = note.model()
|
||||||
self.setupTabs()
|
self.form = aqt.forms.fields.Ui_Dialog()
|
||||||
v1 = QVBoxLayout()
|
|
||||||
v1.addWidget(self.tabs)
|
|
||||||
self.bbox = QDialogButtonBox(QDialogButtonBox.Close)
|
|
||||||
v1.addWidget(self.bbox)
|
|
||||||
self.setLayout(v1)
|
|
||||||
self.updateTabs()
|
|
||||||
self.exec_()
|
|
||||||
return
|
|
||||||
|
|
||||||
def setupTabs(self):
|
|
||||||
self.tabs = QTabWidget()
|
|
||||||
self.tabs.setTabsClosable(True)
|
|
||||||
self.tabs.setUsesScrollButtons(True)
|
|
||||||
self.tabs.setMovable(True)
|
|
||||||
add = QPushButton("+")
|
|
||||||
add.setFixedWidth(30)
|
|
||||||
self.tabs.setCornerWidget(add)
|
|
||||||
|
|
||||||
def updateTabs(self):
|
|
||||||
self.forms = []
|
|
||||||
self.tabs.clear()
|
|
||||||
for t in self.model['tmpls']:
|
|
||||||
self.addTab(t)
|
|
||||||
|
|
||||||
def addTab(self, t):
|
|
||||||
w = QWidget()
|
|
||||||
h = QHBoxLayout()
|
|
||||||
h.addStretch()
|
|
||||||
label = QLabel(_("Name:"))
|
|
||||||
h.addWidget(label)
|
|
||||||
edit = QLineEdit()
|
|
||||||
edit.setFixedWidth(200)
|
|
||||||
h.addWidget(edit)
|
|
||||||
h.addStretch()
|
|
||||||
v = QVBoxLayout()
|
|
||||||
v.addLayout(h)
|
|
||||||
l = QHBoxLayout()
|
|
||||||
l.setMargin(0)
|
|
||||||
l.setSpacing(3)
|
|
||||||
left = QWidget()
|
|
||||||
# template area
|
|
||||||
tform = aqt.forms.template.Ui_Form()
|
|
||||||
tform.setupUi(left)
|
|
||||||
l.addWidget(left, 5)
|
|
||||||
# preview area
|
|
||||||
right = QWidget()
|
|
||||||
pform = aqt.forms.preview.Ui_Form()
|
|
||||||
pform.setupUi(right)
|
|
||||||
l.addWidget(right, 5)
|
|
||||||
v.addLayout(l)
|
|
||||||
w.setLayout(v)
|
|
||||||
self.tabs.addTab(w, t['name'])
|
|
||||||
self.forms.append([tform, pform, edit])
|
|
||||||
|
|
||||||
def old():
|
|
||||||
self.form = aqt.forms.clayout.Ui_Dialog()
|
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
self.setWindowTitle(_("%s Layout") % self.model['name'])
|
|
||||||
self.plastiqueStyle = None
|
|
||||||
if isMac or isWin:
|
|
||||||
self.plastiqueStyle = QStyleFactory.create("plastique")
|
|
||||||
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
|
|
||||||
self.onHelp)
|
|
||||||
self.setupCards()
|
|
||||||
self.setupFields()
|
|
||||||
self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
||||||
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
|
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
|
||||||
restoreSplitter(self.form.splitter, "clayout")
|
self.fillFields()
|
||||||
restoreGeom(self, "CardLayout")
|
self.setupSignals()
|
||||||
if not self.reload(first=True):
|
self.form.fieldList.setCurrentRow(0)
|
||||||
return
|
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
def reload(self, first=False):
|
def fillFields(self):
|
||||||
self.cards = self.col.previewCards(self.note, self.type)
|
self.form.fieldList.clear()
|
||||||
if not self.cards:
|
for f in self.model['flds']:
|
||||||
self.accept()
|
self.form.fieldList.addItem(f['name'])
|
||||||
if first:
|
|
||||||
showInfo(_("Please enter some text first."))
|
def setupSignals(self):
|
||||||
else:
|
c = self.connect
|
||||||
showInfo(_("The current note was deleted."))
|
s = SIGNAL
|
||||||
return
|
f = self.form
|
||||||
self.fillCardList()
|
c(f.fieldList, s("currentRowChanged(int)"), self.onRowChange)
|
||||||
self.fillFieldList()
|
c(f.fieldAdd, s("clicked()"), self.onAdd)
|
||||||
self.fieldChanged()
|
c(f.fieldDelete, s("clicked()"), self.onDelete)
|
||||||
self.readField()
|
c(f.fieldUp, s("clicked()"), self.onUp)
|
||||||
return True
|
c(f.fieldDown, s("clicked()"), self.onDown)
|
||||||
|
c(f.sortField, s("clicked()"), self.onSortField)
|
||||||
|
|
||||||
|
def onRowChange(self, idx):
|
||||||
|
self.loadField(idx)
|
||||||
|
|
||||||
|
def onAdd(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onDelete(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onSortField(self):
|
||||||
|
# don't allow user to disable; it makes no sense
|
||||||
|
self.form.sortField.setChecked(True)
|
||||||
|
self.model['sortf'] = self.form.fieldList.currentRow()
|
||||||
|
|
||||||
|
def loadField(self, idx):
|
||||||
|
fld = self.model['flds'][idx]
|
||||||
|
f = self.form
|
||||||
|
f.fieldName.setText(fld['name'])
|
||||||
|
f.fontFamily.setCurrentFont(QFont(fld['font']))
|
||||||
|
f.fontSize.setValue(fld['size'])
|
||||||
|
f.sticky.setChecked(fld['sticky'])
|
||||||
|
print self.model['sortf'] == fld['ord']
|
||||||
|
f.sortField.setChecked(self.model['sortf'] == fld['ord'])
|
||||||
|
f.rtl.setChecked(fld['rtl'])
|
||||||
|
|
||||||
# Cards & Preview
|
# Cards & Preview
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -317,9 +317,9 @@ def applyStyles(widget):
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getBase(deck):
|
def getBase(col):
|
||||||
base = None
|
base = None
|
||||||
mdir = deck.media.dir()
|
mdir = col.media.dir()
|
||||||
if isWin:
|
if isWin:
|
||||||
prefix = u"file:///"
|
prefix = u"file:///"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -226,13 +226,9 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Cards</string>
|
<string>Cards</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionSetDeck"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="actionReposition"/>
|
<addaction name="actionReposition"/>
|
||||||
<addaction name="actionReschedule"/>
|
<addaction name="actionReschedule"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionToggleSuspend"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="actionDelete"/>
|
<addaction name="actionDelete"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuJump">
|
<widget class="QMenu" name="menuJump">
|
||||||
|
@ -259,10 +255,6 @@
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionAddItems"/>
|
<addaction name="actionAddItems"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionToggleMark"/>
|
|
||||||
<addaction name="actionAddTag"/>
|
|
||||||
<addaction name="actionDeleteTag"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="actionFindReplace"/>
|
<addaction name="actionFindReplace"/>
|
||||||
<addaction name="actionFindDuplicates"/>
|
<addaction name="actionFindDuplicates"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>372</width>
|
<width>403</width>
|
||||||
<height>340</height>
|
<height>352</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -131,7 +131,7 @@
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Font</string>
|
<string>Editing Font</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -145,14 +145,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="4" column="1">
|
||||||
<widget class="QLabel" name="label_18">
|
|
||||||
<property name="text">
|
|
||||||
<string>Options</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QCheckBox" name="rtl">
|
<widget class="QCheckBox" name="rtl">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Reverse text direction (RTL)</string>
|
<string>Reverse text direction (RTL)</string>
|
||||||
|
@ -169,13 +162,27 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QCheckBox" name="sticky">
|
<widget class="QCheckBox" name="sticky">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Remember last input</string>
|
<string>Remember last input</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_18">
|
||||||
|
<property name="text">
|
||||||
|
<string>Options</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QRadioButton" name="sortField">
|
||||||
|
<property name="text">
|
||||||
|
<string>Sort by this field in the browser</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
Loading…
Reference in a new issue