Skip to content

Commit 4ab282b

Browse files
authored
Future-proof Chart against changing Toga Widget initialization (#194)
Updates API usage to match Toga 0.5, updates version specifiers to match. Also adds an explicit matplotlib dependency, and adapts to a recent matplotlib API change.
1 parent 20b8439 commit 4ab282b

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

changes/194.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The initialization of Chart has been updated to be compatible with Toga 0.5.0.

examples/chart/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ def startup(self):
6666
self.chart,
6767
toga.Box(
6868
children=[toga.Label("𝜇"), self.mu],
69-
style=Pack(padding=(5, 10)),
69+
style=Pack(margin=(5, 10)),
7070
),
7171
toga.Box(
7272
children=[toga.Label("𝜎"), self.sigma],
73-
style=Pack(padding=(5, 10)),
73+
style=Pack(margin=(5, 10)),
7474
),
7575
toga.Button(
7676
"Recreate data",
7777
on_press=self.recreate_data,
78-
style=Pack(padding=(10, 10, 20, 10)),
78+
style=Pack(margin=(10, 10, 20, 10)),
7979
),
8080
],
8181
style=Pack(direction=COLUMN),

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ classifiers = [
3737
"Topic :: Software Development",
3838
"Topic :: Software Development :: User Interfaces",
3939
]
40+
dependencies = [
41+
"matplotlib >= 3.9.0",
42+
"toga-core >= 0.5.0, < 0.6.0",
43+
]
4044

4145
[project.optional-dependencies]
4246
# Extras used by developers *of* briefcase are pinned to specific versions to
@@ -46,7 +50,7 @@ dev = [
4650
"pytest == 8.3.5",
4751
"setuptools_scm == 8.2.0",
4852
"tox == 4.25.0",
49-
"toga-dummy >= 0.4.0",
53+
"toga-dummy >= 0.5.0, < 0.6.0",
5054
]
5155
# Docs are always built on a specific Python version; see RTD and tox config files.
5256
docs = [

src/toga_chart/chart.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(
4444

4545
super().__init__(id=id, style=style)
4646

47+
def _create(self):
4748
self._impl = self.canvas._impl
4849

4950
@Widget.app.setter
@@ -193,13 +194,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
193194
# Math mode text must be rendered using paths.
194195
# Otherwise, we can use canvas-level text markup.
195196
if ismath:
196-
path, transform = self._get_text_path_transform(
197-
x, y, s, prop, angle, ismath
198-
)
199-
color = gc.get_rgb()
200-
201-
gc.set_linewidth(0.75)
202-
self.draw_path(gc, path, transform, rgbFace=color)
197+
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath)
203198
else:
204199
self._canvas.context.translate(x, y)
205200
self._canvas.context.rotate(-math.radians(angle))

0 commit comments

Comments
 (0)