From 7249f2504e9c276b8ed542c6ddfc55526611e3df Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 19 Jun 2020 11:52:58 +0200 Subject: [PATCH 1/2] Mention keyboard modifiers in toolbar tooltip texts. Otherwise the feature is a bit obscure... --- lib/matplotlib/backend_bases.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 3aae2d5972ed..37d7d276ea93 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2818,8 +2818,12 @@ class NavigationToolbar2: ('Back', 'Back to previous view', 'back', 'back'), ('Forward', 'Forward to next view', 'forward', 'forward'), (None, None, None, None), - ('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'), - ('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'), + ('Pan', + 'Left button pans, Right button zooms\n' + 'x/y fixes axis, CTRL fixes aspect', + 'move', 'pan'), + ('Zoom', 'Zoom to rectangle\nx/y fixes axis, CTRL fixes aspect', + 'zoom_to_rect', 'zoom'), ('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'), (None, None, None, None), ('Save', 'Save the figure', 'filesave', 'save_figure'), From 272800eccff177b0ebb8112535016b984ad3c336 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 19 Jun 2020 18:36:45 +0200 Subject: [PATCH 2/2] Make macos toolbar also get tooltips from base class. --- lib/matplotlib/backends/backend_macosx.py | 7 +++- src/_macosx.m | 43 ++++++++--------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index 9558c5e6899f..609f89c99c05 100644 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -113,8 +113,13 @@ class NavigationToolbar2Mac(_macosx.NavigationToolbar2, NavigationToolbar2): def __init__(self, canvas): self.canvas = canvas # Needed by the _macosx __init__. + data_path = cbook._get_data_path('images') + _, tooltips, image_names, _ = zip(*NavigationToolbar2.toolitems) _macosx.NavigationToolbar2.__init__( - self, str(cbook._get_data_path('images'))) + self, + tuple(str(data_path / image_name) + ".pdf" + for image_name in image_names if image_name is not None), + tuple(tooltip for tooltip in tooltips if tooltip is not None)) NavigationToolbar2.__init__(self, canvas) def draw_rubberband(self, event, x0, y0, x1, y1): diff --git a/src/_macosx.m b/src/_macosx.m index 72fb8e4852f1..5ce5d203ea67 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -1108,8 +1108,6 @@ -(void)save_figure:(id)sender self->height = height; - const char* basedir; - obj = PyObject_GetAttrString((PyObject*)self, "canvas"); if (obj==NULL) { @@ -1130,8 +1128,6 @@ -(void)save_figure:(id)sender return -1; } - if(!PyArg_ParseTuple(args, "s", &basedir)) return -1; - NSRect bounds = [view bounds]; NSWindow* window = [view window]; @@ -1141,27 +1137,17 @@ -(void)save_figure:(id)sender bounds.size.height += height; [window setContentSize: bounds.size]; - NSString* dir = [NSString stringWithCString: basedir - encoding: NSASCIIStringEncoding]; + const char* images[7]; + const char* tooltips[7]; + if (!PyArg_ParseTuple(args, "(sssssss)(sssssss)", + &images[0], &images[1], &images[2], &images[3], + &images[4], &images[5], &images[6], + &tooltips[0], &tooltips[1], &tooltips[2], &tooltips[3], + &tooltips[4], &tooltips[5], &tooltips[6])) { + return -1; + } NSButton* buttons[7]; - - NSString* images[7] = {@"home.pdf", - @"back.pdf", - @"forward.pdf", - @"move.pdf", - @"zoom_to_rect.pdf", - @"subplots.pdf", - @"filesave.pdf"}; - - NSString* tooltips[7] = {@"Reset original view", - @"Back to previous view", - @"Forward to next view", - @"Pan axes with left mouse, zoom with right", - @"Zoom to rectangle", - @"Configure subplots", - @"Save the figure"}; - SEL actions[7] = {@selector(home:), @selector(back:), @selector(forward:), @@ -1169,7 +1155,6 @@ -(void)save_figure:(id)sender @selector(zoom:), @selector(configure_subplots:), @selector(save_figure:)}; - NSButtonType buttontypes[7] = {NSMomentaryLightButton, NSMomentaryLightButton, NSMomentaryLightButton, @@ -1194,9 +1179,11 @@ -(void)save_figure:(id)sender rect.origin.x = gap; rect.origin.y = 0.5*(height - rect.size.height); - for (i = 0; i < 7; i++) - { - NSString* filename = [dir stringByAppendingPathComponent: images[i]]; + for (i = 0; i < 7; i++) { + NSString* filename = [NSString stringWithCString: images[i] + encoding: NSUTF8StringEncoding]; + NSString* tooltip = [NSString stringWithCString: tooltips[i] + encoding: NSUTF8StringEncoding]; NSImage* image = [[NSImage alloc] initWithContentsOfFile: filename]; buttons[i] = [[NSButton alloc] initWithFrame: rect]; [image setSize: size]; @@ -1205,7 +1192,7 @@ -(void)save_figure:(id)sender [buttons[i] setImage: image]; [buttons[i] scaleUnitSquareToSize: scale]; [buttons[i] setImagePosition: NSImageOnly]; - [buttons[i] setToolTip: tooltips[i]]; + [buttons[i] setToolTip: tooltip]; [[window contentView] addSubview: buttons[i]]; [buttons[i] release]; [image release]; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy