Hi John,
> This does not show the error dialog for me in Linux.
it seems like you need to have a frame open to see the effect (your
code works regardless of whether LogNull is there). Try the code
below.
The solution is indeed to use "local log = wx.wxLogNull()", but it
needs to be used *before* wxFile constructor, because this is where it
is failing (not in the Write method as I thought initially). Thanks
for getting me on the right track.
require "wx"
function FileWrite(file,content)
-- local log = wx.wxLogNull() --<-- LogNull code should be here
local file = wx.wxFile(file, wx.wxFile.write)
if not file:IsOpened() then return nil, wx.wxSysErrorMsg() end
local log = wx.wxLogNull()
file:Write(content, #content)
file:Close()
log:delete() -- this doesn't seem to be needed
return true
end
function main()
-- create the wxFrame window
local frame = wx.wxFrame( wx.NULL, -- no parent for
toplevel windows
wx.wxID_ANY, -- don't need a wxWindow ID
"wxLua Minimal Demo", -- caption on the frame
wx.wxDefaultPosition, -- let system place the frame
wx.wxSize(450, 450), -- set the size of the frame
wx.wxDEFAULT_FRAME_STYLE ) -- use default frame styles
-- show the frame window
frame:Show(true)
if not FileWrite("/my-read-only-file", "something") then
wx.wxMessageBox("Unable to save file.", "Error", wx.wxOK + wx.wxCENTRE)
end
end
main()
wx.wxGetApp():MainLoop()
Paul.
On Thu, Aug 16, 2012 at 8:21 PM, John Labenski <[email protected]> wrote:
> On Thu, Aug 16, 2012 at 10:56 PM, Paul K <[email protected]> wrote:
>> Hi all,
>>
>> I'm working with an application that saves data in files and some of
>> the operations may trigger file errors. I'm handling those errors
>> myself and don't want to see the standard error message shown by
>> wxwidgets. How do I disable it? Here is the code that I have:
>>
>> local file = wx.wxFile(filename, wx.wxFile.write)
>> file:Write("something", #"something")
>>
>> If the file is write protected, I get "can't open file '...' (error 5:
>> access is denied)". I know, I can check for that condition, but this
>> is not what the question is about. I'd like to disable that message.
>>
>> 1. use wxLogNull. I read C++ examples, but not sure how this should be
>> used in wxlua (according to examples, you just need to "instantiate"
>> this logNull object):
>
> This does not show the error dialog for me in Linux.
>
> local log = wx.wxLogNull()
> local file = wx.wxFile("/aaa", wx.wxFile.write)
> print(file:IsOpened())
> if (file:IsOpened())
> -- This asserts as it should if the file is not opened
> file:Write("something", #"something")
> end()
> log:delete()
>
> Regards,
> John
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> wxlua-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wxlua-users
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
wxlua-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxlua-users