def standard_css(self) -> str: palette = theme_manager.default_palette color_hl = palette.color(QPalette.ColorRole.Highlight).name() if isWin: # T: include a font for your language on Windows, eg: "Segoe UI", "MS Mincho" family = tr.qt_misc_segoe_ui() button_style = "button { font-family:%s; }" % family button_style += "\n:focus { outline: 1px solid %s; }" % color_hl font = f"font-size:12px;font-family:{family};" elif isMac: family = "Helvetica" font = f'font-size:15px;font-family:"{family}";' button_style = """ button { -webkit-appearance: none; background: #fff; border: 1px solid #ccc; border-radius:5px; font-family: Helvetica }""" else: family = self.font().family() color_hl_txt = palette.color( QPalette.ColorRole.HighlightedText).name() color_btn = palette.color(QPalette.ColorRole.Button).name() font = f'font-size:14px;font-family:"{family}";' button_style = """ /* Buttons */ button{{ background-color: {color_btn}; font-family:"{family}"; }} button:focus{{ border-color: {color_hl} }} button:active, button:active:hover {{ background-color: {color_hl}; color: {color_hl_txt};}} /* Input field focus outline */ textarea:focus, input:focus, input[type]:focus, .uneditable-input:focus, div[contenteditable="true"]:focus {{ outline: 0 none; border-color: {color_hl}; }}""".format( family=family, color_btn=color_btn, color_hl=color_hl, color_hl_txt=color_hl_txt, ) zoom = self.zoomFactor() window_bg_day = self.get_window_bg_color(False).name() window_bg_night = self.get_window_bg_color(True).name() body_bg = window_bg_night if theme_manager.night_mode else window_bg_day if is_rtl(anki.lang.currentLang): lang_dir = "rtl" else: lang_dir = "ltr" return f"""
def standard_css_new(self) -> str: palette = theme_manager.default_palette color_hl = palette.color(QPalette.Highlight).name() family = config["Interface Font"] font_size = config["Font Size"] if isWin: # T: include a font for your language on Windows, eg: "Segoe UI", "MS Mincho" button_style = "button { font-size: 12px; font-family:%s; }" % family button_style += "\n:focus { outline: 1px solid %s; }" % color_hl font = f"font-size:{font_size}px;font-family:{family};" elif isMac: font = f'font-size:{font_size}px;font-family:"{family}";' button_style = """ button { -webkit-appearance: none; background: #fff; border: 1px solid #ccc; border-radius:5px; font-family: %s }""" % family else: color_hl_txt = palette.color(QPalette.HighlightedText).name() color_btn = palette.color(QPalette.Button).name() font = f'font-size:{font_size}px;font-family:"{family}";' button_style = """ /* Buttons */ button{ background-color: %(color_btn)s; font-family:"%(family)s"; } button:focus{ border-color: %(color_hl)s } button:active, button:active:hover { background-color: %(color_hl)s; color: %(color_hl_txt)s;} /* Input field focus outline */ textarea:focus, input:focus, input[type]:focus, .uneditable-input:focus, div[contenteditable="true"]:focus { outline: 0 none; border-color: %(color_hl)s; }""" % { "family": family, "color_btn": color_btn, "color_hl": color_hl, "color_hl_txt": color_hl_txt, } zoom = self.zoomFactor() window_bg_day = self.get_window_bg_color(False).name() window_bg_night = self.get_window_bg_color(True).name() body_bg = window_bg_night if theme_manager.night_mode else window_bg_day if is_rtl(anki.lang.currentLang): lang_dir = "rtl" else: lang_dir = "ltr" return f"""
def standard_css(self) -> str: palette = self.style().standardPalette() color_hl = palette.color(QPalette.Highlight).name() if isWin: # T: include a font for your language on Windows, eg: "Segoe UI", "MS Mincho" family = tr(TR.QT_MISC_SEGOE_UI) button_style = "button { font-family:%s; }" % family button_style += "\n:focus { outline: 1px solid %s; }" % color_hl font = "font-size:12px;font-family:%s;" % family elif isMac: family = "Helvetica" font = 'font-size:15px;font-family:"%s";' % family button_style = """ button { -webkit-appearance: none; background: #fff; border: 1px solid #ccc; border-radius:5px; font-family: Helvetica }""" else: family = self.font().family() color_hl_txt = palette.color(QPalette.HighlightedText).name() color_btn = palette.color(QPalette.Button).name() font = 'font-size:14px;font-family:"%s";' % family button_style = """ /* Buttons */ button{ background-color: %(color_btn)s; font-family:"%(family)s"; } button:focus{ border-color: %(color_hl)s } button:active, button:active:hover { background-color: %(color_hl)s; color: %(color_hl_txt)s;} /* Input field focus outline */ textarea:focus, input:focus, input[type]:focus, .uneditable-input:focus, div[contenteditable="true"]:focus { outline: 0 none; border-color: %(color_hl)s; }""" % { "family": family, "color_btn": color_btn, "color_hl": color_hl, "color_hl_txt": color_hl_txt, } zoom = self.zoomFactor() background = self._getWindowColor().name() if is_rtl(anki.lang.currentLang): lang_dir = "rtl" else: lang_dir = "ltr" return f"""
def stdHtml( self, body: str, css: Optional[list[str]] = None, js: Optional[list[str]] = None, head: str = "", context: Optional[Any] = None, default_css: bool = True, ) -> None: css = (["css/webview.css"] if default_css else []) + ([] if css is None else css) web_content = WebContent( body=body, head=head, js=["js/webview.js"] + (["js/vendor/jquery.min.js"] if js is None else js), css=css, ) gui_hooks.webview_will_set_content(web_content, context) csstxt = "" if "css/webview.css" in css: # we want our dynamic styling to override the defaults in # css/webview.css, but come before user-provided stylesheets so that # they can override us if necessary web_content.css.remove("css/webview.css") csstxt = self.bundledCSS("css/webview.css") csstxt += f"<style>{self.standard_css()}</style>" csstxt += "\n".join( self.bundledCSS(fname) for fname in web_content.css) jstxt = "\n".join( self.bundledScript(fname) for fname in web_content.js) from aqt import mw head = mw.baseHTML() + csstxt + jstxt + web_content.head body_class = theme_manager.body_class() if theme_manager.night_mode: doc_class = "night-mode" else: doc_class = "" if is_rtl(anki.lang.current_lang): lang_dir = "rtl" else: lang_dir = "ltr" html = f""" <!doctype html> <html class="{doc_class}" dir="{lang_dir}"> <head> <title>{self.title}</title> {head} </head> <body class="{body_class}">{web_content.body}</body> </html>""" # print(html) self.setHtml(html)
def stdHtml( self, body: str, css: Optional[List[str]] = None, js: Optional[List[str]] = None, head: str = "", context: Optional[Any] = None, ): web_content = WebContent( body=body, head=head, js=["webview.js"] + (["jquery.js"] if js is None else js), css=["webview.css"] + ([] if css is None else css), ) gui_hooks.webview_will_set_content(web_content, context) palette = self.style().standardPalette() color_hl = palette.color(QPalette.Highlight).name() if isWin: # T: include a font for your language on Windows, eg: "Segoe UI", "MS Mincho" family = _('"Segoe UI"') widgetspec = "button { font-family:%s; }" % family widgetspec += "\n:focus { outline: 1px solid %s; }" % color_hl fontspec = "font-size:12px;font-family:%s;" % family elif isMac: family = "Helvetica" fontspec = 'font-size:15px;font-family:"%s";' % family widgetspec = """ button { -webkit-appearance: none; background: #fff; border: 1px solid #ccc; border-radius:5px; font-family: Helvetica }""" else: family = self.font().family() color_hl_txt = palette.color(QPalette.HighlightedText).name() color_btn = palette.color(QPalette.Button).name() fontspec = 'font-size:14px;font-family:"%s";' % family widgetspec = """ /* Buttons */ button{ background-color: %(color_btn)s; font-family:"%(family)s"; } button:focus{ border-color: %(color_hl)s } button:active, button:active:hover { background-color: %(color_hl)s; color: %(color_hl_txt)s;} /* Input field focus outline */ textarea:focus, input:focus, input[type]:focus, .uneditable-input:focus, div[contenteditable="true"]:focus { outline: 0 none; border-color: %(color_hl)s; }""" % { "family": family, "color_btn": color_btn, "color_hl": color_hl, "color_hl_txt": color_hl_txt, } csstxt = "\n".join(self.bundledCSS(fname) for fname in web_content.css) jstxt = "\n".join( self.bundledScript(fname) for fname in web_content.js) from aqt import mw head = mw.baseHTML() + csstxt + jstxt + web_content.head body_class = theme_manager.body_class() if is_rtl(anki.lang.currentLang): lang_dir = "rtl" else: lang_dir = "ltr" html = """ <!doctype html> <html><head> <title>{}</title> <style> body {{ zoom: {}; background: {}; direction: {}; {} }} {} </style> {} </head> <body class="{}">{}</body> </html>""".format( self.title, self.zoomFactor(), self._getWindowColor().name(), lang_dir, fontspec, widgetspec, head, body_class, web_content.body, ) # print(html) self.setHtml(html)