From: The D. <the...@bl...> - 2005-07-28 18:59:29
|
I found some possible problem with that extended toolbar thing. A dialog, directly called by tool click, doesn't have focus correctly, and I don't yet know why. It takes a click on the main app title bar, or on the dialog space, or on the close button on the dialog itself, before any attempt to close the dialog window will work. It's as if the focus is somewhere completely hidden, and must be recalled before a manual response works. I've included some code showing this. The first button calls the dialog directly. The second first calls a save dialog, which on closing calls a test dialog identical to that called by the first button. This second one works. This is why I never noticed the problem before (my first one calls a save or load dialog before calling a dialog I made for other stuff). It was only when I wanted to make a new one for config settings, that I saw this. Do you have any idea why this happens? Also, might some simple method by applied to make sure the focus or whatever it is allows a proper response to the first click on the program windows? (I tried a SetFocus() on the dialog after ShowModal() but that didn't fix it). The code: --------------------------------------------------------------------------------------------------- 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. FilePane=wx.wxFileDialog(FRAME,"","","","All files (*.*)|*.*",wx.wxOPEN) 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:EndModal(1) end ) CNFG:ConnectEvent(-1,wx.wxEVT_COMMAND_BUTTON_CLICKED, function(EV) CNFG:EndModal(1) end ) function FindTool(Z) 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 DoThings() FilePane:ShowModal() --FilePane:EndModal(1) CNFG:CentreOnParent() CNFG:ShowModal(wx.TRUE) -- Show selector dialog. Button ID will be set to VN (Voice Number). 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:ShowModal(wx.TRUE) elseif (ID==202) then DoThings() end end FRAME:Centre() FRAME:Show(wx.TRUE) --------------------------------------------------------------------------------------------------- |