Skip to content

Commit

Permalink
AbstractAbbreviation: Type-check abbreviations.
Browse files Browse the repository at this point in the history
Added a function to batch-add multiple abbreviations.
  • Loading branch information
luziferius committed May 23, 2019
1 parent 44f08f3 commit 50c17b6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/autokey/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,22 @@ def get_word_chars(self):
return self.wordChars.pattern

def add_abbreviation(self, abbr):
if not isinstance(abbr, str):
raise ValueError("Abbreviations must be strings. Cannot add abbreviation '{}', having type {}.".format(
abbr, type(abbr)
))
self.abbreviations.append(abbr)
if TriggerMode.ABBREVIATION not in self.modes:
self.modes.append(TriggerMode.ABBREVIATION)

def add_abbreviations(self, abbreviation_list: typing.Iterable[str]):
if not isinstance(abbreviation_list, list):
abbreviation_list = list(abbreviation_list)
if not all(isinstance(abbr, str) for abbr in abbreviation_list):
raise ValueError("All added Abbreviations must be strings.")
self.abbreviations += abbreviation_list
if TriggerMode.ABBREVIATION not in self.modes:
self.modes.append(TriggerMode.ABBREVIATION)

def clear_abbreviations(self):
self.abbreviations = []
Expand Down Expand Up @@ -354,8 +369,8 @@ def _should_trigger_window_title(self, window_info):
class AbstractHotkey(AbstractWindowFilter):

def __init__(self):
self.modifiers = []
self.hotKey = None
self.modifiers = [] # type: typing.List[Key]
self.hotKey = None # type: typing.Optional[str]

def get_serializable(self):
d = {
Expand All @@ -375,6 +390,7 @@ def set_hotkey(self, modifiers, key):
modifiers.sort()
self.modifiers = modifiers
self.hotKey = key
self.modes.append(TriggerMode.HOTKEY)

def check_hotkey(self, modifiers, key, windowTitle):
if self.hotKey is not None and self._should_trigger_window_title(windowTitle):
Expand Down

0 comments on commit 50c17b6

Please sign in to comment.