Skip to content

Commit 0ca263e

Browse files
committedJul 28, 2013
Merge pull request #110 from balshetzer/master
Minor update
2 parents c2c5102 + 370be49 commit 0ca263e

9 files changed

+348
-35
lines changed
 

‎README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Supported stenotype protocols:
1414
* TX Bolt (a.k.a. Gemini TX)
1515
* Stentura
1616
* Treal
17+
* Passport
1718

1819
Contact the authors if you would like Plover to support your stenotype
1920
machine.

‎plover/dictionary/rtfcre_dict.py

+30-22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import re
1818
from plover.steno import normalize_steno
1919
from plover.steno_dictionary import StenoDictionary
20+
# TODO: Move dictionary format somewhere more caninical than formatting.
21+
from plover.formatting import META_RE
2022

2123
# A regular expression to capture an individual entry in the dictionary.
2224
DICT_ENTRY_PATTERN = re.compile(r'(?s)(?<!\\){\\\*\\cxs (?P<steno>[^}]+)}' +
@@ -81,19 +83,19 @@ def _re_handle_escaped_newline(self, m):
8183
return '{#Return}{#Return}'
8284

8385
def _re_handle_infix(self, m):
84-
r'\\cxds ([^{}\\\r\n]+)\\cxds'
86+
r'\\cxds ([^{}\\\r\n]+)\\cxds ?'
8587
return '{^%s^}' % m.group(1)
8688

8789
def _re_handle_suffix(self, m):
8890
r'\\cxds ([^{}\\\r\n ]+)'
8991
return '{^%s}' % m.group(1)
9092

9193
def _re_handle_prefix(self, m):
92-
r'([^{}\\\r\n ]+)\\cxds'
94+
r'([^{}\\\r\n ]+)\\cxds ?'
9395
return '{%s^}' % m.group(1)
9496

9597
def _re_handle_commands(self, m):
96-
r'(\\\*)?\\([a-z]+)(-?[0-9]+)?[ ]?'
98+
r'(\\\*)?\\([a-z]+)(-?[0-9]+)? ?'
9799

98100
ignore = bool(m.group(1))
99101
command = m.group(2)
@@ -294,31 +296,37 @@ def load_dictionary(s):
294296
HEADER = ("{\\rtf1\\ansi{\\*\\cxrev100}\\cxdict{\\*\\cxsystem Plover}" +
295297
"{\\stylesheet{\\s0 Normal;}}\n")
296298

299+
def format_translation(t):
300+
t = ' '.join([x.strip() for x in META_RE.findall(t) if x.strip()])
301+
302+
t = re.sub(r'{\.}', '{\\cxp. }', t)
303+
t = re.sub(r'{!}', '{\\cxp! }', t)
304+
t = re.sub(r'{\?}', '{\\cxp? }', t)
305+
t = re.sub(r'{\,}', '{\\cxp, }', t)
306+
t = re.sub(r'{:}', '{\\cxp: }', t)
307+
t = re.sub(r'{;}', '{\\cxp; }', t)
308+
t = re.sub(r'{\^}', '\\cxds ', t)
309+
t = re.sub(r'{\^([^^}]*)}', '\\cxds \\1', t)
310+
t = re.sub(r'{([^^}]*)\^}', '\\1\\cxds ', t)
311+
t = re.sub(r'{\^([^^}]*)\^}', '\\cxds \\1\\cxds ', t)
312+
t = re.sub(r'{-\|}', '\\cxfc ', t)
313+
t = re.sub(r'{>}', '\\cxfls ', t)
314+
t = re.sub(r'{ }', ' ', t)
315+
t = re.sub(r'{&([^}]+)}', '{\\cxfing \\1}', t)
316+
t = re.sub(r'{#([^}]+)}', '\\{#\\1\\}', t)
317+
t = re.sub(r'{PLOVER:([a-zA-Z]+)}', '\\{PLOVER:\\1\\}', t)
318+
t = re.sub(r'\\"', '"', t)
319+
320+
return t
321+
322+
297323
# TODO: test this
298324
def save_dictionary(d, fp):
299325
fp.write(HEADER)
300326

301327
for s, t in d.items():
302328
s = '/'.join(s)
303-
304-
t = re.sub(r'{\.}', '{\\cxp. }', t)
305-
t = re.sub(r'{!}', '{\\cxp! }', t)
306-
t = re.sub(r'{\?}', '{\\cxp? }', t)
307-
t = re.sub(r'{\,}', '{\\cxp, }', t)
308-
t = re.sub(r'{:}', '{\\cxp: }', t)
309-
t = re.sub(r'{;}', '{\\cxp; }', t)
310-
t = re.sub(r'{\^}', '\\cxds ', t)
311-
t = re.sub(r'{\^([^^}]*)}', '\\cxds \\1', t)
312-
t = re.sub(r'{([^^}]*)\^}', '\\1\\cxds ', t)
313-
t = re.sub(r'{\^([^^}]*)\^}', '\\cxds \\1\\cxds ', t)
314-
t = re.sub(r'{-\|}', '\\cxfc ', t)
315-
t = re.sub(r'{>}', '\\cxfls ', t)
316-
t = re.sub(r'{ }', ' ', t)
317-
t = re.sub(r'{&([^}]+)}', '{\\cxfing \\1}', t)
318-
t = re.sub(r'{#([^}]+)}', '\\{#\\1\\}', t)
319-
t = re.sub(r'{PLOVER:([a-zA-Z]+)}', '\\{PLOVER:\\1\\}', t)
320-
t = re.sub(r'\\"', '"', t)
321-
329+
t = format_translation(t)
322330
entry = "{\\*\\cxs %s}%s\r\n" % (s, t)
323331
fp.write(entry)
324332

‎plover/dictionary/test_rtfcre_dict.py

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Copyright (c) 2013 Hesky Fisher
22
# See LICENSE.txt for details.
33

4-
from plover.steno_dictionary import StenoDictionary
5-
from rtfcre_dict import load_dictionary, TranslationConverter
4+
from plover.dictionary.rtfcre_dict import load_dictionary, TranslationConverter, format_translation, save_dictionary
65
import mock
76
import re
87
import unittest
8+
from cStringIO import StringIO
99

1010
class TestCase(unittest.TestCase):
1111

@@ -25,9 +25,12 @@ def test_converter(self):
2525
(r'\_', '-'),
2626
('\\\r\n', '{#Return}{#Return}'),
2727
(r'\cxds', '{^}'),
28+
(r'pre\cxds ', '{pre^}'),
29+
(r'pre\cxds ', '{pre^} '),
2830
(r'pre\cxds', '{pre^}'),
2931
(r'\cxds post', '{^post}'),
3032
(r'\cxds in\cxds', '{^in^}'),
33+
(r'\cxds in\cxds ', '{^in^}'),
3134
(r'\cxfc', '{-|}'),
3235
(r'\cxfl', '{>}'),
3336
(r'pre\cxfl', 'pre{>}'),
@@ -74,6 +77,7 @@ def test_converter(self):
7477
(r'{\cxconf [{\cxc abc}|{\cxc def}]}', 'def'),
7578
(r'{\cxconf [{\cxc abc}|{\cxc def}|{\cxc ghi}]}', 'ghi'),
7679
(r'{\cxconf [{\cxc abc}|{\cxc {\cxp... }}]}', '{^... ^}'),
80+
(r'be\cxds{\*\cxsvatdictentrydate\yr2006\mo5\dy10}', '{be^}'),
7781

7882
(r'{\nonexistant {\cxp .}}', '{.}'),
7983
(r'{\*\nonexistant {\cxp .}}', ''),
@@ -172,8 +176,35 @@ def __call__(self, s):
172176
expected = dict((normalize(k), convert(v))
173177
for k, v in expected.iteritems())
174178
assertEqual(load_dictionary(make_dict(s)), expected)
175-
179+
180+
def test_format_translation(self):
181+
cases = (
182+
('', ''),
183+
('{^in^}', '\cxds in\cxds '),
184+
('{pre^}', 'pre\cxds '),
185+
('{pre^} ', 'pre\cxds '),
186+
('{pre^} ', 'pre\cxds ')
187+
)
188+
189+
failed = False
190+
format_str = "format({}) != {}: {}"
191+
for before, expected in cases:
192+
result = format_translation(before)
193+
if result != expected:
194+
failed = True
195+
print format_str.format(before, expected, result)
176196

197+
self.assertFalse(failed)
198+
199+
def test_save_dictionary(self):
200+
f = StringIO()
201+
d = {
202+
'S/T': '{pre^}',
203+
}
204+
save_dictionary(d, f)
205+
expected = '{\\rtf1\\ansi{\\*\\cxrev100}\\cxdict{\\*\\cxsystem Plover}{\\stylesheet{\\s0 Normal;}}\n{\\*\\cxs S///T}pre\\cxds \r\n}\n'
206+
self.assertEqual(f.getvalue(), expected)
207+
177208

178209
if __name__ == '__main__':
179210
unittest.main()

‎plover/gui/paper_tape.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def display(parent, config):
152152
StrokeDisplayDialog(parent, config)
153153

154154

155+
# This class exists solely so that the text doesn't get grayed out when the
156+
# window is not in focus.
155157
# This class exists solely so that the text doesn't get grayed out when the
156158
# window is not in focus.
157159
class MyStaticText(wx.PyControl):
@@ -233,7 +235,6 @@ def GetDefaultAttributes(self):
233235
def ShouldInheritColours(self):
234236
return True
235237

236-
237238
class fake_config(object):
238239
def __init__(self):
239240
self.on_top = True

‎plover/gui/serial_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""A graphical user interface for configuring a serial port."""
66

77
from serial import Serial
8-
from serial.tools.list_ports import comports
8+
from plover.oslayer.comscan import comports
99
import string
1010
import wx
1111
import wx.animate

‎plover/machine/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def start_capture(self):
157157

158158
try:
159159
self.serial_port = serial.Serial(**self.serial_params)
160-
except serial.SerialException:
160+
except serial.SerialException as e:
161+
print e
161162
self._error()
162163
return
163164
if self.serial_port is None or not self.serial_port.isOpen():

‎plover/oslayer/comscan.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from serial.tools.list_ports import comports as serial_comports
2+
3+
try:
4+
from plover.oslayer.list_ports_posix import comports as alternative_comports
5+
except ImportError:
6+
alternative_comports = lambda: []
7+
8+
def comports():
9+
try:
10+
return serial_comports()
11+
except NameError:
12+
# For some reason, the official release of pyserial 2.6 has a simple NameError in it :(
13+
return alternative_comports()

0 commit comments

Comments
 (0)