Skip to content

Commit 475b577

Browse files
committed
Keep both the Kivy UI and Web API
This reverts commit 6e09a03.
1 parent 693049f commit 475b577

18 files changed

+4166
-828
lines changed

poetry.lock

Lines changed: 2042 additions & 826 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ torch = "^2.1.0"
3131
torchvision = "^0.16.0"
3232
timm = "^0.6.13"
3333
structlog = "^22.3.0"
34+
kivy = { extras = ["base"], version = "^2.1.0" }
35+
plyer = "^2.1.0"
36+
pyobjus = [
37+
{ version = "^1.2.1", platform = "darwin" },
38+
{ version = "^1.2.1", platform = "linux" },
39+
]
3440

3541
# [tool.poetry.group.dev.dependencies] # Can't install these dev deps with pip, so they're in the main deps
3642
black = "^23.3.0"
@@ -54,6 +60,8 @@ asyncio_mode = 'auto'
5460
profile = "black"
5561

5662
[tool.poetry.scripts]
63+
trapdata = 'trapdata.ui.main:run'
64+
trapdata-test = 'trapdata.tests.test_pipeline:process_deployments'
5765
ami = 'trapdata.cli.base:cli'
5866

5967
# [tool.setuptools.package_data]

trapdata/cli/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import typer
55

6-
from trapdata.cli import export, queue, settings, shell, show, test
6+
from trapdata.cli import db, export, queue, settings, shell, show, test
77
from trapdata.db.base import get_session_class
88
from trapdata.db.models.events import get_or_create_monitoring_sessions
99
from trapdata.db.models.queue import add_monitoring_session_to_queue
@@ -14,11 +14,22 @@
1414
cli.add_typer(shell.cli, name="shell", help="Open an interactive shell")
1515
cli.add_typer(test.cli, name="test", help="Run tests")
1616
cli.add_typer(show.cli, name="show", help="Show data for use in other commands")
17+
cli.add_typer(db.cli, name="db", help="Create, update and manage the database")
1718
cli.add_typer(
1819
queue.cli, name="queue", help="Add and manage images in the processing queue"
1920
)
2021

2122

23+
@cli.command()
24+
def gui():
25+
"""
26+
Launch graphic interface
27+
"""
28+
from trapdata.ui.main import run
29+
30+
run()
31+
32+
2233
@cli.command("import")
2334
def import_data(image_base_path: Optional[pathlib.Path] = None, queue: bool = True):
2435
"""

trapdata/cli/db.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import typer
2+
from trapdata import db
3+
from trapdata.cli import settings
4+
5+
cli = typer.Typer(no_args_is_help=True)
6+
7+
8+
@cli.command()
9+
def create():
10+
"""
11+
Create database tables and sqlite file if neccessary.
12+
"""
13+
db.create_db(settings.database_url)
14+
db.migrate(settings.database_url)
15+
db.check_db(settings.database_url, quiet=False)
16+
17+
18+
@cli.command()
19+
def update():
20+
"""
21+
Run database migrations to update the database schema.
22+
"""
23+
db.migrate(settings.database_url)
24+
db.check_db(settings.database_url, quiet=False)
25+
26+
27+
@cli.command()
28+
def reset():
29+
"""
30+
Backup and recreate database tables.
31+
"""
32+
reset = typer.confirm("Are you sure you want to reset the database?")
33+
if reset:
34+
db.reset_db(settings.database_url)
35+
else:
36+
typer.Abort()
37+
38+
39+
@cli.command()
40+
def check():
41+
"""
42+
Validate database tables and ORM models.
43+
"""
44+
db.check_db(settings.database_url, quiet=False)
45+
46+
47+
if __name__ == "__main__":
48+
cli()

trapdata/settings.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import configparser
12
import pathlib
23
import sys
34
from functools import lru_cache
@@ -167,6 +168,7 @@ def customise_sources( # UK spelling
167168
return (
168169
init_settings,
169170
env_settings,
171+
kivy_settings_source,
170172
file_secret_settings,
171173
)
172174

@@ -175,10 +177,39 @@ class PipelineSettings(Settings):
175177
image_base_path: FilePath # Override default settings to enforce image_base_path
176178

177179

178-
cli_help_message = """
180+
def kivy_settings_path() -> pathlib.Path:
181+
project_root = pathlib.Path(__file__).parent
182+
kivy_settings_path = project_root / "ui" / "trapdata.ini"
183+
return kivy_settings_path
184+
185+
186+
def kivy_settings_source(settings: BaseSettings) -> dict[str, str]:
187+
"""
188+
Load settings set by user in the Kivy GUI app.
189+
"""
190+
path = kivy_settings_path()
191+
if not path.exists():
192+
return {}
193+
else:
194+
config = configparser.ConfigParser()
195+
config.read(kivy_settings_path())
196+
kivy_settings = [config.items(section) for section in config.sections()]
197+
kivy_settings_flat = dict(
198+
[item for section in kivy_settings for item in section]
199+
)
200+
null_values = ["None"]
201+
kivy_settings_flat = {
202+
k: v for k, v in kivy_settings_flat.items() if v not in null_values
203+
}
204+
return kivy_settings_flat
205+
206+
207+
cli_help_message = f"""
179208
Configuration for the CLI is currently set in the following sources, in order of priority:
180209
- The system environment (os.environ)
181210
- ".env" file (see ".env.example"), prefix settings with "AMI_"
211+
- Kivy settings panel in the GUI app
212+
- Directly in the Kivy settings file: {kivy_settings_path()}
182213
"""
183214

184215

trapdata/ui/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)