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

Skip to content

Commit 2199e3e

Browse files
authored
Merge pull request #17701 from meeseeksmachine/auto-backport-of-pr-17687-on-v3.3.x
Backport PR #17687 on branch v3.3.x (Mention keyboard modifiers in toolbar tooltip texts.)
2 parents 61276cd + 44d9c53 commit 2199e3e

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,8 +2818,12 @@ class NavigationToolbar2:
28182818
('Back', 'Back to previous view', 'back', 'back'),
28192819
('Forward', 'Forward to next view', 'forward', 'forward'),
28202820
(None, None, None, None),
2821-
('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'),
2822-
('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'),
2821+
('Pan',
2822+
'Left button pans, Right button zooms\n'
2823+
'x/y fixes axis, CTRL fixes aspect',
2824+
'move', 'pan'),
2825+
('Zoom', 'Zoom to rectangle\nx/y fixes axis, CTRL fixes aspect',
2826+
'zoom_to_rect', 'zoom'),
28232827
('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'),
28242828
(None, None, None, None),
28252829
('Save', 'Save the figure', 'filesave', 'save_figure'),

lib/matplotlib/backends/backend_macosx.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ class NavigationToolbar2Mac(_macosx.NavigationToolbar2, NavigationToolbar2):
113113

114114
def __init__(self, canvas):
115115
self.canvas = canvas # Needed by the _macosx __init__.
116+
data_path = cbook._get_data_path('images')
117+
_, tooltips, image_names, _ = zip(*NavigationToolbar2.toolitems)
116118
_macosx.NavigationToolbar2.__init__(
117-
self, str(cbook._get_data_path('images')))
119+
self,
120+
tuple(str(data_path / image_name) + ".pdf"
121+
for image_name in image_names if image_name is not None),
122+
tuple(tooltip for tooltip in tooltips if tooltip is not None))
118123
NavigationToolbar2.__init__(self, canvas)
119124

120125
def draw_rubberband(self, event, x0, y0, x1, y1):

src/_macosx.m

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,6 @@ -(void)save_figure:(id)sender
11081108

11091109
self->height = height;
11101110

1111-
const char* basedir;
1112-
11131111
obj = PyObject_GetAttrString((PyObject*)self, "canvas");
11141112
if (obj==NULL)
11151113
{
@@ -1130,8 +1128,6 @@ -(void)save_figure:(id)sender
11301128
return -1;
11311129
}
11321130

1133-
if(!PyArg_ParseTuple(args, "s", &basedir)) return -1;
1134-
11351131
NSRect bounds = [view bounds];
11361132
NSWindow* window = [view window];
11371133

@@ -1141,35 +1137,24 @@ -(void)save_figure:(id)sender
11411137
bounds.size.height += height;
11421138
[window setContentSize: bounds.size];
11431139

1144-
NSString* dir = [NSString stringWithCString: basedir
1145-
encoding: NSASCIIStringEncoding];
1140+
const char* images[7];
1141+
const char* tooltips[7];
1142+
if (!PyArg_ParseTuple(args, "(sssssss)(sssssss)",
1143+
&images[0], &images[1], &images[2], &images[3],
1144+
&images[4], &images[5], &images[6],
1145+
&tooltips[0], &tooltips[1], &tooltips[2], &tooltips[3],
1146+
&tooltips[4], &tooltips[5], &tooltips[6])) {
1147+
return -1;
1148+
}
11461149

11471150
NSButton* buttons[7];
1148-
1149-
NSString* images[7] = {@"home.pdf",
1150-
@"back.pdf",
1151-
@"forward.pdf",
1152-
@"move.pdf",
1153-
@"zoom_to_rect.pdf",
1154-
@"subplots.pdf",
1155-
@"filesave.pdf"};
1156-
1157-
NSString* tooltips[7] = {@"Reset original view",
1158-
@"Back to previous view",
1159-
@"Forward to next view",
1160-
@"Pan axes with left mouse, zoom with right",
1161-
@"Zoom to rectangle",
1162-
@"Configure subplots",
1163-
@"Save the figure"};
1164-
11651151
SEL actions[7] = {@selector(home:),
11661152
@selector(back:),
11671153
@selector(forward:),
11681154
@selector(pan:),
11691155
@selector(zoom:),
11701156
@selector(configure_subplots:),
11711157
@selector(save_figure:)};
1172-
11731158
NSButtonType buttontypes[7] = {NSMomentaryLightButton,
11741159
NSMomentaryLightButton,
11751160
NSMomentaryLightButton,
@@ -1194,9 +1179,11 @@ -(void)save_figure:(id)sender
11941179
rect.origin.x = gap;
11951180
rect.origin.y = 0.5*(height - rect.size.height);
11961181

1197-
for (i = 0; i < 7; i++)
1198-
{
1199-
NSString* filename = [dir stringByAppendingPathComponent: images[i]];
1182+
for (i = 0; i < 7; i++) {
1183+
NSString* filename = [NSString stringWithCString: images[i]
1184+
encoding: NSUTF8StringEncoding];
1185+
NSString* tooltip = [NSString stringWithCString: tooltips[i]
1186+
encoding: NSUTF8StringEncoding];
12001187
NSImage* image = [[NSImage alloc] initWithContentsOfFile: filename];
12011188
buttons[i] = [[NSButton alloc] initWithFrame: rect];
12021189
[image setSize: size];
@@ -1205,7 +1192,7 @@ -(void)save_figure:(id)sender
12051192
[buttons[i] setImage: image];
12061193
[buttons[i] scaleUnitSquareToSize: scale];
12071194
[buttons[i] setImagePosition: NSImageOnly];
1208-
[buttons[i] setToolTip: tooltips[i]];
1195+
[buttons[i] setToolTip: tooltip];
12091196
[[window contentView] addSubview: buttons[i]];
12101197
[buttons[i] release];
12111198
[image release];

0 commit comments

Comments
 (0)