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("pause", "pause16", pause)
|
||||
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(),
|
||||
right), self._css, focus=False)
|
||||
|
||||
|
|
|
@ -156,12 +156,14 @@ Please create a new card first."""))
|
|||
def renderPreview(self):
|
||||
c = self.card
|
||||
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
|
||||
base = getBase(self.mw.col)
|
||||
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(
|
||||
html % (styles, ti(mungeQA(c.a()), 'a')))
|
||||
html % (base, styles, ti(mungeQA(c.a()), 'a')))
|
||||
|
||||
def maybeTextInput(self, txt, type='q'):
|
||||
if type == 'q':
|
||||
|
|
|
@ -269,8 +269,10 @@ class Editor(object):
|
|||
# align to right
|
||||
self.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding))
|
||||
b = self._addButton
|
||||
b("fields", self.onFields, "Ctrl+f",
|
||||
shortcut(_("Layout (Ctrl+f)")), size=False, text=_("Fields"))
|
||||
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)"),
|
||||
check=True)
|
||||
b("text_italic", self.toggleItalic, "Ctrl+i", _("Italic text (Ctrl+i)"),
|
||||
|
@ -306,6 +308,11 @@ class Editor(object):
|
|||
def disableButtons(self):
|
||||
self.enableButtons(False)
|
||||
|
||||
def onFields(self):
|
||||
from aqt.fields import FieldDialog
|
||||
self.saveNow()
|
||||
FieldDialog(self.mw, self.note, parent=self.widget)
|
||||
|
||||
def onCardLayout(self):
|
||||
from aqt.clayout import CardLayout
|
||||
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, \
|
||||
openHelp
|
||||
from anki.utils import isMac, isWin
|
||||
import aqt.templates
|
||||
|
||||
# raise Exception("Remember to disallow media&latex refs in edit.")
|
||||
|
||||
# need to strip the field management code out of this
|
||||
|
||||
# - add sort field
|
||||
|
||||
class CardLayout(QDialog):
|
||||
class FieldDialog(QDialog):
|
||||
|
||||
def __init__(self, mw, note, ord=0, parent=None):
|
||||
QDialog.__init__(self, parent or mw, Qt.Window)
|
||||
self.mw = aqt.mw
|
||||
self.parent = parent or mw
|
||||
self.note = note
|
||||
self.ord = ord
|
||||
self.col = self.mw.col
|
||||
self.mm = self.mw.col.models
|
||||
self.model = note.model()
|
||||
self.setupTabs()
|
||||
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 = aqt.forms.fields.Ui_Dialog()
|
||||
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.Close).setAutoDefault(False)
|
||||
restoreSplitter(self.form.splitter, "clayout")
|
||||
restoreGeom(self, "CardLayout")
|
||||
if not self.reload(first=True):
|
||||
return
|
||||
self.fillFields()
|
||||
self.setupSignals()
|
||||
self.form.fieldList.setCurrentRow(0)
|
||||
self.exec_()
|
||||
|
||||
##########################################################################
|
||||
|
||||
def reload(self, first=False):
|
||||
self.cards = self.col.previewCards(self.note, self.type)
|
||||
if not self.cards:
|
||||
self.accept()
|
||||
if first:
|
||||
showInfo(_("Please enter some text first."))
|
||||
else:
|
||||
showInfo(_("The current note was deleted."))
|
||||
return
|
||||
self.fillCardList()
|
||||
self.fillFieldList()
|
||||
self.fieldChanged()
|
||||
self.readField()
|
||||
return True
|
||||
def fillFields(self):
|
||||
self.form.fieldList.clear()
|
||||
for f in self.model['flds']:
|
||||
self.form.fieldList.addItem(f['name'])
|
||||
|
||||
def setupSignals(self):
|
||||
c = self.connect
|
||||
s = SIGNAL
|
||||
f = self.form
|
||||
c(f.fieldList, s("currentRowChanged(int)"), self.onRowChange)
|
||||
c(f.fieldAdd, s("clicked()"), self.onAdd)
|
||||
c(f.fieldDelete, s("clicked()"), self.onDelete)
|
||||
c(f.fieldUp, s("clicked()"), self.onUp)
|
||||
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
|
||||
##########################################################################
|
||||
|
|
|
@ -317,9 +317,9 @@ def applyStyles(widget):
|
|||
except (IOError, OSError):
|
||||
pass
|
||||
|
||||
def getBase(deck):
|
||||
def getBase(col):
|
||||
base = None
|
||||
mdir = deck.media.dir()
|
||||
mdir = col.media.dir()
|
||||
if isWin:
|
||||
prefix = u"file:///"
|
||||
else:
|
||||
|
|
|
@ -226,13 +226,9 @@
|
|||
<property name="title">
|
||||
<string>Cards</string>
|
||||
</property>
|
||||
<addaction name="actionSetDeck"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionReposition"/>
|
||||
<addaction name="actionReschedule"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionToggleSuspend"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionDelete"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuJump">
|
||||
|
@ -259,10 +255,6 @@
|
|||
</property>
|
||||
<addaction name="actionAddItems"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionToggleMark"/>
|
||||
<addaction name="actionAddTag"/>
|
||||
<addaction name="actionDeleteTag"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionFindReplace"/>
|
||||
<addaction name="actionFindDuplicates"/>
|
||||
<addaction name="separator"/>
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>372</width>
|
||||
<height>340</height>
|
||||
<width>403</width>
|
||||
<height>352</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -131,7 +131,7 @@
|
|||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Font</string>
|
||||
<string>Editing Font</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -145,14 +145,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_18">
|
||||
<property name="text">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="rtl">
|
||||
<property name="text">
|
||||
<string>Reverse text direction (RTL)</string>
|
||||
|
@ -169,13 +162,27 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="sticky">
|
||||
<property name="text">
|
||||
<string>Remember last input</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</item>
|
||||
<item>
|
||||
|
|
Loading…
Reference in a new issue