#!/usr/bin/env python

import sys
import lockfile
import plover.gui.main

# Ensure only one instance of Plover is running at a time.
LOCK_FILE = '/tmp/plover'
lock = lockfile.FileLock(LOCK_FILE)
try:
    lock.acquire(0)
except lockfile.AlreadyLocked:
    print "Another instance of Plover is already running."
    sys.exit(1)
except lockfile.LockFailed:
    print "The lock file %s cannot be locked." % LOCK_FILE
    sys.exit(2)

# Create and start the user interface. Clean up the lock file afterward.
try:
    print "If Plover is quit using Ctrl-c, the /tmp/plover.lock file must \
be removed before Plover can be run again."
    gui = plover.gui.main.PloverGUI()
    gui.MainLoop()
finally:
    lock.release()
