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

Skip to content

Commit 7065b44

Browse files
committed
Make macos toolbar also get tooltips from base class.
1 parent 7249f25 commit 7065b44

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

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),
122+
tooltips)
118123
NavigationToolbar2.__init__(self, canvas)
119124

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

src/_macosx.m

Lines changed: 14 additions & 27 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+
char* images[7];
1141+
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];

0 commit comments

Comments
 (0)