screenkey 2.19 KB
Newer Older
1
#!/usr/bin/env python2
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
# Copyright (c) 2010 Pablo Seminario <pabluk@gmail.com>
# 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 3 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, see <http://www.gnu.org/licenses/>.

import os
import logging
from optparse import OptionParser
import pygtk
pygtk.require('2.0')
import gtk
import gettext
import locale

locale.setlocale(locale.LC_ALL, '')
gettext.install('screenkey', unicode=True)

from Screenkey import APP_NAME, APP_DESC, VERSION
from Screenkey.screenkey import Screenkey

gtk.gdk.threads_init()

def Main():
    parser = OptionParser(description=APP_DESC, version=VERSION)
    parser.add_option("--no-detach", action="store_true", 
        dest="nodetach", default=False, 
        help=_("do not detach from the parent"))
    parser.add_option("-d", "--debug", action="store_true", 
        dest="debug", default=False, help=_("show debug information"))
    (options, args) = parser.parse_args()

    if options.debug:
        if options.nodetach:
            # Send debug messages to standard output
            logfile = None
        else:
            logfile = os.path.join(os.path.expanduser('~'), 
                                   '.screenkey.log')
            username = os.environ.get('SUDO_USER')
            if username:
                homedir = os.path.expanduser('~%s' % username)
                if homedir != '~%s' % username:
                    logfile = os.path.join(homedir, '.screenkey.log')
        logging.basicConfig(filename=logfile, level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger(APP_NAME)

    s = Screenkey(logger=logger, nodetach=options.nodetach)
    gtk.main()


if __name__ == "__main__":
    Main()