~nhanb/mcross

3e25052f06835a8f2038c4d4e2a694a25f399b35 — Frederick Yin 11 months ago 1f36198
Add CLI arguments to pick custom fonts

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
2 files changed, 39 insertions(+), 15 deletions(-)

M src/mcross/gui/controller.py
M src/mcross/gui/view.py
M src/mcross/gui/controller.py => src/mcross/gui/controller.py +10 -1
@@ 2,6 2,7 @@ import logging
import threading
import time
import traceback
import argparse
from ssl import SSLCertVerificationError
from tkinter import READABLE, Tk, messagebox



@@ 19,13 20,21 @@ 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.root.alt_shortcuts = set()
        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")


M src/mcross/gui/view.py => src/mcross/gui/view.py +29 -14
@@ 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


@@ 142,19 142,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",