~ubuntu-branches/ubuntu/lucid/anki/lucid-updates

« back to all changes in this revision

Viewing changes to ankiqt/ui/addcards.py

  • Committer: Bazaar Package Importer
  • Author(s): Mackenzie Morgan
  • Date: 2010-05-31 15:55:50 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100531155550-wj3tag8bvp6fwhpo
Tags: 0.9.9.8.6-2~lucid1
Backport from maverick to fix FTBFS (LP: #550145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from ankiqt.ui.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter
13
13
from ankiqt import ui
14
14
from anki.sound import clearAudioQueue
 
15
from anki.hooks import addHook, removeHook
15
16
 
16
17
class FocusButton(QPushButton):
17
18
    def focusInEvent(self, evt):
28
29
            windParent = parent
29
30
        QDialog.__init__(self, windParent, Qt.Window)
30
31
        self.parent = parent
 
32
        ui.utils.applyStyles(self)
31
33
        self.config = parent.config
32
34
        self.dialog = ankiqt.forms.addcards.Ui_AddCards()
33
35
        self.dialog.setupUi(self)
 
36
        self.setWindowTitle(_("Add Items - %s") % parent.deck.name())
34
37
        self.setupEditor()
35
38
        self.addChooser()
36
39
        self.addButtons()
37
40
        self.setupStatus()
38
 
        self.modelChanged(self.parent.deck.currentModel)
 
41
        self.modelChanged()
39
42
        self.addedItems = 0
40
43
        self.forceClose = False
41
44
        restoreGeom(self, "add")
42
45
        restoreSplitter(self.dialog.splitter, "add")
43
46
        self.show()
 
47
        addHook('guiReset', self.modelChanged)
44
48
        ui.dialogs.open("AddCards", self)
45
49
 
46
50
    def setupEditor(self):
82
86
 
83
87
    def setupStatus(self):
84
88
        "Make the status background the same colour as the frame."
85
 
        p = self.dialog.status.palette()
86
 
        c = unicode(p.color(QPalette.Window).name())
87
 
        self.dialog.status.setStyleSheet(
88
 
            "* { background: %s; color: #000000; }" % c)
89
 
 
90
 
    def modelChanged(self, model):
 
89
        if not sys.platform.startswith("darwin"):
 
90
            p = self.dialog.status.palette()
 
91
            c = unicode(p.color(QPalette.Window).name())
 
92
            self.dialog.status.setStyleSheet(
 
93
                "* { background: %s; }" % c)
 
94
        self.connect(self.dialog.status, SIGNAL("anchorClicked(QUrl)"),
 
95
                     self.onLink)
 
96
 
 
97
    def onLink(self, url):
 
98
        browser = ui.dialogs.get("CardList", self.parent)
 
99
        browser.dialog.filterEdit.setText("fid:" + url.toString())
 
100
        browser.updateSearch()
 
101
        browser.onFact()
 
102
 
 
103
    def modelChanged(self, model=None):
91
104
        oldFact = self.editor.fact
92
105
        # create a new fact
93
106
        fact = self.parent.deck.newFact()
127
140
The input you have provided would make an empty
128
141
question or answer on all cards."""), parent=self)
129
142
            return
130
 
        self.dialog.status.append(_("Added %(num)d card(s) for '%(str)s'.") % {
 
143
        self.dialog.status.append(
 
144
            _("Added %(num)d card(s) for <a href=\"%(id)d\">"
 
145
              "%(str)s</a>.") % {
131
146
            "num": len(fact.cards),
 
147
            "id": fact.id,
132
148
            # we're guaranteed that all fields will exist now
133
149
            "str": stripHTML(fact[fact.fields[0].name]),
134
150
            })
135
151
        # stop anything playing
136
152
        clearAudioQueue()
137
153
        self.parent.deck.setUndoEnd(n)
 
154
        self.parent.deck.checkDue()
138
155
        self.parent.updateTitleBar()
 
156
        self.parent.statusView.redraw()
139
157
        # start a new fact
140
158
        f = self.parent.deck.newFact()
141
159
        f.tags = self.parent.deck.lastTags
160
178
 
161
179
    def reject(self):
162
180
        if self.onClose():
 
181
            self.modelChooser.deinit()
163
182
            QDialog.reject(self)
164
183
 
165
184
    def onClose(self):
 
185
        removeHook('guiReset', self.modelChanged)
166
186
        # stop anything playing
167
187
        clearAudioQueue()
168
188
        if (self.forceClose or self.editor.fieldsAreBlank() or
169
189
            ui.utils.askUser(_("Close and lose current input?"),
170
190
                            self)):
 
191
            self.modelChooser.deinit()
171
192
            self.editor.close()
172
193
            ui.dialogs.close("AddCards")
173
194
            self.parent.deck.s.flush()