-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path__init__.py
More file actions
22 lines (18 loc) · 795 Bytes
/
__init__.py
File metadata and controls
22 lines (18 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sys
import _plotdevice # make sure the c-extensions are accessible for the submodules
# allow Libraries to request a _ctx reference
def register(module):
"""When called within a library's __init__.py, returns the currently bound context.
After having registered, the module's _ctx variable will be updated whenever the
context changes. Libraries should register themselves using the following snippet:
from plotdevice.lib import register
_ctx = register(__name__)
"""
_bound['modules'].append(module)
return _bound['ctx']
# keep registered libraries up-to-date when the context is re-bound
def bind(ctx):
_bound['ctx'] = ctx
for module in _bound['modules']:
setattr(sys.modules[module], '_ctx', ctx)
_bound = {"ctx":None, "modules":[]}