move the toolbar into a separate file and make it global

This commit is contained in:
Damien Elmes 2011-11-27 11:25:13 +09:00
parent f75ef69fba
commit f2a39aad2a
11 changed files with 134 additions and 63 deletions

View file

@ -32,6 +32,9 @@ Suba, and Xtru.
Anki icon by Alex Fraser (CC GNU GPL)
Deck icon by Laurent Baumann (CC BY-NC-SA 3.0)
Deck browser icons from:
http://led24.de/iconset
http://p.yusukekamiyamane.com/
Other icons under LGPL or public domain.
"""

View file

@ -62,7 +62,6 @@ body { margin: 1em; }
_body = """
<center>
<h1>%(title)s</h1>
<table cellspacing=0 cellpading=3 width=100%%>
%(tree)s
</table>
@ -98,12 +97,10 @@ body { margin: 1em; }
return buf
def _dueImg(self, due, new):
if due and new:
i = "both"
elif due:
i = "green"
if due:
i = "clock-icon"
elif new:
i = "blue"
i = "plus-circle"
else:
i = "none"
return '<img valign=bottom src="qrc:/icons/%s.png">' % i

View file

@ -15,7 +15,7 @@ from anki.utils import stripHTML, checksum, isWin, isMac
from anki.hooks import runHook, addHook, removeHook
import anki.consts
import aqt, aqt.progress, aqt.webview
import aqt, aqt.progress, aqt.webview, aqt.toolbar
from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \
saveState, restoreState, getOnlyText, askUser, GetTextDialog, \
askUserDialog, applyStyles, getText, showText, showCritical, getFile
@ -182,8 +182,10 @@ Are you sure?"""):
restoreState(self, "mainWindow")
else:
self.resize(500, 400)
# toolbar needs to be retranslated
self.toolbar.draw()
# show and raise window for osx
self.show()
# raise window for osx
self.activateWindow()
self.raise_()
# maybe sync
@ -312,14 +314,23 @@ title="%s">%s</button>''' % (
# main window
self.form = aqt.forms.main.Ui_MainWindow()
self.form.setupUi(self)
self.web = aqt.webview.AnkiWebView(self.form.centralwidget)
# toolbar
tweb = aqt.webview.AnkiWebView()
tweb.setObjectName("toolbarWeb")
tweb.setFocusPolicy(Qt.WheelFocus)
tweb.setFixedHeight(32)
self.toolbar = aqt.toolbar.Toolbar(self, tweb)
# main area
self.web = aqt.webview.AnkiWebView()
self.web.setObjectName("mainText")
self.web.setFocusPolicy(Qt.WheelFocus)
# add in a layout
self.mainLayout = QVBoxLayout()
self.mainLayout.addWidget(self.web)
self.mainLayout.setContentsMargins(0,0,0,0)
self.mainLayout.setSpacing(0)
self.mainLayout.addWidget(tweb)
self.mainLayout.addWidget(self.web)
self.form.centralwidget.setLayout(self.mainLayout)
addHook("undoEnd", self.maybeEnableUndo)
def closeAllWindows(self):
aqt.dialogs.closeAll()
@ -607,6 +618,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
aqt.studyopts.StudyOptions(self)
def onOverview(self):
self.col.reset()
self.moveToState("overview")
def onGroups(self, parent=None):

View file

@ -67,25 +67,7 @@ class Overview(object):
shareLink = '<a class=smallLink href="review">Reviews and Updates</a>'
else:
shareLink = ""
header = """
<table id=header width=100%%>
<tr>
<td width=20%>
<a class="hitem" href="anki">Anki &#9662</a>
</td>
<td align=center>
<a class=hitem href="decks">Decks</a>
<a class=hitem href="study">Study</a>
<a class=hitem href="add">Add</a>
<a class=hitem href="browse">Browse</a>
</td>
<td width=20% align=right>
<a class=hitem href="stats"><img src="qrc:/icons/view-statistics.png"></a>
<a class=hitem href="sync"><img src="qrc:/icons/view-refresh.png"></a>
</td></tr></table>
<div id=headerSpace></div>
""" #% deck['name']
header = ""
self.web.stdHtml(self._overviewBody % dict(
title=_("Overview"),
table=tbl,
@ -134,29 +116,6 @@ $(function () {
.sub { font-size: 80%; color: #555; }
.smallLink { font-size: 12px; }
h3 { margin-bottom: 0; }
#headerSpace { height: 22px; }
#header {
z-index: 100;
position: fixed;
height: 22px;
font-size: 12px;
margin:0;
background: -webkit-gradient(linear, left top, left bottom,
from(#ddd), to(#fff));
border-bottom: 1px solid #ccc;
font-weight: bold;
}
body { margin: 0; }
.deck { }
.hitem { display: inline-block; padding: 4px; padding-right: 6px;
text-decoration: none; color: #000;
}
.hborder { border: 1px solid #ddd; }
.hitem:hover {
background: #333;
color: #fff;
}
.icon { padding-top: 2px; }
"""
def _overviewTable(self):

