|
6 | 6 |
|
7 | 7 | import matplotlib as mpl |
8 | 8 | from matplotlib import _api, backend_tools, cbook |
9 | | -from matplotlib._pylab_helpers import Gcf |
10 | | -from matplotlib.backend_bases import ( |
11 | | - FigureCanvasBase, FigureManagerBase, ToolContainerBase) |
| 9 | +from matplotlib.backend_bases import FigureCanvasBase, ToolContainerBase |
12 | 10 | from matplotlib.backend_tools import Cursors |
13 | 11 | from matplotlib.figure import Figure |
14 | 12 |
|
|
29 | 27 | from gi.repository import Gio, GLib, GObject, Gtk, Gdk |
30 | 28 | from . import _backend_gtk |
31 | 29 | from ._backend_gtk import ( |
32 | | - backend_version, _BackendGTK, _NavigationToolbar2GTK, |
| 30 | + backend_version, _BackendGTK, _FigureManagerGTK, _NavigationToolbar2GTK, |
33 | 31 | TimerGTK as TimerGTK3, |
34 | 32 | ) |
35 | 33 |
|
@@ -293,130 +291,6 @@ def flush_events(self): |
293 | 291 | context.iteration(True) |
294 | 292 |
|
295 | 293 |
|
296 | | -class FigureManagerGTK3(FigureManagerBase): |
297 | | - """ |
298 | | - Attributes |
299 | | - ---------- |
300 | | - canvas : `FigureCanvas` |
301 | | - The FigureCanvas instance |
302 | | - num : int or str |
303 | | - The Figure number |
304 | | - toolbar : Gtk.Toolbar |
305 | | - The toolbar |
306 | | - vbox : Gtk.VBox |
307 | | - The Gtk.VBox containing the canvas and toolbar |
308 | | - window : Gtk.Window |
309 | | - The Gtk.Window |
310 | | - """ |
311 | | - |
312 | | - def __init__(self, canvas, num): |
313 | | - app = _backend_gtk._create_application() |
314 | | - self.window = Gtk.Window() |
315 | | - app.add_window(self.window) |
316 | | - super().__init__(canvas, num) |
317 | | - |
318 | | - self.window.set_wmclass("matplotlib", "Matplotlib") |
319 | | - icon_ext = "png" if sys.platform == "win32" else "svg" |
320 | | - self.window.set_icon_from_file( |
321 | | - str(cbook._get_data_path(f"images/matplotlib.{icon_ext}"))) |
322 | | - |
323 | | - self.vbox = Gtk.Box() |
324 | | - self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL) |
325 | | - self.window.add(self.vbox) |
326 | | - self.vbox.show() |
327 | | - |
328 | | - self.canvas.show() |
329 | | - |
330 | | - self.vbox.pack_start(self.canvas, True, True, 0) |
331 | | - # calculate size for window |
332 | | - w, h = self.canvas.get_width_height() |
333 | | - |
334 | | - if self.toolbar is not None: |
335 | | - self.toolbar.show() |
336 | | - self.vbox.pack_end(self.toolbar, False, False, 0) |
337 | | - min_size, nat_size = self.toolbar.get_preferred_size() |
338 | | - h += nat_size.height |
339 | | - |
340 | | - self.window.set_default_size(w, h) |
341 | | - |
342 | | - self._destroying = False |
343 | | - self.window.connect("destroy", lambda *args: Gcf.destroy(self)) |
344 | | - self.window.connect("delete_event", lambda *args: Gcf.destroy(self)) |
345 | | - if mpl.is_interactive(): |
346 | | - self.window.show() |
347 | | - self.canvas.draw_idle() |
348 | | - |
349 | | - self.canvas.grab_focus() |
350 | | - |
351 | | - def destroy(self, *args): |
352 | | - if self._destroying: |
353 | | - # Otherwise, this can be called twice when the user presses 'q', |
354 | | - # which calls Gcf.destroy(self), then this destroy(), then triggers |
355 | | - # Gcf.destroy(self) once again via |
356 | | - # `connect("destroy", lambda *args: Gcf.destroy(self))`. |
357 | | - return |
358 | | - self._destroying = True |
359 | | - self.vbox.destroy() |
360 | | - self.window.destroy() |
361 | | - self.canvas.destroy() |
362 | | - if self.toolbar: |
363 | | - self.toolbar.destroy() |
364 | | - |
365 | | - def show(self): |
366 | | - # show the figure window |
367 | | - self.window.show() |
368 | | - self.canvas.draw() |
369 | | - if mpl.rcParams['figure.raise_window']: |
370 | | - if self.window.get_window(): |
371 | | - self.window.present() |
372 | | - else: |
373 | | - # If this is called by a callback early during init, |
374 | | - # self.window (a GtkWindow) may not have an associated |
375 | | - # low-level GdkWindow (self.window.get_window()) yet, and |
376 | | - # present() would crash. |
377 | | - _api.warn_external("Cannot raise window yet to be setup") |
378 | | - |
379 | | - def full_screen_toggle(self): |
380 | | - if self.window.get_window().get_state() & Gdk.WindowState.FULLSCREEN: |
381 | | - self.window.unfullscreen() |
382 | | - else: |
383 | | - self.window.fullscreen() |
384 | | - |
385 | | - def _get_toolbar(self): |
386 | | - # must be inited after the window, drawingArea and figure |
387 | | - # attrs are set |
388 | | - if mpl.rcParams['toolbar'] == 'toolbar2': |
389 | | - toolbar = NavigationToolbar2GTK3(self.canvas) |
390 | | - elif mpl.rcParams['toolbar'] == 'toolmanager': |
391 | | - toolbar = ToolbarGTK3(self.toolmanager) |
392 | | - else: |
393 | | - toolbar = None |
394 | | - return toolbar |
395 | | - |
396 | | - def get_window_title(self): |
397 | | - return self.window.get_title() |
398 | | - |
399 | | - def set_window_title(self, title): |
400 | | - self.window.set_title(title) |
401 | | - |
402 | | - def resize(self, width, height): |
403 | | - """Set the canvas size in pixels.""" |
404 | | - width = int(width / self.canvas.device_pixel_ratio) |
405 | | - height = int(height / self.canvas.device_pixel_ratio) |
406 | | - if self.toolbar: |
407 | | - toolbar_size = self.toolbar.size_request() |
408 | | - height += toolbar_size.height |
409 | | - canvas_size = self.canvas.get_allocation() |
410 | | - if canvas_size.width == canvas_size.height == 1: |
411 | | - # A canvas size of (1, 1) cannot exist in most cases, because |
412 | | - # window decorations would prevent such a small window. This call |
413 | | - # must be before the window has been mapped and widgets have been |
414 | | - # sized, so just change the window's starting size. |
415 | | - self.window.set_default_size(width, height) |
416 | | - else: |
417 | | - self.window.resize(width, height) |
418 | | - |
419 | | - |
420 | 294 | class NavigationToolbar2GTK3(_NavigationToolbar2GTK, Gtk.Toolbar): |
421 | 295 | @_api.delete_parameter("3.6", "window") |
422 | 296 | def __init__(self, canvas, window=None): |
@@ -730,8 +604,11 @@ def error_msg_gtk(msg, parent=None): |
730 | 604 | FigureCanvasGTK3, _backend_gtk.ConfigureSubplotsGTK) |
731 | 605 | backend_tools._register_tool_class( |
732 | 606 | FigureCanvasGTK3, _backend_gtk.RubberbandGTK) |
733 | | -FigureManagerGTK3._toolbar2_class = NavigationToolbar2GTK3 |
734 | | -FigureManagerGTK3._toolmanager_toolbar_class = ToolbarGTK3 |
| 607 | + |
| 608 | + |
| 609 | +class FigureManagerGTK3(_FigureManagerGTK): |
| 610 | + _toolbar2_class = NavigationToolbar2GTK3 |
| 611 | + _toolmanager_toolbar_class = ToolbarGTK3 |
735 | 612 |
|
736 | 613 |
|
737 | 614 | @_BackendGTK.export |
|
0 commit comments