本文整理汇总了Python中matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg.grab_focus方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTKAgg.grab_focus方法的具体用法?Python FigureCanvasGTKAgg.grab_focus怎么用?Python FigureCanvasGTKAgg.grab_focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg
的用法示例。
在下文中一共展示了FigureCanvasGTKAgg.grab_focus方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WidgetsWrapper
# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import grab_focus [as 别名]
class WidgetsWrapper(object):
def __init__(self):
self.widgets = gtk.glade.XML('mpl_with_glade.glade')
self.widgets.signal_autoconnect(GladeHandlers.__dict__)
self['windowMain'].connect('destroy', lambda x: gtk.main_quit())
self['windowMain'].move(10, 10)
self.figure = Figure(figsize=(8, 6), dpi=72)
self.axis = self.figure.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axis.plot(t, s)
self.axis.set_xlabel('time (s)')
self.axis.set_ylabel('voltage')
self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea
self.canvas.show()
self.canvas.set_size_request(600, 400)
self.canvas.set_events(
gtk.gdk.BUTTON_PRESS_MASK |
gtk.gdk.KEY_PRESS_MASK |
gtk.gdk.KEY_RELEASE_MASK
)
self.canvas.set_flags(gtk.HAS_FOCUS | gtk.CAN_FOCUS)
self.canvas.grab_focus()
def keypress(widget, event):
print('key press')
def buttonpress(widget, event):
print('button press')
self.canvas.connect('key_press_event', keypress)
self.canvas.connect('button_press_event', buttonpress)
def onselect(xmin, xmax):
print(xmin, xmax)
span = SpanSelector(self.axis, onselect, 'horizontal', useblit=False,
rectprops=dict(alpha=0.5, facecolor='red'))
self['vboxMain'].pack_start(self.canvas, True, True)
self['vboxMain'].show()
# below is optional if you want the navigation toolbar
self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
self.navToolbar.lastDir = '/var/tmp/'
self['vboxMain'].pack_start(self.navToolbar)
self.navToolbar.show()
sep = gtk.HSeparator()
sep.show()
self['vboxMain'].pack_start(sep, True, True)
self['vboxMain'].reorder_child(self['buttonClickMe'], -1)
def __getitem__(self, key):
return self.widgets.get_widget(key)
示例2: MainView
# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import grab_focus [as 别名]
class MainView(BasePlotView, gtk.Frame):
"""
A Gtk Frame based plotting widget for dreampy
that contains additional tool bar items for printing
and adding notes
"""
def __init__(self, win, **kwargs):
gtk.Frame.__init__(self)
BasePlotView.__init__(self, **kwargs)
self.win = win
self.title = None
#Put some stuff
# self.suppress_header = kwargs.get('suppress_header', False)
# self.suppress_title = kwargs.get('suppress_title', False)
# self.suppress_legend = kwargs.get('suppress_legend', False)
self.vbox = gtk.VBox(False, 0)
self.add(self.vbox)
self.sw = gtk.ScrolledWindow()
self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.vbox.pack_start(self.sw, True, True, 0)
self.sw.show()
self.f = Figure(figsize=(5,4), dpi=100)
self.canvas = FigureCanvas(self.f) # a gtk.DrawingArea
self.canvas.set_size_request(400,300)
self.sw.add_with_viewport (self.canvas)
self.canvas.show_all()
self.toolbar = NavToolBar(self.canvas, self.win)
self.vbox.pack_start(self.toolbar, False, False)
self.toolbar.show()
self.vbox.show()
# self.autoscale = True
# self.xmin = None
# self.xmax = None
# self.ymin = None
# self.ymax = None
# self.image = None
# self.hold_plot = False
# self.keyid = None
# self.filter = None
# self.labelsize = 8
# self.titlesize = 10
# self.ticklabelsize = 8
# self.ticklabelweight = 'normal'
# self.labelweight = 'bold'
# self.titleweight = 'bold'
# self.legendsize = 8
# self.legendweight = 'normal'
# self.hdrlabelsize = 9
# self.hdrlabelweight = 'normal'
# self.cur_axname = None
self.refresh_canvas()
self.show_all()
#self.gtk_catchup()
def gtk_catchup(self):
gtk.gdk.threads_enter()
while gtk.events_pending():
gtk.main_iteration()
gtk.gdk.threads_leave()
def create_arrow_button(self, arrow_type, shadow_type):
button = gtk.Button()
self.arrow = gtk.Arrow(arrow_type, shadow_type)
button.add(self.arrow)
button.show()
self.arrow.show()
return button
def list_widgets_turnoff(self):
self.left_button.set_sensitive(False)
self.right_button.set_sensitive(False)
self.ignore_button.set_sensitive(False)
#if self.keyid:
# self.canvas.disconnect(self.keyid)
def disconnect_event(self, sig):
if self.canvas:
self.canvas.mpl_disconnect(sig)
def connect_event(self, eventname, eventfunc):
if self.canvas:
self.canvas.set_flags(gtk.CAN_FOCUS) #to grab focus for keystrokes
self.canvas.grab_focus() #to grab focus for keystrokes
return self.canvas.mpl_connect(eventname, eventfunc)
def redraw_plot(self):
if self.hold_plot is False:
if hasattr(self.canvas, 'show_all'):
self.canvas.show_all()
self.canvas.draw()
self.gtk_catchup()