~ubuntu-branches/ubuntu/natty/anki/natty

« back to all changes in this revision

Viewing changes to ankiqt/ui/addcards.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Bombe
  • Date: 2010-10-22 12:50:51 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20101022125051-hrscik3rhw9z31zh
Tags: 1.0.1-1
* Imported Upstream version 1.0.1 (Closes: #598167)
* Upstream version no longer contains string exceptions (Closes:
  #585262)
* Use getlocale(LC_MESSAGES) for default interface language instead of
  getdefaultlocale() (Closes: 576158)
* Switch to version 3.0 (quilt) package format
* Bump Standards-Version to 3.9.1, no changes necessary
* Remove some more code from libanki/anki/lang.py that is not needed
  with the fixed locale path patch
* Add Vcs-Git control fields pointing to the collab-maint repository
  on Alioth
* Remove *.anki exclusion on dh_compress, left over from time when
  example decks were included
* In anki launcher set sys.path[0] to /usr/share/anki rather than
  prepending it to sys.path
* debian/copyright: Copy list of contributors from about dialog

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
        self.editor = ui.facteditor.FactEditor(self,
52
52
                                               self.dialog.fieldsArea,
53
53
                                               self.parent.deck)
 
54
        self.editor.addMode = True
54
55
 
55
56
    def addChooser(self):
56
57
        self.modelChooser = ui.modelchooser.ModelChooser(self,
122
123
        self.setTabOrder(self.addButton, self.closeButton)
123
124
        self.setTabOrder(self.closeButton, self.helpButton)
124
125
 
125
 
    def addCards(self):
126
 
        # make sure updated
127
 
        self.editor.saveFieldsNow()
128
 
        fact = self.editor.fact
129
 
        n = _("Add")
130
 
        self.parent.deck.setUndoStart(n)
 
126
    def reportAddedFact(self, fact):
 
127
        self.dialog.status.append(
 
128
            _("Added %(num)d card(s) for <a href=\"%(id)d\">"
 
129
              "%(str)s</a>.") % {
 
130
            "num": len(fact.cards),
 
131
            "id": fact.id,
 
132
            # we're guaranteed that all fields will exist now
 
133
            "str": stripHTML(fact[fact.fields[0].name]),
 
134
            })
 
135
 
 
136
    def addFact(self, fact):
131
137
        try:
132
138
            fact = self.parent.deck.addFact(fact)
133
139
        except FactInvalidError:
140
146
The input you have provided would make an empty
141
147
question or answer on all cards."""), parent=self)
142
148
            return
143
 
        self.dialog.status.append(
144
 
            _("Added %(num)d card(s) for <a href=\"%(id)d\">"
145
 
              "%(str)s</a>.") % {
146
 
            "num": len(fact.cards),
147
 
            "id": fact.id,
148
 
            # we're guaranteed that all fields will exist now
149
 
            "str": stripHTML(fact[fact.fields[0].name]),
150
 
            })
 
149
 
 
150
        self.reportAddedFact(fact)
 
151
        return fact
 
152
 
 
153
    def initializeNewFact(self, old_fact):
 
154
        f = self.parent.deck.newFact()
 
155
        f.tags = self.parent.deck.lastTags
 
156
        return f
 
157
 
 
158
    def clearOldFact(self, old_fact):
 
159
        f = self.initializeNewFact(old_fact)
 
160
        self.editor.setFact(f, check=True, scroll=True)
 
161
        # let completer know our extra tags
 
162
        self.editor.tags.addTags(parseTags(self.parent.deck.lastTags))
 
163
        return f
 
164
 
 
165
    def addCards(self):
 
166
        # make sure updated
 
167
        self.editor.saveFieldsNow()
 
168
        fact = self.editor.fact
 
169
        n = _("Add")
 
170
        self.parent.deck.setUndoStart(n)
 
171
 
 
172
        fact = self.addFact(fact)
 
173
        if not fact:
 
174
            return
 
175
 
151
176
        # stop anything playing
152
177
        clearAudioQueue()
 
178
 
153
179
        self.parent.deck.setUndoEnd(n)
154
180
        self.parent.deck.checkDue()
155
181
        self.parent.updateTitleBar()
156
182
        self.parent.statusView.redraw()
 
183
 
157
184
        # start a new fact
158
 
        f = self.parent.deck.newFact()
159
 
        f.tags = self.parent.deck.lastTags
160
 
        self.editor.setFact(f, check=True, scroll=True)
161
 
        # let completer know our extra tags
162
 
        self.editor.tags.addTags(parseTags(self.parent.deck.lastTags))
 
185
        self.clearOldFact(fact)
 
186
 
163
187
        self.maybeSave()
164
188
 
165
189
    def keyPressEvent(self, evt):