本文整理汇总了Python中matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg.add_events方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTKAgg.add_events方法的具体用法?Python FigureCanvasGTKAgg.add_events怎么用?Python FigureCanvasGTKAgg.add_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg
的用法示例。
在下文中一共展示了FigureCanvasGTKAgg.add_events方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: canvas
# 需要导入模块: from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg [as 别名]
# 或者: from matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg import add_events [as 别名]
class Gtk_NetworkCanvas:
"""Gtk_NetworkCanvas class.
This class contains the canvas to draw the topology. It implements event listener and zoom.
Parameters
----------
canvas : the gtk canvas to draw
adjustement : used for zoom scroll bar
zoom_scale : a scroll bar to zoom
redraw : a button to redraw the graph
popup : a popup for interaction on right click
bRefresh : bool. if True enable refresh with do_refresh function
corners : the limit of the canvas drawing area
press : bool. True if mouse click on canvas (used for zoom)
x_old, y_old : position for zoom
"""
def __init__(self):
fig = plt.figure(num=None, facecolor='w', edgecolor='k')
plt.axis('off')
plt.subplots_adjust(left=0., right=1., bottom=0., top=1., wspace=0.2, hspace=0.2)
self.canvas = FigureCanvas(fig)
self.canvas.add_events(
gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.BUTTON_RELEASE_MASK)
self.canvas.connect("motion_notify_event", self.on_motion)
self.canvas.connect("button-press-event", self.on_click)
self.canvas.connect("button-release-event", self.on_release)
self.canvas.connect("scroll-event", self.on_scroll)
self.canvas.connect("leave-notify-event", self.on_lose_focus)
self.adjustement = gtk.Adjustment(0.0, 0.0, 100.0, 1.0, 1.0, 1.0)
self.adjustement_signal = self.adjustement.connect("value-changed", self.on_zoom_changed)
self.zoom_scale = gtk.HScale(self.adjustement)
self.zoom_scale.set_draw_value(False)
self.zoom_value = 0.0
self.redraw = gtk.Button("Redraw")
self.redraw.connect("clicked", self.on_redraw)
self.hbox = gtk.HBox()
self.hbox.pack_start(self.zoom_scale, True, True, 0)
self.hbox.pack_end(self.redraw, False, False, 0)
self.vbox = gtk.VBox()
self.vbox.pack_start(self.canvas, True, True, 0)
self.vbox.pack_end(self.hbox, False, False, 0)
self.popup = Gtk_NewtworkPopupMenu()
self.bRefresh = True
self.corners = None
self.press = False
self.x_old = 0
self.y_old = 0
self.bg_img = None
def on_click(self, widget, event):
"""Event listener : click
If double left click :
- on edge, show edges rules
- on firewall, show firewall conf
- on interface, add note
If left click :
- on edge, show message
- on firewall, show message interaction firewall
- on interface, show message interaction interface
- else move x/y limit drawing area
If right click :
- on edge, show edge menu
- on firewall, show firewall menu
- on interface, show interface menu
- else show canvas menu
"""
if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
dbl_click = False
dbl_click |= self.on_dblclick_edge()
dbl_click |= self.on_dblclick_node()
if not dbl_click:
Gtk_Main.Gtk_Main().lateral_pane.help_message.change_message(Gtk_Message.TOPOLOGY_MESSAGE)
if event.button == 3 and event.type == gtk.gdk.BUTTON_PRESS:
right_click = False
right_click |= self.on_right_click_edge(event)
right_click |= self.on_right_click_node(event)
if not right_click:
Gtk_Main.Gtk_Main().lateral_pane.help_message.change_message(Gtk_Message.ON_BACKGROUND_CLICK)
self.popup.popup_clear(event)
if event.button == 1 and event.type == gtk.gdk.BUTTON_PRESS:
left_click = False
left_click |= self.on_left_click_edge()
left_click |= self.on_left_click_node()
if not left_click:
self.press = True
self.x_old = event.x
self.y_old = event.y
Gtk_Main.Gtk_Main().lateral_pane.help_message.change_message(Gtk_Message.TOPOLOGY_MESSAGE)
return True
def on_dblclick_edge(self):
"""Show interface rules"""
def get_firewall(x, y):
#.........这里部分代码省略.........