(a line should look like: qprtfs *usr [ ])
Code: Select all
local WS_CANCEL = false
local WS_ENTER = true
local rtx = {}
local sfl_elem = 3
function bld_IO_elem(attr_opt)
local _attr =
{
visiblelines = attr_opt.visiblelines or '1',
multiline = attr_opt.multiline or 'NO',
readonly = attr_opt.readonly or 'NO'
}
-- there are no mandatory attr_opt
if attr_opt.value then
_attr.value = attr_opt.value
end
if attr_opt.filter then
_attr.filter = attr_opt.filter
end
if attr_opt.mask then
_attr.mask = attr_opt.mask
end
-- end optional attributes
local sfl_lin = iup.text(_attr)
return sfl_lin
end
function bld_O_elem(attr_opt)
local _attr =
{
title = attr_opt.name or '',
visiblelines = attr_opt.visiblelines or '1',
multiline = attr_opt.multiline or 'NO',
readonly = attr_opt.readonly or 'YES'
}
-- there are no mandatory attr_opt
if attr_opt.value then
_attr.value = attr_opt.value
end
if attr_opt.filter then
_attr.filter = attr_opt.filter
end
if attr_opt.mask then
_attr.mask = attr_opt.mask
end
-- end optional attributes
local out_elem = iup.label(_attr)
return out_elem
end
function bld_gbox(_tbl)
local _attr =
{
numdiv = sfl_elem or 0,
expandchildren = 'HORIZONTAL',
orientation = 'HORIZONTAL',
alignmentlin = 'ACENTER',
normalizesize = 'YES',
gaplin = '10',
gapcol = '10',
}
local gbox = iup.gridbox{_attr}
local attr_opt = {}
for qvar, _V in pairs(QSYSVAL) do
-- lbl KEY
-- ctx *sys, *usr
-- alwchg 1 or 0
-- typ (num) or (char)
-- val value
-- lim (low - high)
-- make a gridbox, sfl_elem columns wide
local this = QSYSVAL[qvar]
-- str key
attr_opt = {name = qvar, readonly = 'YES'}
local _key = bld_O_elem(attr_opt)
gbox:append(_key)
-- end key
local ctx = this.QCTX
attr_opt = {name = ctx, readonly = 'YES'}
local _ctx = bld_O_elem(attr_opt)
gbox:append(_ctx)
local val = this.QVAL
local typ = type(this.QTYP)
if typ == 'number' then
attr_opt = {name = val, value = val or 0, filter = 'NUMBER', mask = IUP_MASK_INT}
end
if typ == 'string' then
attr_opt = {name = val, value = val or ''}
end
local alwchg = this.QALWCHG
if alwchg == '0' then
attr_opt.readonly = 'YES'
val = bld_O_elem(attr_opt)
else
attr_opt.readonly = 'YES'
val = bld_IO_elem(attr_opt)
end
gbox:append(val)
end -- for k,v
return gbox
end
local function GetResults()
local sflsiz = qwcsysval.numlin
for i = 1, sflsiz do
local key = iup.GetChild(qwcsysval, (i - 1) * sfl_elem)
local ctx = iup.GetBrother(key)
local val = iup.GetBrother(ctx)
print(key, ctx, val)
end
end
local function matDLG(qwcsysval)
-- local dlg_attr = {}
local btn_attr = {}
btn_attr = {name = 'ENTER', title = 'ENTER',
action = function(self)
-- GetResults()
rtx.rc = WS_ENTER
-- rtx.TAG = TAG
return iup.CLOSE
end
}
local btn_ENTER = iup.button(btn_attr)
btn_attr = {name = 'EXIT', title = 'EXIT',
action = function(self)
rtx.rc = WS_CANCEL
rtx.TAG = ''
return iup.CLOSE
end
}
local btn_EXIT = iup.button(btn_attr)
-- Creates frame with dropdown list
local sfl = iup.vbox{iup.scrollbox{qwcsysval}}
local fn_keys = iup.hbox{btn_ENTER, btn_EXIT}
-- Creates a dialog with frame(s) and title
local dlg_attr =
{
iup.vbox{sfl, iup.hbox{fn_keys}},
title = 'System Values',
size = 'HALFxHALF',
margin = '5x5'
}
local dlg = iup.dialog(dlg_attr)
return dlg
end -- fn matDLG
-- EXEC()
QSYSVAL =
{
['QPRTLSC'] =
{
QCTX = '*SYS',
QVAL = 198,
QDESC = 'Landscape PrintFile length',
QALWCHG = '0',
QTYP = 0,
QRULES = {},
}, -- landscape
['QPRTPTT'] =
{
QCTX = '*SYS',
QVAL = 198,
QDESC = 'Portrait PrintFile length',
QALWCHG = '0',
QTYP = 0,
QRULES = {},
}, -- portrait
['QPRTFD'] =
{
QCTX = '*USR',
QVAL = '',
QDESC = 'field delimiter',
QALWCHG = '1',
QTYP = '',
QRULES = {},
}, -- field delimiter
['QPRTFS'] =
{
QCTX = '*USR',
QVAL = '',
QDESC = 'field separator',
QALWCHG = '1',
QTYP = '',
QRULES = {},
}, -- field separator
['QPRTPG'] =
{
QCTX = '*USR',
QVAL = '',
QDESC = 'field paragraph',
QALWCHG = '1',
QTYP = '',
QRULES = {},
}, -- field paragraph
['QAWBAS'] =
{
QCTX = '*USR',
QVAL = '',
QDESC = 'Aboville length',
QALWCHG = '1',
QTYP = '',
QRULES = {},
}, -- Arboville len
['QFMBAS'] =
{
QCTX = '*USR',
QVAL = '',
QDESC = 'Family Marriage length',
QALWCHG = '1',
QTYP = '',
QRULES = {},
}, -- fam len
['QGABAS'] =
{
QCTX = '*USR',
QVAL = '',
QDESC = 'grave address length',
QALWCHG = '1',
QTYP = '',
QRULES = {},
}, -- gadr len
['QBASLATI'] =
{
QCTX = '*USR',
QVAL = 46.4598781,
QDESC = 'home base latitude',
QALWCHG = '1',
QTYP = 0,
QRULES = {},
}, -- baselati
['QBASLONG'] =
{
QCTX = '*USR',
QVAL = -95.6600150,
QDESC = 'home base longitude',
QALWCHG = '1',
QTYP = 0,
QRULES = {},
}, -- baselati
}
-- global because of (getresults)
qwcsysval = bld_gbox(QSYSVAL)
-- dlg must be global
dlg = matDLG(qwcsysval)
dlg:show(iup.CENTER, iup.CENTER)
iup.MainLoop()
dlg:destroy()
-- savTBL(_qfp, QSYSVAL)
return