* iup gridbox program not executing correctly.

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

iup gridbox program not executing correctly.

Post by Ron Melby »

I am creating what I believe to be a 3 across gridbox (sfl_elem =3 is numdiv in the gridbox) but somehow I am not getting the link, getresults see no brothers, and it displays as a list, one entry per line, while I expect 3. Something very simple I do not understand, or I misunderstand. Thanks.
(a line should look like: qprtfs *usr [ ])
Untitled.png
Untitled.png (112.84 KiB) Viewed 2704 times

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
Last edited by Ron Melby on 15 May 2021 11:47, edited 1 time in total.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28342
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup gbox program not executing correctly.

Post by tatewise »

Replace
local gbox = iup.gridbox{ _attr }
With
local gbox = iup.gridbox( _attr )

i.e. Replace { curly brackets } with ( parentheses )

Just like you did on line 30 : local sfl_lin = iup.text(_attr) and line 54 : local out_elem = iup.label(_attr)

Otherwise, effectively what you have is local gbox = iup.gridbox{ { ... } }
Where the table items are hidden within an internal table.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup gridbox program not executing correctly.

Post by Ron Melby »

yes, thank you, I am always having trouble with those ({ and )} -- and I cannot see well enough to distinguish them, and zerobrane does not allow me to color them differently. And it is even worse to see in fh debug.

now on to trying to fix get results.
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup gridbox program not executing correctly.

Post by Ron Melby »

this is getresults() in the above code
I have 3 elements across in each line of my gridbox
sfl contains the pointer to the first line---
which is
key = QPRTFS (the key to the table I am working on
ctx = *USR or *SYS
VAL --some value-- or ''

on display as
QPRTFS *USR 1
I read in the userdata line at 2.
I get the key at 4 correctly
I then need to get the pointer to item 2 in the list, ctx, and then 3 val
I am getting a pointer to something but its not 'the brother' that is valid.
but name and value are the error messages
at some point I would like to undertand what I am doing, the documentation is next to nil, and at some point I would like to find a way to generalize the loop for n 'fields' and return name and value for each field. thanks.


local function sfl_readc()
local sflsiz = qwcsysval.numlin
1. for i = 1, sflsiz do
2. local sfl = iup.GetChild(qwcsysval, (i - 1) * sfl_elem)
3. local udta = tostring(sfl) -- this is just for debugging its a pointer(handle)
4. local key = sfl.title

-- obj
local ctx = iup.GetBrother(sfl.key)
___cnam = ctx.name or 'ctx name error '
___cval = ctx.value or 'ctx value error'
local val = iup.GetBrother(sfl.ctx)
___vnam = val.name or 'val name error '
___vval = val.value or 'ctx value error'

local dbg = dbg
end
end
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28342
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup gridbox program not executing correctly.

Post by tatewise »

I don't use iup.gridbox and I agree its documentation is sparse.

I use iup.matrix instead which can be found in the IUP Controls under Additional + iupControls + iupMatrix
In its documentation under Utility Functions it mentions these Lua functions:
ih:setcell(lin, col: number, value: string)
ih:getcell(lin, col: number) -> (cell: string)

I use those to set and get cell values in iup.matrix and maybe the same work for iup.gridbox.
e.g.
gbox:setcell( 1, 2, 3 )
x = gbox:getcell( 1, 2 )
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: iup gridbox program not executing correctly.

Post by ColeValleyGirl »

gridbox doesn't provide the facility to query the content of a cell by position -- it's a means of organising other iup controls, not displaying and querying data. There are ways of handling a gridbox to act as data storage (essentially by creating a table of the data elements in the grid once the grid has been completed) but it's unnecessarily complicated if iupmatrix will do the job better.
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup gridbox program not executing correctly.

Post by Ron Melby »

thanks mike and helen

I guess at some point you should prepared to be innundated about iup matrix. I am off to read that documentation
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup gridbox program not executing correctly.

Post by Ron Melby »

OK, things are not as they seem, here-- I would like some help with where I find the documentation for this, it is not in gridbox.

Helen, you use a gridbox in Research Planner
Mike, you use a gridbox in Flexible CSV importer.

local lbl = iup.label
{
title = options.name or '',
visiblelines = options.visiblelines or '1',
multiline = options.multiline or 'NO',
readonly = options.readonly or 'NO'
}

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
and so on....

I see in these tables things like name, value and so on --
absolute attributes in that table I understand from the iupgridbox attributes documentation.
and you can stuff a great deal of custom stuff in there as well...

question is, what displays on the screen? value? where is the documentation for what to actually display?

I have a bit of a system worked out... (found where my problem lies with my reading of gridbox line stuff... AND can fix it if I understand the other stuff)

so an example layout would be:

KEY = [KEY] value undefined QCTX = value = (usr or sys) QVAL = value = some alphaor numeric value or ''

those same fields will repeat for every line, this precludes the use of get and set handle, which is no problem because I have a way to deal with that I believe.

so, fundamentally the display is a key value pair title or value how does it know which to display and so on?

So in the case of key I want the Name, I know its a key so its the value
in the case of QCTX I want the name of the variable and its value, and same for QVAL
so
the subfile would display
QPRTFD (the key name) *USR (the value of qctx) , (the value of QVAL)

where is the documentation for title, value and all the user stuff?

after I get this (i see limitations, but cant leave this unfinished, and not going to abandon it...
then I am going to do matrix and set and get cell. (it is going to be more complex though....
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28342
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup gridbox program not executing correctly.

Post by tatewise »

In the Flexible CSV Importer most of the code was inherited from the previous authors and I just added updates.
So I don't know where they got their design from or what documentation they used.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: iup gridbox program not executing correctly.

Post by ColeValleyGirl »

What displays on the screen is whatever the controls you've put into the gridbox display. So (this is a snippet and won't execute standalone):

Code: Select all

       
        local gboxOptions1 = MakeGridbox{}         --function makes a gridbox, 2 columns wide, default settings     
        UseTag = MakeToggle{title="Research Tag"}  --function makes a toggle control
        TagLabel = MakeText{name = "TagLabel"} --function makes a text control
        gboxOptions1:append(UseTag) --gridbox will display the toggle control to the user
        gboxOptions1:append(TagLabel) --gridbox will display the text control to the user

To access the data values, you access the controls e.g. UseTag.value, TagLabel.value (or you do some clever jiggery-pokery with control callbacks.

You could construct a table of controls, and then drop those controls into the gridbox for display, but access them via the table.
Post Reply