From: The D. <the...@bl...> - 2005-07-31 14:00:45
|
-- In the absence of an answer, I've made a workround: -- Use Show() and Enable() instead of ShowModal() and EndModal(). -- This suggests the problem might be in the inbuilt wxWidgets or wxLua code for ShowModal(). -- -- I've removed the FilePane in this example, showing that the existing ShowModal() doesn't let the dialog respond to the first click if the file dialog didn't immediately preceed the ShowModal for my own dialog(). In other words, the second tool button does what the first one did before. -- The first button now uses the workround, and the means of closing the dialog now work as they should, at first attempt, with the dialog having the same effect that ShowModal() would have it was working right. ---------------------------------------------------------------------------------------------------------------------------------------------------- local FS=wx.wxDEFAULT_FRAME_STYLE-wx.wxMAXIMIZE_BOX-wx.wxRESIZE_BORDER FRAME=wx.wxFrame(wx.wxNull,-1,"",wx.wxDefaultPosition,wx.wxSize(432,310),FS) -- Main GUI frame, supports menus and all good stuffs. PANEL=wx.wxPanel(FRAME,-1) -- Dialog-like control/surface in a Frame. BANK=wx.wxDialog(PANEL,-1,"",wx.wxPoint(-1,-1),wx.wxSize(426,266)) -- Make two identical test dialogs. CNFG=wx.wxDialog(PANEL,-1,"",wx.wxPoint(-1,-1),wx.wxSize(426,266)) IDB=0 BMP_I=wx.wxBitmapFromFile("Bitmaps/new.bmp",wx.wxBITMAP_TYPE_BMP) BMP_O=wx.wxBitmapFromFile("Bitmaps/open.bmp",wx.wxBITMAP_TYPE_BMP) TBAR=wx.wxToolBar(PANEL,ID_TOOLBAR,wx.wxPoint(-1,14),wx.wxSize(-1,-1),wx.wxTB_FLAT) TBAR:AddTool(201,BMP_I,wx.wxNullBitmap,wx.FALSE,wx.wxNull,"") TBAR:AddTool(202,BMP_O,wx.wxNullBitmap,wx.FALSE,wx.wxNull,"") TBAR:Realize() TBAR:Move(-1,-2) TBAR:SetSize(440,-1) TBAR:ConnectEvent(-1,wx.wxEVT_LEFT_DOWN, -- When any part of the toolbar is left-clicked, look for a tool. function(EV) IDB=FindTool(EV) EV:Skip() end -- Use Skip() to avoid interference with native left click handler. ) TBAR:ConnectEvent(-1,wx.wxEVT_LEFT_UP, -- When a left click on the toolbar is released, call ReadTool(). function(EV) ReadTool(EV) EV:Skip() end -- Use Skip() to avoid interference with native left click handler. ) BANK:ConnectEvent(-1,wx.wxEVT_COMMAND_BUTTON_CLICKED, function(EV) BANK:Show(nil) FRAME:Enable(1) FRAME:SetFocus(1) end ) CNFG:ConnectEvent(-1,wx.wxEVT_COMMAND_BUTTON_CLICKED, function(EV) CNFG:EndModal(1) end ) function FindTool(Z) -- Z is reused. Starts as event, becomes tool ID if tool is found. Z=TBAR:FindToolForPosition(Z:GetX(),Z:GetY()) -- When toolbar (or tool) is clicked, look for tool where clicked. if Z then Z=Z:GetId() end return Z -- If tool was found, return it's ID, or otherwise return nil. end function ReadTool(EV) local ID=FindTool(EV) -- Get the toolbar button's ID, which is how the tool is indexed. if (ID~=IDB) then return end IDB=0 -- If button down/up were not on same tool, do nothing. Reset IDB. if (ID==201) then BANK:CentreOnParent() BANK:Show(1) FRAME:Enable(nil) elseif (ID==202) then CNFG:CentreOnParent() CNFG:ShowModal(1) end end FRAME:Centre() FRAME:Show(wx.TRUE) ---------------------------------------------------------------------------------------------------------------------------------------------------- |