-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): board support show project tree and model list
- Loading branch information
Showing
5 changed files
with
83 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from dataclasses import dataclass | ||
|
||
import rich.repr | ||
from textual import events | ||
from textual._types import MessageTarget | ||
from textual.widget import Message | ||
from textual.widgets import TreeClick, TreeControl | ||
|
||
from starwhale.core.instance.view import InstanceTermView | ||
from starwhale.core.project.model import Project | ||
|
||
|
||
@dataclass | ||
class ProjectEntry: | ||
path: str | ||
is_project: bool | ||
|
||
|
||
@rich.repr.auto | ||
class ProjectClick(Message, bubble=True): | ||
def __init__(self, sender: MessageTarget, uri: str) -> None: | ||
self.uri = uri | ||
super().__init__(sender) | ||
|
||
|
||
class ProjectTree(TreeControl[ProjectEntry]): | ||
def __init__(self, uri: str, name: str): | ||
data = ProjectEntry("", False) | ||
super().__init__(uri, name=name, data=data) | ||
|
||
async def on_mount(self, event: events.Mount) -> None: | ||
ins = InstanceTermView().list() | ||
for i in ins: | ||
await self.root.add(i["name"], ProjectEntry(i["name"], False)) | ||
await self.root.expand() | ||
self.refresh(layout=True) | ||
|
||
async def handle_tree_click(self, message: TreeClick[ProjectEntry]) -> None: | ||
dir_entry = message.node.data | ||
# root entry | ||
if not dir_entry.path: | ||
return | ||
if dir_entry.is_project: | ||
await self.emit(ProjectClick(self, dir_entry.path)) | ||
else: | ||
if not message.node.loaded: | ||
ins = message.node.data.path | ||
ps, _ = Project.list(ins) | ||
for i in ps: | ||
await message.node.add( | ||
i["name"], ProjectEntry(f"{ins}/{i['name']}", True) | ||
) | ||
await message.node.expand() | ||
message.node.loaded = True | ||
else: | ||
await message.node.toggle() |