|
4 | 4 |
|
5 | 5 | import click |
6 | 6 | from jumpstarter_driver_composite.client import CompositeClient |
| 7 | +from nanokvm.models import MouseButton |
7 | 8 | from PIL import Image |
8 | 9 |
|
9 | 10 | from jumpstarter.client import DriverClient |
10 | 11 | from jumpstarter.client.decorators import driver_click_group |
11 | 12 |
|
| 13 | +# Re-export MouseButton for convenience |
| 14 | +__all__ = ["NanoKVMVideoClient", "NanoKVMHIDClient", "NanoKVMClient", "MouseButton"] |
| 15 | + |
12 | 16 |
|
13 | 17 | @dataclass(kw_only=True) |
14 | 18 | class NanoKVMVideoClient(DriverClient): |
@@ -134,25 +138,24 @@ def mouse_move_rel(self, dx: float, dy: float): |
134 | 138 | """ |
135 | 139 | self.call("mouse_move_rel", dx, dy) |
136 | 140 |
|
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): |
138 | 142 | """ |
139 | 143 | Click a mouse button |
140 | 144 |
|
141 | 145 | Args: |
142 | | - button: Mouse button to click ("left", "right", "middle") |
| 146 | + button: Mouse button to click (MouseButton enum or "left", "right", "middle" string) |
143 | 147 | x: Optional X coordinate (0.0 to 1.0) for absolute positioning before click |
144 | 148 | y: Optional Y coordinate (0.0 to 1.0) for absolute positioning before click |
145 | 149 |
|
146 | 150 | Example:: |
147 | 151 |
|
148 | | - # Click at current position |
| 152 | + # Using string (backward compatible) |
149 | 153 | hid.mouse_click("left") |
150 | | -
|
151 | | - # Click at center of screen |
152 | 154 | hid.mouse_click("left", 0.5, 0.5) |
153 | 155 |
|
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) |
156 | 159 | """ |
157 | 160 | if x is not None and y is not None: |
158 | 161 | self.call("mouse_click", button, x, y) |
@@ -234,7 +237,14 @@ def move_rel(dx, dy): |
234 | 237 | @click.option("--y", type=float, default=None, help="Optional Y coordinate (0.0-1.0)") |
235 | 238 | def mouse_click_cmd(button, x, y): |
236 | 239 | """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) |
238 | 248 | if x is not None and y is not None: |
239 | 249 | click.echo(f"Clicked {button} button at ({x}, {y})") |
240 | 250 | else: |
@@ -397,6 +407,21 @@ def get_image_download_status(self) -> dict: |
397 | 407 | """ |
398 | 408 | return self.call("get_image_download_status") |
399 | 409 |
|
| 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 | + |
400 | 425 | def cli(self): # noqa: C901 |
401 | 426 | """Create CLI interface with device management and child commands""" |
402 | 427 | base = super().cli() |
@@ -498,4 +523,15 @@ def download_status(): |
498 | 523 | if status['percentage']: |
499 | 524 | click.echo(f"Progress: {status['percentage']}") |
500 | 525 |
|
| 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 | + |
501 | 537 | return base |
0 commit comments