Best way to use unload()

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Best way to use unload()

Postby BackRaw » Thu Jan 22, 2015 6:43 pm

Hi,

I'm not quite sure what's the best and most effective and clear way of using unload().
For example, I have a myaddon/menus.py file:

Syntax: Select all

from menus import Option
from menus import SimpleMenu


def menu1_callback(menu, index, option):
pass

def menu2_callback(menu, index, option):
pass


menu1 = SimpleMenu(select_callback=menu1_callback)

# add content

menu2 = SimpleMenu(select_callback=menu2_callback)

# add content
and a myaddon/myaddon.py file:

Syntax: Select all

from myaddon.menus import menu1
from myaddon.menus import menu2


# use ONLY menu1 in events

def unload():
menu1.clear()
menu2.clear()
Now, Would it be better and clearer to have

Syntax: Select all

def unload():
menu1.clear()
menu2.clear()
within myaddon/menus.py for clearing them? Is it even needed to clear them on unload, or is this method just available for the build callback? Thanks! :)
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Jan 22, 2015 6:57 pm

Every menu is a subclass of a list, so this will just empty your menu. You would rather want to call close(). However, every menu is also a subclass of the AutoUnload class. This means that your menu will be closed automatically when your plugin has been unloaded. The menu just needs to be in the global scope of your main plugin file. And since you import it to your main plugin file, it's already in the global scope.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Thu Jan 22, 2015 7:10 pm

Ayuto wrote:Every menu is a subclass of a list, so this will just empty your menu. You would rather want to call close(). However, every menu is also a subclass of the AutoUnload class. This means that your menu will be closed automatically when your plugin has been unloaded. The menu just needs to be in the global scope of your main plugin file. And since you import it to your main plugin file, it's already in the global scope.


That's what I needed. Thanks.
My Github repositories:

Source.Python: https://github.com/backraw

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 107 guests