Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting and casting object when it is of a derived widget type #355

Open
riaancillie opened this issue Oct 8, 2024 · 0 comments
Open

Getting and casting object when it is of a derived widget type #355

riaancillie opened this issue Oct 8, 2024 · 0 comments

Comments

@riaancillie
Copy link

riaancillie commented Oct 8, 2024

I have created a custom widget by deriving it from a base LVGL object

class SpinLabel(lv.label):

    def __init__(self, parent):
        super().__init__(parent)
        self.add_flag(lv.obj.FLAG.SCROLLABLE)
        self.set_user_data(self)

When trying to style the object in a custom theme's onApply callback is there any way to determine if the object is my custom widget and if so, how do I cast it to that object type so that I can access it's methods? So far, it seems only the base lv.label type is accessible and even if I check the id() of the created custom object vs the id() of the obj in the theme callback, the two IDs are different.

class sdLvglTheme(lv.theme_t):
....
def apply(self, theme, obj):
                
        #print(obj.get_class())    
        #print(obj.get_class() == lv.label_class)
        try:
            #SpinLabel.__cast__(obj).setValue(2)
            if (obj.get_class() == lv.label_class):
                s =  lv.label.__cast__(obj)
                s.set_text("2")
                print(s)
            #s.setValue(2)
            a = obj.get_user_data().__dereference__(3)
            print(bytes(a))            
        except Exception as e:
            print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant