Skip to content

Commit

Permalink
Merge pull request #1558 from sol/dry-up
Browse files Browse the repository at this point in the history
plover/machine/*: DRY up / remove code duplication
  • Loading branch information
sammdot authored Jul 14, 2023
2 parents d5386f8 + c39a087 commit 78f5020
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
5 changes: 5 additions & 0 deletions plover/machine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def _notify(self, steno_keys):
for callback in self.stroke_subscribers:
callback(steno_keys)

def _notify_keys(self, steno_keys):
steno_keys = self.keymap.keys_to_actions(steno_keys)
if steno_keys:
self._notify(steno_keys)

def set_suppression(self, enabled):
'''Enable keyboard suppression.
Expand Down
4 changes: 1 addition & 3 deletions plover/machine/geminipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,4 @@ def run(self):
for j in range(1, 8):
if (b & (0x80 >> j)):
steno_keys.append(STENO_KEY_CHART[i * 7 + j - 1])
steno_keys = self.keymap.keys_to_actions(steno_keys)
if steno_keys:
self._notify(steno_keys)
self._notify_keys(steno_keys)
4 changes: 1 addition & 3 deletions plover/machine/passport.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def _handle_packet(self, packet):
shadow = int(shadow, base=16)
if shadow >= 8:
steno_keys.append(key)
steno_keys = self.keymap.keys_to_actions(steno_keys)
if steno_keys:
self._notify(steno_keys)
self._notify_keys(steno_keys)

def run(self):
"""Overrides base class run method. Do not call directly."""
Expand Down
4 changes: 1 addition & 3 deletions plover/machine/procat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ def run(self):
log.error('discarding invalid packet: %s',
binascii.hexlify(packet))
continue
steno_keys = self.keymap.keys_to_actions(
self._notify_keys(
self.process_steno_packet(packet)
)
if steno_keys:
self._notify(steno_keys)

@staticmethod
def process_steno_packet(raw):
Expand Down
7 changes: 1 addition & 6 deletions plover/machine/stentura.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,10 @@ class Stentura(plover.machine.base.SerialStenotypeBase):
^
'''

def _on_stroke(self, keys):
steno_keys = self.keymap.keys_to_actions(keys)
if steno_keys:
self._notify(steno_keys)

def run(self):
"""Overrides base class run method. Do not call directly."""
try:
_loop(self.serial_port, self.finished, self._on_stroke, self._ready)
_loop(self.serial_port, self.finished, self._notify_keys, self._ready)
except _StopException:
pass
except Exception:
Expand Down

0 comments on commit 78f5020

Please sign in to comment.