mirror of
https://github.com/ankitects/anki.git
synced 2025-11-14 00:27:13 -05:00
Factor out drawField
This commit is contained in:
parent
f3b81d0024
commit
c0003c4c03
1 changed files with 33 additions and 27 deletions
|
|
@ -370,6 +370,36 @@ class FactEditor(object):
|
||||||
self.fieldsFrame.setLayout(self.fieldsGrid)
|
self.fieldsFrame.setLayout(self.fieldsGrid)
|
||||||
self.fieldsGrid.setMargin(0)
|
self.fieldsGrid.setMargin(0)
|
||||||
|
|
||||||
|
def drawField(self, field, n):
|
||||||
|
# label
|
||||||
|
l = QLabel(field.name)
|
||||||
|
self.labels.append(l)
|
||||||
|
self.fieldsGrid.addWidget(l, n, 0)
|
||||||
|
# edit widget
|
||||||
|
w = FactEdit(self)
|
||||||
|
w.setTabChangesFocus(True)
|
||||||
|
w.setAcceptRichText(True)
|
||||||
|
w.setMinimumSize(20, 60)
|
||||||
|
w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||||
|
w.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
|
w.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
|
if field.fieldModel.features:
|
||||||
|
w.setLayoutDirection(Qt.RightToLeft)
|
||||||
|
else:
|
||||||
|
w.setLayoutDirection(Qt.LeftToRight)
|
||||||
|
runHook("makeField", w, field)
|
||||||
|
self.fieldsGrid.addWidget(w, n, 1)
|
||||||
|
self.fields[field.name] = (field, w)
|
||||||
|
self.widgets[w] = field
|
||||||
|
# catch changes
|
||||||
|
w.connect(w, SIGNAL("lostFocus"),
|
||||||
|
lambda w=w: self.onFocusLost(w))
|
||||||
|
w.connect(w, SIGNAL("textChanged()"),
|
||||||
|
self.onTextChanged)
|
||||||
|
w.connect(w, SIGNAL("currentCharFormatChanged(QTextCharFormat)"),
|
||||||
|
lambda w=w: self.formatChanged(w))
|
||||||
|
return w
|
||||||
|
|
||||||
def drawFields(self, noFocus=False, check=False):
|
def drawFields(self, noFocus=False, check=False):
|
||||||
self.parent.setUpdatesEnabled(False)
|
self.parent.setUpdatesEnabled(False)
|
||||||
self._makeGrid()
|
self._makeGrid()
|
||||||
|
|
@ -381,39 +411,15 @@ class FactEditor(object):
|
||||||
n = 0
|
n = 0
|
||||||
first = True
|
first = True
|
||||||
last = None
|
last = None
|
||||||
|
|
||||||
for field in fields:
|
for field in fields:
|
||||||
# label
|
w = self.drawField(field, n)
|
||||||
l = QLabel(field.name)
|
|
||||||
self.labels.append(l)
|
|
||||||
self.fieldsGrid.addWidget(l, n, 0)
|
|
||||||
# edit widget
|
|
||||||
w = FactEdit(self)
|
|
||||||
last = w
|
last = w
|
||||||
w.setTabChangesFocus(True)
|
|
||||||
w.setAcceptRichText(True)
|
|
||||||
w.setMinimumSize(20, 60)
|
|
||||||
w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
|
||||||
w.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
||||||
w.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
||||||
if field.fieldModel.features:
|
|
||||||
w.setLayoutDirection(Qt.RightToLeft)
|
|
||||||
else:
|
|
||||||
w.setLayoutDirection(Qt.LeftToRight)
|
|
||||||
runHook("makeField", w, field)
|
|
||||||
self.fieldsGrid.addWidget(w, n, 1)
|
|
||||||
self.fields[field.name] = (field, w)
|
|
||||||
self.widgets[w] = field
|
|
||||||
# catch changes
|
|
||||||
w.connect(w, SIGNAL("lostFocus"),
|
|
||||||
lambda w=w: self.onFocusLost(w))
|
|
||||||
w.connect(w, SIGNAL("textChanged()"),
|
|
||||||
self.onTextChanged)
|
|
||||||
w.connect(w, SIGNAL("currentCharFormatChanged(QTextCharFormat)"),
|
|
||||||
lambda w=w: self.formatChanged(w))
|
|
||||||
if first:
|
if first:
|
||||||
self.focusTarget = w
|
self.focusTarget = w
|
||||||
first = False
|
first = False
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
# update available tags
|
# update available tags
|
||||||
self.tags.setDeck(self.deck)
|
self.tags.setDeck(self.deck)
|
||||||
# update fields
|
# update fields
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue