From: John L. <jla...@gm...> - 2005-07-21 21:41:39
|
On 7/21/05, The Doctor <the...@bl...> wrote: > Lastly, another question.. How would I make a tool, to be later added to = a toolbar? I want to assign it to a variable so I can get direct access to = mouse events on it. I've seen that tools can be added later, but nothing to= show how to make them in advance of this. Instead of storing variables to your controls, you can get them from the events. Try this. local toolBar =3D frame:CreateToolBar() toolBar:AddTool(100, bmp) bmpButton =3D wx.wxBitmapButton(toolBar, 101, bmp) toolBar:AddControl(bmpButton) toolBar:Realize() =20 function bmpButtonHandler(event) local bmpButton =3D event:GetEventObject():DynamicCast("wxBitmapButt= on") print(bmpButton) -- this is the button itself end bmpButton:ConnectEvent(101, wx.wxEVT_COMMAND_BUTTON_CLICKED, bmpButtonHandler) > My context: >=20 > TBAR:ConnectEvent(-1,wx.wxEVT_LEFT_UP, > function(EV) if (EV:ControlDown()) then DoThings() end EV:Skip() = end > ) >=20 > In the above code, I can use DoThings() to set a global variable as a fla= g, then test that flag during the handling for the tool, as this flag would= be set on ControlDown() for any toolbar click, whether on a tool or not. T= his is awkward though, as I'll have to think of ways to reset that flag if = anything else on the toolbar was clicked with the Ctrl key held. I added a= =20 Why not just pass the event to the DoThings function and get the info (like window id) from it inside the function? The les globals the better since it's less likely you'll accidently overwrite them. >ZZ=3DTBAR:AddTool(wx.wxID_SAVE...) but although ZZ exists, as userdata, it's not the >kind of userdata I need, I can't get an ID out of it, and such.. I haven't even found out yet >what ZZ actually is. :) I also tried replacing the -1 in the above code with the ID of the >button I wanted, The wxToolbar is basicly a black hole, you only get the button pressed events back. I don't think there are ways to get the mouse events for the tools. That's why I suggested using wxButtons. Regards, John Labenski |