panelworks 0.4.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. panelworks/__init__.py +6 -0
  2. panelworks/__main__.py +3 -0
  3. panelworks/_examples/arduino_bench/arduino_bench.ino +37 -0
  4. panelworks/_examples/arduino_bench.json +20 -0
  5. panelworks/_examples/arduino_bench.py +29 -0
  6. panelworks/_examples/cistern_mqtt.json +66 -0
  7. panelworks/_examples/cistern_mqtt.py +22 -0
  8. panelworks/_examples/gauges/logo.png +0 -0
  9. panelworks/_examples/gauges.json +25 -0
  10. panelworks/_examples/gauges.py +100 -0
  11. panelworks/_examples/hvac_console.json +423 -0
  12. panelworks/_examples/hvac_console.py +39 -0
  13. panelworks/_examples/led_panel/led_panel.ino +22 -0
  14. panelworks/_examples/led_panel.json +14 -0
  15. panelworks/_examples/led_panel.py +30 -0
  16. panelworks/_examples/n8n/panelworks-demo.workflow.json +89 -0
  17. panelworks/_examples/n8n_demo.json +106 -0
  18. panelworks/_examples/n8n_demo.py +23 -0
  19. panelworks/_examples/power_meter/meter_sim.py +112 -0
  20. panelworks/_examples/power_meter.json +31 -0
  21. panelworks/_examples/power_meter.py +67 -0
  22. panelworks/_examples/pumppanel.json +26 -0
  23. panelworks/_examples/pumppanel.py +76 -0
  24. panelworks/_examples/rack_status/agent/private.snmprec +31 -0
  25. panelworks/_examples/rack_status/agent/public.snmprec +31 -0
  26. panelworks/_examples/rack_status/agent_sim.py +57 -0
  27. panelworks/_examples/rack_status.json +45 -0
  28. panelworks/_examples/rack_status.py +73 -0
  29. panelworks/_examples/truck_scale/scale_sim.py +108 -0
  30. panelworks/_examples/truck_scale.json +249 -0
  31. panelworks/_examples/truck_scale.py +164 -0
  32. panelworks/_examples/truck_scale_log.json +32 -0
  33. panelworks/_examples/truck_scale_log.py +17 -0
  34. panelworks/assets/panelworks.ico +0 -0
  35. panelworks/assets/panelworks.png +0 -0
  36. panelworks/chart.py +245 -0
  37. panelworks/cli.py +78 -0
  38. panelworks/codeeditor.py +468 -0
  39. panelworks/data.py +387 -0
  40. panelworks/designer.py +2547 -0
  41. panelworks/gauge.py +268 -0
  42. panelworks/immediate.py +246 -0
  43. panelworks/make_exe.py +188 -0
  44. panelworks/mcp_bridge.py +415 -0
  45. panelworks/menus.py +257 -0
  46. panelworks/modbus.py +336 -0
  47. panelworks/mqtt.py +416 -0
  48. panelworks/picture.py +425 -0
  49. panelworks/polling.py +243 -0
  50. panelworks/runtime.py +1181 -0
  51. panelworks/serialport.py +421 -0
  52. panelworks/slider.py +100 -0
  53. panelworks/snmp.py +430 -0
  54. panelworks/updates.py +237 -0
  55. panelworks/util.py +259 -0
  56. panelworks/webhooks.py +179 -0
  57. panelworks/webview.py +647 -0
  58. panelworks-0.4.2.dist-info/METADATA +780 -0
  59. panelworks-0.4.2.dist-info/RECORD +63 -0
  60. panelworks-0.4.2.dist-info/WHEEL +5 -0
  61. panelworks-0.4.2.dist-info/entry_points.txt +4 -0
  62. panelworks-0.4.2.dist-info/licenses/LICENSE +21 -0
  63. panelworks-0.4.2.dist-info/top_level.txt +1 -0
