select cards when adding in editor, ignore empty cards

This commit is contained in:
Damien Elmes 2008-11-28 17:11:57 +09:00
parent 9c720452b9
commit 360cf3c373
5 changed files with 87 additions and 137 deletions

View file

@ -5,27 +5,27 @@ def importAll():
# a hack
import main
import about
import unsaved
import help
import preferences
import activetags
import addcards
import lookup
import sync
import view
import cardlist
import update
import importing
import exporting
import status
import deckproperties
import modelproperties
import modelchooser
import displayproperties
import utils
import exporting
import facteditor
import help
import importing
import lookup
import modelchooser
import modelproperties
import preferences
import status
import sync
import tagedit
import tray
import activetags
import unsaved
import update
import utils
import view
class DialogManager(object):

View file

@ -511,10 +511,19 @@ where id in (%s)""" % ",".join([
self.updateAfterCardChange(reset=True)
def addCards(self):
raise
# for id in self.selectedFacts():
# self.deck.addMissingCards(self.deck.s.query(Fact).get(id))
# self.updateSearch()
sf = self.selectedFacts()
if not sf:
return
cms = [x.id for x in self.deck.s.query(Fact).get(sf[0]).\
model.cardModels]
d = AddCardChooser(self, cms)
if not d.exec_():
return
for id in sf:
self.deck.addCards(self.deck.s.query(Fact).get(id),
d.selectedCms)
self.deck.flushMod()
self.updateSearch()
def selectFacts(self):
sm = self.dialog.tableView.selectionModel()
@ -523,3 +532,47 @@ where id in (%s)""" % ",".join([
if card.id in cardIds:
sm.select(self.model.index(i, 0),
QItemSelectionModel.Select | QItemSelectionModel.Rows)
class AddCardChooser(QDialog):
def __init__(self, parent, cms):
QDialog.__init__(self, parent)
self.parent = parent
self.cms = cms
self.dialog = ankiqt.forms.addcardmodels.Ui_Dialog()
self.dialog.setupUi(self)
self.connect(self.dialog.buttonBox, SIGNAL("helpRequested()"),
self.onHelp)
self.displayCards()
restoreGeom(self, "addCardModels")
def displayCards(self):
self.cms = self.parent.deck.s.all("""
select id, name, active from cardModels
where id in %s
order by ordinal""" % ids2str(self.cms))
self.items = []
for cm in self.cms:
item = QListWidgetItem(cm[1], self.dialog.list)
self.dialog.list.addItem(item)
self.items.append(item)
idx = self.dialog.list.indexFromItem(item)
if cm[2]:
mode = QItemSelectionModel.Select
else:
mode = QItemSelectionModel.Deselect
self.dialog.list.selectionModel().select(idx, mode)
def accept(self):
self.selectedCms = []
for i, item in enumerate(self.items):
idx = self.dialog.list.indexFromItem(item)
if self.dialog.list.selectionModel().isSelected(idx):
self.selectedCms.append(self.cms[i][0])
saveGeom(self, "addCardModels")
QDialog.accept(self)
def onHelp(self):
QDesktopServices.openUrl(QUrl(ankiqt.appWiki +
"Editor#AddCards"))

View file

@ -1,28 +1,22 @@
<ui version="4.0" >
<class>InfoDialog</class>
<widget class="QDialog" name="InfoDialog" >
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>409</width>
<height>284</height>
<width>248</width>
<height>268</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
<string>Add Cards</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QTextEdit" name="textEdit" >
<property name="readOnly" >
<bool>true</bool>
<widget class="QListWidget" name="list" >
<property name="selectionMode" >
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
@ -32,7 +26,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Close</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
@ -43,7 +37,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>InfoDialog</receiver>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
@ -59,7 +53,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>InfoDialog</receiver>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >

View file

@ -241,7 +241,7 @@
<normaloff>:/icons/Anki_Add_Tag.png</normaloff>:/icons/Anki_Add_Tag.png</iconset>
</property>
<property name="text" >
<string>Add Tag...</string>
<string>&amp;Add Tag...</string>
</property>
</action>
<action name="actionDeleteTag" >
@ -250,7 +250,7 @@
<normaloff>:/icons/Anki_Del_Tag.png</normaloff>:/icons/Anki_Del_Tag.png</iconset>
</property>
<property name="text" >
<string>Delete Tag...</string>
<string>&amp;Delete Tag...</string>
</property>
</action>
<action name="actionAddCards" >
@ -259,7 +259,7 @@
<normaloff>:/icons/Anki_Card.png</normaloff>:/icons/Anki_Card.png</iconset>
</property>
<property name="text" >
<string>Add Cards...</string>
<string>Add &amp;Cards...</string>
</property>
</action>
<action name="actionResetProgress" >
@ -277,7 +277,7 @@
<normaloff>:/icons/fileclose.png</normaloff>:/icons/fileclose.png</iconset>
</property>
<property name="text" >
<string>&amp;Close</string>
<string>Close</string>
</property>
</action>
<action name="actionSelectAll" >

View file

@ -1,97 +0,0 @@
<ui version="4.0" >
<class>Sort</class>
<widget class="QDialog" name="Sort" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>425</width>
<height>358</height>
</rect>
</property>
<property name="windowTitle" >
<string>Anki</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>20</number>
</property>
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Please choose a field to sort by.</string>
</property>
<property name="alignment" >
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="fields" >
<property name="font" >
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="editTriggers" >
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="tabKeyNavigation" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Sort</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Sort</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>