41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import turtle
|
|
from typing import Optional, Collection, Any
|
|
from controls.device import SynchronyDevice
|
|
import time
|
|
import inspect
|
|
|
|
class TurtleDevice(SynchronyDevice):
|
|
def open(self):
|
|
super().open()
|
|
turtle.Turtle()
|
|
|
|
def close(self):
|
|
super().close()
|
|
turtle.bye()
|
|
|
|
def execute(self, action_name: str, *args, **kwargs):
|
|
getattr(turtle, action_name)(args[0], *kwargs)
|
|
|
|
def read(self, trait_name: str):
|
|
pass
|
|
|
|
def write(self, trait_name: str, value: Any) -> bool:
|
|
pass
|
|
|
|
def invalidate(self, trait_name: str):
|
|
pass
|
|
|
|
def trait_descriptors(self):
|
|
traits = [attr for attr in turtle.Turtle.__dict__
|
|
if attr.startswith('__') and not attr.startswith('_')]
|
|
return traits
|
|
|
|
def action_descriptors(self):
|
|
actions = [(name, func.__doc__) for name, func in inspect.getmembers(turtle.Turtle)
|
|
if callable(func) and not name.startswith('__') and not name.startswith('_')]
|
|
return actions
|
|
|
|
def __getitem__(self, trait_name: str):
|
|
"""Return logical state of trait `trait_name`."""
|
|
pass
|