So, I decided to dive right in and see if I could build a plugin, but (entirely predictably as I know nothing about python), I've run into some problems.
I've found occasions where I'd like to be able to display two object containers, one after the other, but I can't figure out how to do it.
I'm trying to build a menu, but only if the user is logged in. If they are not logged in, I'd like to display a message saying so, and then the preferences link so they can check/enter their login details.
At present I can only seem to do one or the other. When I try to return two objects I get either a "tuple" error or an "is not JSON serializable" error. If I try to branch to another method to do one of the objectContainers, only the objectContainer in the main method gets displayed.
I'm new to all this (as you can probably guess), so there might be a few more questions like this from me.
It is always best to use an existing Plugin as an example when you first start. That way you have something to reference when you have questions. Also, including the code that is giving you an error can help others see where you are having issues.
You would just have one object container, but you would use oc.add to add all the objects for the menu or for fixing the login and you would put those in an if/else statement so the object container will only add one or the other. Then you would end the function with return oc to return the objects you added.
def SomeMenu():
oc = ObjectContainer()
# Code for calling login info and authentication
log_in = some_code
if log_in=='some value':
oc.add(DirectoryObject(key=Callback(MenuItem1, title="Menu Item 1"), title="Menu Item 1"))
oc.add(DirectoryObject(key=Callback(MenuItem2, title="Menu Item 2"), title="Menu Item 2"))
else:
# Here you could send them to a function to fix it or return an error message
oc.add(DirectoryObject(key=Callback(LoginError, title='Login Error'), title="Login Error", summary="Enter login info"))
OR
return ObjectContainer(header='Log In Failed', message='Please check your log in in Preferences')