4
4
import six
5
5
6
6
import os , sys
7
- def fn_name (): return sys ._getframe (1 ).f_code .co_name
8
7
9
8
try :
10
9
import gi
@@ -28,23 +27,21 @@ def fn_name(): return sys._getframe(1).f_code.co_name
28
27
29
28
import matplotlib
30
29
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 )
35
35
from matplotlib .backend_managers import ToolManager
36
- from matplotlib import backend_tools
37
-
38
36
from matplotlib .cbook import is_writable_file_like
39
37
from matplotlib .figure import Figure
40
38
from matplotlib .widgets import SubplotTool
41
39
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 )
45
42
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 ())
48
45
49
46
# the true dots per inch on the screen; should be display dependent
50
47
# 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):
119
116
self ._timer = None
120
117
return False
121
118
122
- class FigureCanvasGTK3 (Gtk .DrawingArea , FigureCanvasBase ):
119
+ class FigureCanvasGTK3 (Gtk .DrawingArea , FigureCanvasBase ):
123
120
keyvald = {65507 : 'control' ,
124
121
65505 : 'shift' ,
125
122
65513 : 'alt' ,
@@ -185,7 +182,6 @@ class FigureCanvasGTK3 (Gtk.DrawingArea, FigureCanvasBase):
185
182
Gdk .EventMask .SCROLL_MASK )
186
183
187
184
def __init__ (self , figure ):
188
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
189
185
FigureCanvasBase .__init__ (self , figure )
190
186
GObject .GObject .__init__ (self )
191
187
@@ -219,7 +215,6 @@ def destroy(self):
219
215
GLib .source_remove (self ._idle_draw_id )
220
216
221
217
def scroll_event (self , widget , event ):
222
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
223
218
x = event .x
224
219
# flipy so y=0 is bottom of canvas
225
220
y = self .get_allocation ().height - event .y
@@ -231,37 +226,30 @@ def scroll_event(self, widget, event):
231
226
return False # finish event propagation?
232
227
233
228
def button_press_event (self , widget , event ):
234
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
235
229
x = event .x
236
230
# flipy so y=0 is bottom of canvas
237
231
y = self .get_allocation ().height - event .y
238
232
FigureCanvasBase .button_press_event (self , x , y , event .button , guiEvent = event )
239
233
return False # finish event propagation?
240
234
241
235
def button_release_event (self , widget , event ):
242
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
243
236
x = event .x
244
237
# flipy so y=0 is bottom of canvas
245
238
y = self .get_allocation ().height - event .y
246
239
FigureCanvasBase .button_release_event (self , x , y , event .button , guiEvent = event )
247
240
return False # finish event propagation?
248
241
249
242
def key_press_event (self , widget , event ):
250
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
251
243
key = self ._get_key (event )
252
- if _debug : print ("hit" , key )
253
244
FigureCanvasBase .key_press_event (self , key , guiEvent = event )
254
245
return True # stop event propagation
255
246
256
247
def key_release_event (self , widget , event ):
257
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
258
248
key = self ._get_key (event )
259
- if _debug : print ("release" , key )
260
249
FigureCanvasBase .key_release_event (self , key , guiEvent = event )
261
250
return True # stop event propagation
262
251
263
252
def motion_notify_event (self , widget , event ):
264
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
265
253
if event .is_hint :
266
254
t , x , y , state = event .window .get_pointer ()
267
255
else :
@@ -279,9 +267,6 @@ def enter_notify_event(self, widget, event):
279
267
FigureCanvasBase .enter_notify_event (self , event )
280
268
281
269
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 ))
285
270
dpival = self .figure .dpi
286
271
winch = allocation .width / dpival
287
272
hinch = allocation .height / dpival
@@ -309,7 +294,6 @@ def _get_key(self, event):
309
294
return key
310
295
311
296
def configure_event (self , widget , event ):
312
- if _debug : print ('FigureCanvasGTK3.%s' % fn_name ())
313
297
if widget .get_property ("window" ) is None :
314
298
return
315
299
w , h = event .width , event .height
@@ -395,7 +379,6 @@ class FigureManagerGTK3(FigureManagerBase):
395
379
396
380
"""
397
381
def __init__ (self , canvas , num ):
398
- if _debug : print ('FigureManagerGTK3.%s' % fn_name ())
399
382
FigureManagerBase .__init__ (self , canvas , num )
400
383
401
384
self .window = Gtk .Window ()
@@ -468,16 +451,15 @@ def notify_axes_change(fig):
468
451
self .canvas .grab_focus ()
469
452
470
453
def destroy (self , * args ):
471
- if _debug : print ('FigureManagerGTK3.%s' % fn_name ())
472
454
self .vbox .destroy ()
473
455
self .window .destroy ()
474
456
self .canvas .destroy ()
475
457
if self .toolbar :
476
458
self .toolbar .destroy ()
477
459
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 ) :
481
463
Gtk .main_quit ()
482
464
483
465
def show (self ):
@@ -497,7 +479,7 @@ def _get_toolbar(self):
497
479
# must be inited after the window, drawingArea and figure
498
480
# attrs are set
499
481
if rcParams ['toolbar' ] == 'toolbar2' :
500
- toolbar = NavigationToolbar2GTK3 (self .canvas , self .window )
482
+ toolbar = NavigationToolbar2GTK3 (self .canvas , self .window )
501
483
elif rcParams ['toolbar' ] == 'toolmanager' :
502
484
toolbar = ToolbarGTK3 (self .toolmanager )
503
485
else :
@@ -941,7 +923,8 @@ def trigger(self, sender, event, data=None):
941
923
icon_filename = 'matplotlib.png'
942
924
else :
943
925
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 )
945
928
946
929
947
930
def error_msg_gtk (msg , parent = None ):
@@ -951,7 +934,7 @@ def error_msg_gtk(msg, parent=None):
951
934
parent = None
952
935
953
936
if not isinstance (msg , six .string_types ):
954
- msg = ',' .join (map (str ,msg ))
937
+ msg = ',' .join (map (str , msg ))
955
938
956
939
dialog = Gtk .MessageDialog (
957
940
parent = parent ,
0 commit comments