mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 17:26: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,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImportDialog</class>
|
||||
<widget class="QDialog" name="ImportDialog">
|
||||
|
@ -5,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>477</width>
|
||||
<height>484</height>
|
||||
<width>440</width>
|
||||
<height>513</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -36,7 +37,7 @@
|
|||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string><b>Tags to append</b>:</string>
|
||||
<string><b>Tags to append</b>:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -50,7 +51,14 @@
|
|||
</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>
|
||||
|
@ -58,7 +66,7 @@
|
|||
<item>
|
||||
<widget class="QGroupBox" name="mappingGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@ -91,7 +99,7 @@
|
|||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="mappingArea">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@ -145,6 +153,7 @@
|
|||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>tagDuplicates</tabstop>
|
||||
<tabstop>autoDetect</tabstop>
|
||||
<tabstop>importButton</tabstop>
|
||||
<tabstop>status</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
|
|
Loading…
Reference in a new issue