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

Skip to content

Small cleanup to GTK backend #20701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
run: |
${{ matrix.XVFB_RUN }} python -mpytest -raR -n auto \
--maxfail=50 --timeout=300 --durations=25 \
--cov-report= --cov=lib --log-level=DEBUG
--cov-report=xml --cov=lib --log-level=DEBUG

- name: Filter C coverage
run: |
Expand Down
37 changes: 19 additions & 18 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import (
_Backend, FigureCanvasBase, FigureManagerBase, NavigationToolbar2,
TimerBase, ToolContainerBase, cursors)
TimerBase, ToolContainerBase)
from matplotlib.backend_tools import Cursors
from matplotlib.figure import Figure
from matplotlib.widgets import SubplotTool

Expand All @@ -33,16 +34,16 @@
_log = logging.getLogger(__name__)

backend_version = "%s.%s.%s" % (
Gtk.get_major_version(), Gtk.get_micro_version(), Gtk.get_minor_version())
Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version())

try:
_display = Gdk.Display.get_default()
cursord = { # deprecated in Matplotlib 3.5.
cursors.MOVE: Gdk.Cursor.new_from_name(_display, "move"),
cursors.HAND: Gdk.Cursor.new_from_name(_display, "pointer"),
cursors.POINTER: Gdk.Cursor.new_from_name(_display, "default"),
cursors.SELECT_REGION: Gdk.Cursor.new_from_name(_display, "crosshair"),
cursors.WAIT: Gdk.Cursor.new_from_name(_display, "wait"),
Cursors.MOVE: Gdk.Cursor.new_from_name(_display, "move"),
Cursors.HAND: Gdk.Cursor.new_from_name(_display, "pointer"),
Cursors.POINTER: Gdk.Cursor.new_from_name(_display, "default"),
Cursors.SELECT_REGION: Gdk.Cursor.new_from_name(_display, "crosshair"),
Cursors.WAIT: Gdk.Cursor.new_from_name(_display, "wait"),
}
except TypeError as exc:
cursord = {} # deprecated in Matplotlib 3.5.
Expand Down Expand Up @@ -90,13 +91,13 @@ def _create_application():
@functools.lru_cache()
def _mpl_to_gtk_cursor(mpl_cursor):
name = {
cursors.MOVE: "move",
cursors.HAND: "pointer",
cursors.POINTER: "default",
cursors.SELECT_REGION: "crosshair",
cursors.WAIT: "wait",
cursors.RESIZE_HORIZONTAL: "ew-resize",
cursors.RESIZE_VERTICAL: "ns-resize",
Cursors.MOVE: "move",
Cursors.HAND: "pointer",
Cursors.POINTER: "default",
Cursors.SELECT_REGION: "crosshair",
Cursors.WAIT: "wait",
Cursors.RESIZE_HORIZONTAL: "ew-resize",
Cursors.RESIZE_VERTICAL: "ns-resize",
}[mpl_cursor]
return Gdk.Cursor.new_from_name(Gdk.Display.get_default(), name)

Expand Down Expand Up @@ -263,7 +264,7 @@ def _get_key(self, event):
for key_mask, prefix in modifiers:
if event.state & key_mask:
if not (prefix == 'shift' and unikey.isprintable()):
key = '{0}+{1}'.format(prefix, key)
key = f'{prefix}+{key}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tacaswell says there's good reason code cove is cranky, and none of these are actually tested - does that mean it needs tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We test key press events in Matplotlib only. This code is used when processing key events from GTK, to translate to Matplotlib. @anntzer tried to test this end, but the fake event creator in GTK doesn't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@story645 Are you meaning to block on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No but I'm not sure what the resolution is

return key

def configure_event(self, widget, event):
Expand Down Expand Up @@ -577,7 +578,7 @@ def save_figure(self, *args):
ff = Gtk.FileFilter()
ff.set_name(name)
for fmt in fmts:
ff.add_pattern("*." + fmt)
ff.add_pattern(f'*.{fmt}')
dialog.add_filter(ff)
if self.canvas.get_default_filetype() in fmts:
dialog.set_filter(ff)
Expand All @@ -587,7 +588,7 @@ def on_notify_filter(*args):
name = dialog.get_filter().get_name()
fmt = self.canvas.get_supported_filetypes_grouped()[name][0]
dialog.set_current_name(
str(Path(dialog.get_current_name()).with_suffix("." + fmt)))
str(Path(dialog.get_current_name()).with_suffix(f'.{fmt}')))

dialog.set_current_folder(mpl.rcParams["savefig.directory"])
dialog.set_current_name(self.canvas.get_default_filename())
Expand Down Expand Up @@ -678,7 +679,7 @@ def toggle_toolitem(self, name, toggled):

def remove_toolitem(self, name):
if name not in self._toolitems:
self.toolmanager.message_event('%s Not in toolbar' % name, self)
self.toolmanager.message_event(f'{name} not in toolbar', self)
return

for group in self._groups:
Expand Down