~ubuntu-branches/ubuntu/trusty/presage/trusty-proposed

« back to all changes in this revision

Viewing changes to apps/python/pyprompter

  • Committer: Bazaar Package Importer
  • Author(s): Matteo Vescovi
  • Date: 2011-08-06 09:26:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110806092615-0wvhajaht9974ncx
Tags: upstream-0.8.6
ImportĀ upstreamĀ versionĀ 0.8.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
##########
 
4
#  Presage, an extensible predictive text entry system
 
5
#  ---------------------------------------------------
 
6
#
 
7
#  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
 
8
#
 
9
#  This program is free software; you can redistribute it and/or modify
 
10
#  it under the terms of the GNU General Public License as published by
 
11
#  the Free Software Foundation; either version 2 of the License, or
 
12
#  (at your option) any later version.
 
13
#
 
14
#  This program is distributed in the hope that it will be useful,
 
15
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#  GNU General Public License for more details.
 
18
#
 
19
#  You should have received a copy of the GNU General Public License along
 
20
#  with this program; if not, write to the Free Software Foundation, Inc.,
 
21
#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
22
 
 
23
import sys
 
24
import getopt
 
25
import os
 
26
 
 
27
PROGRAM_NAME = 'pyprompter'
 
28
config = None
 
29
suggestions = None
 
30
 
 
31
def print_version():
 
32
   print """
 
33
%s (%s) version %s
 
34
Copyright (C) 2004 Matteo Vescovi.
 
35
This is free software; see the source for copying conditions.  There is NO
 
36
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
 
37
to the extent permitted by law.
 
38
""" % (PROGRAM_NAME, 'presage', '0.8.6')
 
39
 
 
40
def print_usage():
 
41
   print """
 
42
Usage: %s [options]
 
43
 
 
44
Options:
 
45
  -h, --help           display this help and exit
 
46
  -v, --version        output version information and exit
 
47
 
 
48
Prompter is a simple predictive text editor, written to demonstrate
 
49
the use of presage, the intelligent predictive text entry system.
 
50
 
 
51
Begin editing. While editing, prompter uses presage to generate
 
52
predictions and displays them in a pop-up prediction list. If the
 
53
desired text is displayed in the prediction list, select it by double
 
54
clicking on it or by highlighting it with the arrow keys and then
 
55
pressing ENTER; the desired text will be automatically entered.
 
56
 
 
57
Direct your bug reports to: %s
 
58
""" % (PROGRAM_NAME, 'matteo.vescovi@yahoo.co.uk')
 
59
 
 
60
def parse_cmd_line_args():
 
61
   short_options = "c:s:hv"
 
62
   long_options  = ["config=", "suggestions=", "help", "version"]
 
63
   
 
64
   try:
 
65
      opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
 
66
   except getopt.GetoptError, err:
 
67
      print str(err)
 
68
      sys.exit(1)
 
69
   
 
70
   for opt, arg in opts:
 
71
      if opt in ('-v', '--version'):
 
72
         print_version()
 
73
         sys.exit()
 
74
      elif opt in ('-h', '--help'):
 
75
         print_usage()
 
76
         sys.exit()
 
77
      elif opt in ('-c', '--config'):
 
78
         global config
 
79
         config = arg
 
80
      elif opt in ('-s', '--suggestions'):
 
81
         global suggestions
 
82
         suggestions = arg
 
83
 
 
84
 
 
85
if __name__ == "__main__":
 
86
   parse_cmd_line_args()
 
87
 
 
88
   try:
 
89
      import prompter.prompter
 
90
   except ImportError, e:
 
91
      print '''
 
92
Error: failed to import module prompter.
 
93
 
 
94
Check that prompter is properly installed (if installed in a
 
95
non-standard location, please set PYTHONPATH accordingly).
 
96
'''
 
97
      print e
 
98
   else:
 
99
      if not config:
 
100
         # try to locate presage.xml config file
 
101
         scriptdir = os.path.dirname(sys.argv[0])
 
102
         # in scriptdir/etc
 
103
         conffile = os.path.join(scriptdir, 'etc', 'presage.xml')
 
104
         if os.path.isfile(conffile):
 
105
            config = conffile
 
106
         else:
 
107
            # in scriptdir/../etc
 
108
            conffile = os.path.join(scriptdir, '..', 'etc', 'presage.xml')
 
109
            if os.path.isfile(conffile):
 
110
               config = conffile
 
111
         print 'Configuration file: ' + str(config)
 
112
 
 
113
      app = prompter.prompter.Prompter("0.8.6", config, suggestions)
 
114
      app.MainLoop()