![]() |
Structural Bioinformatics Library
Template C++ / Python API for developping structural bioinformatics applications.
|
Public Member Functions | |
| __init__ (self, str ui_path) | |
| Dict | convert (self) |
| Dict[str, int] | extract_window_geometry (self) |
| List[Dict] | parse_widgets (self) |
Static Public Member Functions | |
| Optional[Dict[str, int]] | extract_geometry_from (ET.Element widget) |
| Tuple[Optional[str], Optional[Dict[str, str]]] | determine_type_and_meta (str name) |
Converter for Qt Designer `.ui` files to a structured JSON layout.
The converter extracts the main window geometry and flattens descendant
widget rectangles into a simple list of components, mapping certain well‐
known name patterns to semantic widget types (e.g., `outputText1` -> TextArea).
Attributes:
ui_path: Filesystem path to the `.ui` XML file.
tree: Parsed ElementTree of the input file.
root: Root element of the parsed XML.
| __init__ | ( | self, | |
| str | ui_path ) |
Initialize the converter with a path to a `.ui` file.
Args:
ui_path: Path to the input `.ui` XML file.
Raises:
ET.ParseError: If the XML cannot be parsed.
FileNotFoundError: If `ui_path` does not exist.
| Dict convert | ( | self | ) |
Convert the `.ui` file into a JSON-compatible dictionary.
This extracts the top-level window geometry, enumerates widgets into a
flat list, and assigns `col`/`row` indices based on absolute positions.
Returns:
A dictionary with a single `"window"` key that contains `title`,
`width`, `height`, and `children` (list of widgets).
|
static |
Infer widget type and metadata from its Qt object `name`.
Naming conventions supported:
* `inputPanel` -> `"Frame"` with label `"Input Panel"`.
* `outputText<N>` -> `"TextArea"` with `file_path="outputText<N>.txt"`.
* `outputFigure<N>` -> `"ImageView"` with `file_path="outputFigure<N>.png"`.
* `outputPDF<N>` -> `"ImageView"` with `file_path="outputPDF<N>.pdf"`.
* `outputTable<N>` -> `"TableView"` with `file_path="outputTable<N>.csv"`.
* `outputHtml<N>` or `outputHTML<N>` -> `"HtmlView"` with `file_path="outputHtml<N>.html"`.
* `outputHtmlTabs` -> `"HtmlView"` with `files_glob="outputHtml*.html"` (render multiple HTML files as tabs).
Args:
name: The Qt object name string.
Returns:
A `(type, meta)` tuple where `type` is a string such as `"TextArea"`
and `meta` is a small dictionary of extra fields, or `(None, None)`
when the name pattern is not recognized.
|
static |
Extract `x`, `y`, `width`, and `height` from a widget element.
Args:
widget: XML element representing a widget with a `geometry` property.
Returns:
A dictionary with integer geometry if present, otherwise `None`.
| Dict[str, int] extract_window_geometry | ( | self | ) |
Extract the main window's size and a default title.
Returns:
A dictionary with `title`, `width`, and `height` keys. If the
geometry is not found, falls back to an 800x600 template.
| List[Dict] parse_widgets | ( | self | ) |
Parse descendant widgets and convert them to layout entries.
The method scans all `.//widget` elements and uses `determine_type_and_meta`
to map widget names to logical types (e.g., `ImageView`, `TableView`).
For each recognized widget, it extracts geometry and returns a flat list.
Returns:
A list of dictionaries with at least `type`, `x`, `y`, `width`, `height`.
Additional metadata (e.g., `file_path`, `label`) is included when known.