Advertisement
Uno-Dan

Untitled

Nov 10th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. ########################################################################################################################
  2. #    File: base.py
  3. #  Author: Dan Huckson, https://github.com/unodan
  4. #    Date: 2018-11-10
  5. ########################################################################################################################
  6.  
  7.  
  8. class Hookman(object):
  9.     instance = None
  10.  
  11.     def __new__(cls, **kwargs):
  12.         if not cls.instance:
  13.             cls.instance = super(Hookman, cls).__new__(cls)
  14.             cls.instance.manager = _HookManager()
  15.  
  16.         return cls.instance.manager
  17.  
  18.  
  19. class _HookManager(object):
  20.     def __init__(self):
  21.         self.hooks = {}
  22.  
  23.     def register(self, window, hook, callback):
  24.  
  25.         if window not in self.hooks:
  26.             self.hooks[window] = {hook: {}}
  27.  
  28.         key = window + '/' + hook + '/' + str(len(self.hooks[window][hook]))
  29.         self.hooks[window][hook].update({key: callback})
  30.  
  31.     def get_hook(self, target, hook):
  32.         if hook in self.hooks[target]:
  33.             print(target, hook)
  34.             return self.hooks[target][hook]
  35.  
  36.     def get_hooks(self, target):
  37.         if target in self.hooks:
  38.             return self.hooks[target]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement