mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
field repositioning
This commit is contained in:
parent
d0a9ec96c1
commit
b1ce366645
2 changed files with 44 additions and 95 deletions
100
aqt/clayout.py
100
aqt/clayout.py
|
@ -9,7 +9,7 @@ from anki.consts import *
|
||||||
import aqt
|
import aqt
|
||||||
from anki.sound import playFromText, clearAudioQueue
|
from anki.sound import playFromText, clearAudioQueue
|
||||||
from aqt.utils import saveGeom, restoreGeom, getBase, mungeQA, \
|
from aqt.utils import saveGeom, restoreGeom, getBase, mungeQA, \
|
||||||
saveSplitter, restoreSplitter, showInfo, isMac, isWin
|
saveSplitter, restoreSplitter, showInfo, isMac, isWin, askUser
|
||||||
from anki.hooks import runFilter
|
from anki.hooks import runFilter
|
||||||
|
|
||||||
class ResizingTextEdit(QTextEdit):
|
class ResizingTextEdit(QTextEdit):
|
||||||
|
@ -22,6 +22,7 @@ class CardLayout(QDialog):
|
||||||
def __init__(self, mw, fact, type=0, ord=0, parent=None):
|
def __init__(self, mw, fact, type=0, 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.fact = fact
|
self.fact = fact
|
||||||
self.type = type
|
self.type = type
|
||||||
self.ord = ord
|
self.ord = ord
|
||||||
|
@ -43,7 +44,7 @@ class CardLayout(QDialog):
|
||||||
self.reload()
|
self.reload()
|
||||||
if not self.cards:
|
if not self.cards:
|
||||||
showInfo(_("Please enter some text first."),
|
showInfo(_("Please enter some text first."),
|
||||||
parent=parent or mw)
|
parent=self.parent)
|
||||||
return
|
return
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ class CardLayout(QDialog):
|
||||||
self.cards = self.deck.previewCards(self.fact, self.type)
|
self.cards = self.deck.previewCards(self.fact, self.type)
|
||||||
self.fillCardList()
|
self.fillCardList()
|
||||||
self.fillFieldList()
|
self.fillFieldList()
|
||||||
self.fieldChanged(0)
|
self.fieldChanged()
|
||||||
self.readField()
|
self.readField()
|
||||||
|
|
||||||
# Cards & Preview
|
# Cards & Preview
|
||||||
|
@ -293,8 +294,6 @@ class CardLayout(QDialog):
|
||||||
self.saveField)
|
self.saveField)
|
||||||
self.connect(self.form.fieldRequired, SIGNAL("stateChanged(int)"),
|
self.connect(self.form.fieldRequired, SIGNAL("stateChanged(int)"),
|
||||||
self.saveField)
|
self.saveField)
|
||||||
self.connect(self.form.numeric, SIGNAL("stateChanged(int)"),
|
|
||||||
self.saveField)
|
|
||||||
w = self.form.fontColour
|
w = self.form.fontColour
|
||||||
if self.plastiqueStyle:
|
if self.plastiqueStyle:
|
||||||
w.setStyle(self.plastiqueStyle)
|
w.setStyle(self.plastiqueStyle)
|
||||||
|
@ -304,10 +303,11 @@ class CardLayout(QDialog):
|
||||||
SIGNAL("stateChanged(int)"),
|
SIGNAL("stateChanged(int)"),
|
||||||
self.saveField)
|
self.saveField)
|
||||||
|
|
||||||
def fieldChanged(self, idx):
|
def fieldChanged(self):
|
||||||
if self.updatingFields:
|
row = self.form.fieldList.currentRow()
|
||||||
return
|
if row == -1:
|
||||||
self.field = self.model.fields[idx]
|
row = 0
|
||||||
|
self.field = self.model.fields[row]
|
||||||
self.readField()
|
self.readField()
|
||||||
self.enableFieldMoveButtons()
|
self.enableFieldMoveButtons()
|
||||||
|
|
||||||
|
@ -387,53 +387,33 @@ class CardLayout(QDialog):
|
||||||
self.form.fieldDown.setEnabled(True)
|
self.form.fieldDown.setEnabled(True)
|
||||||
|
|
||||||
def addField(self):
|
def addField(self):
|
||||||
f = FieldModel(required=False, unique=False)
|
f = self.model.newField()
|
||||||
f.name = _("Field %d") % (len(self.model.fieldModels) + 1)
|
l = len(self.model.fields)
|
||||||
self.deck.addFieldModel(self.model, f)
|
f['name'] = _("Field %d") % l
|
||||||
try:
|
self.mw.progress.start()
|
||||||
self.deck.db.refresh(self.fact)
|
self.model.addField(f)
|
||||||
except:
|
self.mw.progress.finish()
|
||||||
# not yet added
|
self.reload()
|
||||||
self.updateFact()
|
self.form.fieldList.setCurrentRow(l)
|
||||||
self.fillFieldList()
|
|
||||||
self.form.fieldList.setCurrentRow(len(self.model.fieldModels)-1)
|
|
||||||
self.form.fieldName.setFocus()
|
self.form.fieldName.setFocus()
|
||||||
self.form.fieldName.selectAll()
|
self.form.fieldName.selectAll()
|
||||||
|
|
||||||
def updateFact(self):
|
|
||||||
oldFact = self.fact
|
|
||||||
model = self.deck.db.query(Model).get(oldFact.model.id)
|
|
||||||
fact = self.deck.newFact(model)
|
|
||||||
for field in fact.fields:
|
|
||||||
try:
|
|
||||||
fact[field.name] = oldFact[field.name]
|
|
||||||
except KeyError:
|
|
||||||
fact[field.name] = u""
|
|
||||||
fact.tags = oldFact.tags
|
|
||||||
self.fact = fact
|
|
||||||
|
|
||||||
def deleteField(self):
|
def deleteField(self):
|
||||||
row = self.form.fieldList.currentRow()
|
row = self.form.fieldList.currentRow()
|
||||||
if row == -1:
|
if row == -1:
|
||||||
return
|
return
|
||||||
if len(self.model.fieldModels) < 2:
|
if len(self.model.fields) < 2:
|
||||||
ui.utils.showInfo(
|
showInfo(
|
||||||
_("Please add a new field first."),
|
_("Please add a new field first."),
|
||||||
parent=self)
|
parent=self)
|
||||||
return
|
return
|
||||||
field = self.model.fieldModels[row]
|
if askUser(_("Delete this field and its data from all facts?"),
|
||||||
count = self.deck.fieldModelUseCount(field)
|
self.parent):
|
||||||
if count:
|
self.mw.progress.start()
|
||||||
if not ui.utils.askUser(
|
self.model.delField(self.field)
|
||||||
_("This field is used by %d cards. If you delete it,\n"
|
self.mw.progress.finish()
|
||||||
"all information in this field will be lost.\n"
|
|
||||||
"\nReally delete this field?") % count,
|
|
||||||
parent=self):
|
|
||||||
return
|
|
||||||
self.deck.deleteFieldModel(self.model, field)
|
|
||||||
self.fillFieldList()
|
|
||||||
# need to update q/a format
|
# need to update q/a format
|
||||||
self.readCard()
|
self.reload()
|
||||||
|
|
||||||
def moveFieldUp(self):
|
def moveFieldUp(self):
|
||||||
row = self.form.fieldList.currentRow()
|
row = self.form.fieldList.currentRow()
|
||||||
|
@ -441,28 +421,20 @@ class CardLayout(QDialog):
|
||||||
return
|
return
|
||||||
if row == 0:
|
if row == 0:
|
||||||
return
|
return
|
||||||
field = self.model.fieldModels[row]
|
self.mw.progress.start()
|
||||||
tField = self.model.fieldModels[row - 1]
|
self.model.moveField(self.field, row-1)
|
||||||
self.model.fieldModels.remove(field)
|
self.mw.progress.finish()
|
||||||
self.model.fieldModels.insert(row - 1, field)
|
self.form.fieldList.setCurrentRow(row-1)
|
||||||
if field.id not in self.fieldOrdinalUpdatedIds:
|
self.reload()
|
||||||
self.fieldOrdinalUpdatedIds.append(field.id)
|
|
||||||
if tField.id not in self.fieldOrdinalUpdatedIds:
|
|
||||||
self.fieldOrdinalUpdatedIds.append(tField.id)
|
|
||||||
self.fillFieldList(row - 1)
|
|
||||||
|
|
||||||
def moveFieldDown(self):
|
def moveFieldDown(self):
|
||||||
row = self.form.fieldList.currentRow()
|
row = self.form.fieldList.currentRow()
|
||||||
if row == -1:
|
if row == -1:
|
||||||
return
|
return
|
||||||
if row == len(self.model.fieldModels) - 1:
|
if row == len(self.model.fields) - 1:
|
||||||
return
|
return
|
||||||
field = self.model.fieldModels[row]
|
self.mw.progress.start()
|
||||||
tField = self.model.fieldModels[row + 1]
|
self.model.moveField(self.field, row+1)
|
||||||
self.model.fieldModels.remove(field)
|
self.mw.progress.finish()
|
||||||
self.model.fieldModels.insert(row + 1, field)
|
self.form.fieldList.setCurrentRow(row+1)
|
||||||
if field.id not in self.fieldOrdinalUpdatedIds:
|
self.reload()
|
||||||
self.fieldOrdinalUpdatedIds.append(field.id)
|
|
||||||
if tField.id not in self.fieldOrdinalUpdatedIds:
|
|
||||||
self.fieldOrdinalUpdatedIds.append(tField.id)
|
|
||||||
self.fillFieldList(row + 1)
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>407</width>
|
<width>472</width>
|
||||||
<height>482</height>
|
<height>531</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab">
|
<widget class="QWidget" name="tab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
@ -42,12 +42,6 @@
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="templateLayout">
|
<layout class="QGridLayout" name="templateLayout">
|
||||||
<property name="margin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QTextEdit" name="cardQuestion">
|
<widget class="QTextEdit" name="cardQuestion">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -137,7 +131,7 @@
|
||||||
<string>Flip</string>
|
<string>Flip</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../icons.qrc">
|
<iconset resource="icons.qrc">
|
||||||
<normaloff>:/icons/multisynk.png</normaloff>:/icons/multisynk.png</iconset>
|
<normaloff>:/icons/multisynk.png</normaloff>:/icons/multisynk.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -212,7 +206,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="allowEmptyAnswer">
|
<widget class="QCheckBox" name="allowEmptyAnswer">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Allow the answer to be blank</string>
|
<string>Add cards even if answer is blank</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -321,12 +315,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="_2">
|
<layout class="QGridLayout" name="_2">
|
||||||
<property name="margin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="fieldName"/>
|
<widget class="QLineEdit" name="fieldName"/>
|
||||||
</item>
|
</item>
|
||||||
|
@ -442,24 +430,17 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="1">
|
<item row="7" 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>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1">
|
|
||||||
<widget class="QCheckBox" name="numeric">
|
|
||||||
<property name="text">
|
|
||||||
<string>Sort as numbers in browser</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1">
|
<item row="5" column="1">
|
||||||
<widget class="QCheckBox" name="fieldRequired">
|
<widget class="QCheckBox" name="fieldRequired">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Prevent empty entries</string>
|
<string>Require text in field</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -519,9 +500,6 @@
|
||||||
<string>Preview</string>
|
<string>Preview</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="_3">
|
<layout class="QVBoxLayout" name="_3">
|
||||||
<property name="spacing">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<property name="margin">
|
<property name="margin">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -582,11 +560,10 @@
|
||||||
<tabstop>fieldUnique</tabstop>
|
<tabstop>fieldUnique</tabstop>
|
||||||
<tabstop>fieldRequired</tabstop>
|
<tabstop>fieldRequired</tabstop>
|
||||||
<tabstop>preserveWhitespace</tabstop>
|
<tabstop>preserveWhitespace</tabstop>
|
||||||
<tabstop>numeric</tabstop>
|
|
||||||
<tabstop>rtl</tabstop>
|
<tabstop>rtl</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../icons.qrc"/>
|
<include location="icons.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
|
|
Loading…
Reference in a new issue