mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
add another toolbar at the bottom
This commit is contained in:
parent
bea1e60fc8
commit
b745567bb3
9 changed files with 93 additions and 32 deletions
|
@ -4,11 +4,11 @@
|
||||||
import os, sys
|
import os, sys
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
|
||||||
appName="Anki"
|
|
||||||
appVersion="2.0-alpha2"
|
appVersion="2.0-alpha2"
|
||||||
appWebsite="http://ankisrs.net/"
|
appWebsite="http://ankisrs.net/"
|
||||||
appHelpSite="http://ankisrs.net/docs/dev/"
|
appHelpSite="http://ankisrs.net/docs/dev/"
|
||||||
appDonate="http://ankisrs.net/support/"
|
appDonate="http://ankisrs.net/support/"
|
||||||
|
appShared="http://test.ankiweb.net/shared/decks/"
|
||||||
mw = None # set on init
|
mw = None # set on init
|
||||||
|
|
||||||
moduleDir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
|
moduleDir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
|
||||||
|
|
|
@ -1415,21 +1415,22 @@ Are you sure you want to continue?""")):
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
class BrowserToolbar(Toolbar):
|
class BrowserToolbar(Toolbar):
|
||||||
always = [
|
|
||||||
["setDeck", "Move to Deck"],
|
|
||||||
["addTags", "Add Tags"],
|
|
||||||
["remTags", "Remove Tags"],
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self, mw, web, browser):
|
def __init__(self, mw, web, browser):
|
||||||
self.browser = browser
|
self.browser = browser
|
||||||
Toolbar.__init__(self, mw, web)
|
Toolbar.__init__(self, mw, web)
|
||||||
|
|
||||||
|
def _centerLinks(self):
|
||||||
|
links = [
|
||||||
|
["setDeck", _("Move to Deck")],
|
||||||
|
["addTags", _("Add Tags")],
|
||||||
|
["remTags", _("Remove Tags")],
|
||||||
|
]
|
||||||
|
return self._linkHTML(links)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
mark = self.browser.isMarked()
|
mark = self.browser.isMarked()
|
||||||
pause = self.browser.isSuspended()
|
pause = self.browser.isSuspended()
|
||||||
links = self.always[:]
|
|
||||||
self.centerLinks = links
|
|
||||||
def borderImg(link, icon, on):
|
def borderImg(link, icon, on):
|
||||||
if on:
|
if on:
|
||||||
fmt = '''\
|
fmt = '''\
|
||||||
|
|
|
@ -3,13 +3,15 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import askUser, getOnlyText
|
from aqt.utils import askUser, getOnlyText, openLink
|
||||||
|
import aqt
|
||||||
|
|
||||||
class DeckBrowser(object):
|
class DeckBrowser(object):
|
||||||
|
|
||||||
def __init__(self, mw):
|
def __init__(self, mw):
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.web = mw.web
|
self.web = mw.web
|
||||||
|
self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb)
|
||||||
|
|
||||||
def show(self, _init=True):
|
def show(self, _init=True):
|
||||||
if _init:
|
if _init:
|
||||||
|
@ -28,18 +30,10 @@ class DeckBrowser(object):
|
||||||
self._selDeck(arg)
|
self._selDeck(arg)
|
||||||
elif cmd == "opts":
|
elif cmd == "opts":
|
||||||
self._showOptions(arg)
|
self._showOptions(arg)
|
||||||
elif cmd == "download":
|
elif cmd == "shared":
|
||||||
self.mw.onGetSharedDeck()
|
self._onShared()
|
||||||
elif cmd == "new":
|
|
||||||
self.mw.onNew()
|
|
||||||
elif cmd == "import":
|
elif cmd == "import":
|
||||||
self.mw.onImport()
|
self.mw.onImport()
|
||||||
elif cmd == "opensel":
|
|
||||||
self.mw.onOpen()
|
|
||||||
elif cmd == "synced":
|
|
||||||
self.mw.onOpenOnline()
|
|
||||||
elif cmd == "refresh":
|
|
||||||
self.refresh()
|
|
||||||
|
|
||||||
def _selDeck(self, did):
|
def _selDeck(self, did):
|
||||||
self.mw.col.decks.select(did)
|
self.mw.col.decks.select(did)
|
||||||
|
@ -74,6 +68,7 @@ body { margin: 1em; }
|
||||||
self.web.stdHtml(self._body%dict(
|
self.web.stdHtml(self._body%dict(
|
||||||
title=_("Decks"),
|
title=_("Decks"),
|
||||||
tree=tree), css=css)
|
tree=tree), css=css)
|
||||||
|
self._drawButtons()
|
||||||
|
|
||||||
def _renderDeckTree(self, nodes, depth=0):
|
def _renderDeckTree(self, nodes, depth=0):
|
||||||
if not nodes:
|
if not nodes:
|
||||||
|
@ -136,3 +131,22 @@ body { margin: 1em; }
|
||||||
Are you sure you wish to delete all of the cards in %s?""")%deck['name']):
|
Are you sure you wish to delete all of the cards in %s?""")%deck['name']):
|
||||||
self.mw.col.decks.rem(did, True)
|
self.mw.col.decks.rem(did, True)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
# Top buttons
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
def _drawButtons(self):
|
||||||
|
links = [
|
||||||
|
["shared", _("Get Shared")],
|
||||||
|
["import", _("Import File")],
|
||||||
|
]
|
||||||
|
buf = ""
|
||||||
|
for b in links:
|
||||||
|
buf += "<button onclick='py.link(\"%s\");'>%s</button>" % tuple(b)
|
||||||
|
self.bottom.draw(buf)
|
||||||
|
self.bottom.web.setFixedHeight(32)
|
||||||
|
self.bottom.web.setLinkHandler(self._linkHandler)
|
||||||
|
|
||||||
|
def _onShared(self):
|
||||||
|
print "fixme: check & warn if schema modified first"
|
||||||
|
openLink(aqt.appShared)
|
||||||
|
|
10
aqt/main.py
10
aqt/main.py
|
@ -326,12 +326,20 @@ title="%s">%s</button>''' % (
|
||||||
self.web.setObjectName("mainText")
|
self.web.setObjectName("mainText")
|
||||||
self.web.setFocusPolicy(Qt.WheelFocus)
|
self.web.setFocusPolicy(Qt.WheelFocus)
|
||||||
self.web.setMinimumWidth(400)
|
self.web.setMinimumWidth(400)
|
||||||
|
# bottom area
|
||||||
|
sweb = self.bottomWeb = aqt.webview.AnkiWebView()
|
||||||
|
#sweb.hide()
|
||||||
|
sweb.setFixedHeight(100)
|
||||||
|
sweb.setObjectName("bottomWeb")
|
||||||
|
sweb.setFocusPolicy(Qt.WheelFocus)
|
||||||
|
sweb.stdHtml("foo")
|
||||||
# add in a layout
|
# add in a layout
|
||||||
self.mainLayout = QVBoxLayout()
|
self.mainLayout = QVBoxLayout()
|
||||||
self.mainLayout.setContentsMargins(0,0,0,0)
|
self.mainLayout.setContentsMargins(0,0,0,0)
|
||||||
self.mainLayout.setSpacing(0)
|
self.mainLayout.setSpacing(0)
|
||||||
self.mainLayout.addWidget(tweb)
|
self.mainLayout.addWidget(tweb)
|
||||||
self.mainLayout.addWidget(self.web)
|
self.mainLayout.addWidget(self.web)
|
||||||
|
self.mainLayout.addWidget(sweb)
|
||||||
self.form.centralwidget.setLayout(self.mainLayout)
|
self.form.centralwidget.setLayout(self.mainLayout)
|
||||||
|
|
||||||
def closeAllWindows(self):
|
def closeAllWindows(self):
|
||||||
|
@ -738,7 +746,7 @@ Please choose a new deck name:"""))
|
||||||
self.enableDeckMenuItems(enabled=False)
|
self.enableDeckMenuItems(enabled=False)
|
||||||
|
|
||||||
def updateTitleBar(self):
|
def updateTitleBar(self):
|
||||||
self.setWindowTitle(aqt.appName)
|
self.setWindowTitle("Anki")
|
||||||
|
|
||||||
# Auto update
|
# Auto update
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -7,6 +7,7 @@ from aqt.qt import *
|
||||||
from anki.consts import NEW_CARDS_RANDOM
|
from anki.consts import NEW_CARDS_RANDOM
|
||||||
from anki.hooks import addHook
|
from anki.hooks import addHook
|
||||||
from aqt.utils import showInfo
|
from aqt.utils import showInfo
|
||||||
|
import aqt
|
||||||
|
|
||||||
class Overview(object):
|
class Overview(object):
|
||||||
"Deck overview."
|
"Deck overview."
|
||||||
|
@ -14,6 +15,7 @@ class Overview(object):
|
||||||
def __init__(self, mw):
|
def __init__(self, mw):
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.web = mw.web
|
self.web = mw.web
|
||||||
|
self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb)
|
||||||
addHook("reset", self.refresh)
|
addHook("reset", self.refresh)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
@ -23,8 +25,9 @@ class Overview(object):
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self._renderPage()
|
self._renderPage()
|
||||||
|
self._renderBottom()
|
||||||
|
|
||||||
# Handlers
|
# Handlers
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
def _keyHandler(self, evt):
|
def _keyHandler(self, evt):
|
||||||
|
@ -127,4 +130,8 @@ h3 { margin-bottom: 0; }
|
||||||
td { font-size: 14px; }
|
td { font-size: 14px; }
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Bottom area
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
def _renderBottom(self):
|
||||||
|
self.bottom.draw("hello")
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Reviewer(object):
|
||||||
self.state = None
|
self.state = None
|
||||||
self.keep = False
|
self.keep = False
|
||||||
self._setupStatus()
|
self._setupStatus()
|
||||||
|
self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb)
|
||||||
addHook("leech", self.onLeech)
|
addHook("leech", self.onLeech)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
|
|
@ -25,22 +25,24 @@ class Toolbar(object):
|
||||||
# Available links
|
# Available links
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
centerLinks = [
|
|
||||||
["decks", "Decks"],
|
|
||||||
["study", "Study"],
|
|
||||||
["add", "Add"],
|
|
||||||
["browse", "Browse"],
|
|
||||||
]
|
|
||||||
|
|
||||||
rightIcons = [
|
rightIcons = [
|
||||||
["stats", "qrc:/icons/view-statistics.png"],
|
["stats", "qrc:/icons/view-statistics.png"],
|
||||||
["sync", "qrc:/icons/view-refresh.png"],
|
["sync", "qrc:/icons/view-refresh.png"],
|
||||||
]
|
]
|
||||||
|
|
||||||
def _centerLinks(self):
|
def _centerLinks(self):
|
||||||
|
links = [
|
||||||
|
["decks", _("Decks")],
|
||||||
|
["study", _("Study")],
|
||||||
|
["add", _("Add")],
|
||||||
|
["browse", _("Browse")],
|
||||||
|
]
|
||||||
|
return self._linkHTML(links)
|
||||||
|
|
||||||
|
def _linkHTML(self, links):
|
||||||
buf = ""
|
buf = ""
|
||||||
for ln, name in self.centerLinks:
|
for ln, name in links:
|
||||||
buf += '<a class=hitem href="%s">%s</a>' % (ln, _(name))
|
buf += '<a class=hitem href="%s">%s</a>' % (ln, name)
|
||||||
buf += " "*3
|
buf += " "*3
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
@ -89,12 +91,16 @@ margin:0;
|
||||||
background: -webkit-gradient(linear, left top, left bottom,
|
background: -webkit-gradient(linear, left top, left bottom,
|
||||||
from(#ddd), to(#fff));
|
from(#ddd), to(#fff));
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
height: 10px;
|
|
||||||
margin-bottom: 1px;
|
margin-bottom: 1px;
|
||||||
border-bottom: 1px solid #aaa;
|
border-bottom: 1px solid #aaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
body { margin: 0; padding: 0; }
|
body {
|
||||||
|
margin: 0; padding: 0;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { -webkit-user-drag: none; }
|
||||||
|
|
||||||
.hitem { display: inline-block; padding: 4px; padding-right: 6px;
|
.hitem { display: inline-block; padding: 4px; padding-right: 6px;
|
||||||
text-decoration: none; color: #000;
|
text-decoration: none; color: #000;
|
||||||
|
@ -104,3 +110,27 @@ background: #333;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class BottomBar(Toolbar):
|
||||||
|
|
||||||
|
_css = Toolbar._css + """
|
||||||
|
#header {
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom,
|
||||||
|
from(#fff), to(#ddd));
|
||||||
|
border-bottom: 0;
|
||||||
|
border-top: 1px solid #aaa;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
_centerBody = """
|
||||||
|
<center><table width=100%% height=100%% id=header><tr><td align=center>
|
||||||
|
%s</td></tr></table></center>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def draw(self, buf):
|
||||||
|
self.web.show()
|
||||||
|
self.web.stdHtml(
|
||||||
|
self._centerBody % buf,
|
||||||
|
self._css)
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 831 B After Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Loading…
Reference in a new issue