3
3
# =============================================================================
4
4
# >> IMPORTS
5
5
# =============================================================================
6
+ # Python Imports
7
+ # Inspect
8
+ from inspect import stack
9
+
6
10
# Source.Python Imports
7
- from stringtables import StringTables
8
11
from core import AutoUnload
12
+ from paths import PLUGIN_PATH
9
13
# Events
10
14
from events .manager import EventRegistry
15
+ # Stringtables
16
+ from stringtables import StringTables
11
17
12
18
13
19
# =============================================================================
@@ -26,7 +32,21 @@ class Downloadables(AutoUnload, set):
26
32
'''Class used to store downloadables for a script'''
27
33
28
34
def __init__ (self ):
29
- '''Add the instance to the downloadables list'''
35
+ '''Sets the __module__ if called by a plugin and
36
+ adds the instance to the downloadables list'''
37
+
38
+ # Get the file that called
39
+ caller = stack ()[1 ][1 ]
40
+
41
+ # Is the calling file in a plugin?
42
+ if PLUGIN_PATH in caller :
43
+
44
+ # Set the module to the plugin's module so that
45
+ # _unload_instance will fire when the plugin is unloaded
46
+ self .__module__ = caller .replace (PLUGIN_PATH , '' )[1 :].replace (
47
+ '/' , '.' ).replace ('\\ ' , '.' ).rsplit ('.' , 1 )[0 ]
48
+
49
+ # Add the instance to the downloadables list
30
50
_DownloadablesListInstance .append (self )
31
51
32
52
def add (self , item ):
0 commit comments