drawpyo
drawpyo copied to clipboard
Add links (to URLs or other pages) to objects
Hey there, is it possible to add links to other pages or urls? Similar to doing it in draw.io
Sorry for the late reply. It´s technically possible. The XML would look like this:
<UserObject label="Test" link="https://github.com/MerrimanInd/drawpyo" linkTarget="_blank" id="abc">
<mxCell style="html=1;" vertex="1" parent="1">
<mxGeometry/>
</mxCell>
</UserObject>
To implement that into drawpyo a few additions need to be made though:
Add links to DiagramBase properties
self.link: Optional[str] = kwargs.get("link", None)
self.link_target: Optional[str] = "_blank" if self.link else None
Modify attributes to support link
@property
def attributes(self) -> Dict[str, Any]:
attrs = {"id": self.id, "parent": self.xml_parent}
# Include link only if set
if self.link:
attrs["link"] = self.link
if self.link_target:
attrs["linkTarget"] = self.link_target
return attrs
Override XML printing when using link
This approach is used for tags and tooltip and just needs to be extended.
open_user_object_tag = f'<UserObject label="{self.xml_ify(self.value)}" id="{self.id}"'
if self.tag:
open_user_object_tag += f' tags="{self.tag}"'
if self.tooltip:
open_user_object_tag += f' tooltip="{self.xml_ify(self.tooltip)}"'
if self.link:
open_user_object_tag += f' link="{self.xml_ify(self.link)}"'
open_user_object_tag += ">"
Hide the value attribute on the inner cell
This is being moved from the Cell to the UserObject.
Add helper function to DiagramBase
def add_link(self, link: str) -> None:
self.link = link
self.link_target = "_blank"