Skip to content

Commit

Permalink
fix for mac?
Browse files Browse the repository at this point in the history
  • Loading branch information
shapiromatron committed Jul 9, 2024
1 parent ca56ecd commit f6491fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions bmds_ui/desktop/components/database_form.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from asyncio import sleep
from pathlib import Path
from typing import Any

Expand All @@ -10,7 +11,6 @@
from textual.validation import Function
from textual.widget import Widget
from textual.widgets import Button, Input, Label, Markdown
from textual.worker import Worker

from ..actions import create_django_db
from ..config import Config, Database
Expand Down Expand Up @@ -146,10 +146,8 @@ def compose(self) -> ComposeResult:

@on(Button.Pressed, "#db-create")
async def on_db_create(self) -> None:
self.get_widget_by_id("actions-row").loading = True
self.create_db()
await self.create_db()

@work(thread=True)
async def create_db(self) -> None:
name = self.query_one("#name").value
path = self.query_one("#path").value
Expand All @@ -161,15 +159,19 @@ async def create_db(self) -> None:
db_path = (Path(path).expanduser().resolve() / db).absolute()
config = Config.get()
db = Database(name=name, description=description, path=db_path)
self._create_django_db(config, db)

@work(exclusive=True)
async def _create_django_db(self, config, db):
actions = self.get_widget_by_id("actions-row")
actions.loading = True
await sleep(0.1)
config.add_db(db)
Config.sync()
create_django_db(config, db)
self.app.call_from_thread(self.dismiss, result=True)

async def on_worker_state_changed(self, message: Worker.StateChanged):
# ensure loading indicator is removed when finished
if message.worker.is_finished:
self.get_widget_by_id("actions-row").loading = False
actions.loading = False
await sleep(0.1)
self.dismiss(True)

@on(Button.Pressed, "#db-update")
async def on_db_update(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [

# desktop
"packaging~=24.0",
"textual~=0.62.0",
"textual~=0.72.0",
"whitenoise~=6.6.0",
]

Expand Down

0 comments on commit f6491fb

Please sign in to comment.