mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 06:07:11 -05:00
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:
parent
a3816b0e9e
commit
9367570900
3 changed files with 167 additions and 51 deletions
|
|
@ -50,6 +50,25 @@ class ChangeMap(QDialog):
|
|||
self.field = 0
|
||||
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):
|
||||
|
||||
def __init__(self, parent):
|
||||
|
|
@ -57,11 +76,6 @@ class ImportDialog(QDialog):
|
|||
self.parent = parent
|
||||
self.dialog = ankiqt.forms.importing.Ui_ImportDialog()
|
||||
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.setupOptions()
|
||||
self.getFile()
|
||||
|
|
@ -83,6 +97,8 @@ class ImportDialog(QDialog):
|
|||
self.dialog.modelArea.setLayout(self.modelChooser)
|
||||
self.connect(self.dialog.importButton, SIGNAL("clicked()"),
|
||||
self.doImport)
|
||||
self.connect(self.dialog.updateButton, SIGNAL("clicked()"),
|
||||
self.doUpdate)
|
||||
|
||||
def getFile(self):
|
||||
key = ";;".join([x[0] for x in importing.Importers])
|
||||
|
|
@ -103,10 +119,8 @@ class ImportDialog(QDialog):
|
|||
self.importerFunc = self.importer[1]
|
||||
if self.importerFunc.needMapper:
|
||||
self.modelChooser.show()
|
||||
self.dialog.tagDuplicates.show()
|
||||
else:
|
||||
self.modelChooser.hide()
|
||||
self.dialog.tagDuplicates.hide()
|
||||
self.dialog.autoDetect.setShown(self.importerFunc.needDelimiter)
|
||||
|
||||
def maybePreview(self):
|
||||
|
|
@ -159,12 +173,17 @@ you can enter it here. Use \\t to represent tab."""),
|
|||
txt = _("Auto-detected &delimiter: %s") % d
|
||||
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..."))
|
||||
t = time.time()
|
||||
self.importer.mapping = self.mapping
|
||||
self.importer.tagsToAdd = unicode(self.tags.text())
|
||||
self.importer.tagDuplicates = self.dialog.tagDuplicates.isChecked()
|
||||
try:
|
||||
n = _("Import")
|
||||
self.parent.deck.setUndoStart(n)
|
||||
|
|
@ -228,6 +247,7 @@ you can enter it here. Use \\t to represent tab."""),
|
|||
self.dialog.mappingArea.show()
|
||||
else:
|
||||
self.dialog.mappingArea.hide()
|
||||
self.dialog.updateButton.hide()
|
||||
return
|
||||
# set up the mapping grid
|
||||
if self.mapwidget:
|
||||
|
|
@ -254,7 +274,6 @@ you can enter it here. Use \\t to represent tab."""),
|
|||
self.grid.addWidget(button, num, 2)
|
||||
self.connect(button, SIGNAL("clicked()"),
|
||||
lambda s=self,n=num: s.changeMappingNum(n))
|
||||
self.tags.setFocus()
|
||||
|
||||
def changeMappingNum(self, n):
|
||||
f = ChangeMap(self.parent, self.model, self.mapping[n]).getField()
|
||||
|
|
|
|||
|
|
@ -26,30 +26,6 @@
|
|||
<property name="margin">
|
||||
<number>9</number>
|
||||
</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><b>Tags to append</b>:</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>
|
||||
<widget class="QPushButton" name="autoDetect">
|
||||
<property name="text">
|
||||
|
|
@ -74,7 +50,7 @@
|
|||
<property name="title">
|
||||
<string>Field mapping</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
|
|
@ -82,20 +58,7 @@
|
|||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout">
|
||||
<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>&Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="mappingArea">
|
||||
<property name="sizePolicy">
|
||||
|
|
@ -112,6 +75,24 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="importButton">
|
||||
<property name="text">
|
||||
<string>&Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="updateButton">
|
||||
<property name="text">
|
||||
<string>&Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
@ -152,9 +133,9 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>tagDuplicates</tabstop>
|
||||
<tabstop>autoDetect</tabstop>
|
||||
<tabstop>importButton</tabstop>
|
||||
<tabstop>updateButton</tabstop>
|
||||
<tabstop>status</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
|
|
|
|||
116
designer/importup.ui
Normal file
116
designer/importup.ui
Normal 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>
|
||||
Loading…
Reference in a new issue