Received: from mail.macaw.me (mail.macaw.me [45.79.76.58]) by mail-b.sr.ht (Postfix) with ESMTPS id 73E4BFF1E9 for <~nhanb/mcross-devel@lists.sr.ht>; Sun, 31 May 2020 06:52:57 +0000 (UTC) Authentication-Results: mail-b.sr.ht; dkim=pass (2048-bit key) header.d=macaw.me header.i=@macaw.me header.b=eUwW5qxh Received: from localhost (unknown [101.224.19.96]) (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 B139D3AF17E; Sun, 31 May 2020 06:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=macaw.me; s=main; t=1590907976; bh=+NshCoOtUsUu/fqY87wSQJe6U0flJAWPifrmHJoPBFo=; h=From:To:Cc:Subject:Date; b=eUwW5qxhXICq4Lld8zGvTYaSmoYHIcyX5nRK2gRK34/DUz62FaOp6b6/9cVg+hRLA wj/cD0l/HPaZnAQmDR2XPyFmo+AwJIwKYMI9GpYSbynlgPm6mXbtkk5Qr+pc2yoRvy khDwxAl4NLQ8J4W0wnfq11stvxifq1mU91AVWbgnEZjrw7uRaFbs2nC5YMGR0SKAXM VcfN7JHVLGnXKPgMMbQvAQ/gbho7ZPBBwC36jR/Yo3cv/H6oFQlvAVIZWasYUftAf7 2CoDU4BuQeNwNwGXh0gXCbdmBBw+zDbdnWOSvlG0tbeinZ5LWTfoa7PPof/kuofRHD 5/6CtOY+wBshw== From: Frederick Yin To: ~nhanb/mcross-devel@lists.sr.ht Cc: Frederick Yin Subject: [PATCH] Add CLI arguments to pick custom fonts Date: Sun, 31 May 2020 14:52:03 +0800 Message-Id: <20200531065202.2765-1-fkfd@macaw.me> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Users can now pick custom fonts via args `--textfont` and `--monofont`. This is a WIP patch. Todos: - Add more font candidates to the "default" font lists - Add help text for arguments - Perhaps a config file --- src/mcross/gui/controller.py | 11 ++++++++- src/mcross/gui/view.py | 43 ++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/mcross/gui/controller.py b/src/mcross/gui/controller.py index dfaccea..861f66d 100644 --- a/src/mcross/gui/controller.py +++ b/src/mcross/gui/controller.py @@ -1,6 +1,7 @@ import logging import threading import traceback +import argparse from ssl import SSLCertVerificationError from tkinter import READABLE, Tk, messagebox =20 @@ -17,12 +18,20 @@ from .view import WAITING_CURSOR, View =20 statusbar_logger =3D logging.getLogger("statusbar") =20 +argparser =3D argparse.ArgumentParser() +argparser.add_argument("--textfont") +argparser.add_argument("--monofont") +args =3D argparser.parse_args() =20 class Controller: def __init__(self): self.root =3D Tk() self.model =3D Model() - self.view =3D View(self.root, self.model) + self.view =3D View( + self.root, + self.model, + fonts=3D(args.textfont, args.monofont) + ) 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 d4a8a5a..cc9fc0f 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): + def __init__(self, root: Tk, model: Model, fonts=3D(None, None)): self.model =3D model =20 # first row - address bar + buttons @@ -128,19 +128,34 @@ class View: text =3D ReadOnlyText(row2, wrap=3D"word") self.text =3D text self.render_page() - text_font =3D pick_font( - [ - "Charis SIL", - "Source Serif Pro", - "Cambria", - "Georgia", - "DejaVu Serif", - "Times New Roman", - "Times", - "TkTextFont", - ] - ) - mono_font =3D pick_font(["Ubuntu Mono", "Consolas", "Courier", "= TkFixedFont"]) + if fonts[0] is None: + text_font =3D pick_font( + [ + "Charis SIL", + "Source Serif Pro", + "Cambria", + "Georgia", + "DejaVu Serif", + "Times New Roman", + "Times", + "TkTextFont", + ] + ) + else: + text_font =3D fonts[0] + + if fonts[1] is None: + mono_font =3D pick_font( + [ + "Ubuntu Mono", + "Consolas", + "Courier", + "TkFixedFont" + ] + ) + else: + mono_font =3D fonts[1] + text.config( font=3D(text_font, 13), bg=3D"#fff8dc", --=20 2.26.2