Skip to content

Commit 8ed2c98

Browse files
committed
textwidget was not updating/reseting correctly
1 parent 92635cb commit 8ed2c98

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/accessvis/widgets/text_widget.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ def __init__(self, lv, width=300, height=50, text_colour='black', background=(0,
99
self.height = height
1010
self.text_colour = text_colour
1111
self.background = background
12+
self.text = None
1213

1314
def _make_mpl(self):
1415
fig, ax = plt.subplots(figsize=(self.width / 100, self.height / 100), dpi=100)
1516
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
1617
ax.set_axis_off()
1718
fig.patch.set_facecolor(self.background)
19+
self.text = ax.text(0.5, 0.5, '', ha='center', va='center', fontsize=20, color=self.text_colour)
1820

1921
return fig, ax
2022

2123
def _update_mpl(self, fig, ax, text='', **kwargs):
22-
ax.text(0.5, 0.5, text, ha='center', va='center', fontsize=20, color=self.text_colour)
24+
self.text.set_text(text)
2325

2426
def _reset_mpl(self, fig, ax, **kwargs):
25-
pass
27+
self.text.set_text('')
28+

src/accessvis/widgets/widget_base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from abc import ABC, abstractmethod
22
from functools import cached_property
3+
4+
import matplotlib.pyplot as plt
35
import numpy as np
46
import os
57

@@ -48,7 +50,7 @@ def remove(self):
4850

4951
class WidgetMPL(Widget):
5052
@abstractmethod
51-
def _make_mpl(self):
53+
def _make_mpl(self) -> tuple[plt.Figure, plt.Axes]:
5254
# Make the basic matplotlib image
5355
# returns Figure, Axis
5456
raise NotImplementedError

0 commit comments

Comments
 (0)