Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Register classes based on ctor #32

Open
tswast opened this issue May 2, 2019 · 0 comments
Open

Register classes based on ctor #32

tswast opened this issue May 2, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@tswast
Copy link
Contributor

tswast commented May 2, 2019

When I get a node from a graph, the graph should return a nice object (custom class) when one exists for it.

I think a class decorator could be used to register classes globally and associate them with a specific value for ctor.

@pikov.register_class(ctor=bytes.fromhex("8b057dd7a9c84b7180cb2d8d6015b833"))
class Frame(SemanticGraphNode):
    def __init__(self, guid_map, guid=None):
        super().__init__(names["frame"], guid_map, guid=guid)

    duration_microseconds = Int64Property(names["frame.duration_microseconds"])
    bitmap = BitmapProperty(names["frame.bitmap"])

    def _to_img(self):
        image_url = self.bitmap._to_data_url()
        if not image_url:
            return None

        return (
            f'<img alt="clip preview" '
            f'src="{image_url}" '
            f'style="width: 5em; {PIXEL_ART_CSS}">'
        )
@tswast tswast added the enhancement New feature or request label May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant