remove toolbar in browser in favour of menu items

This commit is contained in:
Damien Elmes 2017-08-11 14:40:51 +10:00
parent 1c88315e86
commit 6c765d7302
3 changed files with 138 additions and 240 deletions

View file

@ -20,7 +20,6 @@ from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA
from anki.hooks import runHook, addHook, remHook from anki.hooks import runHook, addHook, remHook
from aqt.webview import AnkiWebView from aqt.webview import AnkiWebView
from aqt.toolbar import Toolbar
from anki.consts import * from anki.consts import *
from anki.sound import playFromText, clearAudioQueue from anki.sound import playFromText, clearAudioQueue
@ -373,7 +372,6 @@ class Browser(QMainWindow):
self.form.splitter_2.setChildrenCollapsible(False) self.form.splitter_2.setChildrenCollapsible(False)
self.form.splitter.setChildrenCollapsible(False) self.form.splitter.setChildrenCollapsible(False)
self.card = None self.card = None
self.setupToolbar()
self.setupColumns() self.setupColumns()
self.setupTable() self.setupTable()
self.setupMenus() self.setupMenus()
@ -386,30 +384,34 @@ class Browser(QMainWindow):
self.setupSearch() self.setupSearch()
self.show() self.show()
def setupToolbar(self):
self.toolbarWeb = AnkiWebView()
self.toolbarWeb.title = "browser toolbar"
self.toolbar = BrowserToolbar(self.mw, self.toolbarWeb, self)
self.form.verticalLayout_3.insertWidget(0, self.toolbarWeb)
self.toolbar.draw()
def setupMenus(self): def setupMenus(self):
# actions # actions
f = self.form f = self.form
if not isMac:
f.actionClose.setVisible(False)
f.actionReposition.triggered.connect(self.reposition)
f.actionReschedule.triggered.connect(self.reschedule)
f.actionChangeModel.triggered.connect(self.onChangeModel)
# edit
f.actionUndo.triggered.connect(self.mw.onUndo)
f.previewButton.clicked.connect(self.onTogglePreview) f.previewButton.clicked.connect(self.onTogglePreview)
f.previewButton.setToolTip(_("Preview Selected Card (%s)") % f.previewButton.setToolTip(_("Preview Selected Card (%s)") %
shortcut(_("Ctrl+Shift+P"))) shortcut(_("Ctrl+Shift+P")))
# edit
f.actionUndo.triggered.connect(self.mw.onUndo)
f.actionInvertSelection.triggered.connect(self.invertSelection) f.actionInvertSelection.triggered.connect(self.invertSelection)
f.actionSelectNotes.triggered.connect(self.selectNotes) f.actionSelectNotes.triggered.connect(self.selectNotes)
f.actionFindReplace.triggered.connect(self.onFindReplace) if not isMac:
f.actionClose.setVisible(False)
# notes
f.actionAdd.triggered.connect(self.mw.onAddCard)
f.actionAdd_Tags.triggered.connect(lambda: self.addTags())
f.actionRemove_Tags.triggered.connect(lambda: self.deleteTags())
f.actionClear_Unused_Tags.triggered.connect(self.clearUnusedTags)
f.actionChangeModel.triggered.connect(self.onChangeModel)
f.actionFindDuplicates.triggered.connect(self.onFindDupes) f.actionFindDuplicates.triggered.connect(self.onFindDupes)
f.actionFindReplace.triggered.connect(self.onFindReplace)
f.actionToggle_Mark.triggered.connect(lambda: self.onMark())
f.actionDelete.triggered.connect(self.deleteNotes)
# cards
f.actionChange_Deck.triggered.connect(self.setDeck)
f.action_Info.triggered.connect(self.showCardInfo)
f.actionReposition.triggered.connect(self.reposition)
f.actionReschedule.triggered.connect(self.reschedule)
f.actionToggle_Suspend.triggered.connect(self.onSuspend)
# jumps # jumps
f.actionPreviousCard.triggered.connect(self.onPreviousCard) f.actionPreviousCard.triggered.connect(self.onPreviousCard)
f.actionNextCard.triggered.connect(self.onNextCard) f.actionNextCard.triggered.connect(self.onNextCard)
@ -426,29 +428,6 @@ class Browser(QMainWindow):
self.pgUpCut.activated.connect(self.onFirstCard) self.pgUpCut.activated.connect(self.onFirstCard)
self.pgDownCut = QShortcut(QKeySequence("Shift+End"), self) self.pgDownCut = QShortcut(QKeySequence("Shift+End"), self)
self.pgDownCut.activated.connect(self.onLastCard) self.pgDownCut.activated.connect(self.onLastCard)
# add note
self.addCut = QShortcut(QKeySequence("Ctrl+E"), self)
self.addCut.activated.connect(self.mw.onAddCard)
# card info
self.infoCut = QShortcut(QKeySequence("Ctrl+Shift+I"), self)
self.infoCut.activated.connect(self.showCardInfo)
# set deck
self.changeDeckCut = QShortcut(QKeySequence("Ctrl+D"), self)
self.changeDeckCut.activated.connect(self.setDeck)
# add/remove tags
self.tagCut1 = QShortcut(QKeySequence("Ctrl+Shift+A"), self)
self.tagCut1.activated.connect(self.addTags)
self.tagCut2 = QShortcut(QKeySequence("Ctrl+Shift+D"), self)
self.tagCut2.activated.connect(self.deleteTags)
self.tagCut3 = QShortcut(QKeySequence("Ctrl+K"), self)
self.tagCut3.activated.connect(self.onMark)
# suspending
self.susCut1 = QShortcut(QKeySequence("Ctrl+J"), self)
self.susCut1.activated.connect(self.onSuspend)
# deletion
self.delCut1 = QShortcut(QKeySequence("Ctrl+Delete"), self)
self.delCut1.setAutoRepeat(False)
self.delCut1.activated.connect(self.deleteNotes)
# add-on hook # add-on hook
runHook('browser.setupMenus', self) runHook('browser.setupMenus', self)
self.mw.maybeHideAccelerators(self) self.mw.maybeHideAccelerators(self)
@ -635,7 +614,6 @@ class Browser(QMainWindow):
self.editor.card = self.card self.editor.card = self.card
self.singleCard = True self.singleCard = True
self._renderPreview(True) self._renderPreview(True)
self.toolbar.update()
def refreshCurrentCard(self, note): def refreshCurrentCard(self, note):
self.model.refreshNote(note) self.model.refreshNote(note)
@ -1278,6 +1256,13 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
self.addTags(tags, label, _("Enter tags to delete:"), self.addTags(tags, label, _("Enter tags to delete:"),
func=self.col.tags.bulkRem) func=self.col.tags.bulkRem)
def clearUnusedTags(self):
self.editor.saveNow(self._clearUnusedTags)
def _clearUnusedTags(self):
self.col.tags.registerNotes()
self.buildTree()
# Suspending and marking # Suspending and marking
###################################################################### ######################################################################
@ -1789,85 +1774,6 @@ Are you sure you want to continue?""")):
def onHelp(self): def onHelp(self):
openHelp("browsermisc") openHelp("browsermisc")
# Toolbar
######################################################################
class BrowserToolbar(Toolbar):
def __init__(self, mw, web, browser):
self.browser = browser
Toolbar.__init__(self, mw, web)
def draw(self):
self.web.onBridgeCmd = self._linkHandler
self.web.stdHtml(self.html(),
css=["toolbar.css", "browser-toolbar.css"])
self.update()
if isLin:
# adjust height on a delay to work around a qt crash when
# opening the browser
self.browser.mw.progress.timer(10, self.web.adjustHeightToFit, False)
else:
self.web.adjustHeightToFit()
def update(self):
for link, enabled in (
("mark", self.browser.isMarked()),
("pause", self.browser.isSuspended())):
if enabled:
self.web.eval("$('#%s').addClass('buttonOn')" % link)
else:
self.web.eval("$('#%s').removeClass('buttonOn')" % link)
def html(self):
def borderImg(link, icon, title, tooltip=None):
fmt = '''\
<a class=hitem title="%s" href=# onclick="pycmd('%s')"><img id=%s valign=bottom src="qrc:/icons/%s.png"> %s</a>'''
return fmt % (tooltip or title, link, link, icon, title)
right = "<div>"
right += borderImg("add", "add16", _("Add"),
shortcut(_("Add Note (Ctrl+E)")))
right += borderImg("info", "info", _("Info"),
shortcut(_("Card Info (Ctrl+Shift+I)")))
right += borderImg("mark", "star16", _("Mark"),
shortcut(_("Mark Note (Ctrl+K)")))
right += borderImg("pause", "pause16", _("Suspend"),
shortcut(_("Suspend Card (Ctrl+J)")))
right += borderImg("setDeck", "deck16", _("Change Deck"),
shortcut(_("Move To Deck (Ctrl+D)")))
right += borderImg("addtag", "addtag16", _("Add Tags"),
shortcut(_("Bulk Add Tags (Ctrl+Shift+A)")))
right += borderImg("deletetag", "deletetag16", _("Remove Tags"), shortcut(_(
"Bulk Remove Tags (Ctrl+Shift+D)")))
right += borderImg("delete", "delete16", _("Delete"), shortcut(_("Ctrl+Delete")))
right += "</div>"
return self._body % right
# Link handling
######################################################################
def _linkHandler(self, l):
if l == "anki":
self.showMenu()
elif l == "add":
self.browser.mw.onAddCard()
elif l == "delete":
self.browser.deleteNotes()
elif l == "setDeck":
self.browser.setDeck()
# icons
elif l == "info":
self.browser.showCardInfo()
elif l == "mark":
self.browser.onMark()
elif l == "pause":
self.browser.onSuspend()
elif l == "addtag":
self.browser.addTags()
elif l == "deletetag":
self.browser.deleteTags()
# Favourites button # Favourites button
###################################################################### ######################################################################
class FavouritesLineEdit(QLineEdit): class FavouritesLineEdit(QLineEdit):

View file

@ -28,16 +28,7 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="leftMargin"> <property name="margin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -85,20 +76,17 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="leftMargin"> <property name="margin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -108,12 +96,6 @@
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QComboBox" name="searchEdit"> <widget class="QComboBox" name="searchEdit">
<property name="sizePolicy"> <property name="sizePolicy">
@ -268,18 +250,10 @@
</property> </property>
<addaction name="actionUndo"/> <addaction name="actionUndo"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionReschedule"/>
<addaction name="actionReposition"/>
<addaction name="separator"/>
<addaction name="actionChangeModel"/>
<addaction name="separator"/>
<addaction name="actionSelectAll"/> <addaction name="actionSelectAll"/>
<addaction name="actionSelectNotes"/> <addaction name="actionSelectNotes"/>
<addaction name="actionInvertSelection"/> <addaction name="actionInvertSelection"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionFindDuplicates"/>
<addaction name="actionFindReplace"/>
<addaction name="separator"/>
<addaction name="actionClose"/> <addaction name="actionClose"/>
</widget> </widget>
<widget class="QMenu" name="menuJump"> <widget class="QMenu" name="menuJump">
@ -302,15 +276,45 @@
</property> </property>
<addaction name="actionGuide"/> <addaction name="actionGuide"/>
</widget> </widget>
<widget class="QMenu" name="menu_Cards">
<property name="title">
<string>&amp;Cards</string>
</property>
<addaction name="actionChange_Deck"/>
<addaction name="separator"/>
<addaction name="actionReschedule"/>
<addaction name="actionReposition"/>
<addaction name="separator"/>
<addaction name="actionToggle_Suspend"/>
<addaction name="separator"/>
<addaction name="action_Info"/>
</widget>
<widget class="QMenu" name="menu_Notes">
<property name="title">
<string>&amp;Notes</string>
</property>
<addaction name="actionAdd"/>
<addaction name="separator"/>
<addaction name="actionAdd_Tags"/>
<addaction name="actionRemove_Tags"/>
<addaction name="actionClear_Unused_Tags"/>
<addaction name="separator"/>
<addaction name="actionChangeModel"/>
<addaction name="separator"/>
<addaction name="actionFindDuplicates"/>
<addaction name="actionFindReplace"/>
<addaction name="separator"/>
<addaction name="actionToggle_Mark"/>
<addaction name="separator"/>
<addaction name="actionDelete"/>
</widget>
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
<addaction name="menu_Notes"/>
<addaction name="menu_Cards"/>
<addaction name="menuJump"/> <addaction name="menuJump"/>
<addaction name="menu_Help"/> <addaction name="menu_Help"/>
</widget> </widget>
<action name="actionReschedule"> <action name="actionReschedule">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/view-pim-calendar.png</normaloff>:/icons/view-pim-calendar.png</iconset>
</property>
<property name="text"> <property name="text">
<string>&amp;Reschedule...</string> <string>&amp;Reschedule...</string>
</property> </property>
@ -324,10 +328,6 @@
</property> </property>
</action> </action>
<action name="actionUndo"> <action name="actionUndo">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/edit-undo.png</normaloff>:/icons/edit-undo.png</iconset>
</property>
<property name="text"> <property name="text">
<string>&amp;Undo</string> <string>&amp;Undo</string>
</property> </property>
@ -341,10 +341,6 @@
</property> </property>
</action> </action>
<action name="actionFind"> <action name="actionFind">
<property name="icon">
<iconset>
<normaloff>:/icons/document-preview.png</normaloff>:/icons/document-preview.png</iconset>
</property>
<property name="text"> <property name="text">
<string>&amp;Find</string> <string>&amp;Find</string>
</property> </property>
@ -353,10 +349,6 @@
</property> </property>
</action> </action>
<action name="actionNote"> <action name="actionNote">
<property name="icon">
<iconset>
<normaloff>:/icons/Anki_Fact.png</normaloff>:/icons/Anki_Fact.png</iconset>
</property>
<property name="text"> <property name="text">
<string>N&amp;ote</string> <string>N&amp;ote</string>
</property> </property>
@ -365,10 +357,6 @@
</property> </property>
</action> </action>
<action name="actionNextCard"> <action name="actionNextCard">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/go-next.png</normaloff>:/icons/go-next.png</iconset>
</property>
<property name="text"> <property name="text">
<string>&amp;Next Card</string> <string>&amp;Next Card</string>
</property> </property>
@ -377,10 +365,6 @@
</property> </property>
</action> </action>
<action name="actionPreviousCard"> <action name="actionPreviousCard">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/go-previous.png</normaloff>:/icons/go-previous.png</iconset>
</property>
<property name="text"> <property name="text">
<string>&amp;Previous Card</string> <string>&amp;Previous Card</string>
</property> </property>
@ -389,10 +373,6 @@
</property> </property>
</action> </action>
<action name="actionGuide"> <action name="actionGuide">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/help.png</normaloff>:/icons/help.png</iconset>
</property>
<property name="text"> <property name="text">
<string>&amp;Guide</string> <string>&amp;Guide</string>
</property> </property>
@ -401,10 +381,6 @@
</property> </property>
</action> </action>
<action name="actionChangeModel"> <action name="actionChangeModel">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/system-software-update.png</normaloff>:/icons/system-software-update.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Change Note Type...</string> <string>Change Note Type...</string>
</property> </property>
@ -421,10 +397,6 @@
</property> </property>
</action> </action>
<action name="actionFindReplace"> <action name="actionFindReplace">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/edit-find-replace.png</normaloff>:/icons/edit-find-replace.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Find and Re&amp;place...</string> <string>Find and Re&amp;place...</string>
</property> </property>
@ -433,19 +405,11 @@
</property> </property>
</action> </action>
<action name="actionCram"> <action name="actionCram">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/view-pim-calendar.png</normaloff>:/icons/view-pim-calendar.png</iconset>
</property>
<property name="text"> <property name="text">
<string>&amp;Cram...</string> <string>&amp;Cram...</string>
</property> </property>
</action> </action>
<action name="actionTags"> <action name="actionTags">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/anki-tag.png</normaloff>:/icons/anki-tag.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Fil&amp;ters</string> <string>Fil&amp;ters</string>
</property> </property>
@ -454,10 +418,6 @@
</property> </property>
</action> </action>
<action name="actionCardList"> <action name="actionCardList">
<property name="icon">
<iconset>
<normaloff>:/icons/generate_07.png</normaloff>:/icons/generate_07.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Card List</string> <string>Card List</string>
</property> </property>
@ -466,19 +426,11 @@
</property> </property>
</action> </action>
<action name="actionFindDuplicates"> <action name="actionFindDuplicates">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/edit-find 2.png</normaloff>:/icons/edit-find 2.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Find &amp;Duplicates...</string> <string>Find &amp;Duplicates...</string>
</property> </property>
</action> </action>
<action name="actionReposition"> <action name="actionReposition">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/view-sort-ascending.png</normaloff>:/icons/view-sort-ascending.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Reposition...</string> <string>Reposition...</string>
</property> </property>
@ -487,10 +439,6 @@
</property> </property>
</action> </action>
<action name="actionFirstCard"> <action name="actionFirstCard">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/arrow-up.png</normaloff>:/icons/arrow-up.png</iconset>
</property>
<property name="text"> <property name="text">
<string>First Card</string> <string>First Card</string>
</property> </property>
@ -499,10 +447,6 @@
</property> </property>
</action> </action>
<action name="actionLastCard"> <action name="actionLastCard">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/arrow-down.png</normaloff>:/icons/arrow-down.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Last Card</string> <string>Last Card</string>
</property> </property>
@ -518,6 +462,75 @@
<string>Ctrl+W</string> <string>Ctrl+W</string>
</property> </property>
</action> </action>
<action name="action_Info">
<property name="text">
<string>&amp;Info...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+I</string>
</property>
</action>
<action name="actionAdd_Tags">
<property name="text">
<string>Add Tags...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+A</string>
</property>
</action>
<action name="actionRemove_Tags">
<property name="text">
<string>Remove Tags...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+D</string>
</property>
</action>
<action name="actionClear_Unused_Tags">
<property name="text">
<string>Clear Unused Tags</string>
</property>
</action>
<action name="actionToggle_Suspend">
<property name="text">
<string>Toggle Suspend</string>
</property>
<property name="shortcut">
<string>Ctrl+J</string>
</property>
</action>
<action name="actionDelete">
<property name="text">
<string>Delete</string>
</property>
<property name="shortcut">
<string>Ctrl+Del</string>
</property>
</action>
<action name="actionAdd">
<property name="text">
<string>Add...</string>
</property>
<property name="shortcut">
<string>Ctrl+E</string>
</property>
</action>
<action name="actionChange_Deck">
<property name="text">
<string>Change Deck...</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="actionToggle_Mark">
<property name="text">
<string>Toggle Mark</string>
</property>
<property name="shortcut">
<string>Ctrl+K</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="icons.qrc"/> <include location="icons.qrc"/>

View file

@ -1,21 +0,0 @@
#header {
font-weight: normal;
}
a {
margin-right: 1em;
}
.hitem {
overflow: hidden;
white-space: nowrap;
}
.hitem img {
padding: 1px;
}
.buttonOn {
border: 1px solid #aaa;
padding: 0 !important;
}