Skip to content

Commit

Permalink
Merge branch 'main' into share-magic-wormhole
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustaballer authored Jul 31, 2023
2 parents f29f199 + 8afb5c5 commit 1a10f8a
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 45 deletions.
6 changes: 4 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[flake8]
exclude=alembic/versions,.venv, openadapt/strategies/__init__.py
docstring-convention=google
exclude =
alembic/versions,
.venv
docstring-convention = google
max-line-length = 88
extend-ignore = ANN101
91 changes: 91 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,97 @@



## v0.7.0 (2023-07-28)

### Feature

* feat: scrub toggle for gui (#375)

* add scrub toggle + write dark_mode to env

* Update config.py

* Update util.py

* Update config.py

* address comments

* Update config.py

* run isort

* from first

* Update openadapt/config.py

* Update openadapt/config.py

* Update openadapt/config.py

* Update openadapt/config.py

* Update openadapt/config.py

* Update openadapt/config.py

* add env file path (also where did the toggle go??)

* Update config.py

* Update config.py

* Update config.py

* isort

* Update util.py

* linted

---------

Co-authored-by: Richard Abrich <[email protected]> ([`1e96a4f`](https://github.com/OpenAdaptAI/OpenAdapt/commit/1e96a4f599b9790509dad865ea3c7b1b254fb19b))


## v0.6.1 (2023-07-28)

### Fix

* fix: modify flake8 config (#429)

* style: modify flake8 config

* add platform check for macOS in pyobjc-framework-avfoundation version

* remove file exclusion in .flake8 and add ignore comment in openadapt/strategies/__init__.py

* resolve lint errors from recent merge ([`f03be2f`](https://github.com/OpenAdaptAI/OpenAdapt/commit/f03be2f9cf100b5bc8dfa34cf76fd60b6eef9f62))


## v0.6.0 (2023-07-26)

### Feature

* feat(crud): compute and save screenshot diff (#367)

* feat(crud): Compute and save screenshot diff

* Add 2 columns in screenshot table to store png_diff_data and png_mask_diff_data.

* CRUD now supports calculation and save screenshots diff data on the flight.

* feat(config): Add SAVE_SCREENSHOT_DIFF environment variable

* SAVE_SCREENSHOT_DIFF indicates that 2 neighbors screenshot will be compared and the difference will be saved to db

* feat(crud): add missing import after merge

* refactor(crud): add missing type annotations

* refactor(crud): add missing type annotations ([`9189bca`](https://github.com/OpenAdaptAI/OpenAdapt/commit/9189bca7aef05ef7801545cc0a55bca54898820a))


## v0.5.8 (2023-07-25)

### Fix
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add png_diff_data and png_diff_mask_data
Revision ID: 8713b142f5de
Revises: 607d1380b5ae
Create Date: 2023-07-09 15:31:28.462388
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = '8713b142f5de'
down_revision = '607d1380b5ae'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('screenshot', schema=None) as batch_op:
batch_op.add_column(sa.Column('png_diff_data', sa.LargeBinary(), nullable=True))
batch_op.add_column(sa.Column('png_diff_mask_data', sa.LargeBinary(), nullable=True))

# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('screenshot', schema=None) as batch_op:
batch_op.drop_column('png_diff_mask_data')
batch_op.drop_column('png_diff_data')

# ### end Alembic commands ###
16 changes: 10 additions & 6 deletions openadapt/app/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from nicegui import ui

from openadapt.app.objects.local_file_picker import LocalFilePicker
from openadapt.app.util import set_dark, sync_switch
from openadapt.app.util import get_scrub, set_dark, set_scrub, sync_switch

PROC = None

Expand All @@ -21,13 +21,17 @@ def settings(dark_mode: bool) -> None:
dark_mode (bool): Current dark mode setting.
"""
with ui.dialog() as settings, ui.card():
s = ui.switch(
"Dark mode",
on_change=lambda: set_dark(dark_mode, s.value),
dark_switch = ui.switch(
"Dark mode", on_change=lambda: set_dark(dark_mode, dark_switch.value)
)
sync_switch(s, dark_mode)
ui.button("Close", on_click=lambda: settings.close())
sync_switch(dark_switch, dark_mode)

scrub_switch = ui.switch(
"Scrubbing", on_change=lambda: set_scrub(scrub_switch.value)
)
sync_switch(scrub_switch, get_scrub())

ui.button("Close", on_click=lambda: settings.close())
settings.open()


Expand Down
12 changes: 6 additions & 6 deletions openadapt/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

import base64
import os
import threading

from nicegui import app, ui

from openadapt import replay, visualize
from openadapt import config, replay, visualize
from openadapt.app.cards import recording_prompt, select_import, settings
from openadapt.app.objects.console import Console
from openadapt.app.util import clear_db, on_export, on_import
Expand All @@ -29,6 +28,8 @@ def run_app() -> None:
app.native.start_args["debug"] = False

dark = ui.dark_mode()
dark.value = config.APP_DARK_MODE

logger = None

# Add logo
Expand Down Expand Up @@ -70,10 +71,9 @@ def run_app() -> None:
)
.tooltip("Record a new replay / Stop recording")
)
ui.icon("visibility", size="64px").on(
"click",
lambda: threading.Thread(target=visualize.main).start(),
).tooltip("Visualize the latest replay")
ui.icon("visibility", size="64px").on("click", visualize.main).tooltip(
"Visualize the latest replay"
)

ui.icon("play_arrow", size="64px").on(
"click",
Expand Down
29 changes: 27 additions & 2 deletions openadapt/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from nicegui import elements, ui

from openadapt import config
from openadapt.app.objects import console
from openadapt.scripts.reset_db import reset_db

Expand Down Expand Up @@ -97,7 +98,29 @@ def sync_switch(
switch: The switch object.
prop: The property object.
"""
switch.value = prop.value
switch.value = prop.value if hasattr(prop, "value") else prop


def set_scrub(value: bool) -> None:
"""Set the scrubbing value.
Args:
value: The value to set.
"""
if config.SCRUB_ENABLED != value:
config.persist_env("SCRUB_ENABLED", value)
config.SCRUB_ENABLED = value
ui.notify("Scrubbing enabled." if value else "Scrubbing disabled.")
ui.notify("You may need to restart the app for this to take effect.")


def get_scrub() -> bool:
"""Get the scrubbing value.
Returns:
bool: The scrubbing value.
"""
return config.SCRUB_ENABLED


def set_dark(dark_mode: ui.dark_mode, value: bool) -> None:
Expand All @@ -107,4 +130,6 @@ def set_dark(dark_mode: ui.dark_mode, value: bool) -> None:
dark_mode: The dark mode object.
value: The value to set.
"""
dark_mode.value = value
if dark_mode.value != value:
dark_mode.value = value
config.persist_env("APP_DARK_MODE", value)
34 changes: 33 additions & 1 deletion openadapt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"ACTION_TEXT_SEP": "-",
"ACTION_TEXT_NAME_PREFIX": "<",
"ACTION_TEXT_NAME_SUFFIX": ">",
# APP CONFIGURATIONS
"APP_DARK_MODE": False,
# SCRUBBING CONFIGURATIONS
"SCRUB_ENABLED": False,
"SCRUB_CHAR": "*",
Expand Down Expand Up @@ -84,6 +86,8 @@
"children",
],
"PLOT_PERFORMANCE": True,
# Calculate and save the difference between 2 neighboring screenshots
"SAVE_SCREENSHOT_DIFF": False,
}

# each string in STOP_STRS should only contain strings
Expand Down Expand Up @@ -134,7 +138,35 @@ def getenv_fallback(var_name: str) -> str:
return rval


load_dotenv(ENV_FILE_PATH)
def persist_env(var_name: str, val: str, env_file_path: str = ENV_FILE_PATH) -> None:
"""Persist an environment variable to a .env file.
Args:
var_name (str): The name of the environment variable.
val (str): The value of the environment variable.
env_file_path (str, optional): The path to the .env file (default: ".env").
"""
if not os.path.exists(env_file_path):
with open(env_file_path, "w") as f:
f.write(f"{var_name}={val}")
else:
# find and replace
with open(env_file_path, "r") as f:
lines = f.readlines()
for i, line in enumerate(lines):
if line.startswith(f"{var_name}="):
lines[i] = f"{var_name}={val}\n"
break
else:
# we didn't find the variable in the file, so append it
if lines[-1][-1] != "\n":
lines.append("\n")
lines.append(f"{var_name}={val}")
with open(env_file_path, "w") as f:
f.writelines(lines)


load_dotenv()

for key in _DEFAULTS:
val = getenv_fallback(key)
Expand Down
Loading

0 comments on commit 1a10f8a

Please sign in to comment.