mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -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()
|
self.widget.show()
|
||||||
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
self.currentKey = None
|
|
||||||
self.helpFrame.hide()
|
self.helpFrame.hide()
|
||||||
self.widget.hide()
|
self.widget.hide()
|
||||||
if self.mainWindow:
|
if self.mainWindow:
|
||||||
self.mainWindow.runHook("helpChanged")
|
self.mainWindow.runHook("helpChanged")
|
||||||
|
|
||||||
def showKey(self, key, noFlush=False, dict=False):
|
def showText(self, text, py={}):
|
||||||
"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"):
|
|
||||||
self.show()
|
self.show()
|
||||||
self.buffer = text
|
self.buffer = text
|
||||||
self.addHider()
|
self.addHider()
|
||||||
self.handlers = py
|
self.handlers = py
|
||||||
if not noFlush:
|
self.flush()
|
||||||
self.flush()
|
|
||||||
self.currentKey = key
|
|
||||||
if self.mainWindow:
|
if self.mainWindow:
|
||||||
self.mainWindow.runHook("helpChanged")
|
self.mainWindow.runHook("helpChanged")
|
||||||
|
|
||||||
|
@ -79,11 +55,6 @@ class HelpArea(object):
|
||||||
self.widget.setHtml(style + '<div id="content">' +
|
self.widget.setHtml(style + '<div id="content">' +
|
||||||
self.buffer + '</div>')
|
self.buffer + '</div>')
|
||||||
|
|
||||||
def addRemover(self, key):
|
|
||||||
self.buffer += (" / <a href=hide:%s>" +
|
|
||||||
_("Don't show this again.")
|
|
||||||
+ "</a>") % key
|
|
||||||
|
|
||||||
def addHider(self):
|
def addHider(self):
|
||||||
self.buffer += _("<p><a href=hide:>Hide this</a>")
|
self.buffer += _("<p><a href=hide:>Hide this</a>")
|
||||||
|
|
||||||
|
@ -96,6 +67,8 @@ class HelpArea(object):
|
||||||
# hide for good
|
# hide for good
|
||||||
self.config[addr] = True
|
self.config[addr] = True
|
||||||
self.hide()
|
self.hide()
|
||||||
|
if "hide" in self.handlers:
|
||||||
|
self.handlers["hide"]()
|
||||||
elif addr.startswith("py:"):
|
elif addr.startswith("py:"):
|
||||||
key = addr[3:]
|
key = addr[3:]
|
||||||
if key in self.handlers:
|
if key in self.handlers:
|
||||||
|
|
|
@ -132,7 +132,12 @@ class AnkiQt(QMainWindow):
|
||||||
self.lastState = getattr(self, "state", None)
|
self.lastState = getattr(self, "state", None)
|
||||||
self.state = state
|
self.state = state
|
||||||
self.updateTitleBar()
|
self.updateTitleBar()
|
||||||
|
if 'state' != 'noDeck':
|
||||||
|
self.mainWin.welcomeText.hide()
|
||||||
|
self.mainWin.mainText.show()
|
||||||
if state == "noDeck":
|
if state == "noDeck":
|
||||||
|
self.mainWin.welcomeText.show()
|
||||||
|
self.mainWin.mainText.hide()
|
||||||
self.help.hide()
|
self.help.hide()
|
||||||
self.currentCard = None
|
self.currentCard = None
|
||||||
self.lastCard = None
|
self.lastCard = None
|
||||||
|
@ -753,13 +758,13 @@ class AnkiQt(QMainWindow):
|
||||||
self.anchorPrefixes = {
|
self.anchorPrefixes = {
|
||||||
'welcome': self.onWelcomeAnchor,
|
'welcome': self.onWelcomeAnchor,
|
||||||
}
|
}
|
||||||
self.connect(self.mainWin.mainText,
|
self.connect(self.mainWin.welcomeText,
|
||||||
SIGNAL("anchorClicked(QUrl)"),
|
SIGNAL("anchorClicked(QUrl)"),
|
||||||
self.anchorClicked)
|
self.anchorClicked)
|
||||||
|
|
||||||
def anchorClicked(self, url):
|
def anchorClicked(self, url):
|
||||||
# prevent the link being handled
|
# prevent the link being handled
|
||||||
self.mainWin.mainText.setSource(QUrl(""))
|
self.mainWin.welcomeText.setSource(QUrl(""))
|
||||||
addr = unicode(url.toString())
|
addr = unicode(url.toString())
|
||||||
fields = addr.split(":")
|
fields = addr.split(":")
|
||||||
if len(fields) > 1 and fields[0] in self.anchorPrefixes:
|
if len(fields) > 1 and fields[0] in self.anchorPrefixes:
|
||||||
|
@ -843,7 +848,6 @@ class AnkiQt(QMainWindow):
|
||||||
|
|
||||||
def onCardStats(self):
|
def onCardStats(self):
|
||||||
self.addHook("showQuestion", self.onCardStats)
|
self.addHook("showQuestion", self.onCardStats)
|
||||||
self.addHook("helpChanged", self.removeCardStatsHook)
|
|
||||||
txt = ""
|
txt = ""
|
||||||
if self.currentCard:
|
if self.currentCard:
|
||||||
txt += _("<h1>Current card</h1>")
|
txt += _("<h1>Current card</h1>")
|
||||||
|
@ -853,12 +857,12 @@ class AnkiQt(QMainWindow):
|
||||||
txt += anki.stats.CardStats(self.deck, self.lastCard).report()
|
txt += anki.stats.CardStats(self.deck, self.lastCard).report()
|
||||||
if not txt:
|
if not txt:
|
||||||
txt = _("No current card or last card.")
|
txt = _("No current card or last card.")
|
||||||
self.help.showText(txt, key="cardStats")
|
self.help.showText(txt, py={'hide': self.removeCardStatsHook})
|
||||||
|
|
||||||
def removeCardStatsHook(self):
|
def removeCardStatsHook(self):
|
||||||
"Remove the update hook if the help menu was changed."
|
"Remove the update hook if the help menu was changed."
|
||||||
if self.help.currentKey != "cardStats":
|
print "rem"
|
||||||
self.removeHook("showQuestion", self.onCardStats)
|
self.removeHook("showQuestion", self.onCardStats)
|
||||||
|
|
||||||
def onShowGraph(self):
|
def onShowGraph(self):
|
||||||
self.setStatus(_("Loading graphs (may take time).."))
|
self.setStatus(_("Loading graphs (may take time).."))
|
||||||
|
@ -1078,8 +1082,7 @@ class AnkiQt(QMainWindow):
|
||||||
# bug triggered by preferences dialog - underlying c++ widgets are not
|
# bug triggered by preferences dialog - underlying c++ widgets are not
|
||||||
# garbage collected until the middle of the child thread
|
# garbage collected until the middle of the child thread
|
||||||
import gc; gc.collect()
|
import gc; gc.collect()
|
||||||
self.bodyView.clearWindow()
|
self.mainWin.welcomeText.setText(u"")
|
||||||
self.bodyView.flush()
|
|
||||||
self.syncThread = ui.sync.Sync(self, u, p, interactive, create,
|
self.syncThread = ui.sync.Sync(self, u, p, interactive, create,
|
||||||
onlyMerge, self.sourcesToCheck)
|
onlyMerge, self.sourcesToCheck)
|
||||||
self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus)
|
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("closeSyncProgress"), self.closeSyncProgress)
|
||||||
self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress)
|
self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress)
|
||||||
self.syncThread.start()
|
self.syncThread.start()
|
||||||
|
self.mainWin.buttonWidget.hide()
|
||||||
|
self.mainWin.mainText.hide()
|
||||||
|
self.mainWin.welcomeText.show()
|
||||||
self.setEnabled(False)
|
self.setEnabled(False)
|
||||||
while not self.syncThread.isFinished():
|
while not self.syncThread.isFinished():
|
||||||
self.app.processEvents()
|
self.app.processEvents()
|
||||||
|
@ -1102,6 +1108,7 @@ class AnkiQt(QMainWindow):
|
||||||
|
|
||||||
def syncFinished(self):
|
def syncFinished(self):
|
||||||
"Reopen after sync finished."
|
"Reopen after sync finished."
|
||||||
|
self.mainWin.buttonWidget.show()
|
||||||
if self.loadAfterSync:
|
if self.loadAfterSync:
|
||||||
self.loadDeck(self.deckPath, sync=False)
|
self.loadDeck(self.deckPath, sync=False)
|
||||||
self.deck.syncName = self.syncName
|
self.deck.syncName = self.syncName
|
||||||
|
@ -1133,7 +1140,7 @@ class AnkiQt(QMainWindow):
|
||||||
|
|
||||||
def setSyncStatus(self, text, *args):
|
def setSyncStatus(self, text, *args):
|
||||||
self.setStatus(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):
|
def syncClockOff(self, diff):
|
||||||
ui.utils.showWarning(
|
ui.utils.showWarning(
|
||||||
|
|
|
@ -30,9 +30,6 @@ class View(object):
|
||||||
self.oldState = getattr(self, 'state', None)
|
self.oldState = getattr(self, 'state', None)
|
||||||
self.state = state
|
self.state = state
|
||||||
if self.state == "initial":
|
if self.state == "initial":
|
||||||
self.shownLearnHelp = False
|
|
||||||
self.shownReviewHelp = False
|
|
||||||
self.shownFinalHelp = False
|
|
||||||
return
|
return
|
||||||
elif self.state == "noDeck":
|
elif self.state == "noDeck":
|
||||||
self.clearWindow()
|
self.clearWindow()
|
||||||
|
@ -47,7 +44,6 @@ class View(object):
|
||||||
return
|
return
|
||||||
self.clearWindow()
|
self.clearWindow()
|
||||||
self.setBackgroundColour()
|
self.setBackgroundColour()
|
||||||
self.maybeHelp()
|
|
||||||
if not self.main.deck.isEmpty():
|
if not self.main.deck.isEmpty():
|
||||||
if not self.main.lastCard or (
|
if not self.main.lastCard or (
|
||||||
not self.main.config['showLastCardContent'] and
|
not self.main.config['showLastCardContent'] and
|
||||||
|
@ -165,34 +161,11 @@ class View(object):
|
||||||
self.write(msg)
|
self.write(msg)
|
||||||
self.write("<br>")
|
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
|
# Welcome/empty/finished deck messages
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def drawWelcomeMessage(self):
|
def drawWelcomeMessage(self):
|
||||||
self.write(_("""
|
self.main.mainWin.welcomeText.setText(_("""
|
||||||
<h1>Welcome to Anki!</h1>
|
<h1>Welcome to Anki!</h1>
|
||||||
<p>
|
<p>
|
||||||
<table>
|
<table>
|
||||||
|
|
|
@ -129,6 +129,16 @@
|
||||||
<property name="margin" >
|
<property name="margin" >
|
||||||
<number>5</number>
|
<number>5</number>
|
||||||
</property>
|
</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>
|
<item>
|
||||||
<widget class="QWebView" name="mainText" >
|
<widget class="QWebView" name="mainText" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
|
@ -137,6 +147,9 @@
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="focusPolicy" >
|
||||||
|
<enum>Qt::WheelFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="url" >
|
<property name="url" >
|
||||||
<url>
|
<url>
|
||||||
<string>about:blank</string>
|
<string>about:blank</string>
|
||||||
|
|
Loading…
Reference in a new issue