apply stylesheet app wide, and add border to win10 menu

the night mode add-on may need updating with this change, but with
a global stylesheet it may be easier to style widgets in the future

menu bar issue:

https://anki.tenderapp.com/discussions/beta-testing/1313-anki-216-beta-1#comment_46664932
This commit is contained in:
Damien Elmes 2018-12-14 20:35:12 +10:00
parent 9e4730f9dd
commit 0769bf7ac9
3 changed files with 31 additions and 10 deletions

View File

@ -18,7 +18,7 @@ from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, htmlToTextLine, \
isWin, intTime, \
isMac, isLin, bodyClass
from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \
saveHeader, restoreHeader, saveState, restoreState, getTag, \
showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA, \
getOnlyText, MenuList, SubMenu
from anki.hooks import runHook, addHook, remHook, runFilter
@ -384,7 +384,6 @@ class Browser(QMainWindow):
def __init__(self, mw):
QMainWindow.__init__(self, None, Qt.Window)
applyStyles(self)
self.mw = mw
self.col = self.mw.col
self.lastFilter = ""

View File

@ -8,6 +8,7 @@ import zipfile
import gc
import time
import faulthandler
import platform
from threading import Thread
from send2trash import send2trash
@ -15,7 +16,7 @@ from aqt.qt import *
from anki import Collection
from anki.utils import isWin, isMac, intTime, splitFields, ids2str, \
devMode
from anki.hooks import runHook, addHook
from anki.hooks import runHook, addHook, runFilter
import aqt
import aqt.progress
import aqt.webview
@ -26,7 +27,7 @@ from aqt.utils import showWarning
import anki.sound
import anki.mpv
from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \
restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \
restoreState, getOnlyText, askUser, showText, tooltip, \
openHelp, openLink, checkInvalidFilename, getFile
import sip
@ -696,7 +697,33 @@ title="%s" %s>%s</button>''' % (
self.form.statusbar.showMessage(text, timeout)
def setupStyle(self):
applyStyles(self)
buf = ""
if isWin and platform.release() == '10':
# add missing bottom border to menubar
buf += """
QMenuBar {
border-bottom: 1px solid #aaa;
background: white;
}
"""
# qt bug? setting the above changes the browser sidebar
# to white as well, so set it back
buf += """
QTreeWidget {
background: #eee;
}
"""
# allow addons to modify the styling
buf = runFilter("setupStyle", buf)
# allow users to extend styling
p = os.path.join(aqt.mw.pm.base, "style.css")
if os.path.exists(p):
buf += open(p).read()
self.app.setStyleSheet(buf)
# Key handling
##########################################################################

View File

@ -350,11 +350,6 @@ def mungeQA(col, txt):
txt = stripSounds(txt)
return txt
def applyStyles(widget):
p = os.path.join(aqt.mw.pm.base, "style.css")
if os.path.exists(p):
widget.setStyleSheet(open(p).read())
def openFolder(path):
if isWin:
subprocess.Popen(["explorer", "file://"+path])