move the button links to actual buttons, fix some bugs

- by using normal buttons we get the native look&feel and space can activate
  the buttons which is what users expect. Unfortunately it seems that the
  buttons are currently hard-coded to a small font size; hopefully this will
  be fixed in a future toolkit release
- remove the space hack from webview
- move the times into the ease buttons
- set a default button on a few screens
- fix a bug with clearing progress after an error
This commit is contained in:
Damien Elmes 2011-03-24 19:47:33 +09:00
parent b699226cfd
commit 8ea949db74
6 changed files with 51 additions and 60 deletions

View file

@ -74,7 +74,8 @@ class DeckBrowser(object):
# ("synced", _("Synced")), # ("synced", _("Synced")),
("refresh", _("Refresh")), ("refresh", _("Refresh")),
] ]
h = "".join(["<a class=but href=%s>%s</a>" % row for row in items]) h = "".join([self.mw.button(
link=row[0], name=row[1]) for row in items])
return h return h
# Event handlers # Event handlers
@ -214,11 +215,9 @@ a { font-size: 80%; }
# no counts # no counts
buf += "<td colspan=2></td>" buf += "<td colspan=2></td>"
# options # options
buf += "<td class=opts><a class=but href='opts:%d'>%s&#9660;</a></td>" % ( buf += "<td class=opts>%s</td>" % (
c, "Options") self.mw.button(link="opts:%d"%c, name=_("Options")+'&#9660'))
buf += "</tr>" buf += "</tr>"
# if c != max:
# buf += "<tr><td colspan=4><hr noshade></td></tr>"
return buf return buf
def _summary(self): def _summary(self):

View file

