mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
refactor help.py, use welcome widget and main widget
This commit is contained in:
parent
2a29a76e69
commit
e1f1812a9e
4 changed files with 34 additions and 68 deletions
|
@ -30,41 +30,17 @@ class HelpArea(object):
|
|||
self.widget.show()
|
||||
|
||||
def hide(self):
|
||||
self.currentKey = None
|
||||
self.helpFrame.hide()
|
||||
self.widget.hide()
|
||||
if self.mainWindow:
|
||||
self.mainWindow.runHook("helpChanged")
|
||||
|
||||
def showKey(self, key, noFlush=False, dict=False):
|
||||
"Look up KEY in DATA and show."
|
||||
text = self.data[key]
|
||||
# accomodate some quirks in QTextEdit's html interpreter
|
||||
text = text.strip()
|
||||
if dict:
|
||||
text = text % dict
|
||||
self.showText(text, noFlush, key=key)
|
||||
|
||||
def showHideableKey(self, key, dict=False):
|
||||
"Look up a hideable KEY in DATA and show."
|
||||
if self.config.get("hide:" + key, False):
|
||||
# user requested not to see this key. if previous key was help, we
|
||||
# need to hide it
|
||||
if self.currentKey in self.data:
|
||||
self.hide()
|
||||
return
|
||||
self.showKey(key, noFlush=True, dict=dict)
|
||||
self.addRemover(key)
|
||||
self.flush()
|
||||
|
||||
def showText(self, text, noFlush=False, py={}, key="misc"):
|
||||
def showText(self, text, py={}):
|
||||
self.show()
|
||||
self.buffer = text
|
||||
self.addHider()
|
||||
self.handlers = py
|
||||
if not noFlush:
|
||||
self.flush()
|
||||
self.currentKey = key
|
||||
if self.mainWindow:
|
||||
self.mainWindow.runHook("helpChanged")
|
||||
|
||||
|
@ -79,11 +55,6 @@ class HelpArea(object):
|
|||
self.widget.setHtml(style + '<div id="content">' +
|
||||
self.buffer + '</div>')
|
||||
|
||||
def addRemover(self, key):
|
||||
self.buffer += (" / <a href=hide:%s>" +
|
||||
_("Don't show this again.")
|
||||
+ "</a>") % key
|
||||
|
||||
def addHider(self):
|
||||
self.buffer += _("<p><a href=hide:>Hide this</a>")
|
||||
|
||||
|
@ -96,6 +67,8 @@ class HelpArea(object):
|
|||
# hide for good
|
||||
self.config[addr] = True
|
||||
self.hide()
|
||||
if "hide" in self.handlers:
|
||||
self.handlers["hide"]()
|
||||
elif addr.startswith("py:"):
|
||||
key = addr[3:]
|
||||
if key in self.handlers:
|
||||
|
|
|
@ -132,7 +132,12 @@ class AnkiQt(QMainWindow):
|
|||
self.lastState = getattr(self, "state", None)
|
||||
self.state = state
|
||||
self.updateTitleBar()
|
||||
if 'state' != 'noDeck':
|
||||
self.mainWin.welcomeText.hide()
|
||||
self.mainWin.mainText.show()
|
||||
if state == "noDeck":
|
||||
self.mainWin.welcomeText.show()
|
||||
self.mainWin.mainText.hide()
|
||||
self.help.hide()
|
||||
self.currentCard = None
|
||||
self.lastCard = None
|
||||
|
@ -753,13 +758,13 @@ class AnkiQt(QMainWindow):
|
|||
self.anchorPrefixes = {
|
||||
'welcome': self.onWelcomeAnchor,
|
||||
}
|
||||
self.connect(self.mainWin.mainText,
|
||||
self.connect(self.mainWin.welcomeText,
|
||||
SIGNAL("anchorClicked(QUrl)"),
|
||||
self.anchorClicked)
|
||||
|
||||
def anchorClicked(self, url):
|
||||
# prevent the link being handled
|
||||
self.mainWin.mainText.setSource(QUrl(""))
|
||||
self.mainWin.welcomeText.setSource(QUrl(""))
|
||||
addr = unicode(url.toString())
|
||||
fields = addr.split(":")
|
||||
if len(fields) > 1 and fields[0] in self.anchorPrefixes:
|
||||
|
@ -843,7 +848,6 @@ class AnkiQt(QMainWindow):
|
|||
|
||||
def onCardStats(self):
|
||||
self.addHook("showQuestion", self.onCardStats)
|
||||
self.addHook("helpChanged", self.removeCardStatsHook)
|
||||
txt = ""
|
||||
if self.currentCard:
|
||||
txt += _("<h1>Current card</h1>")
|
||||
|
@ -853,11 +857,11 @@ class AnkiQt(QMainWindow):
|
|||
txt += anki.stats.CardStats(self.deck, self.lastCard).report()
|
||||
if not txt:
|
||||
txt = _("No current card or last card.")
|
||||
self.help.showText(txt, key="cardStats")
|
||||
self.help.showText(txt, py={'hide': self.removeCardStatsHook})
|
||||
|
||||
def removeCardStatsHook(self):
|
||||
"Remove the update hook if the help menu was changed."
|
||||
if self.help.currentKey != "cardStats":
|
||||
print "rem"
|
||||
self.removeHook("showQuestion", self.onCardStats)
|
||||
|
||||
def onShowGraph(self):
|
||||
|
@ -1078,8 +1082,7 @@ class AnkiQt(QMainWindow):
|
|||
# bug triggered by preferences dialog - underlying c++ widgets are not
|
||||
# garbage collected until the middle of the child thread
|
||||
import gc; gc.collect()
|
||||
self.bodyView.clearWindow()
|
||||
self.bodyView.flush()
|
||||
self.mainWin.welcomeText.setText(u"")
|
||||
self.syncThread = ui.sync.Sync(self, u, p, interactive, create,
|
||||
onlyMerge, self.sourcesToCheck)
|
||||
self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus)
|
||||
|
@ -1093,6 +1096,9 @@ class AnkiQt(QMainWindow):
|
|||
self.connect(self.syncThread, SIGNAL("closeSyncProgress"), self.closeSyncProgress)
|
||||
self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress)
|
||||
self.syncThread.start()
|
||||
self.mainWin.buttonWidget.hide()
|
||||
self.mainWin.mainText.hide()
|
||||
self.mainWin.welcomeText.show()
|
||||
self.setEnabled(False)
|
||||
while not self.syncThread.isFinished():
|
||||
self.app.processEvents()
|
||||
|
@ -1102,6 +1108,7 @@ class AnkiQt(QMainWindow):
|
|||
|
||||
def syncFinished(self):
|
||||
"Reopen after sync finished."
|
||||
self.mainWin.buttonWidget.show()
|
||||
if self.loadAfterSync:
|
||||
self.loadDeck(self.deckPath, sync=False)
|
||||
self.deck.syncName = self.syncName
|
||||
|
@ -1133,7 +1140,7 @@ class AnkiQt(QMainWindow):
|
|||
|
||||
def setSyncStatus(self, text, *args):
|
||||
self.setStatus(text, *args)
|
||||
self.mainWin.mainText.append("<font size=+6>" + text + "</font>")
|
||||
self.mainWin.welcomeText.append("<font size=+6>" + text + "</font>")
|
||||
|
||||
def syncClockOff(self, diff):
|
||||
ui.utils.showWarning(
|
||||
|
|
|
@ -30,9 +30,6 @@ class View(object):
|
|||
self.oldState = getattr(self, 'state', None)
|
||||
self.state = state
|
||||
if self.state == "initial":
|
||||
self.shownLearnHelp = False
|
||||
self.shownReviewHelp = False
|
||||
self.shownFinalHelp = False
|
||||
return
|
||||
elif self.state == "noDeck":
|
||||
self.clearWindow()
|
||||
|
@ -47,7 +44,6 @@ class View(object):
|
|||
return
|
||||
self.clearWindow()
|
||||
self.setBackgroundColour()
|
||||
self.maybeHelp()
|
||||
if not self.main.deck.isEmpty():
|
||||
if not self.main.lastCard or (
|
||||
not self.main.config['showLastCardContent'] and
|
||||
|
@ -165,34 +161,11 @@ class View(object):
|
|||
self.write(msg)
|
||||
self.write("<br>")
|
||||
|
||||
# Help
|
||||
##########################################################################
|
||||
|
||||
def maybeHelp(self):
|
||||
return
|
||||
stats = self.main.deck.sched.getStats()
|
||||
if not stats['pending']:
|
||||
self.main.help.hide()
|
||||
elif (self.main.currentCard and
|
||||
self.main.currentCard.nextTime > time.time()):
|
||||
if not self.shownFinalHelp:
|
||||
self.shownFinalHelp = True
|
||||
self.main.help.showHideableKey("finalReview")
|
||||
elif stats['learnMode']:
|
||||
if not self.shownLearnHelp:
|
||||
if stats['pending'] != 0:
|
||||
self.shownLearnHelp = True
|
||||
self.main.help.showHideableKey("learn")
|
||||
else:
|
||||
if not self.shownReviewHelp:
|
||||
self.shownReviewHelp = True
|
||||
self.main.help.showHideableKey("review")
|
||||
|
||||
# Welcome/empty/finished deck messages
|
||||
##########################################################################
|
||||
|
||||
def drawWelcomeMessage(self):
|
||||
self.write(_("""
|
||||
self.main.mainWin.welcomeText.setText(_("""
|
||||
<h1>Welcome to Anki!</h1>
|
||||
<p>
|
||||
<table>
|
||||
|
|
|
@ -129,6 +129,16 @@
|
|||
<property name="margin" >
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="welcomeText" >
|
||||
<property name="focusPolicy" >
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWebView" name="mainText" >
|
||||
<property name="sizePolicy" >
|
||||
|
@ -137,6 +147,9 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy" >
|
||||
<enum>Qt::WheelFocus</enum>
|
||||
</property>
|
||||
<property name="url" >
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
|
|
Loading…
Reference in a new issue