1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#!/usr/bin/python
##########
# Presage, an extensible predictive text entry system
# ------------------------------------------------------
# Copyright (C) 2009 John Hills
# Copyright (C) 2009 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
import getopt
import os
PROGRAM_NAME = 'pypresagemate'
def print_version():
print """
%s (%s) version %s
Copyright (C) 2010 Matteo Vescovi.
Copyright (C) 2010 John Hills.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
""" % (PROGRAM_NAME, 'presage', '0.9.1')
def print_usage():
print """
Usage: %s [options]
Options:
-h, --help display this help and exit
-v, --version output version information and exit
Pypresagemate is a universal predictive text companion.
Pypresagemate works alongside any AT-SPI aware application. The
Assistive Technology Service Provider Interface (AT-SPI) is a
toolkit-neutral way of providing accessibility facilities in
applications. Pypresagemate works in the background by tracking what
keystrokes are typed and displaying predictions in its window. When a
prediction is selected, text is sent to the active application.
Direct your bug reports to: %s
""" % (PROGRAM_NAME, 'matteo.vescovi@yahoo.co.uk')
def parse_cmd_line_args():
short_options = "hv"
long_options = ["help", "version"]
try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
print str(err)
sys.exit(1)
for opt, arg in opts:
if opt in ('-v', '--version'):
print_version()
sys.exit()
elif opt in ('-h', '--help'):
print_usage()
sys.exit()
if __name__ == "__main__":
parse_cmd_line_args()
try:
import presagemate.presagemate
except ImportError, e:
print '''
Error: failed to import module presagemate.
Check that prompter is properly installed (if installed in a
non-standard location, please set PYTHONPATH accordingly).
'''
print e
else:
if not config:
# try to locate presage.xml config file
scriptdir = os.path.dirname(sys.argv[0])
# in scriptdir/etc
conffile = os.path.join(scriptdir, 'etc', 'presage.xml')
if os.path.isfile(conffile):
config = conffile
else:
# in scriptdir/../etc
conffile = os.path.join(scriptdir, '..', 'etc', 'presage.xml')
if os.path.isfile(conffile):
config = conffile
print 'Configuration file: ' + str(config)
|