@ -142,41 +142,25 @@ class AnkiQt(QMainWindow):
sharedCSS = """ sharedCSS = """
body { body {
/*background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#bbb));*/ background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#bbb));
background: #eee; /*background: #eee;*/
margin: 2em; margin: 2em;
} }
a:hover { background-color: #aaa; } a:hover { background-color: #aaa; }
.but {
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6);
-webkit-user-drag: none;
-webkit-user-select: none;
background-color: #ccc;
border-radius: 5px;
border: 1px solid #aaa;
color: #000;
display: inline-block;
font-size: 80%;
margin: 0 5 0 5;
padding: 3;
text-decoration: none;
text-align: center;
}
.but:focus, .but:hover { background-color: #aaa; }
.gbut { background-color: #7c7; }
.gbut:hover, .gbut:focus { background-color: #5a5; }
h1 { margin-bottom: 0.2em; } h1 { margin-bottom: 0.2em; }
hr { margin:5 0 5 0; border:0; height:1px; background-color:#ccc; } hr { margin:5 0 5 0; border:0; height:1px; background-color:#ccc; }
""" """
def button(self, link, name, key=None, class_=""): def button(self, link, name, key=None, class_="", id=""):
class_ = "but "+ class_ class_ = "but "+ class_
if key: if key:
key = _("Shortcut key: %s") % key key = _("Shortcut key: %s") % key
else: else:
key = "" key = ""
return '<a class="%s" title="%s" href="%s">%s</a>' % ( return '''
class_, key, link, name) <button id="%s" class="%s" onclick="py.link('%s');return false;"
title="%s">%s</button>''' % (
id, class_, link, key, name)
# Signal handling # Signal handling
########################################################################## ##########################################################################

View file

@ -31,7 +31,7 @@ class Overview(object):
def _keyHandler(self, evt): def _keyHandler(self, evt):
txt = evt.text() txt = evt.text()
if evt.key() == Qt.Key_Space: if txt == "s":
self._linkHandler("study") self._linkHandler("study")
elif txt == "c": elif txt == "c":
self._linkHandler("cram") self._linkHandler("cram")
@ -88,7 +88,8 @@ class Overview(object):
%(opts)s %(opts)s
</center> </center>
<script id="source" language="javascript" type="text/javascript"> <script>
$("#study").focus();
$(function () { $(function () {
var d = %(fcdata)s; var d = %(fcdata)s;
if (d) { if (d) {
@ -122,7 +123,7 @@ $(function () {
buf += line % ( buf += line % (
"<a href=chgrp>%s</a>" % _("Selected Groups"), "<a href=chgrp>%s</a>" % _("Selected Groups"),
counts[0], counts[1], counts[0], counts[1],
but("study", _("Study"), _("space"), "gbut") + but("study", _("Study"), _("s"), "gbut", id="study") +
but("cram", _("Cram"), "c")) but("cram", _("Cram"), "c"))
buf += line % ( buf += line % (
_("Whole Deck"), _("Whole Deck"),

View file

@ -117,7 +117,7 @@ class ProgressManager(object):
"Restore the interface after an error." "Restore the interface after an error."
if self._levels: if self._levels:
self._levels = 1 self._levels = 1
self.finishProgress() self.finish()
def _maybeShow(self): def _maybeShow(self):
delta = time.time() - self._firstTime delta = time.time() - self._firstTime

View file

@ -78,8 +78,8 @@ class Reviewer(object):
<div id=a></div> <div id=a></div>
<div id=filler></div> <div id=filler></div>
</td></tr></table> </td></tr></table>
<a id=ansbut class="but ansbut" href=ans onclick="showans();"> <a id=ansbut class="ansbut ansbutbig" href=ans onclick="showans();">
<div class=ansbut>%(showans)s</div> <div class=ansbuttxt>%(showans)s</div>
</a> </a>
<div id=easebuts> <div id=easebuts>
</div> </div>
@ -110,6 +110,7 @@ function showans () {
location.hash = "a"; location.hash = "a";
} }
$("#ansbut").hide(); $("#ansbut").hide();
$("#defease").focus();
}; };
$(document).ready(function () { $(document).ready(function () {
$(".ansbut").focus(); $(".ansbut").focus();
@ -183,14 +184,13 @@ $(".ansbut").focus();
else: else:
extra = "" extra = ""
return ''' return '''
<a %s class="but easebut" href=ease%d>%s</a>''' % (extra, i, label) <a %s class="ansbut easebut" href=ease%d>%s</a>''' % (extra, i, label)
for i in range(0, len(labels)): for i in range(0, len(labels)):
times.append(self._buttonTime(i, default-1)) l = labels[i]
buttons.append(but(labels[i], i+1)) l += "<br><small>%s</small>" % self._buttonTime(i, default-1)
buf = ("<table><tr><td align=center>" + buttons.append(but(l, i+1))
"</td><td align=center>".join(times) + "</td></tr>") buf = ("<table><tr><td>" +
buf += ("<tr><td>" + "</td><td>".join(buttons) + "</td></tr></table>")
"</td><td>".join(buttons) + "</td></tr></table>")
return "<center>" + buf + "</center>" return "<center>" + buf + "</center>"
return buf return buf
@ -202,7 +202,6 @@ $(".ansbut").focus();
txt = '<span style="color: #700">%s</span>' % txt txt = '<span style="color: #700">%s</span>' % txt
elif i == green: elif i == green:
txt = '<span style="color: #070">%s</span>' % txt txt = '<span style="color: #070">%s</span>' % txt
txt = '<span class=time>%s</span>' % txt
return txt return txt
# Answering a card # Answering a card
@ -261,19 +260,34 @@ $(".ansbut").focus();
########################################################################## ##########################################################################
_css = """ _css = """
a.ansbut { .ansbut {
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6);
-webkit-user-drag: none;
-webkit-user-select: none;
background-color: #ddd;
border-radius: 5px;
border: 1px solid #aaa;
color: #000;
display: inline-block;
font-size: 80%;
margin: 0 5 0 5;
padding: 3;
text-decoration: none;
text-align: center;
}
.but:focus, .but:hover { background-color: #aaa; }
.ansbutbig {
bottom: 1em; bottom: 1em;
height: 40px; height: 40px;
left: 50%; left: 50%;
margin-left: -125px; margin-left: -125px !important;
position: fixed; position: fixed;
width: 250px; width: 250px;
font-size: 100%; font-size: 100%;
} }
a.ansbut:focus { .ansbut:focus {
background: #c7c7c7;
} }
div.ansbut { div.ansbuttxt {
position: relative; top: 25%; position: relative; top: 25%;
} }
@ -283,7 +297,7 @@ margin: 0px;
#easebuts { #easebuts {
bottom: 1em; bottom: 1em;
height: 55px; height: 47px;
left: 50%; left: 50%;
margin-left: -200px; margin-left: -200px;
position: fixed; position: fixed;
@ -446,12 +460,12 @@ div#filler {
<center> <center>
%s %s
<p> <p>
<a class=but id=ov href=ov>%s</a> %s %s
<a class=but href=dlist>%s</a>
<script>$("#ov").focus();</script> <script>$("#ov").focus();</script>
</center>""" % (self.mw.deck.sched.finishedMsg(), </center>""" % (self.mw.deck.sched.finishedMsg(),
_("Overview"), self.mw.button(key="o", name=_("Overview"), link="ov", id='ov'),
_("Deck List")) self.mw.button(key="o", name=_("Deck List"), link="dlist"))
self.web.stdHtml(buf, css=self.mw.sharedCSS) self.web.stdHtml(buf, css=self.mw.sharedCSS)
runHook('deckFinished') runHook('deckFinished')

View file

@ -84,13 +84,6 @@ class AnkiWebView(QWebView):
<html><head><style>%s</style> <html><head><style>%s</style>
<script src="qrc:/jquery.min.js"></script> <script src="qrc:/jquery.min.js"></script>
<script src="qrc:/jquery.flot.min.js"></script> <script src="qrc:/jquery.flot.min.js"></script>
<script>
$(document).keydown(function(e) {
if(e.which==32 && document.activeElement.nodeName == "A") {
py.link(document.activeElement.href);
}
});
</script>
</head> </head>
<body class="%s">%s</body></html>""" % (css, bodyClass, body), loadCB) <body class="%s">%s</body></html>""" % (css, bodyClass, body), loadCB)
# ensure we're focused # ensure we're focused