Python: Working with classes and style_class
See original GitHub issueHello,
I’m having issue with the python implementation to define style_classes and classes for streams.
- 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:
- 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))
- 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
- 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.
I hope everything is clear. Any help is welcome on this.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hitting a test failure i’m fixing first then will release
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: