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

Skip to content

Commit ed2d37c

Browse files
committed
Various cleanups to backends code.
Removed some debug statements and old comments; whitespace / line wrapping.
1 parent eb6e422 commit ed2d37c

File tree

3 files changed

+42
-110
lines changed

3 files changed

+42
-110
lines changed

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import six
55

66
import os, sys
7-
def fn_name(): return sys._getframe(1).f_code.co_name
87

98
try:
109
import gi
@@ -28,23 +27,21 @@ def fn_name(): return sys._getframe(1).f_code.co_name
2827

2928
import matplotlib
3029
from matplotlib._pylab_helpers import Gcf
31-
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
32-
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase
33-
from matplotlib.backend_bases import (ShowBase, ToolContainerBase,
34-
StatusbarBase)
30+
from matplotlib.backend_bases import (
31+
FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
32+
NavigationToolbar2, RendererBase, TimerBase, cursors)
33+
from matplotlib.backend_bases import (
34+
ShowBase, ToolContainerBase, StatusbarBase)
3535
from matplotlib.backend_managers import ToolManager
36-
from matplotlib import backend_tools
37-
3836
from matplotlib.cbook import is_writable_file_like
3937
from matplotlib.figure import Figure
4038
from matplotlib.widgets import SubplotTool
4139

42-
from matplotlib import cbook, colors as mcolors, lines, verbose, rcParams
43-
44-
backend_version = "%s.%s.%s" % (Gtk.get_major_version(), Gtk.get_micro_version(), Gtk.get_minor_version())
40+
from matplotlib import (
41+
backend_tools, cbook, colors as mcolors, lines, verbose, rcParams)
4542

46-
_debug = False
47-
#_debug = True
43+
backend_version = "%s.%s.%s" % (
44+
Gtk.get_major_version(), Gtk.get_micro_version(), Gtk.get_minor_version())
4845

4946
# the true dots per inch on the screen; should be display dependent
5047
# see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi
@@ -119,7 +116,7 @@ def _on_timer(self):
119116
self._timer = None
120117
return False
121118

122-
class FigureCanvasGTK3 (Gtk.DrawingArea, FigureCanvasBase):
119+
class FigureCanvasGTK3(Gtk.DrawingArea, FigureCanvasBase):
123120
keyvald = {65507 : 'control',
124121
65505 : 'shift',
125122
65513 : 'alt',
@@ -185,7 +182,6 @@ class FigureCanvasGTK3 (Gtk.DrawingArea, FigureCanvasBase):
185182
Gdk.EventMask.SCROLL_MASK)
186183

187184
def __init__(self, figure):
188-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
189185
FigureCanvasBase.__init__(self, figure)
190186
GObject.GObject.__init__(self)
191187

@@ -219,7 +215,6 @@ def destroy(self):
219215
GLib.source_remove(self._idle_draw_id)
220216

221217
def scroll_event(self, widget, event):
222-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
223218
x = event.x
224219
# flipy so y=0 is bottom of canvas
225220
y = self.get_allocation().height - event.y
@@ -231,37 +226,30 @@ def scroll_event(self, widget, event):
231226
return False # finish event propagation?
232227

233228
def button_press_event(self, widget, event):
234-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
235229
x = event.x
236230
# flipy so y=0 is bottom of canvas
237231
y = self.get_allocation().height - event.y
238232
FigureCanvasBase.button_press_event(self, x, y, event.button, guiEvent=event)
239233
return False # finish event propagation?
240234

241235
def button_release_event(self, widget, event):
242-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
243236
x = event.x
244237
# flipy so y=0 is bottom of canvas
245238
y = self.get_allocation().height - event.y
246239
FigureCanvasBase.button_release_event(self, x, y, event.button, guiEvent=event)
247240
return False # finish event propagation?
248241

249242
def key_press_event(self, widget, event):
250-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
251243
key = self._get_key(event)
252-
if _debug: print("hit", key)
253244
FigureCanvasBase.key_press_event(self, key, guiEvent=event)
254245
return True # stop event propagation
255246

256247
def key_release_event(self, widget, event):
257-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
258248
key = self._get_key(event)
259-
if _debug: print("release", key)
260249
FigureCanvasBase.key_release_event(self, key, guiEvent=event)
261250
return True # stop event propagation
262251

263252
def motion_notify_event(self, widget, event):
264-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
265253
if event.is_hint:
266254
t, x, y, state = event.window.get_pointer()
267255
else:
@@ -279,9 +267,6 @@ def enter_notify_event(self, widget, event):
279267
FigureCanvasBase.enter_notify_event(self, event)
280268

281269
def size_allocate(self, widget, allocation):
282-
if _debug:
283-
print("FigureCanvasGTK3.%s" % fn_name())
284-
print("size_allocate (%d x %d)" % (allocation.width, allocation.height))
285270
dpival = self.figure.dpi
286271
winch = allocation.width / dpival
287272
hinch = allocation.height / dpival
@@ -309,7 +294,6 @@ def _get_key(self, event):
309294
return key
310295

311296
def configure_event(self, widget, event):
312-
if _debug: print('FigureCanvasGTK3.%s' % fn_name())
313297
if widget.get_property("window") is None:
314298
return
315299
w, h = event.width, event.height
@@ -395,7 +379,6 @@ class FigureManagerGTK3(FigureManagerBase):
395379
396380
"""
397381
def __init__(self, canvas, num):
398-
if _debug: print('FigureManagerGTK3.%s' % fn_name())
399382
FigureManagerBase.__init__(self, canvas, num)
400383

401384
self.window = Gtk.Window()
@@ -468,16 +451,15 @@ def notify_axes_change(fig):
468451
self.canvas.grab_focus()
469452

470453
def destroy(self, *args):
471-
if _debug: print('FigureManagerGTK3.%s' % fn_name())
472454
self.vbox.destroy()
473455
self.window.destroy()
474456
self.canvas.destroy()
475457
if self.toolbar:
476458
self.toolbar.destroy()
477459

478-
if Gcf.get_num_fig_managers()==0 and \
479-
not matplotlib.is_interactive() and \
480-
Gtk.main_level() >= 1:
460+
if (Gcf.get_num_fig_managers() == 0 and
461+
not matplotlib.is_interactive() and
462+
Gtk.main_level() >= 1):
481463
Gtk.main_quit()
482464

483465
def show(self):
@@ -497,7 +479,7 @@ def _get_toolbar(self):
497479
# must be inited after the window, drawingArea and figure
498480
# attrs are set
499481
if rcParams['toolbar'] == 'toolbar2':
500-
toolbar = NavigationToolbar2GTK3 (self.canvas, self.window)
482+
toolbar = NavigationToolbar2GTK3(self.canvas, self.window)
501483
elif rcParams['toolbar'] == 'toolmanager':
502484
toolbar = ToolbarGTK3(self.toolmanager)
503485
else:
@@ -941,7 +923,8 @@ def trigger(self, sender, event, data=None):
941923
icon_filename = 'matplotlib.png'
942924
else:
943925
icon_filename = 'matplotlib.svg'
944-
window_icon = os.path.join(matplotlib.rcParams['datapath'], 'images', icon_filename)
926+
window_icon = os.path.join(
927+
matplotlib.rcParams['datapath'], 'images', icon_filename)
945928

946929

947930
def error_msg_gtk(msg, parent=None):
@@ -951,7 +934,7 @@ def error_msg_gtk(msg, parent=None):
951934
parent = None
952935

953936
if not isinstance(msg, six.string_types):
954-
msg = ','.join(map(str,msg))
937+
msg = ','.join(map(str, msg))
955938

956939
dialog = Gtk.MessageDialog(
957940
parent = parent,

lib/matplotlib/backends/backend_qt5.py

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@
9090
QtCore.Qt.Key_Meta)
9191

9292

93-
def fn_name():
94-
return sys._getframe(1).f_code.co_name
95-
96-
DEBUG = False
97-
9893
cursord = {
9994
cursors.MOVE: QtCore.Qt.SizeAllCursor,
10095
cursors.HAND: QtCore.Qt.PointingHandCursor,
@@ -123,8 +118,6 @@ def _create_qApp():
123118
global qApp
124119

125120
if qApp is None:
126-
if DEBUG:
127-
print("Starting up QApplication")
128121
app = QtWidgets.QApplication.instance()
129122
if app is None:
130123
# check for DISPLAY env variable on X11 build of Qt
@@ -233,8 +226,6 @@ class FigureCanvasQT(QtWidgets.QWidget, FigureCanvasBase):
233226
}
234227

235228
def __init__(self, figure):
236-
if DEBUG:
237-
print('FigureCanvasQt qt5: ', figure)
238229
_create_qApp()
239230

240231
# NB: Using super for this call to avoid a TypeError:
@@ -292,8 +283,6 @@ def mousePressEvent(self, event):
292283
if button is not None:
293284
FigureCanvasBase.button_press_event(self, x, y, button,
294285
guiEvent=event)
295-
if DEBUG:
296-
print('button pressed:', event.button())
297286

298287
def mouseDoubleClickEvent(self, event):
299288
x, y = self.mouseEventCoords(event.pos())
@@ -302,22 +291,17 @@ def mouseDoubleClickEvent(self, event):
302291
FigureCanvasBase.button_press_event(self, x, y,
303292
button, dblclick=True,
304293
guiEvent=event)
305-
if DEBUG:
306-
print('button doubleclicked:', event.button())
307294

308295
def mouseMoveEvent(self, event):
309296
x, y = self.mouseEventCoords(event)
310297
FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=event)
311-
# if DEBUG: print('mouse move')
312298

313299
def mouseReleaseEvent(self, event):
314300
x, y = self.mouseEventCoords(event)
315301
button = self.buttond.get(event.button())
316302
if button is not None:
317303
FigureCanvasBase.button_release_event(self, x, y, button,
318304
guiEvent=event)
319-
if DEBUG:
320-
print('button released')
321305

322306
def wheelEvent(self, event):
323307
x, y = self.mouseEventCoords(event)
@@ -326,28 +310,18 @@ def wheelEvent(self, event):
326310
steps = event.angleDelta().y() / 120
327311
else:
328312
steps = event.pixelDelta().y()
329-
330-
if steps != 0:
313+
if steps:
331314
FigureCanvasBase.scroll_event(self, x, y, steps, guiEvent=event)
332-
if DEBUG:
333-
print('scroll event: delta = %i, '
334-
'steps = %i ' % (event.delta(), steps))
335315

336316
def keyPressEvent(self, event):
337317
key = self._get_key(event)
338-
if key is None:
339-
return
340-
FigureCanvasBase.key_press_event(self, key, guiEvent=event)
341-
if DEBUG:
342-
print('key press', key)
318+
if key is not None:
319+
FigureCanvasBase.key_press_event(self, key, guiEvent=event)
343320

344321
def keyReleaseEvent(self, event):
345322
key = self._get_key(event)
346-
if key is None:
347-
return
348-
FigureCanvasBase.key_release_event(self, key, guiEvent=event)
349-
if DEBUG:
350-
print('key release', key)
323+
if key is not None:
324+
FigureCanvasBase.key_release_event(self, key, guiEvent=event)
351325

352326
@property
353327
def keyAutoRepeat(self):
@@ -363,9 +337,6 @@ def keyAutoRepeat(self, val):
363337
def resizeEvent(self, event):
364338
w = event.size().width() * self._dpi_ratio
365339
h = event.size().height() * self._dpi_ratio
366-
if DEBUG:
367-
print('resize (%d x %d)' % (w, h))
368-
print("FigureCanvasQt.resizeEvent(%d, %d)" % (w, h))
369340
dpival = self.figure.dpi
370341
winch = w / dpival
371342
hinch = h / dpival
@@ -478,8 +449,6 @@ class FigureManagerQT(FigureManagerBase):
478449
"""
479450

480451
def __init__(self, canvas, num):
481-
if DEBUG:
482-
print('FigureManagerQT.%s' % fn_name())
483452
FigureManagerBase.__init__(self, canvas, num)
484453
self.canvas = canvas
485454
self.window = MainWindow()
@@ -578,11 +547,8 @@ def destroy(self, *args):
578547
return
579548
self.window._destroying = True
580549
self.window.destroyed.connect(self._widgetclosed)
581-
582550
if self.toolbar:
583551
self.toolbar.destroy()
584-
if DEBUG:
585-
print("destroy figure manager")
586552
self.window.close()
587553

588554
def get_window_title(self):
@@ -712,8 +678,6 @@ def set_message(self, s):
712678
self.locLabel.setText(s)
713679

714680
def set_cursor(self, cursor):
715-
if DEBUG:
716-
print('Set cursor', cursor)
717681
self.canvas.setCursor(cursord[cursor])
718682

719683
def draw_rubberband(self, event, x0, y0, x1, y1):
@@ -724,7 +688,7 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
724688
w = abs(x1 - x0)
725689
h = abs(y1 - y0)
726690

727-
rect = [int(val)for val in (min(x0, x1), min(y0, y1), w, h)]
691+
rect = [int(val) for val in (min(x0, x1), min(y0, y1), w, h)]
728692
self.canvas.drawRectangle(rect)
729693

730694
def remove_rubberband(self):

0 commit comments

Comments
 (0)