Create desktop icon
This commit is contained in:
parent
5753624065
commit
9f95387b4b
@ -21,6 +21,7 @@ python_requires = >=3.8
|
|||||||
install_requires =
|
install_requires =
|
||||||
requests
|
requests
|
||||||
requests-futures
|
requests-futures
|
||||||
|
desktop-file
|
||||||
|
|
||||||
[options.packages.find]
|
[options.packages.find]
|
||||||
where = src
|
where = src
|
||||||
|
@ -19,8 +19,8 @@ def dequotify(string):
|
|||||||
class Config:
|
class Config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._configparser = ConfigParser()
|
self._configparser = ConfigParser()
|
||||||
config_dir_path = Path(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.ConfigLocation))
|
config_dir_path = Path(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppConfigLocation))
|
||||||
config_path = config_dir_path / "fime" / "fime.conf"
|
config_path = config_dir_path / "fime.conf"
|
||||||
if config_path.exists():
|
if config_path.exists():
|
||||||
print(f'Reading config file "{config_path}"')
|
print(f'Reading config file "{config_path}"')
|
||||||
with open(config_path) as f:
|
with open(config_path) as f:
|
||||||
|
@ -12,12 +12,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from PySide2 import QtCore
|
from PySide2 import QtCore
|
||||||
|
|
||||||
data_dir_path = os.path.join(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation),
|
|
||||||
"fime")
|
|
||||||
|
|
||||||
tasks_path = os.path.join(data_dir_path, "tasks.json")
|
|
||||||
|
|
||||||
data_path = os.path.join(data_dir_path, "data_{}.json")
|
|
||||||
save_delay = 3 * 60
|
save_delay = 3 * 60
|
||||||
max_jira_tasks = 50
|
max_jira_tasks = 50
|
||||||
|
|
||||||
@ -84,6 +78,8 @@ class Tasks:
|
|||||||
|
|
||||||
class Data(MutableMapping):
|
class Data(MutableMapping):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
data_dir_path = QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation)
|
||||||
|
self.data_path = os.path.join(data_dir_path, "data_{}.json")
|
||||||
if not os.path.exists(data_dir_path):
|
if not os.path.exists(data_dir_path):
|
||||||
os.mkdir(data_dir_path)
|
os.mkdir(data_dir_path)
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
@ -101,7 +97,7 @@ class Data(MutableMapping):
|
|||||||
atexit.register(cleanup)
|
atexit.register(cleanup)
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
dpath = data_path.format(key)
|
dpath = self.data_path.format(key)
|
||||||
if key not in self._cache and os.path.exists(dpath):
|
if key not in self._cache and os.path.exists(dpath):
|
||||||
with open(dpath, "r") as f:
|
with open(dpath, "r") as f:
|
||||||
self._cache[key] = json.loads(f.read())
|
self._cache[key] = json.loads(f.read())
|
||||||
@ -128,7 +124,7 @@ class Data(MutableMapping):
|
|||||||
for key in self._hot_keys:
|
for key in self._hot_keys:
|
||||||
print(f"... saving dict {key} ...")
|
print(f"... saving dict {key} ...")
|
||||||
to_write = self._cache[key] # apparently thread-safe
|
to_write = self._cache[key] # apparently thread-safe
|
||||||
with open(data_path.format(key), "w+") as f:
|
with open(self.data_path.format(key), "w+") as f:
|
||||||
f.write(json.dumps(to_write))
|
f.write(json.dumps(to_write))
|
||||||
self._hot_keys = set()
|
self._hot_keys = set()
|
||||||
self._saving = False
|
self._saving = False
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import desktop_file
|
||||||
|
|
||||||
from fime.config import Config
|
from fime.config import Config
|
||||||
|
|
||||||
@ -131,8 +133,39 @@ class App:
|
|||||||
print(f'handling signal "{signal.strsignal(signo)}"')
|
print(f'handling signal "{signal.strsignal(signo)}"')
|
||||||
self.app.quit()
|
self.app.quit()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def write_icon():
|
||||||
|
icon_path = str(Path(__file__).parent / "fime.svg")
|
||||||
|
if "main" not in sys.argv[0]:
|
||||||
|
QtCore.QFile.copy(":/icons/appointment-new.svg", icon_path)
|
||||||
|
return icon_path
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_shortcut(icon_path):
|
||||||
|
shortcut_file = Path(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation)) \
|
||||||
|
/ "shortcut"
|
||||||
|
print(f"shortcut file: {shortcut_file}")
|
||||||
|
shortcut_file_contents = ""
|
||||||
|
if shortcut_file.exists():
|
||||||
|
with open(shortcut_file, "r") as f:
|
||||||
|
shortcut_file_contents = f.read()
|
||||||
|
if shortcut_file_contents.strip() == __file__:
|
||||||
|
return
|
||||||
|
shortcut = desktop_file.Shortcut(desktop_file.getMenuPath(), "fime", sys.argv[0])
|
||||||
|
shortcut.setTitle("Fime")
|
||||||
|
shortcut.setComment("Simple time tracking app written with Python and Qt")
|
||||||
|
shortcut.setIcon(icon_path)
|
||||||
|
shortcut.save()
|
||||||
|
if "main" not in sys.argv[0]:
|
||||||
|
print("Successfully created menu shortcut")
|
||||||
|
shortcut_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(shortcut_file, "w") as f:
|
||||||
|
f.write(__file__)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
timer = QtCore.QTimer()
|
icon_path = self.write_icon()
|
||||||
|
self.create_shortcut(icon_path)
|
||||||
|
timer = QtCore.QTimer(None)
|
||||||
# interrupt event loop regularly for signal handling
|
# interrupt event loop regularly for signal handling
|
||||||
timer.timeout.connect(lambda: None)
|
timer.timeout.connect(lambda: None)
|
||||||
timer.start(500)
|
timer.start(500)
|
||||||
@ -161,6 +194,8 @@ class App:
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
|
# important for QStandardPath to be correct
|
||||||
|
QtCore.QCoreApplication.setApplicationName("fime")
|
||||||
app = App()
|
app = App()
|
||||||
app.run()
|
app.run()
|
||||||
except FimeException as e:
|
except FimeException as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user