Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5e5962f

Browse filesBrowse files
committed
DOC: Use a data class in the menu example
1 parent cb5cb9c commit 5e5962f
Copy full SHA for 5e5962f

File tree

Expand file treeCollapse file tree

1 file changed

+10
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-7
lines changed

‎galleries/examples/widgets/menu.py

Copy file name to clipboardExpand all lines: galleries/examples/widgets/menu.py
+10-7Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.