Skip to content

Commit 86abe7a

Browse files
authoredMay 9, 2022
Merge branch 'main' into add-features-scatter
2 parents e1941b0 + 451dfac commit 86abe7a

File tree

12 files changed

+61
-7
lines changed

12 files changed

+61
-7
lines changed
 

‎setup.cfg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name = napari_matplotlib
33
description = A plugin to use Matplotlib with napari
44
long_description = file: README.md
55
long_description_content_type = text/markdown
6-
url = https://github.com/dstansby/napari-matplotlib
6+
url = https://github.com/matplotlib/napari-matplotlib
77
author = David Stansby
88
author_email = d.stansby@ucl.ac.uk
99
license = BSD-3-Clause
1010
license_file = LICENSE
1111
classifiers =
12-
Development Status :: 2 - Pre-Alpha
12+
Development Status :: 3 - Alpha
1313
Framework :: napari
1414
Intended Audience :: Developers
1515
License :: OSI Approved :: BSD License
@@ -22,10 +22,10 @@ classifiers =
2222
Programming Language :: Python :: 3.10
2323
Topic :: Software Development :: Testing
2424
project_urls =
25-
Bug Tracker = https://github.com/dstansby/napari-matplotlib/issues
26-
Documentation = https://github.com/dstansby/napari-matplotlib#README.md
27-
Source Code = https://github.com/dstansby/napari-matplotlib
28-
User Support = https://github.com/dstansby/napari-matplotlib/issues
25+
Bug Tracker = https://github.com/matplotlib/napari-matplotlib/issues
26+
Documentation = https://github.com/matplotlib/napari-matplotlib#README.md
27+
Source Code = https://github.com/matplotlib/napari-matplotlib
28+
User Support = https://github.com/matplotlib/napari-matplotlib/issues
2929

3030
[options]
3131
packages = find:

‎src/napari_matplotlib/base.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
NavigationToolbar2QT,
66
)
77
from qtpy.QtWidgets import QVBoxLayout, QWidget
8+
from qtpy.QtGui import QIcon
9+
from pathlib import Path
10+
import os
811

912
mpl.rc("axes", edgecolor="white")
1013
mpl.rc("axes", facecolor="#262930")
@@ -15,6 +18,9 @@
1518
mpl.rc("xtick", color="white")
1619
mpl.rc("ytick", color="white")
1720

21+
# Icons modified from
22+
# https://github.com/matplotlib/matplotlib/tree/main/lib/matplotlib/mpl-data/images
23+
ICON_ROOT = Path(__file__).parent / "icons"
1824
__all__ = ["NapariMPLWidget"]
1925

2026

@@ -47,8 +53,10 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
4753

4854
self.viewer = napari_viewer
4955
self.canvas = FigureCanvas()
56+
self.canvas.figure.set_tight_layout(True)
5057
self.canvas.figure.patch.set_facecolor("#262930")
51-
self.toolbar = NavigationToolbar2QT(self.canvas, self)
58+
self.toolbar = NapariNavigationToolbar(self.canvas, self)
59+
self._replace_toolbar_icons()
5260

5361
self.setLayout(QVBoxLayout())
5462
self.layout().addWidget(self.toolbar)
@@ -115,8 +123,54 @@ def draw(self) -> None:
115123
This is a no-op, and is intended for derived classes to override.
116124
"""
117125

126+
118127
def _on_update_layers(self) -> None:
119128
"""This function is called when self.layers is updated via self.update_layers()
120129
121130
This is a no-op, and is intended for derived classes to override.
122131
"""
132+
133+
def _replace_toolbar_icons(self):
134+
# Modify toolbar icons and some tooltips
135+
for action in self.toolbar.actions():
136+
text = action.text()
137+
if text == "Pan":
138+
action.setToolTip(
139+
"Pan/Zoom: Left button pans; Right button zooms; Click once to activate; Click again to deactivate"
140+
)
141+
if text == "Zoom":
142+
action.setToolTip(
143+
"Zoom to rectangle; Click once to activate; Click again to deactivate"
144+
)
145+
if len(text) > 0: # i.e. not a separator item
146+
icon_path = os.path.join(ICON_ROOT, text + ".png")
147+
action.setIcon(QIcon(icon_path))
148+
149+
150+
class NapariNavigationToolbar(NavigationToolbar2QT):
151+
"""Custom Toolbar style for Napari."""
152+
153+
def __init__(self, canvas, parent):
154+
super().__init__(canvas, parent)
155+
156+
def _update_buttons_checked(self):
157+
"""Update toggle tool icons when selected/unselected."""
158+
super()._update_buttons_checked()
159+
# changes pan/zoom icons depending on state (checked or not)
160+
if "pan" in self._actions:
161+
if self._actions["pan"].isChecked():
162+
self._actions["pan"].setIcon(
163+
QIcon(os.path.join(ICON_ROOT, "Pan_checked.png"))
164+
)
165+
else:
166+
self._actions["pan"].setIcon(QIcon(os.path.join(ICON_ROOT,
167+
"Pan.png")))
168+
if "zoom" in self._actions:
169+
if self._actions["zoom"].isChecked():
170+
self._actions["zoom"].setIcon(
171+
QIcon(os.path.join(ICON_ROOT, "Zoom_checked.png"))
172+
)
173+
else:
174+
self._actions["zoom"].setIcon(
175+
QIcon(os.path.join(ICON_ROOT, "Zoom.png"))
176+
)

‎src/napari_matplotlib/icons/Back.png

6.52 KB
Loading
6.79 KB
Loading
6.38 KB
Loading

‎src/napari_matplotlib/icons/Home.png

6.98 KB
Loading

‎src/napari_matplotlib/icons/Pan.png

6.95 KB
Loading
11.5 KB
Loading

‎src/napari_matplotlib/icons/Save.png

7.21 KB
Loading
6.58 KB
Loading

‎src/napari_matplotlib/icons/Zoom.png

7.88 KB
Loading
12.1 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.