On 07/08/2016 09:57 AM, Rob Gaddi wrote:
Michael Selik wrote:
On Jul 7, 2016, at 7:46 PM, Rob Gaddi <rgaddi@highlandtechnology.invalid> wrote:

I've got a package that contains a global ensmartened dict that allows
all the various parts of my program to share state.

The simplest solution would be to use a module as your singleton. For example, 
"registry.py" would work. Pydoc will show its docstring, and it will have all 
the features you had been using, with the added benefit of not needing to enforce its 
singletonness.


REALLY needs to be an object, preferably dict-like.  For instance, one
of the things it does is provide a .getKeyChanged(self, key) method that
returns a keyChanged QSignal so that various elements of the program can
all register for notifications triggered by __setitem__.  That way, when
Registry['dut'] gets updated, all of the various GUI elements reliant on
information about the dut all dump their old data and find out about the
newly connected device.

Get the best of both worlds -- insert your Registry object into sys.modules. It is then importable from anywhere, yet still has all its native object power.

Something like this should do the trick:

# untested
import sys
sys.modules['%s.registry' % __name__] = _Register()

and then elsewhere:

from blah import registery
registry.whatever()

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to