1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
"""KanbanView (app) for Things 3.""" |
5
|
|
|
|
6
|
|
|
from __future__ import print_function |
7
|
|
|
|
8
|
|
|
# pylint: disable=duplicate-code |
9
|
|
|
__author__ = "Alexander Willner" |
10
|
|
|
__copyright__ = "Copyright 2020 Alexander Willner" |
11
|
|
|
__credits__ = ["Luc Beaulieu", "Alexander Willner"] |
12
|
|
|
__license__ = "Apache License 2.0" |
13
|
|
|
__version__ = "2.1.2" |
14
|
|
|
__maintainer__ = "Alexander Willner" |
15
|
|
|
__email__ = "[email protected]" |
16
|
|
|
__status__ = "Development" |
17
|
|
|
|
18
|
|
|
import sys |
19
|
|
|
from os import system |
20
|
|
|
from threading import Thread |
21
|
|
|
import webview # type: ignore |
|
|
|
|
22
|
|
|
import objc # type: ignore # pylint: disable=unused-import # noqa F401 |
|
|
|
|
23
|
|
|
import pkg_resources.py2_warn # type: ignore # pylint: disable=unused-import # noqa F401 |
|
|
|
|
24
|
|
|
import things3.things3_api as things3_api |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class Things3App(): |
28
|
|
|
"""App wrapper for simple read-only API for Things 3.""" |
29
|
|
|
|
30
|
|
|
database = None |
31
|
|
|
FILE = "kanban.html" |
32
|
|
|
|
33
|
|
|
def open_api(self): |
34
|
|
|
"""Delay opening the browser.""" |
35
|
|
|
print(f"Using database 2: {self.database}") |
36
|
|
|
things3_api.Things3API(database=self.database).main() |
37
|
|
|
|
38
|
|
|
def __init__(self, database=None): |
39
|
|
|
self.database = database |
40
|
|
|
|
41
|
|
|
def main(self): |
42
|
|
|
"""Run the app.""" |
43
|
|
|
# kill possible zombie processes; can't use psutil in py2app context |
44
|
|
|
system('lsof -nti:' + str(things3_api.Things3API.PORT) + |
45
|
|
|
' | xargs kill -9') |
46
|
|
|
|
47
|
|
|
print(f"Using database 1: {self.database}") |
48
|
|
|
|
49
|
|
|
webview.create_window( |
50
|
|
|
title='KanbanView for Things 3', |
51
|
|
|
url=f'http://localhost:{things3_api.Things3API.PORT}/{self.FILE}', |
52
|
|
|
width=1024, |
53
|
|
|
min_size=(1024, 600), |
54
|
|
|
frameless=True) |
55
|
|
|
|
56
|
|
|
thread = Thread(target=self.open_api) |
57
|
|
|
try: |
58
|
|
|
thread.start() |
59
|
|
|
webview.start() |
60
|
|
|
except KeyboardInterrupt: |
61
|
|
|
print("Shutting down...") |
62
|
|
|
thread.join() |
63
|
|
|
sys.exit(0) |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
if __name__ == "__main__": |
67
|
|
|
Things3App().main() |
68
|
|
|
|