From 9e3a36537d07700ec49f432940b95cf2ee9689e8 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Dec 2009 08:13:06 -0800 Subject: First insert of the various lua files. --- iupe-tview.lua | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 iupe-tview.lua (limited to 'iupe-tview.lua') diff --git a/iupe-tview.lua b/iupe-tview.lua new file mode 100644 index 0000000..4048b56 --- /dev/null +++ b/iupe-tview.lua @@ -0,0 +1,108 @@ +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 -- cgit v1.2.3