mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
39.68k stars 2.54k forks source link

Can't set attrs parameters for Custom Node class #731

Open iazulkarnain-tlkm opened 2 years ago

iazulkarnain-tlkm commented 2 years ago

The Problem

I can't set attr parameters and its values when creating a new instance of the Custom Node class.

How to reproduce the problem

from diagrams.custom import Custom
rabbitmq_icon = "icons/rabbitmq_icon.png"
test = Custom("crawler_news_kazee_q", rabbitmq_icon,pin="true",pos="4,2")

Error notification

TypeError: Custom.__init__() got an unexpected keyword argument 'pin'

Original codes

The original codes for custom node class is:

"""
Custom provides the possibility of load an image to be presented as a node.
"""

from diagrams import Node

class Custom(Node):
    _provider = "custom"
    _type = "custom"
    _icon_dir = None

    fontcolor = "#ffffff"

    def _load_icon(self):
        return self._icon

    def __init__(self, label, icon_path):
        self._icon = icon_path
        super().__init__(label)

Proposed Fix:

"""
Custom provides the possibility of load an image to be presented as a node.
"""

from diagrams import Node

class Custom(Node):
    _provider = "custom"
    _type = "custom"
    _icon_dir = None

    fontcolor = "#ffffff"

    def _load_icon(self):
        return self._icon

    def __init__(self, label, icon_path, **attrs):
        self._icon = icon_path
        super().__init__(label,**attrs)
bdsoha commented 1 year ago

@iazulkarnain-tlkm @mingrammer This was fixed already in #437 and can be closed.