support updating of decks, simplify importing dialog

- can now choose 'update' instead of 'import', so users can maintain their
  data in a separate spreadsheet or file for bulk editing
- remove 'tags to append' option, as it makes the dialog a bit crowded. users
  can add 'tags:' to the start of their text files instead
- removed option to tag instead of suppress duplicates - a separate duplicate
  finding tool will be written instead
This commit is contained in:
Damien Elmes 2010-11-26 01:57:29 +09:00
parent a3816b0e9e
commit 9367570900
3 changed files with 167 additions and 51 deletions

View file

@ -50,6 +50,25 @@ class ChangeMap(QDialog):
self.field = 0 self.field = 0
QDialog.accept(self) QDialog.accept(self)
class UpdateMap(QDialog):
def __init__(self, parent, numFields, fieldModels):
QDialog.__init__(self, parent, Qt.Window)
self.parent = parent
self.fieldModels = fieldModels
self.dialog = ankiqt.forms.importup.Ui_Dialog()
self.dialog.setupUi(self)
for i in range(numFields):
self.dialog.fileField.addItem("Field %d" % (i+1))
for m in fieldModels:
self.dialog.deckField.addItem(m.name)
self.exec_()
def accept(self):
self.updateKey = (
self.dialog.fileField.currentIndex(),
self.fieldModels[self.dialog.deckField.currentIndex()].id)
QDialog.accept(self)
class ImportDialog(QDialog): class ImportDialog(QDialog):
def __init__(self, parent): def __init__(self, parent):
@ -57,11 +76,6 @@ class ImportDialog(QDialog):
self.parent = parent self.parent = parent
self.dialog = ankiqt.forms.importing.Ui_ImportDialog() self.dialog = ankiqt.forms.importing.Ui_ImportDialog()
self.dialog.setupUi(self) self.dialog.setupUi(self)
self.tags = ui.tagedit.TagEdit(parent)
self.tags.setDeck(parent.deck)
self.dialog.topGrid.addWidget(self.tags,0,1,1,1)
self.setTabOrder(self.tags, self.dialog.tagDuplicates)
self.setTabOrder(self.dialog.tagDuplicates, self.dialog.autoDetect)
self.setupMappingFrame() self.setupMappingFrame()
self.setupOptions() self.setupOptions()
self.getFile() self.getFile()
@ -83,6 +97,8 @@ class ImportDialog(QDialog):
self.dialog.modelArea.setLayout(self.modelChooser) self.dialog.modelArea.setLayout(self.modelChooser)
self.connect(self.dialog.importButton, SIGNAL("clicked()"), self.connect(self.dialog.importButton, SIGNAL("clicked()"),
self.doImport) self.doImport)
self.connect(self.dialog.updateButton, SIGNAL("clicked()"),
self.doUpdate)
def getFile(self): def getFile(self):
key = ";;".join([x[0] for x in importing.Importers]) key = ";;".join([x[0] for x in importing.Importers])
@ -103,10 +119,8 @@ class ImportDialog(QDialog):
self.importerFunc = self.importer[1] self.importerFunc = self.importer[1]
if self.importerFunc.needMapper: if self.importerFunc.needMapper:
self.modelChooser.show() self.modelChooser.show()
self.dialog.tagDuplicates.show()
else: else:
self.modelChooser.hide() self.modelChooser.hide()
self.dialog.tagDuplicates.hide()
self.dialog.autoDetect.setShown(self.importerFunc.needDelimiter) self.dialog.autoDetect.setShown(self.importerFunc.needDelimiter)
def maybePreview(self): def maybePreview(self):
@ -159,12 +173,17 @@ you can enter it here. Use \\t to represent tab."""),
txt = _("Auto-detected &delimiter: %s") % d txt = _("Auto-detected &delimiter: %s") % d
self.dialog.autoDetect.setText(txt) self.dialog.autoDetect.setText(txt)
def doImport(self): def doUpdate(self):
f = UpdateMap(self.parent,
self.importer.fields(),
self.model.fieldModels)
self.importer.updateKey = f.updateKey
self.doImport(True)
def doImport(self, update=False):
self.dialog.status.setText(_("Importing...")) self.dialog.status.setText(_("Importing..."))
t = time.time() t = time.time()
self.importer.mapping = self.mapping self.importer.mapping = self.mapping
self.importer.tagsToAdd = unicode(self.tags.text())
self.importer.tagDuplicates = self.dialog.tagDuplicates.isChecked()
try: try:
n = _("Import") n = _("Import")
self.parent.deck.setUndoStart(n) self.parent.deck.setUndoStart(n)
@ -228,6 +247,7 @@ you can enter it here. Use \\t to represent tab."""),
self.dialog.mappingArea.show() self.dialog.mappingArea.show()
else: else:
self.dialog.mappingArea.hide() self.dialog.mappingArea.hide()
self.dialog.updateButton.hide()
return return
# set up the mapping grid # set up the mapping grid
if self.mapwidget: if self.mapwidget:
@ -254,7 +274,6 @@ you can enter it here. Use \\t to represent tab."""),
self.grid.addWidget(button, num, 2) self.grid.addWidget(button, num, 2)
self.connect(button, SIGNAL("clicked()"), self.connect(button, SIGNAL("clicked()"),
lambda s=self,n=num: s.changeMappingNum(n)) lambda s=self,n=num: s.changeMappingNum(n))
self.tags.setFocus()
def changeMappingNum(self, n): def changeMappingNum(self, n):
f = ChangeMap(self.parent, self.model, self.mapping[n]).getField() f = ChangeMap(self.parent, self.model, self.mapping[n]).getField()

View file

@ -26,30 +26,6 @@
<property name="margin"> <property name="margin">
<number>9</number> <number>9</number>
</property> </property>
<item>
<layout class="QGridLayout" name="topGrid">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;b&gt;Tags to append&lt;/b&gt;:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="tagDuplicates">
<property name="text">
<string>Tag facts with duplicate fields instead of deleting</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="autoDetect"> <widget class="QPushButton" name="autoDetect">
<property name="text"> <property name="text">
@ -74,7 +50,7 @@
<property name="title"> <property name="title">
<string>Field mapping</string> <string>Field mapping</string>
</property> </property>
<layout class="QHBoxLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
@ -82,20 +58,7 @@
<number>9</number> <number>9</number>
</property> </property>
<item> <item>
<layout class="QGridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="2">
<widget class="QPushButton" name="importButton">
<property name="text">
<string>&amp;Import</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QFrame" name="mappingArea"> <widget class="QFrame" name="mappingArea">
<property name="sizePolicy"> <property name="sizePolicy">
@ -112,6 +75,24 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="importButton">
<property name="text">
<string>&amp;Import</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateButton">
<property name="text">
<string>&amp;Update</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@ -152,9 +133,9 @@
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>tagDuplicates</tabstop>
<tabstop>autoDetect</tabstop> <tabstop>autoDetect</tabstop>
<tabstop>importButton</tabstop> <tabstop>importButton</tabstop>
<tabstop>updateButton</tabstop>
<tabstop>status</tabstop> <tabstop>status</tabstop>
<tabstop>buttonBox</tabstop> <tabstop>buttonBox</tabstop>
</tabstops> </tabstops>

116
designer/importup.ui Normal file
View file

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>286</width>
<height>182</height>
</rect>
</property>
<property name="windowTitle">
<string>Update Facts</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Update your deck based on matching entries in the file.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Field in File:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Field in Deck:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="deckField"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="fileField"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>fileField</tabstop>
<tabstop>deckField</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</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>Dialog</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>