View file

@ -526,6 +526,7 @@ div#filler {
##########################################################################
def _setupStatus(self):
return
self._statusWidgets = []
sb = self.mw.form.statusbar
def addWgt(w, stretch=0):

102
aqt/toolbar.py Normal file
View file

@ -0,0 +1,102 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# -*- coding: utf-8 -*-
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
from aqt.webview import AnkiWebView
class Toolbar(object):
def __init__(self, mw, web):
self.mw = mw
self.web = web
self.web.page().mainFrame().setScrollBarPolicy(
Qt.Vertical, Qt.ScrollBarAlwaysOff)
self.web.setLinkHandler(self._linkHandler)
self.draw()
def draw(self):
body = self._body % (self._centerLinks(), self._rightIcons())
self.web.stdHtml(body, self._css)
# Available links
######################################################################
centerLinks = [
["decks", "Decks"],
["study", "Study"],
["add", "Add"],
["browse", "Browse"],
]
rightIcons = [
["stats", "qrc:/icons/view-statistics.png"],
["sync", "qrc:/icons/view-refresh.png"],
]
def _centerLinks(self):
buf = ""
for ln, name in self.centerLinks:
buf += '<a class=hitem href="%s">%s</a>' % (ln, _(name))
return buf
def _rightIcons(self):
buf = ""
for ln, icon in self.rightIcons:
buf += '<a class=hitem href="%s"><img src="%s"></a>' % (
ln, icon)
return buf
# Link handling
######################################################################
def _linkHandler(self, l):
if l == "anki":
self.showMenu()
elif l == "decks":
self.mw.moveToState("deckBrowser")
elif l == "study":
self.mw.onOverview()
elif l == "add":
self.mw.onAddCard()
elif l == "browse":
self.mw.onBrowse()
elif l == "stats":
self.mw.onStats()
elif l == "sync":
self.mw.onSync()
# HTML & CSS
######################################################################
_body = """
<table id=header width=100%%>
<tr>
<td width=20%%><a class="hitem" href="anki">Anki &#9662</a></td>
<td align=center>%s</td>
<td width=20%% align=right>%s</td>
</tr></table>
"""
_css = """
#header {
font-size: 12px;
margin:0;
background: -webkit-gradient(linear, left top, left bottom,
from(#ddd), to(#fff));
font-weight: bold;
height: 10px;
margin-bottom: 1px;
border-bottom: 1px solid #aaa;
}
body { margin: 0; padding: 0; }
.hitem { display: inline-block; padding: 4px; padding-right: 6px;
text-decoration: none; color: #000;
}
.hitem:hover {
background: #333;
color: #fff;
}
"""

View file

@ -28,8 +28,8 @@ class Bridge(QObject):
class AnkiWebPage(QWebPage):
def __init__(self, parent, jsErr):
QWebPage.__init__(self, parent)
def __init__(self, jsErr):
QWebPage.__init__(self)
self._jsErr = jsErr
def javaScriptConsoleMessage(self, msg, line, srcID):
self._jsErr(msg, line, srcID)
@ -38,11 +38,11 @@ class AnkiWebPage(QWebPage):
##########################################################################
class AnkiWebView(QWebView):
def __init__(self, parent):
QWebView.__init__(self, parent)
def __init__(self):
QWebView.__init__(self)
self.setObjectName("mainText")
self._bridge = Bridge()
self._page = AnkiWebPage(parent, self._jsErr)
self._page = AnkiWebPage(self._jsErr)
self._loadFinishedCB = None
self.setPage(self._page)
self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)

View file

@ -3,6 +3,8 @@
<file>icons/blue.png</file>
<file>icons/both.png</file>
<file>icons/green.png</file>
<file>icons/clock-icon.png</file>
<file>icons/plus-circle.png</file>
<file>icons/none.png</file>
<file>icons/edit-find 2.png</file>
<file>icons/edit-find-replace.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -137,11 +137,6 @@
<addaction name="menu_Settings"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusbar">
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
</widget>
<action name="actionExit">
<property name="icon">
<iconset resource="icons.qrc">