browser now works
This commit is contained in:
parent
21a99a0dd5
commit
863e36d4a7
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
import anki.hooks
|
import anki
|
||||||
|
|
||||||
|
|
||||||
class Anki:
|
class Anki:
|
||||||
@ -28,6 +28,7 @@ class Anki:
|
|||||||
collection.addNote(note)
|
collection.addNote(note)
|
||||||
collection.autosave()
|
collection.autosave()
|
||||||
self.startEditing()
|
self.startEditing()
|
||||||
|
return note.id
|
||||||
|
|
||||||
|
|
||||||
def canAddNote(self, deckName, modelName, fields):
|
def canAddNote(self, deckName, modelName, fields):
|
||||||
@ -50,14 +51,14 @@ class Anki:
|
|||||||
for name, value in fields.items():
|
for name, value in fields.items():
|
||||||
note[name] = value
|
note[name] = value
|
||||||
|
|
||||||
return None if note.dupeOrEmpty() else note
|
if not note.dupeOrEmpty():
|
||||||
|
return note
|
||||||
|
|
||||||
|
|
||||||
def browseNote(self, noteId):
|
def browseNote(self, noteId):
|
||||||
browser = ui.dialogs.get('CardList', self.window())
|
browser = aqt.dialogs.open('Browser', self.window())
|
||||||
browser.dialog.filterEdit.setText('fid:' + str(noteId))
|
browser.form.searchEdit.lineEdit().setText('nid:{0}'.format(noteId))
|
||||||
browser.updateSearch()
|
browser.onSearch()
|
||||||
browser.onnote()
|
|
||||||
|
|
||||||
|
|
||||||
def startEditing(self):
|
def startEditing(self):
|
||||||
@ -90,7 +91,8 @@ class Anki:
|
|||||||
|
|
||||||
def modelFieldNames(self, modelName):
|
def modelFieldNames(self, modelName):
|
||||||
model = self.models().byName(modelName)
|
model = self.models().byName(modelName)
|
||||||
return None if model is None else [field['name'] for field in model['flds']]
|
if model is not None:
|
||||||
|
return [field['name'] for field in model['flds']]
|
||||||
|
|
||||||
|
|
||||||
def decks(self):
|
def decks(self):
|
||||||
|
@ -259,7 +259,6 @@ class MainWindowReader(QtGui.QMainWindow):
|
|||||||
definition.sentence
|
definition.sentence
|
||||||
)
|
)
|
||||||
self.ankiAddFact(markup)
|
self.ankiAddFact(markup)
|
||||||
self.updateDefinitions()
|
|
||||||
if command == 'addFactReading':
|
if command == 'addFactReading':
|
||||||
markup = reader_util.buildFactMarkupReading(
|
markup = reader_util.buildFactMarkupReading(
|
||||||
definition.reading,
|
definition.reading,
|
||||||
@ -267,7 +266,6 @@ class MainWindowReader(QtGui.QMainWindow):
|
|||||||
definition.sentence
|
definition.sentence
|
||||||
)
|
)
|
||||||
self.ankiAddFact(markup)
|
self.ankiAddFact(markup)
|
||||||
self.updateDefinitions()
|
|
||||||
elif command == 'copyDefinition':
|
elif command == 'copyDefinition':
|
||||||
reader_util.copyDefinitions([definition])
|
reader_util.copyDefinitions([definition])
|
||||||
|
|
||||||
@ -295,7 +293,7 @@ class MainWindowReader(QtGui.QMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
def onUpdaterSearchResult(self, result):
|
def onUpdaterSearchResult(self, result):
|
||||||
if result and result > constants['version']:
|
if result is not None and result > constants['version']:
|
||||||
QtGui.QMessageBox.information(
|
QtGui.QMessageBox.information(
|
||||||
self,
|
self,
|
||||||
'Yomichan',
|
'Yomichan',
|
||||||
@ -358,21 +356,18 @@ class MainWindowReader(QtGui.QMainWindow):
|
|||||||
|
|
||||||
self.updateArchiveFiles(filename, names)
|
self.updateArchiveFiles(filename, names)
|
||||||
|
|
||||||
if len(files) == 0:
|
|
||||||
content = unicode()
|
content = unicode()
|
||||||
elif len(files) == 1:
|
if len(files) == 1:
|
||||||
fp = tp.extractfile(files[0])
|
fp = tp.extractfile(files[0])
|
||||||
content = fp.read()
|
content = fp.read()
|
||||||
fp.close()
|
fp.close()
|
||||||
else:
|
elif len(files) > 1:
|
||||||
index, ok = self.selectFileName(names)
|
index, ok = self.selectFileName(names)
|
||||||
if ok:
|
if ok:
|
||||||
fp = tp.extractfile(files[index])
|
fp = tp.extractfile(files[index])
|
||||||
content = fp.read()
|
content = fp.read()
|
||||||
fp.close()
|
fp.close()
|
||||||
self.state.archiveIndex = index
|
self.state.archiveIndex = index
|
||||||
else:
|
|
||||||
content = unicode()
|
|
||||||
else:
|
else:
|
||||||
self.state.archiveIndex = None
|
self.state.archiveIndex = None
|
||||||
with open(filename, 'rb') as fp:
|
with open(filename, 'rb') as fp:
|
||||||
@ -383,7 +378,7 @@ class MainWindowReader(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def selectFileName(self, names):
|
def selectFileName(self, names):
|
||||||
if self.state.archiveIndex is not None:
|
if self.state.archiveIndex is not None:
|
||||||
return (self.state.archiveIndex, True)
|
return self.state.archiveIndex, True
|
||||||
|
|
||||||
item, ok = QtGui.QInputDialog.getItem(
|
item, ok = QtGui.QInputDialog.getItem(
|
||||||
self,
|
self,
|
||||||
|
Loading…
Reference in New Issue
Block a user