Hi, I'm just getting started using wxLua, and have hit a couple of problems.

I tried writing a small file-tree view with Icons in wxLua but had a
few issues. I've included the code at the end of this email.

If I run it as-is (with 'lua fileview.lua') I get a segmentation fault
after a few icons have loaded. If I disable garbage collection (with
collectgarbage('stop')) then the segfault goes away, but I get error
messages saying that the icons couldn't be loaded (the filenames seem
to be strings such as "gnome-compressed" and not actual filenames). If
I hardcode a path to an icon, then it loads properly, though all the
files obviously have that one icon. Either way, if I turn garbage
collection back on I get a segmentation fault.

I'm using the GTK port of wxWidgets, compiled from the 2.8.11 source
tarball with --enable-debug. My version of wxLua was also compiled
from the source tarball. I'm using a 64-bit installation of Ubuntu
10.4, and running in the Gnome desktop environment.

Also, in case it's important, the wxIcon(wxIconLocation) constructor
seems not to be bound, so I'm using wxIcon(iconLoc:GetFileName(),
wx.wxBITMAP_TYPE_ANY) instead.

Is there a bug, or am I doing something very wrong? :x

    henk


PS. This is the code I'm trying to run. I added a
collectgarbage('collect') call in a place which seems to cause it to
consistently crash every time.
---

require 'wx'
require 'lfs'

--collectgarbage('stop')

frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, 'wxLua Minimal Demo',
                   wx.wxDefaultPosition, wx.wxSize(450, 450),
                   wx.wxDEFAULT_FRAME_STYLE)

---- file tree ----------------------------------------------------------------

treeCtrl = wx.wxTreeCtrl(frame, wx.wxID_ANY)
treeCtrl:SetImageList(wx.wxImageList(16, 16))
root = treeCtrl:AddRoot('files')

do
  local icons = {}
  local function getIcon(filename)
    local ext = string.match(filename, '.+%.([^.]*)$')

    if ext and not icons[ext] then
      local ft = wx.wxTheMimeTypesManager:GetFileTypeFromExtension(ext)
      if ft then
        local iconLoc = wx.wxIconLocation()
        if ft:GetIcon(iconLoc) then
          print('found for ' .. ext .. ': "' .. iconLoc:GetFileName() .. '"')
          local icon = wx.wxIcon(iconLoc:GetFileName(), wx.wxBITMAP_TYPE_ANY)
          --local icon =
wx.wxIcon("/usr/share/icons/gnome/16x16/mimetypes/unknown.png",
wx.wxBITMAP_TYPE_ANY)
          collectgarbage('collect')
          if icon:Ok() then
            icons[ext] = treeCtrl:GetImageList():Add(icon)
          end
          print('there are now ' ..
treeCtrl:GetImageList():GetImageCount() .. ' icons')
        end
      end
    end
    return icons[ext]
  end
  local function recurse (dir, parentNode)
    for f in lfs.dir(dir) do
      if f ~= '.' and f ~= '..' then
        local node = treeCtrl:AppendItem(parentNode, f)

        local icon = getIcon(f)
        if icon then
          treeCtrl:SetItemImage(node, icon)
        end

        if lfs.attributes(dir .. '/' .. f).mode == 'directory' then
          recurse(dir .. '/' .. f, node)
        end
      end
    end
    treeCtrl:SortChildren(parentNode)
  end
  recurse('.', root)
end

---- init ---------------------------------------------------------------------

frame:Show(true)
wx.wxGetApp():MainLoop()

---

------------------------------------------------------------------------------

_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to