allow locking of all objects
This commit is contained in:
parent
09711116a7
commit
e0db621595
14 changed files with 290 additions and 36 deletions
|
|
@ -3,7 +3,7 @@ import copy
|
|||
import numpy
|
||||
from numpy import pi
|
||||
|
||||
from . import PatternError
|
||||
from .error import PatternError, PatternLockedError
|
||||
from .utils import is_scalar, vector2, rotation_matrix_2d
|
||||
|
||||
|
||||
|
|
@ -12,9 +12,9 @@ __author__ = 'Jan Petykiewicz'
|
|||
|
||||
class Label:
|
||||
"""
|
||||
A circle, which has a position and radius.
|
||||
A text annotation with a position and layer (but no size; it is not drawn)
|
||||
"""
|
||||
__slots__ = ('_offset', '_layer', '_string', 'identifier')
|
||||
__slots__ = ('_offset', '_layer', '_string', 'identifier', 'locked')
|
||||
# [x_offset, y_offset]
|
||||
_offset: numpy.ndarray
|
||||
|
||||
|
|
@ -27,6 +27,13 @@ class Label:
|
|||
# Arbitrary identifier tuple
|
||||
identifier: Tuple
|
||||
|
||||
locked: bool # If True, any changes to the label will raise a PatternLockedError
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if self.locked and name != 'locked':
|
||||
raise PatternLockedError()
|
||||
object.__setattr__(self, name, value)
|
||||
|
||||
# ---- Properties
|
||||
# offset property
|
||||
@property
|
||||
|
|
@ -78,11 +85,20 @@ class Label:
|
|||
def __init__(self,
|
||||
string: str,
|
||||
offset: vector2=(0.0, 0.0),
|
||||
layer: int=0):
|
||||
layer: int=0,
|
||||
locked: bool = False):
|
||||
self.unlock()
|
||||
self.identifier = ()
|
||||
self.string = string
|
||||
self.offset = numpy.array(offset, dtype=float)
|
||||
self.layer = layer
|
||||
self.locked = locked
|
||||
|
||||
def __copy__(self) -> 'Label':
|
||||
return Label(string=self.string,
|
||||
offset=self.offset.copy(),
|
||||
layer=self.layer,
|
||||
locked=self.locked)
|
||||
|
||||
def __deepcopy__(self, memo: Dict = None) -> 'Label':
|
||||
memo = {} if memo is None else memo
|
||||
|
|
@ -134,4 +150,20 @@ class Label:
|
|||
"""
|
||||
return numpy.array([self.offset, self.offset])
|
||||
|
||||
def lock(self) -> 'Label':
|
||||
"""
|
||||
Lock the Label
|
||||
|
||||
:return: self
|
||||
"""
|
||||
object.__setattr__(self, 'locked', True)
|
||||
return self
|
||||
|
||||
def unlock(self) -> 'Label':
|
||||
"""
|
||||
Unlock the Label
|
||||
|
||||
:return: self
|
||||
"""
|
||||
object.__setattr__(self, 'locked', False)
|
||||
return self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue