Received: from mail.macaw.me (mail.macaw.me [45.79.76.58]) by mail-b.sr.ht (Postfix) with ESMTPS id 0E41BFF0F5 for <~nhanb/mcross-devel@lists.sr.ht>; Sun, 14 Jun 2020 12:47:13 +0000 (UTC) Authentication-Results: mail-b.sr.ht; dkim=pass (2048-bit key) header.d=macaw.me header.i=@macaw.me header.b=pj9rTAc0 Received: from localhost (unknown [153.99.181.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.macaw.me (Postfix) with ESMTPSA id 0CBAB3AF511; Sun, 14 Jun 2020 12:47:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=macaw.me; s=main; t=1592138831; bh=0i+5++gUaRX8ZKH6i7UHLdXT5QJflupFaOJwKZLvMjE=; h=From:To:Cc:Subject:Date; b=pj9rTAc0SHjVT3AwYk2dS4aNrcEqyu87M0+L0HRanXcrJuxxFct8EMlh+8SZQV7m7 b6c4W2j0f4p/jexFq8dCIsQe/XqfagCK+z11FyWdQ6lTGBLMNt9Sr2//QlDH+pu8hW lob8OZA1gs7HZzs0xMVX+8XZ8kXq14EBn49XJyx9lBNeTIwwgNdOPMWbKvZK79mNcr h8Ksm5B5yCmldQNKdc/vmtAE9PB+3p6DOUy/dU1jAGUubCOG3HP4/2IP9/TmnlXTpY 8hL1nql1LRc8G+kPVsS8+z6kHFYlebHbsBs1ECTi/eeyzygCTRhRwmWJq49Owvj6hC A4C5aQD24lsfw== From: Frederick Yin To: ~nhanb/mcross-devel@lists.sr.ht Cc: Frederick Yin Subject: [PATCH] Dark mode Date: Sun, 14 Jun 2020 20:46:46 +0800 Message-Id: <20200614124645.6225-1-fkfd@macaw.me> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable This commit introduces CLI arg `--dark`, which toggles dark mode. The effect should be like https://fkfd.me/static/mcross_dark.png --- src/mcross/__init__.py | 1 + src/mcross/gui/controller.py | 4 +++- src/mcross/gui/view.py | 10 +++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mcross/__init__.py b/src/mcross/__init__.py index 200999f..eb8be0e 100644 --- a/src/mcross/__init__.py +++ b/src/mcross/__init__.py @@ -9,6 +9,7 @@ def run(): argparser =3D argparse.ArgumentParser() argparser.add_argument("--textfont") argparser.add_argument("--monofont") + argparser.add_argument("--dark", action=3D"store_true") args =3D argparser.parse_args() =20 # Actually start the program diff --git a/src/mcross/gui/controller.py b/src/mcross/gui/controller.py index 92d59c7..ca6b684 100644 --- a/src/mcross/gui/controller.py +++ b/src/mcross/gui/controller.py @@ -25,7 +25,9 @@ class Controller: self.root =3D Tk() self.root.alt_shortcuts =3D set() self.model =3D Model() - self.view =3D View(self.root, self.model, fonts=3D(args.textfont= , args.monofont)) + self.view =3D View( + self.root, self.model, fonts=3D(args.textfont, args.monofont= ), dark=3Dargs.dark + ) self.root.title("McRoss Browser") self.root.geometry("800x600") =20 diff --git a/src/mcross/gui/view.py b/src/mcross/gui/view.py index a52f30c..7e5ed33 100644 --- a/src/mcross/gui/view.py +++ b/src/mcross/gui/view.py @@ -71,7 +71,7 @@ class View: back_callback =3D None forward_callback =3D None =20 - def __init__(self, root: Tk, model: Model, fonts=3D(None, None)): + def __init__(self, root: Tk, model: Model, fonts=3D(None, None), dar= k=3DFalse): self.model =3D model =20 # first row - address bar + buttons @@ -165,8 +165,8 @@ class View: =20 text.config( font=3D(text_font, 13), - bg=3D"#fff8dc", - fg=3D"black", + bg=3D"#212121" if dark else "#fff8dc", + fg=3D"#eee" if dark else "black", padx=3D5, pady=3D5, # hide blinking insertion cursor: @@ -176,12 +176,12 @@ class View: height=3D1, ) text.pack(side=3D"left", fill=3D"both", expand=3DTrue) - text.tag_config("link", foreground=3D"brown") + text.tag_config("link", foreground=3D"#ff8a65" if dark else "bro= wn") text.tag_bind("link", "", self._on_link_enter) text.tag_bind("link", "", self._on_link_leave) text.tag_bind("link", "", self._on_link_click) text.tag_config("pre", font=3D(mono_font, 13)) - text.tag_config("listitem", foreground=3D"#044604") + text.tag_config("listitem", foreground=3D"#64c664" if dark else = "#044604") =20 base_heading_font =3D font.Font(font=3Dtext["font"]) base_heading_font.config(weight=3D"bold") --=20 2.27.0