def __init__(self, panel): """Add toolbar tool to panel and subscribe to capture events.""" self.hook = HookCollection( start='madgui.component.matching.start') self.cid = None self.segment = panel.view.segment self.panel = panel self.view = panel.view self.matcher = None # toolbar tool res = PackageResource('madgui.data') with res.open('cursor.xpm') as xpm: img = wx.ImageFromStream(xpm, wx.BITMAP_TYPE_XPM) bmp = wx.BitmapFromImage(img) self.toolbar = panel.toolbar self.tool = panel.toolbar.AddCheckTool( wx.ID_ANY, bitmap=bmp, shortHelp='Beam matching', longHelp='Match by specifying constraints for envelope x(s), y(s).') panel.Bind(wx.EVT_TOOL, self.OnMatchClick, self.tool) # setup mouse capture panel.hook.capture_mouse.connect(self.stop_match)