Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating bigclock with RGB color pickers #668

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 72 additions & 25 deletions apps/bigclock/big_clock.star
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Author: Joey Hoer

load("render.star", "render")
load("schema.star", "schema")
load("math.star", "math")
load("re.star", "re")
load("time.star", "time")
load("sunrise.star", "sunrise")
load("encoding/base64.star", "base64")
Expand All @@ -24,8 +26,16 @@ DEFAULT_TIMEZONE = "US/Eastern"
DEFAULT_IS_24_HOUR_FORMAT = True
DEFAULT_HAS_LEADING_ZERO = False
DEFAULT_HAS_FLASHING_SEPERATOR = True
DEFAULT_COLOR_DAYTIME = "#fff" # White
DEFAULT_COLOR_NIGHTTIME = "#fff" # White

# White
DEFAULT_COLOR_RED_DAYTIME = "255"
DEFAULT_COLOR_GREEN_DAYTIME = "255"
DEFAULT_COLOR_BLUE_DAYTIME = "255"

# Red
DEFAULT_COLOR_RED_NIGHTTIME = "255"
DEFAULT_COLOR_GREEN_NIGHTTIME = "0"
DEFAULT_COLOR_BLUE_NIGHTTIME = "0"

# Constants
TTL = 21600 # 6 hours
Expand Down Expand Up @@ -77,7 +87,9 @@ iVBORw0KGgoAAAANSUhEUgAAAAQAAAAOAQAAAAAgEYC1AAAAAnRSTlMAAQGU/a4AAAAPSURBVHgBY0g
AQzQAEQUAH5wCQbfIiwYAAAAASUVORK5CYII=
""")

DEGREE = 0.01745329251
# Convert RGB tuple to hex
def rgb_to_hex(r, g, b):
return "#" + str("%x" % ((1 << 24) + (r << 16) + (g << 8) + b))[1:]

# It would be easier to use a custom font, but we can use images instead.
# The images have a black background and transparent foreground. This
Expand Down Expand Up @@ -150,8 +162,18 @@ def main(config):
is_24_hour_format = config.bool("is_24_hour_format", DEFAULT_IS_24_HOUR_FORMAT)
has_leading_zero = config.bool("has_leading_zero", DEFAULT_HAS_LEADING_ZERO)
has_flashing_seperator = config.bool("has_flashing_seperator", DEFAULT_HAS_FLASHING_SEPERATOR)
color_daytime = config.get("color_daytime", DEFAULT_COLOR_DAYTIME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit over half of all installations of big-clock are using a non-default value for color_daytime or color_nighttime. It would be great if we could make this change backwards compatible so that these installations continue to function as before.

Copy link
Contributor Author

@joeyhoer joeyhoer Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also a bit concerned about backwards compatibility, and I agree that most users will find the RGB values confusing. I was actually considering using HSL instead, as that's a little easier to understand, but ultimately decided against it.

I could not think of a way to support both the selector and the default color, unless the user types in a hex value — but again, that would require input validation.

I believe the best solution here is a color picker schema.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Color picker schema would be great. It's just a matter of finding the time to build it out. Lot of other priorities as always. =(

For backwards compatibility, the app should still receive the color_daytime parameter for existing installations (even when it's been removed from get_schema()), so it'd just be a matter of checking for that field first (with the same default) and then letting the new RGB parameters override it.

Copy link
Contributor Author

@joeyhoer joeyhoer Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Receive via a config.get("color_daytime"?

What happens in the future, when you implement a color picker, and then we need to revert back to color_daytime and people have the RGB values stored?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should still be passed the same way for older installations.

When there's a colorpicker field, you'd need to introduce a new field ID, like colors_daytime_rgb, to keep backwards compatibility.

Copy link
Contributor Author

@joeyhoer joeyhoer Sep 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the RGB values are not intuitive, and there would be more complexity switching back and forth between the various methods to achieve backwards compatibility, I think it would be best to wait until there is an official colorpicker schema.

I'm going to close the pull request, and hopefully we can come back to this at a later date. Thanks!

color_nighttime = config.get("color_nighttime", DEFAULT_COLOR_NIGHTTIME)

# Set daytime color
color_red_daytime = config.get("color_red_daytime", DEFAULT_COLOR_RED_DAYTIME)
color_green_daytime = config.get("color_green_daytime", DEFAULT_COLOR_GREEN_DAYTIME)
color_blue_daytime = config.get("color_blue_daytime", DEFAULT_COLOR_BLUE_DAYTIME)
color_daytime = rgb_to_hex(int(color_red_daytime), int(color_green_daytime), int(color_blue_daytime))

# Set nighttime color
color_red_nighttime = config.get("color_red_nighttime", DEFAULT_COLOR_RED_NIGHTTIME)
color_green_nighttime = config.get("color_green_nighttime", DEFAULT_COLOR_GREEN_NIGHTTIME)
color_blue_nighttime = config.get("color_blue_nighttime", DEFAULT_COLOR_BLUE_NIGHTTIME)
color_nighttime = rgb_to_hex(int(color_red_nighttime), int(color_green_nighttime), int(color_blue_nighttime))

frames = []
print_time = current_time
Expand Down Expand Up @@ -202,16 +224,9 @@ def main(config):
)

def get_schema():
colors = [
schema.Option(display = "White", value = "#fff"),
schema.Option(display = "Red", value = "#f00"),
schema.Option(display = "Dark Red", value = "#200"),
schema.Option(display = "Green", value = "#0f0"),
schema.Option(display = "Blue", value = "#00f"),
schema.Option(display = "Yellow", value = "#ff0"),
schema.Option(display = "Cyan", value = "#0ff"),
schema.Option(display = "Magenta", value = "#f0f"),
]
zeroTo255 = []
for n in range(256):
zeroTo255.append(schema.Option(display = str(n), value = str(n)))

return schema.Schema(
version = "1",
Expand Down Expand Up @@ -244,20 +259,52 @@ def get_schema():
default = DEFAULT_HAS_FLASHING_SEPERATOR,
),
schema.Dropdown(
id = "color_daytime",
id = "color_red_daytime",
icon = "sun",
name = "Daytime red RGB value",
desc = "The red RGB color value to use during daytime.",
options = zeroTo255,
default = DEFAULT_COLOR_RED_DAYTIME,
),
schema.Dropdown(
id = "color_green_daytime",
icon = "sun",
name = "Daytime green RGB value",
desc = "The green RGB color value to use during daytime.",
options = zeroTo255,
default = DEFAULT_COLOR_GREEN_DAYTIME,
),
schema.Dropdown(
id = "color_blue_daytime",
icon = "sun",
name = "Daytime color",
desc = "The color to display in the daytime.",
options = colors,
default = DEFAULT_COLOR_DAYTIME,
name = "Daytime blue RGB value",
desc = "The blue RGB color value to use during daytime.",
options = zeroTo255,
default = DEFAULT_COLOR_BLUE_DAYTIME,
),
schema.Dropdown(
id = "color_red_nighttime",
icon = "moon",
name = "Nighttime red RGB value",
desc = "The red RGB color value to use during nighttime.",
options = zeroTo255,
default = DEFAULT_COLOR_RED_NIGHTTIME,
),
schema.Dropdown(
id = "color_green_nighttime",
icon = "moon",
name = "Nighttime green RGB value",
desc = "The green RGB color value to use during nighttime.",
options = zeroTo255,
default = DEFAULT_COLOR_GREEN_NIGHTTIME,
),
schema.Dropdown(
id = "color_nighttime",
id = "color_blue_nighttime",
icon = "moon",
name = "Nighttime color",
desc = "The color to display at night.",
options = colors,
default = DEFAULT_COLOR_NIGHTTIME,
name = "Nighttime blue RGB value",
desc = "The blue RGB color value to use during nighttime.",
options = zeroTo255,
default = DEFAULT_COLOR_BLUE_NIGHTTIME,
),
],
)