Skip to content
Merged
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ having to use the .utils package. See more details below.

```python
modes_info = gdtf_fixture.dmx_modes.as_dict()

```

##### .utils.get\_geometry\_by\_name
Expand All @@ -176,7 +175,7 @@ gdtf_fixture.geometries.get_geometry_by_name("geometry name")
##### .utils.get\_geometry\_by\_type

```python
#this is a static method and requires a root_geometry
# this is a static method and requires a root_geometry
gdtf_fixture.geometries.get_geometry_by_type(geometry_root, geometry_type)
```

Expand Down
5 changes: 3 additions & 2 deletions pygdtf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,9 @@ def _read_xml(self, xml_node: "Element", xml_parent: Optional["Element"] = None)
color_str = xml_node.attrib.get("Color")
self.color = ColorCIE(str_repr=color_str) if color_str else ColorCIE()
self.filter = NodeLink("FilterCollect", xml_node.attrib.get("Filter"))
self.media_file_name = Resource(
name=xml_node.attrib.get("MediaFileName", ""), extension="png"
media_file_name = xml_node.attrib.get("MediaFileName")
self.media_file_name = (
Resource(name=media_file_name, extension="png") if media_file_name else None
)
self.facets = [PrismFacet(xml_node=i) for i in xml_node.findall("Facet")]
animation_system_node = xml_node.find("AnimationSystem")
Expand Down
108 changes: 108 additions & 0 deletions tests/test_wheel_slot_media_file_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# MIT License
#
# Copyright (C) 2026 Marvin
#
# This file is part of pygdtf.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pathlib import Path
from xml.etree import ElementTree

import pygdtf

# WheelSlot._read_xml() read a missing MediaFileName as "" instead of None
# (default on xml_node.attrib.get), so to_xml() - which only checks "is this
# not None" - always wrote MediaFileName="" back out, even for slots that
# never had that attribute in the source. Harmless to the XSD (empty string
# is still a valid value) but pollutes every wheel slot on round-trip.
_DSC_XML = """<?xml version="1.0" encoding="UTF-8"?>
<GDTF DataVersion="1.2">
<FixtureType Name="Test" ShortName="Test" LongName="Test" Manufacturer="Test"
Description="Test" FixtureTypeID="00000000-0000-0000-0000-000000000000"
Thumbnail="" ThumbnailOffsetX="0" ThumbnailOffsetY="0" RefFT="" CanHaveChildren="No">
<AttributeDefinitions>
<ActivationGroups/>
<FeatureGroups>
<FeatureGroup Name="Gobo" Pretty="Gobo">
<Feature Name="Gobo"/>
</FeatureGroup>
</FeatureGroups>
<Attributes>
<Attribute Name="Gobo1" Pretty="G1" Feature="Gobo.Gobo" PhysicalUnit="None"/>
</Attributes>
</AttributeDefinitions>
<Wheels>
<Wheel Name="Gobo Wheel">
<Slot Name="Open"/>
<Slot Name="Gobo 1" MediaFileName="gobo01"/>
</Wheel>
</Wheels>
<PhysicalDescriptions>
<ColorSpace Mode="sRGB"/>
<AdditionalColorSpaces/>
<Gamuts/>
<Filters/>
<Emitters/>
<DMXProfiles/>
<CRIs/>
<Connectors/>
<Properties/>
</PhysicalDescriptions>
<Models>
<Model Name="Base" PrimitiveType="Cube"/>
</Models>
<Geometries>
<Geometry Name="Base" Model="Base"/>
</Geometries>
<DMXModes>
<DMXMode Name="Default" Geometry="Base">
<DMXChannels>
<DMXChannel Offset="1" Geometry="Base">
<LogicalChannel Attribute="Gobo1">
<ChannelFunction Name="Open" Attribute="Gobo1" Default="0/1"/>
</LogicalChannel>
</DMXChannel>
</DMXChannels>
</DMXMode>
</DMXModes>
</FixtureType>
</GDTF>
"""


def test_wheel_slot_roundtrip_omits_empty_media_file_name(tmp_path: Path):
dsc_file = tmp_path / "description.xml"
dsc_file.write_text(_DSC_XML, encoding="utf-8")

with pygdtf.FixtureType(dsc_file=str(dsc_file)) as fixture:
writer = pygdtf.FixtureTypeWriter(fixture)
output = tmp_path / "roundtrip.xml"
writer.write_gdtf(output)

root = ElementTree.fromstring(output.read_bytes())
slots = root.findall("./FixtureType/Wheels/Wheel/Slot")
assert len(slots) == 2

open_slot, gobo_slot = slots
assert open_slot.get("Name") == "Open"
assert "MediaFileName" not in open_slot.attrib

assert gobo_slot.get("Name") == "Gobo 1"
assert gobo_slot.get("MediaFileName") == "gobo01"
Loading