Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e5962f

Browse files
committed
DOC: Use a data class in the menu example
1 parent cb5cb9c commit 5e5962f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

galleries/examples/widgets/menu.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
66
Using texts to construct a simple menu.
77
"""
8+
9+
from dataclasses import dataclass
10+
811
import matplotlib.pyplot as plt
912

1013
import matplotlib.artist as artist
1114
import matplotlib.patches as patches
15+
from matplotlib.typing import ColorType
1216

1317

18+
@dataclass
1419
class ItemProperties:
15-
def __init__(self, fontsize=14, labelcolor='black', bgcolor='yellow',
16-
alpha=1.0):
17-
self.fontsize = fontsize
18-
self.labelcolor = labelcolor
19-
self.bgcolor = bgcolor
20-
self.alpha = alpha
20+
fontsize: float = 14
21+
labelcolor: ColorType = 'black'
22+
bgcolor: ColorType = 'yellow'
23+
alpha: float = 1.0
2124

2225

2326
class MenuItem(artist.Artist):
@@ -130,7 +133,7 @@ def on_move(self, event):
130133
menuitems = []
131134
for label in ('open', 'close', 'save', 'save as', 'quit'):
132135
def on_select(item):
133-
print('you selected %s' % item.labelstr)
136+
print(f'you selected {item.labelstr}')
134137
item = MenuItem(fig, label, props=props, hoverprops=hoverprops,
135138
on_select=on_select)
136139
menuitems.append(item)

0 commit comments

Comments
 (0)