mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
auto-detect filename when importing
This commit is contained in:
parent
c2b99e2de6
commit
966effe37b
2 changed files with 25 additions and 62 deletions
|
@ -1,7 +1,7 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
import os, copy, time, sys
|
import os, copy, time, sys, re
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
import anki
|
import anki
|
||||||
|
@ -53,49 +53,49 @@ class ImportDialog(QDialog):
|
||||||
self.dialog.setupUi(self)
|
self.dialog.setupUi(self)
|
||||||
self.tags = ui.tagedit.TagEdit(parent)
|
self.tags = ui.tagedit.TagEdit(parent)
|
||||||
self.tags.setDeck(parent.deck)
|
self.tags.setDeck(parent.deck)
|
||||||
self.dialog.topGrid.addWidget(self.tags,2,1,1,1)
|
self.dialog.topGrid.addWidget(self.tags,0,1,1,1)
|
||||||
self.setupMappingFrame()
|
self.setupMappingFrame()
|
||||||
self.setupOptions()
|
self.setupOptions()
|
||||||
|
self.getFile()
|
||||||
|
if not self.file:
|
||||||
|
return
|
||||||
|
self.dialog.groupBox.setTitle(os.path.basename(self.file))
|
||||||
|
self.maybePreview()
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
def setupOptions(self):
|
def setupOptions(self):
|
||||||
self.file = None
|
|
||||||
self.model = self.parent.deck.currentModel
|
self.model = self.parent.deck.currentModel
|
||||||
self.modelChooser = ui.modelchooser.ModelChooser(self,
|
self.modelChooser = ui.modelchooser.ModelChooser(self,
|
||||||
self.parent,
|
self.parent,
|
||||||
self.parent.deck,
|
self.parent.deck,
|
||||||
self.modelChanged)
|
self.modelChanged)
|
||||||
self.importerChanged(0)
|
|
||||||
self.connect(self.dialog.type, SIGNAL("activated(int)"),
|
|
||||||
self.importerChanged)
|
|
||||||
self.dialog.type.insertItems(0, QStringList(list(zip(*importing.Importers)[0])))
|
|
||||||
self.connect(self.dialog.file, SIGNAL("clicked()"),
|
|
||||||
self.changeFile)
|
|
||||||
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.maybePreview()
|
|
||||||
|
|
||||||
def importerChanged(self, idx):
|
def getFile(self):
|
||||||
self.importerFunc = zip(*importing.Importers)[1][idx]
|
key = ";;".join([x[0] for x in importing.Importers])
|
||||||
|
file = ui.utils.getFile(self.parent, _("Import"), "import", key)
|
||||||
|
if not file:
|
||||||
|
self.file = None
|
||||||
|
return
|
||||||
|
self.file = unicode(file)
|
||||||
|
ext = os.path.splitext(self.file)[1]
|
||||||
|
self.importer = None
|
||||||
|
for i in importing.Importers:
|
||||||
|
for mext in re.findall("[( ]?\*\.(.+?)[) ]", i[0]):
|
||||||
|
if ext == "." + mext:
|
||||||
|
self.importer = i
|
||||||
|
break
|
||||||
|
if not self.importer:
|
||||||
|
self.importer = importing.Importers[0]
|
||||||
|
self.importerFunc = self.importer[1]
|
||||||
if self.importerFunc.needMapper:
|
if self.importerFunc.needMapper:
|
||||||
self.modelChooser.show()
|
self.modelChooser.show()
|
||||||
self.dialog.tagDuplicates.show()
|
self.dialog.tagDuplicates.show()
|
||||||
else:
|
else:
|
||||||
self.modelChooser.hide()
|
self.modelChooser.hide()
|
||||||
self.dialog.tagDuplicates.hide()
|
self.dialog.tagDuplicates.hide()
|
||||||
self.dialog.file.setText(_("Choose file..."))
|
|
||||||
self.file = None
|
|
||||||
self.maybePreview()
|
|
||||||
|
|
||||||
def changeFile(self):
|
|
||||||
key = zip(*importing.Importers)[0][self.dialog.type.currentIndex()]
|
|
||||||
file = ui.utils.getFile(self, _("Import file"), "import", key)
|
|
||||||
if not file:
|
|
||||||
return
|
|
||||||
self.file = unicode(file)
|
|
||||||
self.dialog.file.setText(os.path.basename(self.file))
|
|
||||||
self.maybePreview()
|
|
||||||
|
|
||||||
def maybePreview(self):
|
def maybePreview(self):
|
||||||
if self.file and self.model:
|
if self.file and self.model:
|
||||||
|
@ -134,7 +134,6 @@ class ImportDialog(QDialog):
|
||||||
txt = (
|
txt = (
|
||||||
_("Importing complete. %(num)d facts imported from %(file)s.\n") %
|
_("Importing complete. %(num)d facts imported from %(file)s.\n") %
|
||||||
{"num": self.importer.total, "file": os.path.basename(self.file)})
|
{"num": self.importer.total, "file": os.path.basename(self.file)})
|
||||||
txt += _("Click the close button or import another file.\n\n")
|
|
||||||
if self.importer.log:
|
if self.importer.log:
|
||||||
txt += _("Log of import:\n") + "\n".join(self.importer.log)
|
txt += _("Log of import:\n") + "\n".join(self.importer.log)
|
||||||
self.dialog.status.setText(txt)
|
self.dialog.status.setText(txt)
|
||||||
|
|
|
@ -33,44 +33,10 @@
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="1" column="0" >
|
|
||||||
<widget class="QLabel" name="label_2" >
|
|
||||||
<property name="text" >
|
|
||||||
<string><b>File to import</b>:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" >
|
|
||||||
<widget class="QPushButton" name="file" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Choose &file...</string>
|
|
||||||
</property>
|
|
||||||
<property name="default" >
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0" >
|
<item row="0" column="0" >
|
||||||
<widget class="QLabel" name="label" >
|
|
||||||
<property name="text" >
|
|
||||||
<string><b>Type of file</b>:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" >
|
|
||||||
<widget class="QComboBox" name="type" >
|
|
||||||
<property name="sizePolicy" >
|
|
||||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" >
|
|
||||||
<widget class="QLabel" name="label_4" >
|
<widget class="QLabel" name="label_4" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>Tags to append:</string>
|
<string><b>Tags to append</b>:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -178,8 +144,6 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>type</tabstop>
|
|
||||||
<tabstop>file</tabstop>
|
|
||||||
<tabstop>tagDuplicates</tabstop>
|
<tabstop>tagDuplicates</tabstop>
|
||||||
<tabstop>importButton</tabstop>
|
<tabstop>importButton</tabstop>
|
||||||
<tabstop>status</tabstop>
|
<tabstop>status</tabstop>
|
||||||
|
|
Loading…
Reference in a new issue