Skip to content

Commit

Permalink
Merge pull request #266 from JohnStrunk/bg-bright
Browse files Browse the repository at this point in the history
Add ability to customize the brightness of the background image
  • Loading branch information
mergify[bot] authored May 12, 2023
2 parents af33e1a + 2ee313a commit bbcdb29
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 26 deletions.
13 changes: 7 additions & 6 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ Title
other information.
Text spacing
This controls the amount of vertical space between lines of text.

Text colors can be customized by clicking on the color swatches and choosing a
new color.

A background image can be inserted using the "Import..." button. The
background image should be a 1280x720 PNG image.
Text colors
The colors can be customized by clicking on the color swatches and choosing
a new color.
Background image
A background image can be inserted using the "Import..." button. The image
should be a 1280x720 PNG image. Once imported, the "image brightness"
adjustment can be used to dim the image if it is too bright.

-----

Expand Down
Binary file modified docs/media/wr-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 36 additions & 19 deletions main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def _appearance(self, parent: Widget) -> Widget:
colorframe.pack(side="top", fill="x")
colorframe.columnconfigure(1, weight=1)
colorframe.columnconfigure(3, weight=1)
colorframe.columnconfigure(5, weight=1)
# 1st col
ttk.Label(colorframe, text="Heading:", anchor="e").grid(
column=0, row=0, sticky="news"
Expand All @@ -219,18 +220,6 @@ def _appearance(self, parent: Widget) -> Widget:
widgets.ColorButton2(colorframe, color_var=self._vm.color_event).grid(
column=1, row=1, sticky="nws", pady=_PADDING
)
ttk.Label(colorframe, text="Odd rows:", anchor="e").grid(
column=0, row=2, sticky="news"
)
widgets.ColorButton2(colorframe, color_var=self._vm.color_odd).grid(
column=1, row=2, sticky="nws", pady=_PADDING
)
ttk.Label(colorframe, text="Even rows:", anchor="e").grid(
column=0, row=3, sticky="news"
)
widgets.ColorButton2(colorframe, color_var=self._vm.color_even).grid(
column=1, row=3, sticky="nws", pady=_PADDING
)
# 2nd col
ttk.Label(colorframe, text="1st place:", anchor="e").grid(
column=2, row=0, sticky="news"
Expand All @@ -250,32 +239,60 @@ def _appearance(self, parent: Widget) -> Widget:
widgets.ColorButton2(colorframe, color_var=self._vm.color_third).grid(
column=3, row=2, sticky="nws", pady=_PADDING
)
# 3rd col
ttk.Label(colorframe, text="Odd rows:", anchor="e").grid(
column=4, row=0, sticky="news"
)
widgets.ColorButton2(colorframe, color_var=self._vm.color_odd).grid(
column=5, row=0, sticky="nws", pady=_PADDING
)
ttk.Label(colorframe, text="Even rows:", anchor="e").grid(
column=4, row=1, sticky="news"
)
widgets.ColorButton2(colorframe, color_var=self._vm.color_even).grid(
column=5, row=1, sticky="nws", pady=_PADDING
)
ttk.Label(colorframe, text="Background:", anchor="e").grid(
column=2, row=3, sticky="news"
column=4, row=2, sticky="news"
)
widgets.ColorButton2(colorframe, color_var=self._vm.color_bg).grid(
column=3, row=3, sticky="nws", pady=_PADDING
column=5, row=2, sticky="nws", pady=_PADDING
)

ttk.Separator(mainframe, orient=HORIZONTAL).pack(side="top", fill="x", pady=10)

bgframelabels = ttk.Frame(mainframe)
bgframelabels.pack(side="top", fill="x")
ttk.Label(bgframelabels, text="Background image:", anchor="e").pack(
side="left", fill="both"
bgframelabels.columnconfigure(1, weight=1)
ttk.Label(bgframelabels, text="Image brightness:", anchor="e").grid(
column=0, row=0, sticky="news"
)
bg_bgight_spin = ttk.Spinbox(
bgframelabels,
from_=0,
to=100,
increment=5,
width=4,
textvariable=self._vm.brightness_bg,
)
bg_bgight_spin.grid(column=1, row=0, sticky="nws", pady=_PADDING)
ToolTip(bg_bgight_spin, "Brightness of the background image (percent: 0-100)")
ttk.Label(bgframelabels, text="Background image:", anchor="e").grid(
column=0, row=1, sticky="news"
)
self._bg_img_label = StringVar()
ttk.Label(
bg_img_label = ttk.Label(
bgframelabels, textvariable=self._bg_img_label, anchor="w", relief="sunken"
).pack(side="left", fill="both", expand=1)
)
bg_img_label.grid(column=1, row=1, sticky="news")
ToolTip(bg_img_label, "Scoreboard background image - Recommended: 1280x720")
self._vm.image_bg.trace_add(
"write",
lambda *_: self._bg_img_label.set(
os.path.basename(self._vm.image_bg.get())[-20:]
),
)
self._vm.image_bg.set(self._vm.image_bg.get())
ToolTip(bgframelabels, "Scoreboard background image - Recommended: 1280x720")

bgframebtns = ttk.Frame(mainframe)
bgframebtns.pack(side="top", fill="x")
Expand Down
5 changes: 4 additions & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Model: # pylint: disable=too-many-instance-attributes,too-few-public-meth

def __init__(self, root: Tk):
self.root = root
self._event_queue: queue.Queue[Callable[[], None]] = queue.Queue(0)
self._event_queue: queue.Queue[Callable[[], None]] = queue.Queue()
root.bind(self._ENQUEUE_EVENT, self._dispatch_event)

########################################
Expand Down Expand Up @@ -149,6 +149,7 @@ def __init__(self, root: Tk):
self.color_second = StringVar()
self.color_third = StringVar()
self.color_bg = StringVar()
self.brightness_bg = IntVar()
# features
self.num_lanes = IntVar()
self.min_times = IntVar()
Expand Down Expand Up @@ -195,6 +196,7 @@ def load(self, filename: str) -> None:
self.color_second.set(data.get("color_second", self.PANTONE200_RED))
self.color_third.set(data.get("color_third", self.PANTONE4505FLATGOLD))
self.color_bg.set(data.get("color_bg", self.BLACK))
self.brightness_bg.set(data.getint("brightness_bg", 100))
self.num_lanes.set(data.getint("num_lanes", 10))
self.min_times.set(data.getint("min_times", 2))
self.time_threshold.set(data.getfloat("time_threshold", 0.30))
Expand Down Expand Up @@ -227,6 +229,7 @@ def save(self, filename: str) -> None:
"color_second": self.color_second.get(),
"color_third": self.color_third.get(),
"color_bg": self.color_bg.get(),
"brightness_bg": str(self.brightness_bg.get()),
"num_lanes": str(self.num_lanes.get()),
"min_times": str(self.min_times.get()),
"time_threshold": str(self.time_threshold.get()),
Expand Down
5 changes: 5 additions & 0 deletions scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sentry_sdk
from matplotlib import font_manager # type: ignore
from PIL import Image, ImageDraw, ImageFont, UnidentifiedImageError
from PIL.ImageEnhance import Brightness

from model import Model
from racetimes import RaceTimes, RawTime
Expand Down Expand Up @@ -107,6 +108,10 @@ def _add_bg_image(self) -> None:
bg_image = bg_image.resize(self.size, Image.BICUBIC)
# Make sure the image modes match
bg_image = bg_image.convert("RGBA")
# Adjust the image brightness
bg_image = Brightness(bg_image).enhance(
float(self._model.brightness_bg.get()) / 100.0
)
# Overlay it, respecting the alpha channel
self._img.alpha_composite(bg_image)
except FileNotFoundError:
Expand Down
1 change: 1 addition & 0 deletions wahoo_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def update_preview() -> None:
model.color_second,
model.color_third,
model.color_bg,
model.brightness_bg,
model.num_lanes,
]:
element.trace_add("write", lambda *_: update_preview())
Expand Down

0 comments on commit bbcdb29

Please sign in to comment.