@@ -95,10 +95,7 @@ def __init__(
95
95
self .width = max_glyphs
96
96
self ._font = font
97
97
self ._text = None
98
- if anchor_point is None :
99
- self ._anchor_point = (0 , 0 )
100
- else :
101
- self ._anchor_point = anchor_point
98
+ self ._anchor_point = anchor_point
102
99
self .x = x
103
100
self .y = y
104
101
@@ -126,7 +123,7 @@ def __init__(
126
123
127
124
if text is not None :
128
125
self ._update_text (str (text ))
129
- if anchored_position is not None :
126
+ if ( anchored_position is not None ) and ( anchor_point is not None ) :
130
127
self .anchored_position = anchored_position
131
128
132
129
def _create_background_box (self , lines , y_offset ):
@@ -374,14 +371,19 @@ def anchor_point(self):
374
371
375
372
@anchor_point .setter
376
373
def anchor_point (self , new_anchor_point ):
377
- current_anchored_position = self .anchored_position
378
- self ._anchor_point = new_anchor_point
379
- self .anchored_position = current_anchored_position
374
+ if self ._anchor_point is not None :
375
+ current_anchored_position = self .anchored_position
376
+ self ._anchor_point = new_anchor_point
377
+ self .anchored_position = current_anchored_position
378
+ else :
379
+ self ._anchor_point = new_anchor_point
380
380
381
381
@property
382
382
def anchored_position (self ):
383
383
"""Position relative to the anchor_point. Tuple containing x,y
384
384
pixel coordinates."""
385
+ if self ._anchor_point is None :
386
+ return None
385
387
return (
386
388
int (self .x + (self ._anchor_point [0 ] * self ._boundingbox [2 ] * self ._scale )),
387
389
int (
@@ -393,6 +395,8 @@ def anchored_position(self):
393
395
394
396
@anchored_position .setter
395
397
def anchored_position (self , new_position ):
398
+ if (self ._anchor_point is None ) or (new_position is None ):
399
+ return # Note: anchor_point must be set before setting anchored_position
396
400
new_x = int (
397
401
new_position [0 ]
398
402
- self ._anchor_point [0 ] * (self ._boundingbox [2 ] * self ._scale )
0 commit comments