예제 #1
0
파일: baseclasses.py 프로젝트: dp0s/Dpowers
    def update_active_dict(cls):
        #this has to be called after cls.NamedClass has been set
        for i in range(len(cls.name_translation_dicts)):
            dic = cls.name_translation_dicts[i]
            StandardizingDict = cls.NamedClass.StandardizingDict
            if not isinstance(dic, StandardizingDict):
                check_type(dict, dic)
                cls.name_translation_dicts[i] = StandardizingDict(dic)
        coll = cls.collector
        if coll is None: return
        check_type(InputEventHandler, coll)
        try:
            final_dict = coll.name_dict.copy()
        except AttributeError:
            final_dict = {}
        if hasattr(coll, "names"):
            for n in coll.names:
                if n not in final_dict: final_dict[n] = n

        for a, b in final_dict.items():
            for dic in cls.name_translation_dicts:
                try:
                    b = dic[b]
                except KeyError:
                    pass
            try:
                final_dict[a] = cls.NamedClass.instance(b)
            except KeyError:
                final_dict[a] = b
        cls._active_dict = final_dict  #this is used each time a key is pressed. It
예제 #2
0
 def __getitem__(self, item):
     ims = self.sequence[item]
     if isinstance(item, int):
         check_type(self.SingleClass, ims)
         return ims
     if isinstance(item, slice):
         return self.__class__(images=ims)
     raise NotImplementedError
예제 #3
0
파일: baseclasses.py 프로젝트: dp0s/Dpowers
 def __init_subclass__(cls):
     cls._active_capturers = 0
     cls._active_reinject_func = None
     cls.reinject_active = False
     for handler in (cls.collector, cls.capturer):
         if handler is not None:
             check_type(InputEventHandler, handler)
             if handler.hook_cls is None: handler.hook_cls = cls
             if handler.hook_cls is not cls: raise ValueError
     cls.__init__.__signature__ = inspect.signature(cls.init)
예제 #4
0
 def __init__(self, files=None, images=None, **load_kwargs):
     self.files = files
     if files:
         check_type(iter_types, files)
         assert images is None
         self.sequence = tuple(
                 self.SingleClass(file=f, **load_kwargs) for f in files)
     elif images:
         assert files is None
         assert load_kwargs == {}
         check_type(CollectionWithProps(self.SingleClass, minlen=1), images)
         self.sequence = images
     self.backend_obj = self.construct_backend_obj()
예제 #5
0
파일: trigman.py 프로젝트: dp0s/Dpowers
 def __init__(self, hook_adaptor=None, timeout=60, hook_buttons=False,
         buffer=2, **custom_key_kwargs):
     super().__init__(timeout=timeout)
     self.eventdict = dict()
     self.blocked_hks = []
     if hook_adaptor is not None: self.adaptor = hook_adaptor
     check_type(HookAdaptor, self.adaptor)
     self.k_old = ""
     self.hm= None
     self.recent_events = collections.deque()
     self.buffer = buffer
     self.hook_buttons = hook_buttons
     if hook_buttons:
         self.stringevent_analyzer = StringAnalyzer(NamedKey, NamedButton)
     else:
         self.stringevent_analyzer = NamedKey.Event
     self.key_kwargs = custom_key_kwargs
예제 #6
0
파일: baseclasses.py 프로젝트: dp0s/Dpowers
 def init(self,
          callback_func=False,
          timeout=60,
          *,
          capture: bool = False,
          reinject_func=None,
          priority: int = 0,
          dedicated_thread=False,
          **custom_kwargs):
     super().__init__(timeout=timeout)
     # this defines the attributes timeout, active
     if callback_func is None:
         callback_func = lambda *args: None
     elif not callable(callback_func) and callback_func is not False:
         raise TypeError("callback_func must be callable, False or None")
     check_type(int, priority)
     check_type(bool, capture)
     self.callback_func = callback_func
     self.priority = priority
     self.reinject_func = reinject_func
     self.capture = capture
     self.custom_kwargs = custom_kwargs
     self.dedicated_thread = dedicated_thread
     if custom_kwargs:
         self.process_custom_kwargs(**custom_kwargs)
         # for the evdev custom hook, this might set the self.capturer and
         # self.collector variables
     if reinject_func is not None:
         if self.collector.reinject_implemented is False:
             raise NotImplementedError(
                 "The following hook implementation does not support "
                 "reinjecting:\n" + str(self.__class__))
         if callback_func is False:
             self.callback_func = lambda *args: None
         self.capture = True
         if not callable(reinject_func):
             self.reinject_func = lambda *args: reinject_func
     if not self.capturer and self.capture is True:
         raise NotImplementedError(
             "The following hook implementation does not support "
             "capturing:\n" + str(self.__class__))
예제 #7
0
파일: waiter.py 프로젝트: dp0s/Dpowers
    def __init__(self,
                 callback_hook=None,
                 maxlen=None,
                 maxtime=20,
                 *,
                 endevents=(),
                 cond_func=None,
                 eventmap=None,
                 wait=True,
                 capture=False,
                 notify=True):
        super().__init__(timeout=maxtime, wait=wait)
        check_type(CallbackHook, callback_hook)
        if callback_hook:
            raise ValueError(f"Arguments of callback hook "
                             f"{callback_hook} were already set.")
        self.maxlen = maxlen
        self.maxtime = maxtime
        if type(endevents) not in (list, tuple): endevents = [endevents]
        self.endevents = endevents
        self.eventmap = eventmap
        self.wait = wait
        self.capture = capture
        if cond_func and not callable(cond_func):
            raise ValueError(
                f"KeyWaiter cond_func {cond_func} is not callable")
        self.cond_func = cond_func
        timeout = maxtime + 5 if maxtime else None
        self.callback_hook = callback_hook(self.called,
                                           timeout,
                                           capture=self.capture)

        self.num = 0
        self.events = []
        if self.eventmap: self.events_mapped = []
        self.notify = notify
예제 #8
0
 def set_translation_dict(self, dic, make_default=False):
     check_type(dict, dic)
     self.translation_dict = dic
     self.create_effective_dict(make_default=make_default)