Skip to content
Draft
Show file tree
Hide file tree
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
1,585 changes: 0 additions & 1,585 deletions example-synoptic/b23-services/synoptic/techui-support/bob/pmac/MOTOR.bob

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<?xml version="1.0" encoding="UTF-8"?>
<display version="2.0.0">
<name>Main</name>
<width>205</width>
<height>120</height>
<grid_color>
<color red="127" green="127" blue="127">
</color>
</grid_color>
<widget type="group" version="2.0.0">
<name>$(M)</name>
<width>205</width>
<height>120</height>
<background_color>
<color name="Read_Background" red="240" green="240" blue="240">
</color>
</background_color>
<widget type="action_button" version="3.0.0">
<name>Tweak Left</name>
<actions>
<action type="write_pv">
<pv_name>$(pv_name)</pv_name>
<value>value</value>
<description>$(name)</description>
</action>
</actions>
<pv_name>$(P):$(M).TWR</pv_name>
<text>-</text>
<y>10</y>
<width>30</width>
<height>20</height>
<font>
<font family="Arial" style="REGULAR" size="12.0">
</font>
</font>
<foreground_color>
<color red="29" green="41" blue="69">
</color>
</foreground_color>
<background_color>
<color name="Background" red="255" green="255" blue="255">
</color>
</background_color>
<tooltip>$(tooltip)</tooltip>
</widget>
<widget type="action_button" version="3.0.0">
<name>Tweak Right</name>
<actions>
<action type="write_pv">
<pv_name>$(pv_name)</pv_name>
<value>value</value>
<description>$(name)</description>
</action>
</actions>
<pv_name>$(P):$(M).TWF</pv_name>
<text>+</text>
<x>140</x>
<y>10</y>
<width>30</width>
<height>20</height>
<font>
<font family="Arial" style="REGULAR" size="12.0">
</font>
</font>
<foreground_color>
<color red="29" green="41" blue="69">
</color>
</foreground_color>
<background_color>
<color name="Background" red="255" green="255" blue="255">
</color>
</background_color>
<tooltip>$(tooltip)</tooltip>
</widget>
<widget type="action_button" version="3.0.0">
<name>OpenDisplay</name>
<actions>
<action type="open_display">
<description>Open Display</description>
<file>{{url}}/{{p_lower}}/pmacAxis.pvi.bob</file>
<macros>
<M>:$(M)</M>
<P>$(P)</P>
</macros>
<target>tab</target>
</action>
</actions>
<text>More</text>
<y>60</y>
<width>40</width>
<height>20</height>
<font>
<font family="Arial" style="REGULAR" size="12.0">
</font>
</font>
<foreground_color>
<color red="255" green="255" blue="255">
</color>
</foreground_color>
<background_color>
<color red="29" green="41" blue="69">
</color>
</background_color>
<tooltip>$(actions)</tooltip>
</widget>
<widget type="action_button" version="3.0.0">
<name>WritePV_28</name>
<actions>
<action type="write_pv">
<pv_name>$(pv_name)</pv_name>
<value>value</value>
<description>$(name)</description>
</action>
</actions>
<pv_name>$(P):$(M).STOP</pv_name>
<text>STOP</text>
<x>130</x>
<y>60</y>
<width>40</width>
<height>20</height>
<font>
<font family="Arial" style="REGULAR" size="12.0">
</font>
</font>
<foreground_color>
<color red="29" green="41" blue="69">
</color>
</foreground_color>
<background_color>
<color name="Background" red="255" green="255" blue="255">
</color>
</background_color>
<tooltip>$(tooltip)</tooltip>
</widget>
<widget type="textentry" version="3.0.0">
<name>TextEntry_27</name>
<pv_name>$(P):$(M).TWV</pv_name>
<x>45</x>
<y>60</y>
<width>80</width>
<font>
<font family="Monospaced" style="REGULAR" size="12.0">
</font>
</font>
<background_color>
<color red="255" green="255" blue="255">
</color>
</background_color>
<horizontal_alignment>1</horizontal_alignment>
<border_width>1</border_width>
<border_color>
<color red="184" green="195" blue="223">
</color>
</border_color>
</widget>
<widget type="byte_monitor" version="2.0.0">
<name>Moving</name>
<pv_name>$(P):$(M).DMOV</pv_name>
<x>150</x>
<y>35</y>
<width>20</width>
<numBits>1</numBits>
<off_color>
<color red="29" green="41" blue="69">
</color>
</off_color>
<on_color>
<color name="Write_Background" red="128" green="255" blue="255">
</color>
</on_color>
<foreground_color>
<color red="76" green="100" blue="171">
</color>
</foreground_color>
</widget>
<widget type="byte_monitor" version="2.0.0">
<name>Serverity</name>
<pv_name>$(P):$(M).SEVR</pv_name>
<y>35</y>
<width>20</width>
<numBits>1</numBits>
<off_color>
<color red="29" green="41" blue="69">
</color>
</off_color>
<on_color>
<color name="Write_Background" red="128" green="255" blue="255">
</color>
</on_color>
<foreground_color>
<color red="76" green="100" blue="171">
</color>
</foreground_color>
</widget>
<widget type="textentry" version="3.0.0">
<name>PV</name>
<pv_name>$(P):$(M)</pv_name>
<x>35</x>
<y>10</y>
<font>
<font family="Monospaced" style="REGULAR" size="12.0">
</font>
</font>
<background_color>
<color red="255" green="255" blue="255">
</color>
</background_color>
<horizontal_alignment>1</horizontal_alignment>
<border_width>1</border_width>
<border_color>
<color red="184" green="195" blue="223">
</color>
</border_color>
</widget>
<widget type="textupdate" version="2.0.0">
<name>Readback PV</name>
<pv_name>$(P):$(M).RBV</pv_name>
<x>25</x>
<y>35</y>
<width>120</width>
<font>
<font family="Monospaced" style="REGULAR" size="12.0">
</font>
</font>
<foreground_color>
<color name="ActiveText" red="255" green="255" blue="0">
</color>
</foreground_color>
<background_color>
<color red="76" green="100" blue="171">
</color>
</background_color>
<horizontal_alignment>1</horizontal_alignment>
<vertical_alignment>1</vertical_alignment>
<border_color>
<color red="196" green="196" blue="196">
</color>
</border_color>
</widget>
</widget>
</display>
1 change: 1 addition & 0 deletions example/t01-services/synoptic/techui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ beamline:
short_dom: t01
long_dom: bl01t
desc: Test Beamline
url: t01-opis.diamond.ac.uk

components:
fshtr:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
"typer>=0.16.0",
"rich>=14.1.0",
"pydantic>=2.11.7",
"jinja2>=3.1.6",
]
scripts = { techui-builder = "techui_builder.__main__:app" }

Expand Down
18 changes: 2 additions & 16 deletions src/techui_builder/autofill.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import logging
import os
from collections import defaultdict
from dataclasses import dataclass, field
from pathlib import Path

from lxml import objectify
from lxml.objectify import ObjectifiedElement

from techui_builder import utils
from techui_builder.builder import Builder, _get_action_group
from techui_builder.models import Component
from techui_builder.utils import read_bob
Expand Down Expand Up @@ -46,20 +45,7 @@ def autofill_bob(self, gui: "Builder"):
child["run_actions_on_mouse_click"] = "true"

def write_bob(self, filename: Path):
# Check if data/ dir exists and if not, make it
data_dir = filename.parent
if not data_dir.exists():
os.mkdir(data_dir)

# Remove any unnecessary xmlns:py and py:pytype metadata from tags
objectify.deannotate(self.tree, cleanup_namespaces=True)

self.tree.write(
filename,
pretty_print=True,
encoding="utf-8",
xml_declaration=True,
)
utils.write_bob(self.tree, filename)
logger_.debug(f"Screen filled for {filename}")

def replace_content(
Expand Down
13 changes: 13 additions & 0 deletions src/techui_builder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
)
_LONG_DOM_RE = re.compile(r"^[a-zA-Z]{2}\d{2}[a-zA-Z]$")
_SHORT_DOM_RE = re.compile(r"^[a-zA-Z]{1}\d{2}(-[0-9]{1})?$")
_OPIS_URL_RE = re.compile(r"^[a-z0-9]{3}-(?:[0-9]-)?opis(?:.[a-z0-9]*)*")


class Beamline(BaseModel):
short_dom: str = Field(description="Short BL domain e.g. b23, ixx-1")
long_dom: str = Field(description="Full BL domain e.g. bl23b")
desc: str = Field(description="Description")
model_config = ConfigDict(extra="forbid")
url: str = Field(description="URL of ixx-opis")

@field_validator("short_dom")
@classmethod
Expand All @@ -75,6 +77,17 @@ def normalize_long_dom(cls, v: str) -> str:

raise ValueError("Invalid long dom.")

@field_validator("url")
@classmethod
def check_url(cls, url: str) -> str:
url = url.strip().lower()
if _OPIS_URL_RE.fullmatch(url):
# url in correct format
# e.g. t01-opis.diamond.ac.uk
return url

raise ValueError("Invalid opis URL.")


class Component(BaseModel):
prefix: str
Expand Down
22 changes: 22 additions & 0 deletions src/techui_builder/render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from dataclasses import dataclass
from pathlib import Path

from jinja2 import Environment, FileSystemLoader

from techui_builder.models import Beamline


@dataclass
class Renderer:
support_screen_path: Path
screen_path: Path
beamline: Beamline

def __post_init__(self):
self.env = Environment(loader=FileSystemLoader(self.support_screen_path))

def load_screen(self):
self.screen_template = self.env.get_template(self.screen_path.name)

def render_screen(self):
rendered_screen = self.screen_template.render(url=self.beamline.url)
24 changes: 24 additions & 0 deletions src/techui_builder/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import logging
import os
from pathlib import Path

from lxml import objectify
from lxml.etree import _ElementTree
from lxml.objectify import ObjectifiedElement


Expand All @@ -14,6 +19,25 @@ def read_bob(path):
return tree, widgets


def write_bob(tree: _ElementTree[ObjectifiedElement], filename: Path):
# Check if data/ dir exists and if not, make it
data_dir = filename.parent
if not data_dir.exists():
os.mkdir(data_dir)

# Remove any unnecessary xmlns:py and py:pytype metadata from tags
objectify.deannotate(tree, cleanup_namespaces=True)

tree.write(
filename,
pretty_print=True,
encoding="utf-8",
xml_declaration=True,
)
logger_ = logging.getLogger()
logger_.debug(f"Screen filled for {filename}")


def get_widgets(root: ObjectifiedElement):
widgets: dict[str, ObjectifiedElement] = {}
# Loop over objects in the xml
Expand Down
Loading