mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
fix bugs in hide/delete in the deck browser; use sel/allCounts()
This commit is contained in:
parent
d0b92313e8
commit
04040e60f2
2 changed files with 23 additions and 33 deletions
|
@ -2,7 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# 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 time, os, stat, shutil
|
import time, os, stat, shutil, re
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
|
@ -112,7 +112,7 @@ class DeckBrowser(object):
|
||||||
self._loadDeck(d)
|
self._loadDeck(d)
|
||||||
|
|
||||||
def _loadDeck(self, rec):
|
def _loadDeck(self, rec):
|
||||||
if 'path' in rec:
|
if rec['state'] == 'ok':
|
||||||
self.mw.loadDeck(rec['path'])
|
self.mw.loadDeck(rec['path'])
|
||||||
|
|
||||||
# HTML generation
|
# HTML generation
|
||||||
|
@ -254,18 +254,22 @@ a { font-size: 80%; }
|
||||||
m.exec_(QCursor.pos())
|
m.exec_(QCursor.pos())
|
||||||
|
|
||||||
def _hideRow(self, c):
|
def _hideRow(self, c):
|
||||||
if aqt.utils.askUser(_("""\
|
d = self._decks[c]
|
||||||
|
if d['state'] == "missing" or aqt.utils.askUser(_("""\
|
||||||
Hide %s from the list? You can File>Open it again later.""") %
|
Hide %s from the list? You can File>Open it again later.""") %
|
||||||
self._decks[c]['name']):
|
d['name']):
|
||||||
self.mw.config.delRecentDeck(self._decks[c]['path'])
|
self.mw.config.delRecentDeck(d['path'])
|
||||||
del self._decks[c]
|
del self._decks[c]
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def _deleteRow(self, c):
|
def _deleteRow(self, c):
|
||||||
|
d = self._decks[c]
|
||||||
|
if d['state'] == 'missing':
|
||||||
|
return self._hideRow(c)
|
||||||
if aqt.utils.askUser(_("""\
|
if aqt.utils.askUser(_("""\
|
||||||
Delete %s? If this deck is synchronized the online version will \
|
Delete %s? If this deck is synchronized the online version will \
|
||||||
not be touched.""") % self._decks[c]['name']):
|
not be touched.""") % d['name']):
|
||||||
deck = self._decks[c]['path']
|
deck = d['path']
|
||||||
os.unlink(deck)
|
os.unlink(deck)
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(re.sub(".anki$", ".media", deck))
|
shutil.rmtree(re.sub(".anki$", ".media", deck))
|
||||||
|
@ -277,12 +281,11 @@ not be touched.""") % self._decks[c]['name']):
|
||||||
# Data gathering
|
# Data gathering
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def _checkDecks(self, forget=False):
|
def _checkDecks(self):
|
||||||
self._decks = []
|
self._decks = []
|
||||||
decks = self.mw.config.recentDecks()
|
decks = self.mw.config.recentDecks()
|
||||||
if not decks:
|
if not decks:
|
||||||
return
|
return
|
||||||
missingDecks = []
|
|
||||||
tx = time.time()
|
tx = time.time()
|
||||||
self.mw.progress.start(max=len(decks))
|
self.mw.progress.start(max=len(decks))
|
||||||
for c, d in enumerate(decks):
|
for c, d in enumerate(decks):
|
||||||
|
@ -290,14 +293,13 @@ not be touched.""") % self._decks[c]['name']):
|
||||||
'x': c+1, 'y': len(decks)})
|
'x': c+1, 'y': len(decks)})
|
||||||
base = os.path.basename(d)
|
base = os.path.basename(d)
|
||||||
if not os.path.exists(d):
|
if not os.path.exists(d):
|
||||||
missingDecks.append(d)
|
self._decks.append({'name': base, 'state': 'missing', 'path':d})
|
||||||
self._decks.append({'name': base, 'state': 'missing'})
|
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
mod = os.stat(d)[stat.ST_MTIME]
|
mod = os.stat(d)[stat.ST_MTIME]
|
||||||
t = time.time()
|
t = time.time()
|
||||||
deck = Deck(d, lock=False)
|
deck = Deck(d, queue=False, lock=False)
|
||||||
counts = deck.sched.counts()
|
counts = deck.sched.selCounts()
|
||||||
dtime = deck.sched.timeToday()
|
dtime = deck.sched.timeToday()
|
||||||
dreps = deck.sched.repsToday()
|
dreps = deck.sched.repsToday()
|
||||||
self._decks.append({
|
self._decks.append({
|
||||||
|
@ -323,10 +325,7 @@ not be touched.""") % self._decks[c]['name']):
|
||||||
state = "in use"
|
state = "in use"
|
||||||
else:
|
else:
|
||||||
state = "corrupt"
|
state = "corrupt"
|
||||||
self._decks.append({'name': base, 'state':state})
|
self._decks.append({'name': base, 'state':state, 'path':d})
|
||||||
if forget:
|
|
||||||
for d in missingDecks:
|
|
||||||
self.mw.config.delRecentDeck(d)
|
|
||||||
self.mw.progress.finish()
|
self.mw.progress.finish()
|
||||||
self._browserLastRefreshed = time.time()
|
self._browserLastRefreshed = time.time()
|
||||||
self._reorderDecks()
|
self._reorderDecks()
|
||||||
|
|
|
@ -70,11 +70,13 @@ $(function () {
|
||||||
|
|
||||||
def _overview(self):
|
def _overview(self):
|
||||||
css = self.mw._sharedCSS + self._overviewCSS
|
css = self.mw._sharedCSS + self._overviewCSS
|
||||||
|
fc = self._ovForecast()
|
||||||
|
tbl = self._overviewTable()
|
||||||
self.web.stdHtml(self._overviewBody % dict(
|
self.web.stdHtml(self._overviewBody % dict(
|
||||||
title=_("Overview"),
|
title=_("Overview"),
|
||||||
table=self._overviewTable(),
|
table=tbl,
|
||||||
fcsub=_("Due over next two weeks"),
|
fcsub=_("Due over next two weeks"),
|
||||||
fcdata=self._ovForecast(),
|
fcdata=fc,
|
||||||
opts=self._ovOpts(),
|
opts=self._ovOpts(),
|
||||||
), css)
|
), css)
|
||||||
|
|
||||||
|
@ -103,20 +105,9 @@ $(function () {
|
||||||
def _ovCounts(self):
|
def _ovCounts(self):
|
||||||
oldNew = self.mw.deck.qconf['newGroups']
|
oldNew = self.mw.deck.qconf['newGroups']
|
||||||
oldRev = self.mw.deck.qconf['revGroups']
|
oldRev = self.mw.deck.qconf['revGroups']
|
||||||
if not oldNew and not oldRev:
|
# we have the limited count already
|
||||||
# everything is enabled, no extra work to work to do
|
selcnt = self.mw.deck.sched.selCounts()
|
||||||
self.mw.deck.reset()
|
allcnt = self.mw.deck.sched.allCounts()
|
||||||
allcnt = self.mw.deck.sched.counts()
|
|
||||||
else:
|
|
||||||
# need to reset to find all cards
|
|
||||||
self.mw.deck.qconf['newGroups'] = []
|
|
||||||
self.mw.deck.qconf['revGroups'] = []
|
|
||||||
self.mw.deck.reset()
|
|
||||||
allcnt = self.mw.deck.sched.counts()
|
|
||||||
self.mw.deck.qconf['newGroups'] = oldNew
|
|
||||||
self.mw.deck.qconf['revGroups'] = oldRev
|
|
||||||
self.mw.deck.reset()
|
|
||||||
selcnt = self.mw.deck.sched.counts()
|
|
||||||
return [
|
return [
|
||||||
selcnt[1] + selcnt[2],
|
selcnt[1] + selcnt[2],
|
||||||
selcnt[0],
|
selcnt[0],
|
||||||
|
|
Loading…
Reference in a new issue