question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python: Working with classes and style_class

See original GitHub issue

Hello,

I’m having issue with the python implementation to define style_classes and classes for streams.

  1. Defining classes on a stream, for example in the circle scenario:
    builder.primitive('/circle').circle([0.0, 0.0, 0.0], self._radius).classes('Bike')

To fix this i had to change the function _format_primitive in primitive.py: from :

    base.classes = self._classes

to :

    [base.classes.append(cls) for cls in  self._classes]

Now this seems to work to apply the classe in the output at least. Now comes the styling for that class. My understanding is that i should be able to do this by building the metadata like this :

    builder.stream("/circle")\
    .coordinate(xviz.COORDINATE_TYPES.IDENTITY)\
     .stream_style({'fill_color': [200, 0, 70, 128]})\
    .category(xviz.CATEGORY.PRIMITIVE)\
    .type(xviz.PRIMITIVE_TYPES.CIRCLE)\
    .style_class("Car", {'fill_color': [200, 200, 70, 128]})\
    .style_class("Bike", {'fill_color': [0, 200, 70, 128]})

I was kinda of able to at least not make it crash by:

  1. Adding the build_class_style function in base_builder.py

    def build_class_style(name, style):
        '''
        Create StyleObjectValue from dictionary. It basically deal with list of bytes.
        '''
        return StyleClass(name=name, style=build_object_style(style))
  1. Replacing the function style_class in metadata.py by this :
    from xviz_avs.builder.base_builder import build_class_style
    (...)
    def style_class(self, name, style):
        if not self._stream_id:
            self._logger.error('A stream must set before adding a style rule.')
            return self

        self._temp_stream.style_classes.append(build_class_style(name, style))
        return self
  1. Results:

Well, this is where it gets rough for me because my understanding of protobuf still sucks. The result i get is that the class i define for my circle is now visible in the circle tool tip like it should be, but the circle is now fully white.

image

I hope everything is clear. Any help is welcome on this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
twojtaszcommented, Jul 13, 2020

Hitting a test failure i’m fixing first then will release

1reaction
twojtaszcommented, Jul 10, 2020

I’ll try to get a release out today, but not until this evening.

On Fri, Jul 10, 2020 at 11:51 AM Kevin Greene notifications@github.com wrote:

Thank you for the quick review cycle!

Would you guys mind doing a minor release to pypi with this bug fix? that way I can just bump the version number instead of having to package a wheel myself to get this in. I’m using it now

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/uber/xviz/issues/593#issuecomment-656830283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALUBXGFPPARWKBRFACP2F3R25PMVANCNFSM4NEYT4QQ .

Read more comments on GitHub >

github_iconTop Results From Across the Web

New-style Classes | Python.org
Types and Objects is the start of a new-style class tutorial with lots of figures and examples, but it's rough and not complete....
Read more >
What is the difference between old style and new style classes ...
New-style classes were introduced in Python 2.2 to unify the concepts of class and type. A new-style class is simply a user-defined type,...
Read more >
What is the difference between old style and ... - Tutorialspoint
In Python 2.x there's two styles of classes depending on the presence or absence of a built-in type as a base-class − "classic"...
Read more >
5.2 New-Style Classes and Instances - Python tutorial
New-style classes and instances are first-class objects just like classic ones, both can have arbitrary attributes, you call a class to create an...
Read more >
New-Style Classes - The Conservative Python 3 Porting Guide
New-Style Classes¶ ... Python 2 had two styles of classes: “old-style” and “new-style”. ... In Python 3, all classes are new-style: object is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found