Skip to content

Commit

Permalink
deprecate old ui, add import/export recording
Browse files Browse the repository at this point in the history
  • Loading branch information
0dm committed May 18, 2023
1 parent a95661f commit c8ad9fe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import sys
import os
import bz2
import requests
from shutil import copyfileobj
from nicegui import app, ui
from openadapt import visualize, replay

SERVER = "<>"

app.native.window_args["resizable"] = False
app.native.start_args["debug"] = True
Expand All @@ -26,6 +30,8 @@
ui.icon("share").tooltip("Share").on(
"click", lambda: (_ for _ in ()).throw(Exception(NotImplementedError))
)
ui.icon("upload").tooltip("Export Data").on("click", lambda: on_export())
ui.icon("download").tooltip("Import Data").on("click", lambda: on_import())


# Record button + popup
Expand Down Expand Up @@ -122,4 +128,37 @@ def clear_db():
print("Database cleared.", file=sys.stderr)


def on_export():
ui.notify("Exporting data to server...")

# compress db with bz2
with open("openadapt.db", "rb") as f:
with bz2.BZ2File("openadapt.db.bz2", "wb", compresslevel=9) as f2:
copyfileobj(f, f2)

# upload to server with requests, and keep file name
files = {
"files": open("openadapt.db.bz2", "rb"),
}

requests.post(SERVER, files=files)

# delete compressed db
os.remove("openadapt.db.bz2")

ui.notify("Exported data to server.")


def on_import():
# TODO create file picker to select file to import, then decompress

with open("openadapt.db", "wb") as f:
with bz2.BZ2File("openadapt.db.bz2", "rb") as f2:
copyfileobj(f2, f)

os.remove("openadapt.db.bz2")

ui.notify("Imported data from server.")


ui.run(title="OpenAdapt Client", native=True, window_size=(400, 350), fullscreen=False)
3 changes: 2 additions & 1 deletion app-old.py → openadapt/deprecated/app-old.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import tkinter as tk
from tkinter import simpledialog
from PIL import Image, ImageTk
from openadapt import record, visualize, replay, console
from openadapt import record, visualize, replay
from openadapt.deprecated import console


class App(tk.Tk):
Expand Down
File renamed without changes.

0 comments on commit c8ad9fe

Please sign in to comment.