Forum Archive

Where to store custom data for a UI view?

halloleooo

I am building a little share extension with a view UI. For this UI I need a few extra variables along side the view of the extension.

What's the best place to store these variables?

  • Global variables (either individually or as a class object with attributes)?

or

  • Using a sub-classed View just to hold these variables in the UI?
cvp

@halloleooo you can add your own attributes to the standard ui.View without sub-classing it.

import ui
v = ui.View()
v.user_attribute = 'my data'
v.present()
print(dir(v))
print(v.user_attribute)
halloleooo

@cvp That's so super-cool! That's the perfect solution for me: Then I don't need global variables!

garysmith21

I'm not sure about the solution, I will show this problem to my team or you can look for a solution here https://computools.com/blog/