added _as_task method to Adjustable, removed Task creation and setting current_task from subclasses; added stop and moved wait to Adjustable (adjusted Motor accordingly)

This commit is contained in:
2020-08-10 19:06:13 +02:00
parent f826cb0a1c
commit 257efebe18
7 changed files with 21 additions and 22 deletions
+15
View File
@@ -1,4 +1,5 @@
from slic.utils import typename
from slic.core.task import Task
from .baseadjustable import BaseAdjustable
from .convenience import SpecConvenience
@@ -10,6 +11,20 @@ class Adjustable(BaseAdjustable, SpecConvenience):
self.units = units
self.current_task = None
def _as_task(self, *args, **kwargs):
self.current_task = task = Task(*args, **kwargs)
return task
def wait(self):
if self.current_task:
return self.current_task.wait()
def stop(self):
if self.current_task:
return self.current_task.stop()
def set(self, *args, **kwargs):
return self.set_target_value(*args, **kwargs)
-5
View File
@@ -20,11 +20,6 @@ class SpecConvenience:
return self.current_task
def wait(self):
if self.current_task:
self.current_task.wait()
def __call__(self, value=None):
if not value is None:
return self.set_target_value(value)
+1 -3
View File
@@ -1,4 +1,3 @@
from slic.core.task import Task
from .adjustable import Adjustable
@@ -14,8 +13,7 @@ class DummyAdjustable(Adjustable):
def set_target_value(self, value, hold=False):
def change():
self._current_value = value
self.current_task = task = Task(change, hold=hold)
return task
return self._as_task(change, hold=hold)
def is_moving(self):
return False
+1 -3
View File
@@ -1,4 +1,3 @@
from slic.core.task import Task
from .adjustable import Adjustable
@@ -17,8 +16,7 @@ class GenericAdjustable(Adjustable):
def set_target_value(self, value, hold=False):
self._last_target = value
change = lambda: self._set(value)
self.current_task = task = Task(change, hold=hold)
return task
return self._as_task(change, hold=hold)
def is_moving(self):
return not self._wait()
+1 -3
View File
@@ -1,6 +1,5 @@
from types import SimpleNamespace
from epics import PV
from slic.core.task import Task
from .adjustable import Adjustable
@@ -37,8 +36,7 @@ class PVAdjustable(Adjustable):
def change():
# use_complete=True enables status in PV.put_complete
self.pvs.setvalue.put(value, wait=True, use_complete=True)
self.current_task = task = Task(change, hold=hold)
return task
return self._as_task(change, hold=hold)
def is_moving(self):
if self.accuracy is not None:
+1 -3
View File
@@ -1,5 +1,4 @@
from epics import PV
from slic.core.task import Task
from slic.utils.printing import printable_dict
from .adjustable import Adjustable
@@ -24,8 +23,7 @@ class PVEnumAdjustable(Adjustable):
def set_target_value(self, value, hold=False):
value = self.states.get(value)
change = lambda: self.pv.put(value, wait=True, use_complete=True)
self.current_task = task = Task(change, hold=hold)
return task
return self._as_task(change, hold=hold)
def is_moving(self):
return not self.pv.put_complete
+2 -5
View File
@@ -3,7 +3,6 @@ from types import SimpleNamespace
from contextlib import contextmanager
import colorama
from slic.core.task import Task
from slic.core.adjustable import Adjustable, AdjustableError
from slic.utils.eco_epics.motor import Motor as EpicsMotor
from slic.utils.eco_epics.utilities_epics import EpicsString
@@ -97,8 +96,7 @@ class Motor(Adjustable):
with self.use_callback(on_change):
self._move(stop, ignore_limits=ignore_limits, wait=True)
self.current_task = task = Task(change, hold=hold, stopper=self._motor.stop)
return task
return self._as_task(change, hold=hold, stopper=self._motor.stop)
def _move(self, *args, **kwargs):
@@ -116,8 +114,7 @@ class Motor(Adjustable):
def stop(self):
try:
if self.current_task:
self.current_task.stop()
return super().stop()
except:
self._motor.stop()