Source code for ahk.directives

"""
Contains directive classes
"""

from types import SimpleNamespace


[docs]class DirectiveMeta(type): """ Overrides __str__ so directives with no arguments can be used without instantiation Overrides __hash__ to make objects 'unique' based upon a hash of the str representation """ def __str__(cls): return f'#{cls.__name__}' def __hash__(self): return hash(str(self)) def __eq__(cls, other): return str(cls) == other
[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): super().__init__(name=self.name, **kwargs) self._kwargs = kwargs
@property def name(self): return self.__class__.__name__ def __str__(self): 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): return str(self) == other def __hash__(self): return hash(str(self))
[docs]class AllowSameLineComments(Directive): pass
[docs]class ClipboardTimeout(Directive):
[docs] def __init__(self, milliseconds=0, **kwargs): 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, **kwargs): kwargs['include_name'] = include_name super().__init__(**kwargs)
[docs]class IncludeAgain(Include): pass
[docs]class InputLevel(Directive):
[docs] def __init__(self, level, **kwargs): kwargs['level'] = level super().__init__(**kwargs)
[docs]class InstallKeybdHook(Directive): pass
[docs]class InstallMouseHook(Directive): pass
[docs]class KeyHistory(Directive):
[docs] def __init__(self, limit=40, **kwargs): kwargs['limit'] = limit super().__init__(**kwargs)
[docs]class MaxHotkeysPerInterval(Directive):
[docs] def __init__(self, value, **kwargs): kwargs['value'] = value super().__init__(**kwargs)
[docs]class MaxMem(Directive):
[docs] def __init__(self, megabytes: int, **kwargs): 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): raise NotImplemented
[docs]class MaxThreadsBuffer(Directive):
[docs] def __init__(self): raise NotImplemented
[docs]class MaxThreadsPerHotkey(Directive):
[docs] def __init__(self): raise NotImplemented
[docs]class NoEnv(Directive): pass
[docs]class NoTrayIcon(Directive): pass
[docs]class Persistent(Directive): pass
[docs]class SingleInstance(Directive): pass
[docs]class UseHook(Directive): pass
[docs]class Warn(Directive): pass
[docs]class WinActivateForce(Directive): pass