from types import SimpleNamespace
from typing import Any
from typing import NoReturn
[docs]class Directive(SimpleNamespace, metaclass=DirectiveMeta):
"""
Simple directive class
They are designed to be hashable and comparable with string equivalent of AHK directive.
Directives that don't require arguments do not need to be instantiated.
"""
[docs] def __init__(self, **kwargs: Any):
apply_to_hotkeys = kwargs.pop('apply_to_hotkeys_process', False)
super().__init__(name=self.name, apply_to_hotkeys_process=apply_to_hotkeys, **kwargs)
self._kwargs = kwargs
@property
def name(self) -> str:
return self.__class__.__name__
def __str__(self) -> str:
if self._kwargs:
arguments = ' '.join(str(value) for key, value in self._kwargs.items())
else:
arguments = ''
return f'#{self.name} {arguments}'.rstrip()
def __eq__(self, other: Any) -> bool:
return bool(str(self) == other)
def __hash__(self) -> int: # type: ignore[override]
return hash(str(self))
[docs]class ClipboardTimeout(Directive):
[docs] def __init__(self, milliseconds: int = 0, **kwargs: Any):
kwargs['milliseconds'] = milliseconds
super().__init__(**kwargs)
[docs]class ErrorStdOut(Directive):
pass
[docs]class HotKeyInterval(ClipboardTimeout):
pass
[docs]class HotKeyModifierTimeout(HotKeyInterval):
pass
[docs]class Include(Directive):
[docs] def __init__(self, include_name: str, **kwargs: Any):
kwargs['include_name'] = include_name
super().__init__(**kwargs)
[docs]class IncludeAgain(Include):
pass
[docs]class InstallKeybdHook(Directive):
pass
[docs]class InstallMouseHook(Directive):
pass
[docs]class KeyHistory(Directive):
[docs] def __init__(self, limit: int = 40, **kwargs: Any):
kwargs['limit'] = limit
super().__init__(**kwargs)
[docs]class MaxHotkeysPerInterval(Directive):
[docs] def __init__(self, value: int, **kwargs: Any):
kwargs['value'] = value
super().__init__(**kwargs)
[docs]class MaxMem(Directive):
[docs] def __init__(self, megabytes: int, **kwargs: Any):
if megabytes < 1:
raise ValueError('megabytes cannot be less than 1')
if megabytes > 4095:
raise ValueError('megabytes cannot exceed 4095')
kwargs['megabytes'] = megabytes
super().__init__(**kwargs)
[docs]class MaxThreads(Directive):
[docs] def __init__(self) -> NoReturn:
raise NotImplementedError()
[docs]class MaxThreadsBuffer(Directive):
[docs] def __init__(self) -> NoReturn:
raise NotImplementedError()
[docs]class MaxThreadsPerHotkey(Directive):
[docs] def __init__(self) -> NoReturn:
raise NotImplementedError()
[docs]class NoTrayIcon(Directive):
pass
[docs]class UseHook(Directive):
pass
[docs]class Warn(Directive):
pass
[docs]class WinActivateForce(Directive):
pass