~nhanb/mcross-devel

Add CLI arguments to pick custom fonts v1 APPLIED

Frederick Yin: 1
 Add CLI arguments to pick custom fonts

 2 files changed, 39 insertions(+), 15 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~nhanb/mcross-devel/patches/10856/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Add CLI arguments to pick custom fonts Export this patch

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

@@ -17,12 +18,20 @@ from .view import WAITING_CURSOR, View

statusbar_logger = logging.getLogger("statusbar")

argparser = argparse.ArgumentParser()
argparser.add_argument("--textfont")
argparser.add_argument("--monofont")
args = argparser.parse_args()

class Controller:
    def __init__(self):
        self.root = Tk()
        self.model = Model()
        self.view = View(self.root, self.model)
        self.view = View(
            self.root,
            self.model,
            fonts=(args.textfont, args.monofont)
        )
        self.root.title("McRoss Browser")
        self.root.geometry("800x600")

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 = None
    forward_callback = None

    def __init__(self, root: Tk, model: Model):
    def __init__(self, root: Tk, model: Model, fonts=(None, None)):
        self.model = model

        # first row - address bar + buttons
@@ -128,19 +128,34 @@ class View:
        text = ReadOnlyText(row2, wrap="word")
        self.text = text
        self.render_page()
        text_font = pick_font(
            [
                "Charis SIL",
                "Source Serif Pro",
                "Cambria",
                "Georgia",
                "DejaVu Serif",
                "Times New Roman",
                "Times",
                "TkTextFont",
            ]
        )
        mono_font = pick_font(["Ubuntu Mono", "Consolas", "Courier", "TkFixedFont"])
        if fonts[0] is None:
            text_font = pick_font(
                [
                    "Charis SIL",
                    "Source Serif Pro",
                    "Cambria",
                    "Georgia",
                    "DejaVu Serif",
                    "Times New Roman",
                    "Times",
                    "TkTextFont",
                ]
            )
        else:
            text_font = fonts[0]

        if fonts[1] is None:
            mono_font = pick_font(
                [
                    "Ubuntu Mono",
                    "Consolas",
                    "Courier",
                    "TkFixedFont"
                ]
            )
        else:
            mono_font = fonts[1]

        text.config(
            font=(text_font, 13),
            bg="#fff8dc",
-- 
2.26.2