8000 Remove obsolete NavigationToolbar and projection_factory code · matplotlib/matplotlib@4243470 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4243470

Browse files
author
Chris Beaumont
committed
Remove obsolete NavigationToolbar and projection_factory code
1 parent e96d353 commit 4243470

12 files changed

+14
-913
lines changed

lib/matplotlib/backends/backend_gtk.py

Lines changed: 1 addition & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,7 @@ def full_screen_toggle(self):
622622
def _get_toolbar(self, canvas):
623623
# must be inited after the window, drawingArea and figure
624624
# attrs are set
625-
if rcParams['toolbar'] == 'classic':
626-
toolbar = NavigationToolbar (canvas, self.window)
627-
elif rcParams['toolbar'] == 'toolbar2':
625+
if rcParams['toolbar'] == 'toolbar2':
628626
toolbar = NavigationToolbar2GTK (canvas, self.window)
629627
else:
630628
toolbar = None
@@ -795,239 +793,6 @@ def _get_canvas(self, fig):
795793
return FigureCanvasGTK(fig)
796794

797795

798-
class NavigationToolbar(gtk.Toolbar):
799-
"""
800-
Public attributes
801-
802-
canvas - the FigureCanvas (gtk.DrawingArea)
803-
win - the gtk.Window
804-
805-
"""
806-
# list of toolitems to add to the toolbar, format is:
807-
# text, tooltip_text, image, callback(str), callback_arg, scroll(bool)
808-
toolitems = (
809-
('Left', 'Pan left with click or wheel mouse (bidirectional)',
810-
gtk.STOCK_GO_BACK, 'panx', -1, True),
811-
('Right', 'Pan right with click or wheel mouse (bidirectional)',
812-
gtk.STOCK_GO_FORWARD, 'panx', 1, True),
813-
('Zoom In X',
814-
'Zoom In X (shrink the x axis limits) with click or wheel'
815-
' mouse (bidirectional)',
816-
gtk.STOCK_ZOOM_IN, 'zoomx', 1, True),
817-
('Zoom Out X',
818-
'Zoom Out X (expand the x axis limits) with click or wheel'
819-
' mouse (bidirectional)',
820-
gtk.STOCK_ZOOM_OUT, 'zoomx', -1, True),
821-
(None, None, None, None, None, None,),
822-
('Up', 'Pan up with click or wheel mouse (bidirectional)',
823-
gtk.STOCK_GO_UP, 'pany', 1, True),
824-
('Down', 'Pan down with click or wheel mouse (bidirectional)',
825-
gtk.STOCK_GO_DOWN, 'pany', -1, True),
826-
('Zoom In Y',
827-
'Zoom in Y (shrink the y axis limits) with click or wheel'
828-
' mouse (bidirectional)',
829-
gtk.STOCK_ZOOM_IN, 'zoomy', 1, True),
830-
('Zoom Out Y',
831-
'Zoom Out Y (expand the y axis limits) with click or wheel'
832-
' mouse (bidirectional)',
833-
gtk.STOCK_ZOOM_OUT, 'zoomy', -1, True),
834-
(None, None, None, None, None, None,),
835-
('Save', 'Save the figure',
836-
gtk.STOCK_SAVE, 'save_figure', None, False),
837-
)
838-
839-
def __init__(self, canvas, window):
840-
"""
841-
figManager is the FigureManagerGTK instance that contains the
842-
toolbar, with attributes figure, window and drawingArea
843-
844-
"""
845-
gtk.Toolbar.__init__(self)
846-
847-
self.canvas = canvas
848-
# Note: gtk.Toolbar already has a 'window' attribute
849-
self.win = window
850-
851-
self.set_style(gtk.TOOLBAR_ICONS)
852-
853-
self._create_toolitems_2_4()
854-
self.update = self._update_2_4
855-
self.fileselect = FileChooserDialog(
856-
title='Save the figure',
857-
parent=self.win,
858-
filetypes=self.canvas.get_supported_filetypes(),
859-
default_filetype=self.canvas.get_default_filetype())
860-
self.show_all()
861-
self.update()
862-
863-
def _create_toolitems_2_4(self):
864-
# use the GTK+ 2.4 GtkToolbar API
865-
iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
866-
if not _new_tooltip_api:
867-
self.tooltips = gtk.Tooltips()
868-
869-
for text, tooltip_text, image_num, callback, callback_arg, scroll \
870-
in self.toolitems:
871-
if text is None:
872-
self.insert( gtk.SeparatorToolItem(), -1 )
873-
continue
874-
image = gtk.Image()
875-
image.set_from_stock(image_num, iconSize)
876-
tbutton = gtk.ToolButton(image, text)
877-
self.insert(tbutton, -1)
878-
if callback_arg:
879-
tbutton.connect('clicked', getattr(self, callback),
880-
callback_arg)
881-
else:
882-
tbutton.connect('clicked', getattr(self, callback))
883-
if scroll:
884-
tbutton.connect('scroll_event', getattr(self, callback))
885-
if _new_tooltip_api:
886-
tbutton.set_tooltip_text(tooltip_text)
887-
else:
888-
tbutton.set_tooltip(self.tooltips, tooltip_text, 'Private')
889-
890-
# Axes toolitem, is empty at start, update() adds a menu if >=2 axes
891-
self.axes_toolitem = gtk.ToolItem()
892-
self.insert(self.axes_toolitem, 0)
893-
if _new_tooltip_api:
894-
self.axes_toolitem.set_tooltip_text(
895-
'Select axes that controls affect')
896-
else:
897-
self.axes_toolitem.set_tooltip (
898-
self.tooltips,
899-
tip_text='Select axes that controls affect',
900-
tip_private = 'Private')
901-
902-
align = gtk.Alignment (xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0)
903-
self.axes_toolitem.add(align)
904-
905-
self.menubutton = gtk.Button ("Axes")
906-
align.add (self.menubutton)
907-
908-
def position_menu (menu):
909-
"""Function for positioning a popup menu.
910-
Place menu below the menu button, but ensure it does not go off
911-
the bottom of the screen.
912-
The default is to popup menu at current mouse position
913-
"""
914-
x0, y0 = self.window.get_origin()
915-
x1, y1, m = self.window.get_pointer()
916-
x2, y2 = self.menubutton.get_pointer()
917-
sc_h = self.get_screen().get_height() # requires GTK+ 2.2 +
918-
w, h = menu.size_request()
919-
920-
x = x0 + x1 - x2
921-
y = y0 + y1 - y2 + self.menubutton.allocation.height
922-
y = min(y, sc_h - h)
923-
return x, y, True
924-
925-
def button_clicked (button, data=None):
926-
self.axismenu.popup (None, None, position_menu, 0,
927-
gtk.get_current_event_time())
928-
929-
self.menubutton.connect ("clicked", button_clicked)
930-
931-
932-
def _update_2_4(self):
933-
# for GTK+ 2.4+
934-
# called by __init__() and FigureManagerGTK
935-
936-
self._axes = self.canvas.figure.axes
937-
938-
if len(self._axes) >= 2:
939-
self.axismenu = self._make_axis_menu()
940-
self.menubutton.show_all()
941-
else:
942-
self.menubutton.hide()
943-
944-
self.set_active(range(len(self._axes)))
945-
946-
947-
def _make_axis_menu(self):
948-
# called by self._update*()
949-
950-
def toggled(item, data=None):
951-
if item == self.itemAll:
952-
for item in items: item.set_active(True)
953-
elif item == self.itemInvert:
954-
for item in items:
955-
item.set_active(not item.get_active())
956-
957-
ind = [i for i,item in enumerate(items) if item.get_active()]
958-
self.set_active(ind)
959-
960-
menu = gtk.Menu()
961-
962-
self.itemAll = gtk.MenuItem("All")
963-
menu.append(self.itemAll)
964-
self.itemAll.connect("activate", toggled)
965-
966-
self.itemInvert = gtk.MenuItem("Invert")
967-
menu.append(self.itemInvert)
968-
self.itemInvert.connect("activate", toggled)
969-
970-
items = []
971-
for i in range(len(self._axes)):
972-
item = gtk.CheckMenuItem("Axis %d" % (i+1))
973-
menu.append(item)
974-
item.connect("toggled", toggled)
975-
item.set_active(True)
976-
items.append(item)
977-
978-
menu.show_all()
979-
return menu
980-
981-
982-
def set_active(self, ind):
983-
self._ind = ind
984-
self._active = [ self._axes[i] for i in self._ind ]
985-
986-
def panx(self, button, direction):
987-
'panx in direction'
988-
989-
for a in self._active:
990-
a.xaxis.pan(direction)
991-
self.canvas.draw()
992-
return True
993-
994-
def pany(self, button, direction):
995-
'pany in direction'
996-
for a in self._active:
997-
a.yaxis.pan(direction)
998-
self.canvas.draw()
999-
return True
1000-
1001-
def zoomx(self, button, direction):
1002-
'zoomx in direction'
1003-
for a in self._active:
1004-
a.xaxis.zoom(direction)
1005-
self.canvas.draw()
1006-
return True
1007-
1008-
def zoomy(self, button, direction):
1009-
'zoomy in direction'
1010-
for a in self._active:
1011-
a.yaxis.zoom(direction)
1012-
self.canvas.draw()
1013-
return True
1014-
1015-
def get_filechooser(self):
1016-
return FileChooserDialog(
1017-
title='Save the figure',
1018-
parent=self.win,
1019-
filetypes=self.canvas.get_supported_filetypes(),
1020-
default_filetype=self.canvas.get_default_filetype())
1021-
1022-
def save_figure(self, *args):
1023-
fname, format = self.get_filechooser().get_filename_from_user()
1024-
if fname:
1025-
try:
1026-
self.canvas.print_figure(fname, format=format)
1027-
except Exception as e:
1028-
error_msg_gtk(str(e), parent=self)
1029-
1030-
1031796
class FileChooserDialog(gtk.FileChooserDialog):
1032797
"""GTK+ 2.4 file selector which presents the user with a menu
1033798
of supported image formats

0 commit comments

Comments
 (0)
0