mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add ability to customize separator when importing, fix tab order
This commit is contained in:
parent
f6066c7ffd
commit
edcad222d0
2 changed files with 112 additions and 57 deletions
|
@ -6,6 +6,7 @@ from PyQt4.QtGui import *
|
|||
from PyQt4.QtCore import *
|
||||
import anki
|
||||
import anki.importing as importing
|
||||
from ankiqt.ui.utils import getOnlyText
|
||||
from anki.errors import *
|
||||
import ankiqt.forms
|
||||
from ankiqt import ui
|
||||
|
@ -59,6 +60,8 @@ class ImportDialog(QDialog):
|
|||
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()
|
||||
|
@ -66,6 +69,9 @@ class ImportDialog(QDialog):
|
|||
return
|
||||
self.dialog.groupBox.setTitle(os.path.basename(self.file))
|
||||
self.maybePreview()
|
||||
self.connect(self.dialog.autoDetect, SIGNAL("clicked()"),
|
||||
self.onDelimiter)
|
||||
self.updateDelimiterButtonText()
|
||||
self.exec_()
|
||||
|
||||
def setupOptions(self):
|
||||
|
@ -101,6 +107,7 @@ class ImportDialog(QDialog):
|
|||
else:
|
||||
self.modelChooser.hide()
|
||||
self.dialog.tagDuplicates.hide()
|
||||
self.dialog.autoDetect.setShown(self.importerFunc.needDelimiter)
|
||||
|
||||
def maybePreview(self):
|
||||
if self.file and self.model:
|
||||
|
@ -113,6 +120,43 @@ class ImportDialog(QDialog):
|
|||
self.model = model
|
||||
self.maybePreview()
|
||||
|
||||
def onDelimiter(self):
|
||||
str = getOnlyText(_("""\
|
||||
By default, Anki will detect the character between fields, such as
|
||||
a tab, comma, and so on. If Anki is detecting the character incorrectly,
|
||||
you can enter it here. Use \\t to represent tab."""),
|
||||
self, help="FileImport")
|
||||
str = str.replace("\\t", "\t")
|
||||
str = str.encode("ascii")
|
||||
self.hideMapping()
|
||||
def updateDelim():
|
||||
self.importer.delimiter = str
|
||||
self.showMapping(hook=updateDelim)
|
||||
self.updateDelimiterButtonText()
|
||||
|
||||
def updateDelimiterButtonText(self):
|
||||
if self.importer.delimiter:
|
||||
d = self.importer.delimiter
|
||||
else:
|
||||
d = self.importer.dialect.delimiter
|
||||
if d == "\t":
|
||||
d = "Tab"
|
||||
elif d == ",":
|
||||
d = "Comma"
|
||||
elif d == " ":
|
||||
d = "Space"
|
||||
elif d == ";":
|
||||
d = "Semicolon"
|
||||
elif d == ":":
|
||||
d = "Colon"
|
||||
else:
|
||||
d = `d`
|
||||
if self.importer.delimiter:
|
||||
txt = _("Manual &delimiter: %s") % d
|
||||
else:
|
||||
txt = _("Auto-detected &delimiter: %s") % d
|
||||
self.dialog.autoDetect.setText(txt)
|
||||
|
||||
def doImport(self):
|
||||
self.dialog.status.setText(_("Importing..."))
|
||||
t = time.time()
|
||||
|
@ -163,10 +207,12 @@ class ImportDialog(QDialog):
|
|||
def hideMapping(self):
|
||||
self.dialog.mappingGroup.hide()
|
||||
|
||||
def showMapping(self, keepMapping=False):
|
||||
def showMapping(self, keepMapping=False, hook=None):
|
||||
# first, check that we can read the file
|
||||
try:
|
||||
self.importer = self.importerFunc(self.parent.deck, self.file)
|
||||
if hook:
|
||||
hook()
|
||||
if not keepMapping:
|
||||
self.mapping = self.importer.mapping
|
||||
except ImportFormatError, e:
|
||||
|
@ -209,6 +255,7 @@ class ImportDialog(QDialog):
|
|||
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()
|
||||
|
@ -222,6 +269,5 @@ class ImportDialog(QDialog):
|
|||
self.showMapping(keepMapping=True)
|
||||
|
||||
def reject(self):
|
||||
print "deinit"
|
||||
self.modelChooser.deinit()
|
||||
QDialog.reject(self)
|
||||
|
|
|
@ -1,105 +1,113 @@
|
|||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImportDialog</class>
|
||||
<widget class="QDialog" name="ImportDialog" >
|
||||
<property name="geometry" >
|
||||
<widget class="QDialog" name="ImportDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>477</width>
|
||||
<height>484</height>
|
||||
<width>440</width>
|
||||
<height>513</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Import options</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="topGrid" >
|
||||
<property name="margin" >
|
||||
<layout class="QGridLayout" name="topGrid">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<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>
|
||||
<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" >
|
||||
<widget class="QCheckBox" name="tagDuplicates">
|
||||
<property name="text">
|
||||
<string>Tag facts with duplicate fields instead of deleting</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" native="1" name="modelArea" />
|
||||
<widget class="QPushButton" name="autoDetect">
|
||||
<property name="text">
|
||||
<string>Auto-detect file format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="modelArea" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="mappingGroup" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
|
||||
<widget class="QGroupBox" name="mappingGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title" >
|
||||
<property name="title">
|
||||
<string>Field mapping</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="2" >
|
||||
<widget class="QPushButton" name="importButton" >
|
||||
<property name="text" >
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="importButton">
|
||||
<property name="text">
|
||||
<string>&Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<widget class="QFrame" name="mappingArea" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="mappingArea">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape" >
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
|
@ -110,20 +118,20 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2" >
|
||||
<property name="title" >
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Status</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="status" >
|
||||
<property name="readOnly" >
|
||||
<widget class="QTextEdit" name="status">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
|
@ -132,11 +140,11 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="orientation" >
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons" >
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
|
@ -145,6 +153,7 @@
|
|||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>tagDuplicates</tabstop>
|
||||
<tabstop>autoDetect</tabstop>
|
||||
<tabstop>importButton</tabstop>
|
||||
<tabstop>status</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
|
@ -157,11 +166,11 @@
|
|||
<receiver>ImportDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
|
@ -173,11 +182,11 @@
|
|||
<receiver>ImportDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
|
|
Loading…
Reference in a new issue