panelworks/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """PanelWorks - draw a form in JSON, write event procedures in Python, and
2
+ drive every object live over MCP (agents) and MQTT (devices)."""
3
+
4
+ __version__ = "0.4.2"
5
+
6
+ from .runtime import Form, load_form, CONTROL_TYPES # noqa: F401,E402
panelworks/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from panelworks.cli import main
2
+
3
+ main()
@@ -0,0 +1,37 @@
1
+ // Companion sketch for examples/arduino_bench.json (PanelWorks Serial control).
2
+ // Sends one JSON line a second; obeys "LED ON" / "LED OFF" lines from the panel.
3
+ // Uno/Nano/ESP32: temperature from A0 (TMP36), light from A1 (LDR divider).
4
+
5
+ const int LED = LED_BUILTIN;
6
+ String cmd;
7
+
8
+ void setup() {
9
+ pinMode(LED, OUTPUT);
10
+ Serial.begin(115200);
11
+ }
12
+
13
+ void loop() {
14
+ static unsigned long last = 0;
15
+ if (millis() - last >= 1000) {
16
+ last = millis();
17
+ float volts = analogRead(A0) * 5.0 / 1023.0; // use 3.3 on an ESP32
18
+ float tempC = (volts - 0.5) * 100.0; // TMP36
19
+ int light = analogRead(A1);
20
+ Serial.print("{\"temp\":");
21
+ Serial.print(tempC, 1);
22
+ Serial.print(",\"light\":");
23
+ Serial.print(light);
24
+ Serial.println("}"); // println ends the line
25
+ }
26
+ while (Serial.available()) {
27
+ char c = Serial.read();
28
+ if (c == '\n') {
29
+ cmd.trim();
30
+ if (cmd == "LED ON") digitalWrite(LED, HIGH);
31
+ if (cmd == "LED OFF") digitalWrite(LED, LOW);
32
+ cmd = "";
33
+ } else {
34
+ cmd += c;
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "ArduinoBench",
3
+ "caption": "Arduino Bench (USB serial)",
4
+ "width": 380,
5
+ "height": 250,
6
+ "code": "arduino_bench.py",
7
+ "objects": {
8
+ "shpLink": {"type": "Shape", "FillColor": "red", "Left": 15, "Top": 18, "Width": 14, "Height": 14},
9
+ "lblLink": {"type": "Label", "Caption": "looking for the Arduino...", "Left": 35, "Top": 14, "Width": 330, "Height": 22},
10
+ "lblT": {"type": "Label", "Caption": "Temperature", "Left": 15, "Top": 50, "Width": 110, "Height": 22},
11
+ "lblTemp": {"type": "Label", "Caption": "--", "FontSize": 20, "FontBold": true, "Left": 130, "Top": 44, "Width": 120, "Height": 34},
12
+ "lblL": {"type": "Label", "Caption": "Light", "Left": 15, "Top": 95, "Width": 110, "Height": 22},
13
+ "pbLight": {"type": "ProgressBar", "Max": 1023, "Left": 130, "Top": 95, "Width": 230, "Height": 22},
14
+ "cmdOn": {"type": "CommandButton", "Caption": "LED On", "Left": 15, "Top": 140, "Width": 100, "Height": 32},
15
+ "cmdOff": {"type": "CommandButton", "Caption": "LED Off", "Left": 125, "Top": 140, "Width": 100, "Height": 32},
16
+ "lblLast": {"type": "Label", "Caption": "", "ForeColor": "#555555", "Left": 15, "Top": 190, "Width": 350, "Height": 22},
17
+ "Serial1": {"type": "Serial", "Port": "auto", "Settings": "115200,n,8,1",
18
+ "Fill": ["temp -> lblTemp.Caption", "light -> pbLight.Value"]}
19
+ }
20
+ }
@@ -0,0 +1,29 @@
1
+ # Event procedures for ArduinoBench.
2
+ # The Serial control's Fill property already copies "temp" and "light" from each
3
+ # JSON line into lblTemp and pbLight, so the code here is only for the extras.
4
+
5
+
6
+ def Serial1_Connected(f):
7
+ f.shpLink.FillColor = "lime green"
8
+ f.lblLink.Caption = f"Connected on {f.Serial1.DeviceName}"
9
+
10
+
11
+ def Serial1_Disconnected(f):
12
+ f.shpLink.FillColor = "red"
13
+ f.lblLink.Caption = "Unplugged - waiting for it to come back..."
14
+
15
+
16
+ def Serial1_Error(f, message):
17
+ f.lblLink.Caption = message
18
+
19
+
20
+ def Serial1_DataArrival(f, line):
21
+ f.lblLast.Caption = "Last line: " + line[:60]
22
+
23
+
24
+ def cmdOn_Click(f):
25
+ f.Serial1.Output = "LED ON"
26
+
27
+
28
+ def cmdOff_Click(f):
29
+ f.Serial1.Output = "LED OFF"
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "CisternMQTT",
3
+ "caption": "Cistern (MQTT)",
4
+ "width": 440,
5
+ "height": 330,
6
+ "code": "cistern_mqtt.py",
7
+ "mqtt": {
8
+ "broker": "localhost",
9
+ "port": 1883,
10
+ "prefix": "panelworks/cistern",
11
+ "mirror": true
12
+ },
13
+ "objects": {
14
+ "lblTitle": {"type": "Label", "Caption": "Cistern level", "FontBold": true,
15
+ "Left": 15, "Top": 12, "Width": 150, "Height": 22},
16
+ "shpNode": {"type": "Shape", "Shape": "Rectangle", "FillColor": "gray",
17
+ "Left": 395, "Top": 14, "Width": 16, "Height": 16,
18
+ "subscribe": {"FillColor": {"topic": "homestead/cistern/status",
19
+ "map": {"online": "lime green", "offline": "red"}}}},
20
+ "lblNode": {"type": "Label", "Caption": "node ?", "Alignment": "Right",
21
+ "Left": 290, "Top": 12, "Width": 100, "Height": 22,
22
+ "subscribe": {"Caption": {"topic": "homestead/cistern/status", "format": "node {}"}}},
23
+
24
+ "barLevel": {"type": "ProgressBar", "Max": 100,
25
+ "Left": 15, "Top": 38, "Width": 260, "Height": 22,
26
+ "subscribe": {"Value": {"topic": "homestead/cistern/level", "json": "level"}}},
27
+ "lblLevel": {"type": "Label", "Caption": "-- %",
28
+ "Left": 285, "Top": 38, "Width": 60, "Height": 22,
29
+ "subscribe": {"Caption": {"topic": "homestead/cistern/level", "json": "level",
30
+ "format": "{:.0f} %"}}},
31
+ "lblTemp": {"type": "Label", "Caption": "Water -- C",
32
+ "Left": 15, "Top": 64, "Width": 160, "Height": 20,
33
+ "subscribe": {"Caption": {"topic": "homestead/cistern/level", "json": "temp",
34
+ "format": "Water {:.1f} C"}}},
35
+
36
+ "shpPump": {"type": "Shape", "Shape": "Oval", "FillColor": "gray",
37
+ "Left": 375, "Top": 40, "Width": 36, "Height": 36,
38
+ "subscribe": {"FillColor": {"topic": "homestead/pump/state",
39
+ "map": {"ON": "lime green", "OFF": "gray", "*": "orange"}}}},
40
+ "lblPump": {"type": "Label", "Caption": "Pump ?", "Alignment": "Center",
41
+ "Left": 345, "Top": 80, "Width": 90, "Height": 20,
42
+ "subscribe": {"Caption": {"topic": "homestead/pump/state",
43
+ "map": {"ON": "running", "OFF": "stopped"}}}},
44
+
45
+ "lblSet": {"type": "Label", "Caption": "Fill to %",
46
+ "Left": 15, "Top": 98, "Width": 70, "Height": 24},
47
+ "txtSetpoint": {"type": "TextBox", "Text": "85",
48
+ "Left": 90, "Top": 98, "Width": 50, "Height": 24,
49
+ "subscribe": {"Text": {"topic": "homestead/cistern/setpoint", "twoWay": true}}},
50
+ "chkAuto": {"type": "CheckBox", "Caption": "Auto (node decides)",
51
+ "Left": 160, "Top": 98, "Width": 180, "Height": 24,
52
+ "subscribe": {"Value": {"topic": "homestead/pump/auto", "twoWay": true}}},
53
+
54
+ "cmdStart": {"type": "CommandButton", "Caption": "Start",
55
+ "Left": 15, "Top": 132, "Width": 90, "Height": 30,
56
+ "publish": {"Click": {"topic": "homestead/pump/cmd", "payload": "ON"}}},
57
+ "cmdStop": {"type": "CommandButton", "Caption": "Stop",
58
+ "Left": 115, "Top": 132, "Width": 90, "Height": 30,
59
+ "publish": {"Click": {"topic": "homestead/pump/cmd", "payload": "OFF"}}},
60
+
61
+ "lstLog": {"type": "ListBox", "Left": 15, "Top": 172, "Width": 410, "Height": 145},
62
+ "mqttMon": {"type": "MQTT", "Broker": "localhost", "Port": 1883,
63
+ "Subscriptions": ["homestead/pump/#", "homestead/cistern/setpoint",
64
+ "homestead/cistern/status"]}
65
+ }
66
+ }
@@ -0,0 +1,22 @@
1
+ # The panel's live values all come from "bind" entries in cistern_mqtt.json.
2
+ # This code only shows the other style: an MQTT control raising events.
3
+ import time
4
+
5
+
6
+ def mqttMon_Connected(f):
7
+ log(f, "MQTT monitor connected")
8
+
9
+
10
+ def mqttMon_Disconnected(f):
11
+ log(f, "MQTT monitor lost the broker")
12
+
13
+
14
+ def mqttMon_MessageArrived(f, topic, payload, retained):
15
+ if not retained: # skip the retained replay on connect
16
+ log(f, f"{topic} = {payload}")
17
+
18
+
19
+ def log(f, text):
20
+ f.lstLog.AddItem(time.strftime("%H:%M:%S ") + text, 0)
21
+ if f.lstLog.ListCount > 100:
22
+ f.lstLog.RemoveItem(100)
Binary file
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "Gauges",
3
+ "caption": "Pump Station - PictureBox demo",
4
+ "width": 620,
5
+ "height": 345,
6
+ "code": "gauges.py",
7
+ "objects": {
8
+ "picLogo": {"type": "PictureBox", "Picture": "gauges/logo.png", "BorderStyle": 0, "Left": 10, "Top": 8, "Width": 56, "Height": 56},
9
+ "lblTitle": {"type": "Label", "Caption": "Pump station", "FontSize": 16, "FontBold": true, "Left": 76, "Top": 12, "Width": 300, "Height": 28},
10
+ "lblSub": {"type": "Label", "Caption": "Both gauges are drawn in code. Click or drag the dial to set the alarm.", "FontSize": 9, "Left": 76, "Top": 42, "Width": 530, "Height": 18},
11
+ "picGauge": {"type": "PictureBox", "BackColor": "white", "FontSize": 9,
12
+ "ScaleLeft": -125, "ScaleTop": 125, "ScaleWidth": 250, "ScaleHeight": -250,
13
+ "Left": 15, "Top": 78, "Width": 250, "Height": 250},
14
+ "picTank": {"type": "PictureBox", "BackColor": "white", "FontSize": 9,
15
+ "ScaleLeft": 0, "ScaleTop": 110, "ScaleWidth": 100, "ScaleHeight": -122,
16
+ "Left": 280, "Top": 78, "Width": 120, "Height": 250},
17
+ "shpAlarm": {"type": "Shape", "FillColor": "gray", "Left": 420, "Top": 84, "Width": 26, "Height": 26},
18
+ "lblAlarm": {"type": "Label", "Caption": "Normal", "FontBold": true, "Left": 454, "Top": 86, "Width": 160, "Height": 22},
19
+ "lblSet": {"type": "Label", "Caption": "Alarm above 75 psi", "Left": 420, "Top": 124, "Width": 190, "Height": 22},
20
+ "lblPress": {"type": "Label", "Caption": "Pressure --", "Left": 420, "Top": 150, "Width": 190, "Height": 22},
21
+ "lblLevel": {"type": "Label", "Caption": "Tank --", "Left": 420, "Top": 174, "Width": 190, "Height": 22},
22
+ "chkRun": {"type": "CheckBox", "Caption": "Simulate readings", "Value": 1, "Left": 420, "Top": 212, "Width": 180, "Height": 24},
23
+ "tmrSim": {"type": "Timer", "Interval": 500, "Enabled": true}
24
+ }
25
+ }
@@ -0,0 +1,100 @@
1
+ # Event procedures for Gauges: a PictureBox demo.
2
+ #
3
+ # picGauge is scaled -125..125 both ways with y pointing up (ScaleHeight is
4
+ # negative), so the centre of the dial is (0, 0) and the usual sin/cos maths works.
5
+ # Angles are degrees, 0 = 3 o'clock, counter-clockwise. The dial runs from
6
+ # 225 degrees (0 psi, bottom left) round to -45 degrees (100 psi, bottom right).
7
+ import math
8
+ import random
9
+
10
+ FULL = 100 # psi at full scale
11
+ state = {"t": 0.0, "psi": 0.0, "level": 50.0, "alarm": 75.0}
12
+
13
+
14
+ def angle(value):
15
+ """Where a reading sits on the dial, in degrees."""
16
+ return 225 - 270 * max(0, min(FULL, value)) / FULL
17
+
18
+
19
+ def polar(r, a):
20
+ return r * math.cos(math.radians(a)), r * math.sin(math.radians(a))
21
+
22
+
23
+ def Form_Load(f):
24
+ f.picLogo.BackColor = f.BackColor # blend the logo into the form
25
+ draw_gauge(f)
26
+ draw_tank(f)
27
+
28
+
29
+ def tmrSim_Timer(f):
30
+ if not f.chkRun.Value:
31
+ return
32
+ s = state
33
+ s["t"] += 0.5
34
+ s["psi"] = 55 + 30 * math.sin(s["t"] / 6) + random.uniform(-2, 2)
35
+ s["level"] = 50 + 40 * math.sin(s["t"] / 25)
36
+ draw_gauge(f)
37
+ draw_tank(f)
38
+ high = s["psi"] > s["alarm"]
39
+ f.shpAlarm.FillColor = "red" if high else "lime green"
40
+ f.lblAlarm.Caption = "HIGH PRESSURE" if high else "Normal"
41
+ f.lblPress.Caption = f"Pressure {s['psi']:.1f} psi"
42
+ f.lblLevel.Caption = f"Tank {s['level']:.0f} %"
43
+
44
+
45
+ def draw_gauge(f):
46
+ g = f.picGauge
47
+ g.Cls()
48
+ g.Circle(0, 0, 100, "gray75", start=-45, end=225, width=10) # the scale band
49
+ g.Circle(0, 0, 100, "tomato", start=-45, end=angle(80), width=10) # red zone, 80-100
50
+ for v in range(0, FULL + 1, 5): # ticks
51
+ a = angle(v)
52
+ inner = 80 if v % 10 == 0 else 86
53
+ g.Line(*polar(inner, a), *polar(92, a), "gray20", width=2 if v % 10 == 0 else 1)
54
+ if v % 20 == 0:
55
+ g.Print(str(v), *polar(66, a), "gray20", anchor="center")
56
+ a = angle(state["alarm"]) # alarm setpoint marker
57
+ g.Polygon([polar(108, a - 4), polar(108, a + 4), polar(97, a)], "dark orange", fill=True)
58
+ a = angle(state["psi"]) # the needle
59
+ g.Polygon([polar(88, a), polar(7, a + 90), polar(18, a + 180), polar(7, a - 90)],
60
+ "firebrick", fill="red")
61
+ g.Circle(0, 0, 9, "gray20", fill="gray30")
62
+ g.FontSize = 18
63
+ g.FontBold = True
64
+ g.Print(f"{state['psi']:.0f}", 0, -48, "black", anchor="center")
65
+ g.FontSize = 9
66
+ g.FontBold = False
67
+ g.Print("psi", 0, -70, "gray40", anchor="center")
68
+
69
+
70
+ def draw_tank(f):
71
+ t = f.picTank
72
+ t.Cls()
73
+ level = max(0, min(100, state["level"]))
74
+ t.Line(10, 0, 66, level, box=True, fill="#3b82f6", color="#2563eb") # water
75
+ t.Line(10, 0, 66, 100, "gray30", box=True, width=2) # tank wall
76
+ for pct in (25, 50, 75):
77
+ t.Line(66, pct, 73, pct, "gray30")
78
+ t.Print(f"{pct}", 76, pct, "gray30", anchor="w")
79
+ t.Print(f"{level:.0f} %", 38, -2, "black", anchor="n")
80
+ t.Print("Tank", 38, 109, "gray30", anchor="n")
81
+
82
+
83
+ def set_alarm(f, x, y):
84
+ if math.hypot(x, y) < 30: # too close to the centre to aim
85
+ return
86
+ a = math.degrees(math.atan2(y, x))
87
+ if a < -90:
88
+ a += 360 # 225 degrees is down-left: keep the dial continuous
89
+ value = round((225 - a) / 270 * FULL)
90
+ state["alarm"] = max(0, min(FULL, value))
91
+ f.lblSet.Caption = f"Alarm above {state['alarm']:.0f} psi"
92
+ draw_gauge(f)
93
+
94
+
95
+ def picGauge_Click(f, x, y):
96
+ set_alarm(f, x, y)
97
+
98
+
99
+ def picGauge_MouseMove(f, x, y):
100
+ set_alarm(f, x, y) # MouseMove fires while the button is held: drag it