Skip to content

Commit

Permalink
5.7.0 - Add light/dark support
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Oct 17, 2024
1 parent 18716c9 commit 77cc9e4
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=runtimepy version=5.6.4
repo=runtimepy version=5.7.0
if: |
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.4
hash=41c5a2511c80b2cbbaee668bb6a75bd2
hash=aa59dcef7f11c767458b14ad97f9de59
=====================================
-->

# runtimepy ([5.6.4](https://pypi.org/project/runtimepy/))
# runtimepy ([5.7.0](https://pypi.org/project/runtimepy/))

[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
![Build Status](https://github.com/vkottler/runtimepy/workflows/Python%20Package/badge.svg)
Expand Down
4 changes: 2 additions & 2 deletions local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 5
minor: 6
patch: 4
minor: 7
patch: 0
entry: runtimepy
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "runtimepy"
version = "5.6.4"
version = "5.7.0"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.11"
Expand Down
4 changes: 2 additions & 2 deletions runtimepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=beefe82269955725f177c01474f7cea1
# hash=c51f4ac6cf134b3c3fa872a096e83489
# =====================================

"""
Expand All @@ -10,7 +10,7 @@

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "5.6.4"
VERSION = "5.7.0"

# runtimepy-specific content.
METRICS_NAME = "metrics"
Expand Down
15 changes: 12 additions & 3 deletions runtimepy/data/css/bootstrap_extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,17 @@ textarea.text-logs {
padding-bottom: 0 !important;

border-top: 0;
background-color: var(--bs-secondary-bg-subtle);
}

.vertical-divider {
flex-basis: 0.75em;
flex-grow: 0;
flex-shrink: 0;
background-color: var(--bs-secondary-bg-subtle);
}

.vertical-divider:hover {
cursor: col-resize;
background-color: var(--bs-secondary-bg);
background-color: var(--bs-highlight-bg) !important;
}

button:hover {
Expand All @@ -99,3 +97,14 @@ button:hover {
.channel-value-input {
width: 6em;
}

/*
* Should probably build the bootstrap stuff from source and set custom Sass:
* https://getbootstrap.com/docs/5.3/customize/sass/
*/

:root {
/* Prefer 'Arial' and 'Consolas' at the highest priority. */
--bs-font-sans-serif: Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
--bs-font-monospace: Consolas, "Liberation Mono", "Courier New", monospace;
}
1 change: 0 additions & 1 deletion runtimepy/data/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ body > :first-child {
width: 100vw;
height: 100vh;
opacity: 1.0;
background-color: var(--bs-secondary-bg-subtle);
}

.click-plot {
Expand Down
36 changes: 29 additions & 7 deletions runtimepy/data/js/classes/WindowHashManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WindowHashManager {
this.tabFilter = "";
this.tabsShown = true;
this.channelsShown = true;
this.lightMode = false;
this.plotChannels = {};
this.filters = {};
this.minTxPeriod = 0.0;
Expand All @@ -17,6 +18,15 @@ class WindowHashManager {
this.update();
}

lightDarkClick(event) {
this.lightMode = !this.lightMode;

document.getElementById("runtimepy")
.setAttribute("data-bs-theme", this.lightMode ? "light" : "dark");

this.update();
}

channelClick(event) {
this.channelsShown = !this.channelsShown;

Expand Down Expand Up @@ -106,6 +116,12 @@ class WindowHashManager {
channelsButton.addEventListener("click", this.channelClick.bind(this));
}

/* Click handler for light/dark toggle. */
let lightDarkButton = document.getElementById("theme-button");
if (lightDarkButton) {
lightDarkButton.addEventListener("click", this.lightDarkClick.bind(this));
}

/* Click handlers for new window buttons. */
for (const button of document.querySelectorAll(".window-button")) {
button.onclick = () => {
Expand Down Expand Up @@ -150,13 +166,6 @@ class WindowHashManager {
}
}

if (split.includes("hide-tabs")) {
tabButton.click();
}
if (split.includes("hide-channels")) {
channelsButton.click();
}

/* Check for tab filter. */
for (let item of split) {
if (item.includes("=")) {
Expand All @@ -171,6 +180,16 @@ class WindowHashManager {
}
}
}

if (split.includes("hide-tabs")) {
tabButton.click();
}
if (split.includes("hide-channels")) {
channelsButton.click();
}
if (split.includes("light-mode")) {
lightDarkButton.click();
}
}
}

Expand Down Expand Up @@ -199,6 +218,9 @@ class WindowHashManager {
if (!this.channelsShown) {
hash += ",hide-channels"
}
if (this.lightMode) {
hash += ",light-mode";
}

if (this.minTxPeriod != 0.0) {
hash += `,min-tx-period-ms=${this.minTxPeriod}`;
Expand Down
2 changes: 1 addition & 1 deletion runtimepy/net/server/app/bootstrap/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def centered_markdown(
div(
text=stream.getvalue(),
parent=horiz_container,
class_str="text-light p-3 pb-0",
class_str="text-body p-3 pb-0",
)

div(parent=horiz_container)
Expand Down
15 changes: 12 additions & 3 deletions runtimepy/net/server/app/bootstrap/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

# internal
from runtimepy import PKG_NAME
from runtimepy.net.server.app.bootstrap import icon_str
from runtimepy.net.server.app.bootstrap.elements import (
BOOTSTRAP_BUTTON,
bootstrap_button,
collapse_button,
flex,
toggle_button,
Expand Down Expand Up @@ -85,16 +87,23 @@ def __init__(self, name: str, parent: Element) -> None:

# Create application container.
self.container = div(parent=parent, id=name)
self.container.add_class("d-flex", "align-items-start")
self.container.add_class("d-flex", "align-items-start", "bg-body")

# Dark theme.
self.container["data-bs-theme"] = "dark"
parent.add_class("bg-dark")

# Buttons.
self.button_column = div(parent=self.container)
self.button_column.add_class(
"d-flex", "flex-column", "h-100", "bg-secondary-subtle"
"d-flex", "flex-column", "h-100", "bg-dark-subtle"
)

# Dark/light theme switch button.
bootstrap_button(
icon_str("lightbulb"),
tooltip=" Toggle light/dark.",
id="theme-button",
parent=self.button_column,
)

# Toggle tabs button.
Expand Down
6 changes: 5 additions & 1 deletion runtimepy/net/server/app/env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ def channel_environments(app: AppInfo, tabs: TabbedContent) -> None:
)

# Add splash screen element.
div(id=f"{PKG_NAME}-splash", parent=tabs.container)
div(
id=f"{PKG_NAME}-splash",
parent=tabs.container,
class_str="bg-success-subtle bg-gradient",
)
2 changes: 1 addition & 1 deletion runtimepy/net/server/app/env/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(

content = div(
parent=div(
parent=modal, class_str="modal-dialog text-light " + TEXT
parent=modal, class_str="modal-dialog text-body " + TEXT
),
class_str="modal-content rounded-0",
)
Expand Down
4 changes: 2 additions & 2 deletions runtimepy/net/server/app/env/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def plot_settings(tabs: TabbedContent) -> None:
div(
text="0 ms ('high', run at native refresh rate)",
parent=container,
class_str="text-nowrap text-primary",
class_str="text-nowrap text-body-emphasis",
)

slider(
Expand All @@ -53,7 +53,7 @@ def plot_settings(tabs: TabbedContent) -> None:
div(
text="100 ms ('low', 10 Hz)",
parent=container,
class_str="text-nowrap text-primary",
class_str="text-nowrap text-body-emphasis",
)

div(tag="hr", parent=modal.body)
4 changes: 2 additions & 2 deletions runtimepy/net/server/app/env/tab/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def compose(self, parent: Element) -> None:
logs = div(
tag="textarea",
parent=div(parent=vert_container, class_str="form-floating"),
class_str=f"form-control rounded-0 {TEXT} text-logs",
class_str=(f"form-control rounded-0 {TEXT} text-logs"),
id=self.get_id("logs"),
title=f"Text logs for {self.name}.",
)
Expand All @@ -258,7 +258,7 @@ def compose(self, parent: Element) -> None:
div(
id=self.get_id("divider"),
parent=container,
class_str="vertical-divider border-start",
class_str="vertical-divider border-start bg-dark-subtle",
)

self._compose_plot(container)
2 changes: 1 addition & 1 deletion runtimepy/net/server/app/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DummyTab(Tab):
def compose(self, parent: Element) -> None:
"""Compose the tab's HTML elements."""

parent.add_class("text-light")
parent.add_class("text-body")

for idx in range(10):
div(parent=parent, text="Hello, world! " + str(idx))
Expand Down
2 changes: 1 addition & 1 deletion runtimepy/net/server/app/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SoundTab(Tab):
def compose(self, parent: Element) -> None:
"""Compose the tab's HTML elements."""

container = div(parent=parent, class_str="text-light")
container = div(parent=parent, class_str="text-body")

div(text="Hello, world! 1", parent=container)
div(text="Hello, world! 2", parent=container)
Expand Down
2 changes: 1 addition & 1 deletion runtimepy/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiofiles
vcorelib>=3.4.1
vcorelib>=3.4.2
svgen>=0.6.8
websockets
psutil
Expand Down

0 comments on commit 77cc9e4

Please sign in to comment.