Skip to content

Commit

Permalink
3.12.0 - Initial functional UI features
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Apr 2, 2024
1 parent a5f5462 commit acde51d
Show file tree
Hide file tree
Showing 19 changed files with 386 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=runtimepy version=3.11.3
repo=runtimepy version=3.12.0
if: |
matrix.python-version == '3.11'
&& 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=9985f72e34bdca8221f1d8d33ff6531a
hash=48f32e0cb1550ad416362e58fb185182
=====================================
-->

# runtimepy ([3.11.3](https://pypi.org/project/runtimepy/))
# runtimepy ([3.12.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: 3
minor: 11
patch: 3
minor: 12
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 = "3.11.3"
version = "3.12.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=4c241d22cd21592b757b41cc596fa46b
# hash=4978a703b8ecd45735226f67d3cd0bf1
# =====================================

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

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "3.11.3"
VERSION = "3.12.0"

# runtimepy-specific content.
METRICS_NAME = "metrics"
2 changes: 1 addition & 1 deletion runtimepy/channel/environment/command/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
self.hooks: list[CommandHook] = []

self.parser_data: dict[str, Any] = {}
self.parser = CommandParser()
self.parser = CommandParser(prog="")
self.parser.data = self.parser_data

self.parser.initialize()
Expand Down
4 changes: 4 additions & 0 deletions runtimepy/data/css/bootstrap_extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@
.collapse:not(.show) {
display: none !important;
}

select.form-select {
width: min-content;
}
60 changes: 53 additions & 7 deletions runtimepy/data/js/classes/TabInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class TabInterface {
this.name = name;
this.worker = new WorkerInterface(this.name, _worker);

/* Send an initialization message. */
this.worker.send({kind : "init"});

/* Relevant elements. */
this.container = document.getElementById("runtimepy-" + this.name);
this.logs = this.query("#" + this.name + "-logs");
Expand All @@ -25,22 +28,60 @@ class TabInterface {
shown_tab = this.name;
}
this.worker.send({kind : msg});

/* Could remove this. */
this.log(msg);
} ];

/* Plot related. */
this.initPlot();
this.initCommand();
this.initControls();
this.initButton();
}

initCommand() {
let command = this.query("#" + this.name + "-command")
if (command) {
command.onkeypress = (event) => {
if (event.key == "Enter") {
let cmd = event.target.value.trim();

if (cmd == "cls" || cmd == "clear") {
this.clearLog();
} else {
this.command(cmd);
}

event.target.value = "";
}
};
}
}

command(data) { this.worker.send({kind : "command", value : data}); }

initControls() {
/* Initialize enumeration command drop downs. */
for (let enums of this.queryAll("select")) {
enums.onchange =
(() => { this.command(`set ${enums.id} ${enums.value}`); })
.bind(this);
}

/* Initialize toggle buttons. */
for (let toggle of this.queryAll("td>button")) {
toggle.onclick =
(() => { this.command(`toggle ${toggle.id}`); }).bind(this);
}
}

initPlot() {
let plot = this.query("#" + this.name + "-plot");
if (plot) {
this.plot = new Plot(plot, this.worker);
this.show_state_handlers.push(this.plot.handle_shown.bind(this.plot));
}

this.initButton();
}

query(data) { return this.container.querySelector(data); }
queryAll(data) { return this.container.querySelectorAll(data); }

initButton() {
let button = document.getElementById("runtimepy-" + this.name + "-tab");
Expand All @@ -52,12 +93,13 @@ class TabInterface {
}

log(message) {
console.log(`(${this.name}) ` + message);
if (this.logs) {
this.logs.value += message + "\n";
}
}

clearLog() { this.logs.value = ""; }

show_state_handler(is_shown) {
for (const handler of this.show_state_handlers) {
handler(is_shown);
Expand All @@ -69,6 +111,10 @@ class TabInterface {
hidden_handler() { this.show_state_handler(false); }

onmessage(data) {
if ("log_message" in data) {
this.log(data["log_message"]);
}

for (const handler of this.message_handlers) {
handler(data);
}
Expand Down
5 changes: 4 additions & 1 deletion runtimepy/net/server/app/bootstrap/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def collapse_button(
return collapse


def toggle_button(parent: Element) -> Element:
def toggle_button(parent: Element, **kwargs) -> Element:
"""Add a boolean-toggle button."""

return div(
Expand All @@ -77,6 +77,7 @@ def toggle_button(parent: Element) -> Element:
parent=parent,
title="toggle value",
class_str="btn " + BOOTSTRAP_BUTTON,
**kwargs,
)


Expand All @@ -85,6 +86,7 @@ def input_box(
label: str = "filter",
pattern: str = ".*",
description: str = None,
**kwargs,
) -> None:
"""Create command input box."""

Expand All @@ -103,5 +105,6 @@ def input_box(
parent=container,
name=label,
title=label + " input",
**kwargs,
)
box.add_class("form-control", "rounded-0", TEXT)
6 changes: 3 additions & 3 deletions runtimepy/net/server/app/env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def channel_environments(app: AppInfo, tabs: TabbedContent) -> None:
# Tab name filter.
input_box(tabs.tabs, label="tab", description="Tab name filter.")

# Sound tab.
SoundTab("sound", app, tabs, source="sound", icon="boombox").entry()

# Connection tabs.
for name, conn in app.connections.items():
ChannelEnvironmentTab(
Expand All @@ -36,6 +33,9 @@ def channel_environments(app: AppInfo, tabs: TabbedContent) -> None:
name, task.command, app, tabs, icon="arrow-repeat"
).entry()

# Sound tab.
SoundTab("sound", app, tabs, source="sound", icon="boombox").entry()

dummy_tabs(3, app, tabs)

# Toggle channel-table button.
Expand Down
25 changes: 25 additions & 0 deletions runtimepy/net/server/app/env/tab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
A module implementing a channel-environment tab HTML interface.
"""

# internal
from runtimepy.net.server.app.env.tab.html import ChannelEnvironmentTabHtml
from runtimepy.net.server.app.env.tab.message import (
ChannelEnvironmentTabMessaging,
)


class ChannelEnvironmentTab(
ChannelEnvironmentTabMessaging, ChannelEnvironmentTabHtml
):
"""A class aggregating all channel-environment tab interfaces."""

all_tabs: dict[str, "ChannelEnvironmentTab"] = {}

def init(self) -> None:
"""Initialize this instance."""

super().init()

# Update global mapping.
type(self).all_tabs[self.name] = self
28 changes: 28 additions & 0 deletions runtimepy/net/server/app/env/tab/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
A module implementing a channel-environment tab HTML interface.
"""

# internal
from runtimepy.channel.environment.command.processor import (
ChannelCommandProcessor,
)
from runtimepy.net.arbiter.info import AppInfo
from runtimepy.net.server.app.bootstrap.tabs import TabbedContent
from runtimepy.net.server.app.tab import Tab


class ChannelEnvironmentTabBase(Tab):
"""A channel-environment tab interface."""

def __init__(
self,
name: str,
command: ChannelCommandProcessor,
app: AppInfo,
tabs: TabbedContent,
icon: str = "alarm",
) -> None:
"""Initialize this instance."""

self.command = command
super().__init__(name, app, tabs, source="env", icon=icon)
Loading

0 comments on commit acde51d

Please sign in to comment.