Repos / mcross / 3e25052f06
commit 3e25052f06835a8f2038c4d4e2a694a25f399b35
Author: Frederick Yin <fkfd@macaw.me>
Date:   Sun May 31 14:52:03 2020 +0800

    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

diff --git a/src/mcross/gui/controller.py b/src/mcross/gui/controller.py
index 3c90421..0a8fa8a 100644
--- a/src/mcross/gui/controller.py
+++ b/src/mcross/gui/controller.py
@@ -2,6 +2,7 @@
 import threading
 import time
 import traceback
+import argparse
 from ssl import SSLCertVerificationError
 from tkinter import READABLE, Tk, messagebox
 
@@ -19,13 +20,21 @@
 
 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")
 
diff --git a/src/mcross/gui/view.py b/src/mcross/gui/view.py
index 0bc57da..ddea0bb 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
@@ -142,19 +142,34 @@ def on_ctrl_l(ev):
         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",