forked from utdemir/simpleshortcuts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·68 lines (52 loc) · 1.63 KB
/
main.py
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
#! /usr/bin/env python2
import os
import sys
import argparse
import sip
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)
from PyQt4.QtGui import QApplication
from mainui import MainUi
from settings import Settings
try:
use_lock = Settings.read()["options"]["use_lock"]
except KeyError:
use_lock = False
if(use_lock):
import fcntl
LOCK_FILE = os.path.join(Settings.settings_path, "simpleshortcuts.lock")
print("Using lock file:", LOCK_FILE)
f = open(LOCK_FILE, "w")
try:
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError as err:
if(err.errno == 11):
print("There is another instance running. Exiting...")
sys.exit(1)
raise err
parser = argparse.ArgumentParser(description="SimpleShortcuts")
parser.add_argument("-s", "--settings",
help="Show the settings dialog",
action="store_true")
parser.add_argument("-i", "--imitate",
help="Show and immediately close the main window.",
action="store_true")
args = parser.parse_args()
app = QApplication(sys.argv)
if args.settings:
from settingsdialog import SettingsDialog
g = SettingsDialog()
else:
try:
g = MainUi()
except Exception as err:
print("An exception has occured!")
print("Try opening the settings dialog with -s parameter and resaving the settings.",
"You may have to delete your settings file as last resort."
)
raise err
g.show()
if args.imitate: sys.exit()
rect = app.desktop().screenGeometry()
g.move(rect.center() - g.rect().center())
app.exec_()