コード例 #1
0
ファイル: test_kmfl.py プロジェクト: HughP/palaso-python-1
 def runtest(self, fname, keys, output):
     k = kmfl("kbds/" + fname)
     res = k.run_items(keysyms_items(keys))
     self.assertEqual(res, output,
                      ("Keying difference for: {0}\n"
                       "expected:\t{1!r}\n"
                       "     got:\t{2!r}\n").format(keys, output, res))
コード例 #2
0
 def runtest(self, fname, keys, output):
     with resources.as_file(pkg_data / fname) as path:
         k = kmfl(path)
     res = k.run_items(keysyms_items(keys))
     self.assertEqual(res, output,
                      ("Keying difference for: {0}\n"
                       "expected:\t{1!r}\n"
                       "     got:\t{2!r}\n").format(keys, output, res))
コード例 #3
0
(opts, kmns) = parser.parse_args()
if len(kmns) == 0:
    sys.stderr.write(parser.expand_prog_name('%prog: missing KEYMAN FILE\n'))
    parser.print_help(file=sys.stderr)
    sys.exit(1)

kb = kmns[0]

overrides = {
    'name': 'NAME',
    'copyright': 'COPYRIGHT',
    'author': 'AUTHOR',
    'language': 'ETHNOLOGUE',
}
km = kmfl(kb)
for k, v in overrides.items():
    opts.ensure_value(k, km.store(v))
if not opts.language: opts.language = "und"

if opts.output:
    outfile = file(opts.output, "w")
else:
    outfile = sys.stdout

if opts.resource:
    resfile = file(opts.resource, "w")
elif opts.output:
    resfile = file(os.path.splitext(opts.output)[0] + ".rc", "w")
else:
    resfile = sys.stdout
コード例 #4
0
#!/usr/bin/env python3
'''
Given a sequence of key tops from a US 101 key keyboard or keyman symbol
notation on stdin print the key names followed by the output the keyman
keyboard would generate.  This allows us to try the keyboard without
needing to install it.
'''
__version__ = '1.0'
__date__ = '21 October 2009'
__author__ = 'Martin Hosken <*****@*****.**>'
import sys
from optparse import OptionParser
from palaso.contexts import defaultapp
from palaso.kmfl import kmfl
from palaso.kmn import keysyms_items

assert __doc__ is not None
parser = OptionParser(usage='%prog [options] <KEYMAN FILE>\n' + __doc__)
_, kmns = parser.parse_args()
if len(kmns) == 0:
    sys.stderr.write(parser.expand_prog_name('%prog: missing KEYMAN FILE\n'))
    parser.print_help(file=sys.stderr)
    sys.exit(1)

with defaultapp():
    k = kmfl(sys.argv[1])
    for ln in sys.stdin.readlines():
        r = k.run_items(keysyms_items(ln.strip()))
        print(f"{ln}\t{r}")
コード例 #5
0
ファイル: coverage.py プロジェクト: silnrsi/palaso-python
 def __init__(self, fname):
     self.kmfl = kmfl(fname)
     self.numrules = self.kmfl.numrules
コード例 #6
0
ファイル: coverage.py プロジェクト: HughP/Palaso-Python
 def __init__(self, fname) :
     self.kmfl = kmfl(fname)
     self.numrules = self.kmfl.num_rules()
コード例 #7
0
ファイル: kmn2xml.py プロジェクト: silnrsi/palaso-python
                  help="Modifiers to apply to keytops")
parser.add_option("-l",
                  "--lang",
                  action="store",
                  help="xml output language [kmxml]")

(opts, kmns) = parser.parse_args()
if not opts.lang: opts.lang = "kmxml"

of = outformats[opts.lang]
if len(kmns) == 0:
    sys.stderr.write(parser.expand_prog_name('%prog: missing KEYMAN FILE\n'))
    parser.print_help(file=sys.stderr)
    sys.exit(1)

kb = kmfl(kmns[0])
out = codecs.getwriter('utf_8')(sys.stdout)
out.write(of['header'](font=opts.font or '',
                       size=opts.font and opts.size or '',
                       name=kb.store('NAME'),
                       modifiers=opts.modifiers or ''))
if opts.modifiers:
    out.writelines(
        map(of['key'], key_tops,
            map(of['prep'], output_modified_chars(unshifted, opts.modifiers)),
            map(of['prep'], output_modified_chars(shifted, opts.modifiers)),
            map(of['bytes'], shifted), map(of['bytes'], unshifted)))
else:
    out.writelines(
        map(outformats[opts.lang]['key'], key_tops,
            map(of['prep'], output_chars(unshifted)),
コード例 #8
0
ファイル: kmn2ldml.py プロジェクト: silnrsi/palaso-python

parser = OptionParser()
parser.add_option("-l", "--lang", help="Language tag for this LDML")

(opts, argv) = parser.parse_args()
id = {}
if opts.lang:
    m = re.match(r'^([^-_]+)(?:[-_]?([^-_]*)[-_]?(.*))$', opts.lang)
    id['language'] = m.group(1)
    if len(m.group(2)) == 4:
        id['script'] = m.group(2)
    elif m.group(2):
        id['territory'] = m.group(2)

kb = kmfl(argv[0])
rules = {}
name = kb.store("NAME")
mnemonic = kb.store("MNEMONIC")
mnemattr = ' mnemonic="1"' if mnemonic else ""
print("""<?xml version="1.0"?>
<ldml>
  <identity>""")

for k, v in id.items():
    print('    <%s type="%s"/>' % (k, v))
print('    <generation date="%s"/>' % (time.strftime('%Y-%m-%d')))
print("""  </identity>
  <special>
    <keyboards xmlns="http://www.palaso.org/ldml/0.2">
      <keyboard name="%s"%s>""" % (name, mnemattr))