Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit e3f15bd

Browse files
committed
nanokvm: add get_images
1 parent 35bfec3 commit e3f15bd

5 files changed

Lines changed: 157 additions & 123 deletions

File tree

packages/jumpstarter-driver-nanokvm/jumpstarter_driver_nanokvm/client.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
import click
66
from jumpstarter_driver_composite.client import CompositeClient
7+
from nanokvm.models import MouseButton
78
from PIL import Image
89

910
from jumpstarter.client import DriverClient
1011
from jumpstarter.client.decorators import driver_click_group
1112

13+
# Re-export MouseButton for convenience
14+
__all__ = ["NanoKVMVideoClient", "NanoKVMHIDClient", "NanoKVMClient", "MouseButton"]
15+
1216

1317
@dataclass(kw_only=True)
1418
class NanoKVMVideoClient(DriverClient):
@@ -134,25 +138,24 @@ def mouse_move_rel(self, dx: float, dy: float):
134138
"""
135139
self.call("mouse_move_rel", dx, dy)
136140

137-
def mouse_click(self, button: str = "left", x: float | None = None, y: float | None = None):
141+
def mouse_click(self, button: MouseButton | str = "left", x: float | None = None, y: float | None = None):
138142
"""
139143
Click a mouse button
140144
141145
Args:
142-
button: Mouse button to click ("left", "right", "middle")
146+
button: Mouse button to click (MouseButton enum or "left", "right", "middle" string)
143147
x: Optional X coordinate (0.0 to 1.0) for absolute positioning before click
144148
y: Optional Y coordinate (0.0 to 1.0) for absolute positioning before click
145149
146150
Example::
147151
148-
# Click at current position
152+
# Using string (backward compatible)
149153
hid.mouse_click("left")
150-
151-
# Click at center of screen
152154
hid.mouse_click("left", 0.5, 0.5)
153155
154-
# Right-click at specific location
155-
hid.mouse_click("right", 0.75, 0.25)
156+
# Using MouseButton enum (recommended)
157+
hid.mouse_click(MouseButton.LEFT)
158+
hid.mouse_click(MouseButton.RIGHT, 0.75, 0.25)
156159
"""
157160
if x is not None and y is not None:
158161
self.call("mouse_click", button, x, y)
@@ -234,7 +237,14 @@ def move_rel(dx, dy):
234237
@click.option("--y", type=float, default=None, help="Optional Y coordinate (0.0-1.0)")
235238
def mouse_click_cmd(button, x, y):
236239
"""Click a mouse button"""
237-
self.mouse_click(button, x, y)
240+
# Convert string to MouseButton enum
241+
button_map = {
242+
"left": MouseButton.LEFT,
243+
"right": MouseButton.RIGHT,
244+
"middle": MouseButton.MIDDLE,
245+
}
246+
button_enum = button_map[button]
247+
self.mouse_click(button_enum, x, y)
238248
if x is not None and y is not None:
239249
click.echo(f"Clicked {button} button at ({x}, {y})")
240250
else:
@@ -397,6 +407,21 @@ def get_image_download_status(self) -> dict:
397407
"""
398408
return self.call("get_image_download_status")
399409

410+
def get_images(self) -> list[str]:
411+
"""
412+
Get the list of available image files
413+
414+
Returns:
415+
List of image file paths available on the NanoKVM device
416+
417+
Example::
418+
419+
images = nanokvm.get_images()
420+
for image in images:
421+
print(f"Available: {image}")
422+
"""
423+
return self.call("get_images")
424+
400425
def cli(self): # noqa: C901
401426
"""Create CLI interface with device management and child commands"""
402427
base = super().cli()
@@ -498,4 +523,15 @@ def download_status():
498523
if status['percentage']:
499524
click.echo(f"Progress: {status['percentage']}")
500525

526+
@image.command()
527+
def list():
528+
"""List available image files"""
529+
images = self.get_images()
530+
if images:
531+
click.echo("Available images:")
532+
for img in images:
533+
click.echo(f" - {img}")
534+
else:
535+
click.echo("No images available")
536+
501537
return base

0 commit comments

Comments
 (0)