start doing turtle task

This commit is contained in:
ilia 2023-10-23 13:44:07 +03:00
parent 5c5d61ec03
commit 48b18048c8
8 changed files with 47 additions and 16 deletions

View File

@ -1,8 +0,0 @@
from turtle import Turtle
from controls.device import SynchronyDevice
class TurtleDevice(SynchronyDevice):
pass # TODO(Homework #3)

View File

@ -1,12 +1,16 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Collection, Any from typing import Optional, Collection, Any
from abc import abstractmethod from abc import ABC, abstractmethod, abstractproperty
from enum import Enum
class DeviceLifecycleState:
pass # TODO(Homework #3)
class DevaceError(Exception): class DeviceLifecycleState(Enum):
INIT = 0
OPEN = 1
CLOSE = 2
class DeviceError(Exception):
pass pass
@ -33,8 +37,7 @@ class ActionDescriptor:
info: Optional[str] = None info: Optional[str] = None
class Device: class Device(ABC):
# TODO(Homework #3)
_state = DeviceLifecycleState.INIT _state = DeviceLifecycleState.INIT
@property @property
@ -44,9 +47,11 @@ class Device:
def close(self): def close(self):
self._state = DeviceLifecycleState.CLOSE self._state = DeviceLifecycleState.CLOSE
@abstractproperty
def trait_descriptors(self) -> Collection[TraitDescriptor]: def trait_descriptors(self) -> Collection[TraitDescriptor]:
pass pass
@abstractproperty
def action_descriptors(self) -> Collection[ActionDescriptor]: def action_descriptors(self) -> Collection[ActionDescriptor]:
pass pass

View File

@ -0,0 +1,34 @@
from turtle import Turtle
from typing import Optional, Collection, Any
from controls.device import SynchronyDevice
from controls.device import TraitDescriptor
from controls.device import ActionDescriptor
class TurtleDevice(SynchronyDevice):
def open(self):
self.turtle = Turtle()
super().open()
def close(self):
self.turtle.clear()
super().close()
def trait_descriptors(self) -> Collection[TraitDescriptor]:
pass
def action_descriptors(self) -> Collection[ActionDescriptor]:
pass
def __getitem__(self, trait_name: str) -> Optional[Any]:
"""Return logical state of trait `trait_name`."""
pass
def read(self, trait_name: str) -> Any:
raise NonReadableTrait
def write(self, trait_name: str, value: Any) -> bool:
self.turtle.write()
def invalidate(self, trait_name: str):
pass