~nhanb/mcross-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
5 2

[PATCH] Dark mode

Details
Message ID
<20200614124645.6225-1-fkfd@macaw.me>
DKIM signature
missing
Download raw message
Patch: +9 -6
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 = argparse.ArgumentParser()
    argparser.add_argument("--textfont")
    argparser.add_argument("--monofont")
    argparser.add_argument("--dark", action="store_true")
    args = argparser.parse_args()

    # 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 = Tk()
        self.root.alt_shortcuts = set()
        self.model = Model()
        self.view = View(self.root, self.model, fonts=(args.textfont, args.monofont))
        self.view = View(
            self.root, self.model, fonts=(args.textfont, args.monofont), dark=args.dark
        )
        self.root.title("McRoss Browser")
        self.root.geometry("800x600")

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

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

        # first row - address bar + buttons
@@ -165,8 +165,8 @@ class View:

        text.config(
            font=(text_font, 13),
            bg="#fff8dc",
            fg="black",
            bg="#212121" if dark else "#fff8dc",
            fg="#eee" if dark else "black",
            padx=5,
            pady=5,
            # hide blinking insertion cursor:
@@ -176,12 +176,12 @@ class View:
            height=1,
        )
        text.pack(side="left", fill="both", expand=True)
        text.tag_config("link", foreground="brown")
        text.tag_config("link", foreground="#ff8a65" if dark else "brown")
        text.tag_bind("link", "<Enter>", self._on_link_enter)
        text.tag_bind("link", "<Leave>", self._on_link_leave)
        text.tag_bind("link", "<Button-1>", self._on_link_click)
        text.tag_config("pre", font=(mono_font, 13))
        text.tag_config("listitem", foreground="#044604")
        text.tag_config("listitem", foreground="#64c664" if dark else "#044604")

        base_heading_font = font.Font(font=text["font"])
        base_heading_font.config(weight="bold")
-- 
2.27.0
Details
Message ID
<62240890-0969-db1b-55c3-6e952b7fb257@imnhan.com>
In-Reply-To
<20200614124645.6225-1-fkfd@macaw.me> (view parent)
DKIM signature
missing
Download raw message
Looks good to me. Merging it now, thanks!

However you probably shouldn't put too much effort into cosmetic 
personalization for now, since I plan to implement some sort of conf 
file / cli arg configuration scheme which will be more granular
(--h1-font, --h1-color, --list-size etc.)
Details
Message ID
<79E3AF0E-0CF0-47A7-9579-FC21BF915318@macaw.me>
In-Reply-To
<62240890-0969-db1b-55c3-6e952b7fb257@imnhan.com> (view parent)
DKIM signature
missing
Download raw message
On June 16, 2020 6:38:00 AM UTC, "Bùi Thành Nhân" <hi@imnhan.com> wrote:
>Looks good to me. Merging it now, thanks!
>
>However you probably shouldn't put too much effort into cosmetic 
>personalization for now, since I plan to implement some sort of conf 
>file / cli arg configuration scheme which will be more granular
>(--h1-font, --h1-color, --list-size etc.)

I'm not so keen on dumping all options into argparse; only the most frequently used, e.g. theme name. The rest go into the config file.

What will the format be? YAML, TOML, INI?

~fkfd
Details
Message ID
<42f45be8-caa1-0339-44ee-1a59416e2e7e@imnhan.com>
In-Reply-To
<62240890-0969-db1b-55c3-6e952b7fb257@imnhan.com> (view parent)
DKIM signature
missing
Download raw message
 > What will the format be? YAML, TOML, INI?

I like TOML the most so most likely that.

The idea is to have a mechanism where you define an option once and it 
becomes available as both a CLI arg and a config item, for example 
defining an `h1-font` option should make the application first read from 
`--h1-font` CLI arg, then fall back to `ht-font` key in the TOML stored 
in, say, `$XDG_CONFIG_HOME/mcross/mcross.toml`.

It's not worth implementing 2 different sets of configuration options IMO.
Details
Message ID
<93D94DD9-1438-42F7-B85F-0EFBF80B1A93@macaw.me>
In-Reply-To
<42f45be8-caa1-0339-44ee-1a59416e2e7e@imnhan.com> (view parent)
DKIM signature
missing
Download raw message
On June 18, 2020 3:57:07 AM UTC, "Bùi Thành Nhân" <hi@imnhan.com> wrote:
> > What will the format be? YAML, TOML, INI?
>
>I like TOML the most so most likely that.
>
>The idea is to have a mechanism where you define an option once and it 
>becomes available as both a CLI arg and a config item, for example 
>defining an `h1-font` option should make the application first read
>from 
>`--h1-font` CLI arg, then fall back to `ht-font` key in the TOML stored
>
>in, say, `$XDG_CONFIG_HOME/mcross/mcross.toml`.

I'm fine with that. One thing I'm unsure about is whether we'll still be able to remain "simple but no simpler", if every node is customizable. I suggest we allow variations in font size (and prob weight) only, except for preformatted text.



~fkfd
Details
Message ID
<ef7bf6f1-3f48-869c-68b8-ed376da66717@imnhan.com>
In-Reply-To
<62240890-0969-db1b-55c3-6e952b7fb257@imnhan.com> (view parent)
DKIM signature
missing
Download raw message
 > still be able to remain "simple but no simpler", if every node is
 > customizable

Well my stance is that only constant values should be configurable, not 
custom behavior. As long as we stick to that the config module should 
add no extra complexity to the rest of the code base. For example,
`bg = 'black' if config.dark else 'white'` is custom logic, while
`bg = config.bg` is just a configurable constant. I'm aiming for the 
latter, so while the number of configurable values increases, the 
complexity is actually decreased.
Reply to thread Export thread (mbox)