diff --git a/aqt/addcards.py b/aqt/addcards.py index d12f271af..5e96af83a 100644 --- a/aqt/addcards.py +++ b/aqt/addcards.py @@ -29,8 +29,8 @@ class AddCards(QDialog): self.form = aqt.forms.addcards.Ui_Dialog() self.form.setupUi(self) self.setWindowTitle(_("Add")) - self.setupEditor() self.setupChooser() + self.setupEditor() self.setupButtons() self.onReset() self.addedItems = 0 @@ -42,14 +42,10 @@ class AddCards(QDialog): def setupEditor(self): self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea) - # get a fact for testing - #fact = self.mw.deck.getFact(3951) - #self.editor.setFact(fact) def setupChooser(self): self.modelChooser = aqt.modelchooser.ModelChooser( self.mw, self.form.modelArea) - # modelChanged func def helpRequested(self): aqt.openHelp("AddItems") @@ -104,12 +100,9 @@ class AddCards(QDialog): except IndexError: break self.editor.setFact(fact) - #self.setTabOrder(self.editor.tags, self.addButton) - #self.setTabOrder(self.addButton, self.closeButton) - #self.setTabOrder(self.closeButton, self.helpButton) def removeTempFact(self, fact): - if not fact: + if not fact or not fact.id: return # we don't have to worry about cards; just the fact self.mw.deck._delFacts([fact.id]) diff --git a/aqt/editcurrent.py b/aqt/editcurrent.py index 6f6328eb6..9d3704b15 100644 --- a/aqt/editcurrent.py +++ b/aqt/editcurrent.py @@ -2,6 +2,10 @@ # -*- coding: utf-8 -*- # License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html + # get a fact for testing + #fact = self.mw.deck.getFact(3951) + #self.editor.setFact(fact) + class EditCurrent(object): def __init__(self, mw): diff --git a/aqt/editor.py b/aqt/editor.py index 8e5125aa7..8bb7c8ff1 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -15,6 +15,9 @@ from aqt.utils import shortcut, showInfo, showWarning, getBase, getFile import aqt import anki.js +# fixme: when tab order returns to the webview, the previously focused field +# is focused, which is not good when the user is tabbing through the dialog + pics = ("jpg", "jpeg", "png", "tif", "tiff", "gif") audio = ("wav", "mp3", "ogg", "flac") @@ -174,6 +177,7 @@ class Editor(object): self.widget = widget self.mw = mw self.fact = None + self.stealFocus = True self._loaded = False self._keepButtons = False # current card, for card layout @@ -296,6 +300,9 @@ class Editor(object): ###################################################################### def bridge(self, str): + if not self.fact or not runHook: + # shutdown + return # focus lost or key/button pressed? if str.startswith("blur") or str.startswith("key"): (type, txt) = str.split(":", 1) @@ -361,6 +368,8 @@ class Editor(object): simplejson.dumps(self.fonts()))) self.checkValid() self.widget.show() + if self.stealFocus: + self.web.setFocus() def fonts(self): return [(f['font'], f['esize'])