loadmodule "luaiup" if not iupe then iupe = {} end if not iupep then iupep = {} end iupep.tableview = { build_branches_r = function (t, branch) for k, v in pairs(t) do local isstr, ks = pcall(function() return k .. "" end) if type(v) == "table" and isstr then local subbranch = { branchname = ks, userid = v } iupep.tableview.build_branches_r(v, subbranch) table.insert(branch, subbranch) end end end, updatetable = function (self, t, name) if type(t) ~= "table" then error "You need a table to display something in the tableview." end local ttreeview = self.ttreeview ttreeview.DELNODE0 = "CHILDREN" local branches = { branchname = name, userid = t } iupep.tableview.build_branches_r(t, branches) iup.TreeSetValue(ttreeview, branches) ttreeview.value = 0 ttreeview:selection_cb(0, 1) self.table = t self.tablename = name end, selection_cb = function (self, id, status) if status == 0 then return end local val = iup.TreeGetUserId(self, id) local attributes = self.attributes attributes.numlin = #val attributes.numlin_visible = #val local l = 1 local isstr, ks, vs for k, v in pairs(val) do isstr, ks = pcall(function() return k .. "" end) if not isstr then ks = "<" .. type(k) .. ">" end attributes:setcell(l, 1, ks) isstr, vs = pcall(function() return v .. "" end) if type(v) == "function" then vs = "--function(...) ... end" elseif not isstr then vs = "<" .. type(v) .. ">" end attributes:setcell(l, 2, vs) l = l + 1 end attributes.redraw = "all" end, map_cb = function (self) iup.TreeSetValue(self, { branchname = "nil" }) end, create = function (tab) local ttreeview = iup.tree {} local attributes = iup.matrix { readonly = "Yes", numcol = 2, numcol_visible = 2, resizematrix = "Yes", markmode = "Single" } ttreeview.selection_cb = iupep.tableview.selection_cb ttreeview.attributes = attributes ttreeview.map_cb = iupep.tableview.map_cb attributes:setcell(0, 1, "Name") attributes:setcell(0, 2, "Value") attributes.alignment1 = "ALEFT" attributes.alignment2 = "ALEFT" local refresh_btn = iup.button { title = "Refresh" } local r = iup.frame { iup.vbox { iup.hbox { iup.sbox { ttreeview, }, iup.frame { attributes, } }, iup.hbox { iup.fill {}, refresh_btn, }, }, unpack(tab), } function refresh_btn:action() r:updatetable(r.table, r.tablename) end r.ttreeview = ttreeview r.updatetable = iupep.tableview.updatetable r.table = {} r.tablename = "nil" return r end, } iupe.tableview = iupep.tableview.create