* iup dialog questions. (I think)

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: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

iup dialog questions. (I think)

Post by Ron Melby »

I have two issues I do not know how to resolve in the code you see here, it is a subset of a much more complex program.

both issues are found by searching for: -- this
) to display 1 or 2 wide? (that will be a parm, but it will only be one of two values) as it is, if I can display it 1 wide somehow, I will parameterize the 1 or 2 wide case.

the second -- this, is sizing the dialog window the table in will be a parameter, as will the number and name of fields to display, so width would be some multiple of number of fields and size. and height would be some division of entries, taking a simple case, 40 entries which I might divide into 4 screens of 10, or 2 screens of 20. that calc is just moving numbers around, but translating it into this raster size for an original window, and knowing that math, and what it means is necessary for initial display and if they want to resize it. I think.

Code: Select all

require 'iuplua'
iup.SetGlobal('CUSTOMQUITMESSAGE', 'YES')
iup.SetGlobal('UTF8MODE','YES')
iup.SetGlobal('UTF8MODE_FILE', 'NO')

WS_Abort  = 'Abort'
WS_CANCEL = false
WS_Cancel = 'Cancel'
WS_ENTER  = true
WS_Ignore = 'Ignore'
WS_OK     = 'OK'
WS_Retry  = 'Retry'

WS_ERR    = 2
WS_YES    = 'Yes'
WS_NO     = 'No'

local rtx = {}

function set_IO_io(options)

  local   IOfld = iup.text
  {
    visiblelines = options.visiblelines or '1',
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }

  if options.value then
    IOfld.value = options.value
  else
    IOfld.value = ''
  end
  if options.filter then
    IOfld.filter = options.filter
  end
  if options.mask ~= nil then
    IOfld.mask = options.mask
  end

  return IOfld
end

function set_IO_o(options)
  local Ofld = iup.label
  {
    title        = options.value or '',
    visiblelines = options.visiblelines or '1',
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }

  return Ofld
end

function _sfl_WRITE(siz)
  local _sfl = iup.gridbox
  {
    alignmentlin   = 'ACENTER',
    expandchildren = 'NO',
    gaplin         = '10',
    gapcol         = '10',
   -- normalizesize  = 'BOTH',
    numdiv         = 5,
    orientation    = 'HORIZONTAL',
  }

  for k, v in pairs(siz) do

    -- this
    local opt = set_IO_io
    {
      name = opt, -- I want this to display 1 wide
      value = fhConvertANSItoUTF8(string.char(0x00)), -- nil, -- '',
      readonly = 'NO'
    }
    _sfl:append(opt)

    local key = set_IO_o
    {
      name = k,
      value = k,
      readonly = 'YES'
    }
    _sfl:append(key)

    local M = set_IO_o
    {
      name   = 'M',
      value  = v.M,
    }
    _sfl:append(M)

    local X = set_IO_o
    {
      name = 'X',
      value = v.X,
    }
    _sfl:append(X)

    local B = set_IO_o
    {
      name   = 'B',
      value  = v.B,
    }
    _sfl:append(B)

  end
  return _sfl
end

function _sfl_CTL(_WS)
  local sfl = iup.vbox{iup.scrollbox{_WS}}

  local btn_ok = iup.button
  {
    name   = 'ENTER',
    title  = 'ENTER',
    action = function(self)
      _sfl_READC(_WS)
      rtx.rc  = WS_ENTER
      rtx.TAG = TAG
      return iup.CLOSE
    end
  }

  local btn_cancel = iup.button
  {
    name   = 'CANCEL',
    title  = 'CANCEL',
    action = function(self)
      rtx.rc  = WS_CANCEL
      rtx.TAG = ''
      return iup.CLOSE
    end
  }

  local fn_keys = iup.hbox{btn_ok, btn_cancel}

  local _ws_dsp = iup.dialog
  {
    iup.vbox{sfl, iup.hbox{fn_keys}},
    title  = 'Column multipliers (y=mx + b)',
    margin = '5x5'
  }

  -- this
  local _ms = iup.Map(_ws_dsp)
  local _rs = _ws_dsp.rastersize
  local _ns = _ws_dsp.naturalsize
  if _rs then
    -- split the numbers but what do they mean and how to calc?
    -- documentation says calc this, but calc how, what is it showing me?
    local _wide, _high = _rs:match('(%d+)[X-x](%d+)')
  end
  _ws_dsp.size = _rs or _ns
  return _ws_dsp
end -- fn _sfl_CTL

function _sfl_READC(_WS)

  for row = 1, _WS.numlin do
    local ent = iup.GetChild(_WS, (i - 1) * _WS.numcol)
    local __opt = ent.value
    local __key = iup.GetBrother(__opt)
  end
end

siz =
{
  ["adr"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["age"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ahn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ara"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["arm"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["bin"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["cem"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dir"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["dob"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dod"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dst"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dup"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["era"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["err"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["erx"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["fct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["fid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gen"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gli"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["gpi"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["gps"] = {["M"] = 0,["X"] = 1,["B"] = 4,},
  ["iid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["lbl"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["loc"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["mdt"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["mml"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["nam"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["nct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["ord"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["oth"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["plc"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptg"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptr"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["rgn"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rlt"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rmn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["rnk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["rte"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["sdf"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["sep"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["set"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["sex"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["src"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["svc"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["tim"] = {["M"] = 0,["X"] = 3,["B"] = 0,},
  ["trk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["war"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["web"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["yr"]  = {["M"] = 0,["X"] = 1,["B"] = 0,},
}

-- EXEC()
if not _WS then
  _WS = _sfl_WRITE(siz)
  _ws_dsp = _sfl_CTL(_WS)
end

_ws_dsp:show(iup.CENTER, iup.CENTER)
iup.MainLoop()
_ws_dsp:destroy()
return
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

To set iup.text box width use visiblecolumns = '1'
e.g.

Code: Select all

function set_IO_io(options)

  local   IOfld = iup.text
  {
    visiblecolumns = options.visiblecolumns or '1',  -- like this
    visiblelines   = options.visiblelines or '1',
    multiline      = options.multiline or 'NO',
    readonly       = options.readonly or 'NO'
  }
BTW: These code lines do nothing useful:

Code: Select all

      name = opt, -- I want this to display 1 wide
      value = fhConvertANSItoUTF8(string.char(0x00)), -- nil, -- '',
Delete all the following code and the iup.dialog automatically sizes itself.

Code: Select all

  -- this
  local _ms = iup.Map(_ws_dsp)
  local _rs = _ws_dsp.rastersize
  local _ns = _ws_dsp.naturalsize
  if _rs then
    -- split the numbers but what do they mean and how to calc?
    -- documentation says calc this, but calc how, what is it showing me?
    local _wide, _high = _rs:match('(%d+)[X-x](%d+)')
  end
  _ws_dsp.size = _rs or _ns
All size values use "widthxheight", where width and height are integer values corresponding to the horizontal and vertical size, respectively.
RasterSize and NaturalSize use pixel integer values. So 100x200 is 100 pixels wide x 200 pixels high
Size uses character fraction unit integer values:
Width in 1/4's of the average width of a character for the current FONT of each control.
Height in 1/8's of the average height of a character for the current FONT of each control.
So 40x80 is 10 chars wide x 10 chars high

Don't use pixel values to set character units or the size will usually be far too big.
It is usually best to avoid setting sizes explicitly and let IUP adapt to the controls automatically.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

the opt field now works well.

however if I remove:
-- this
--[[
local _ms = iup.Map(_ws_dsp)
local _rs = _ws_dsp.rastersize
local _ns = _ws_dsp.naturalsize
if _rs then
-- split the numbers but what do they mean and how to calc?
-- documentation says calc this, but calc how, what is it showing me?
local _wide, _high = _rs:match('(%d+)[X-x](%d+)')
end
_ws_dsp.size = _rs or _ns
]]

then the window is teeny-tiny, where I want it to be correct size, in terms of width, and height, and it is still not doing that. so I am missing something.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

On my 1600 x 900 monitor, with a 10 pt Arial font, and the siz table reduced to 11 rows the dialog looks like this:
Dialog.png
Dialog.png (7.69 KiB) Viewed 5154 times
If you have a much larger higher resolution monitor then try using a larger font setting:

Code: Select all

  local _ws_dsp = iup.dialog
  {
    font = 'Arial, 24',
    iup.vbox{sfl, iup.hbox{fn_keys}},
    title  = 'Column multipliers (y=mx + b)',
    margin = '5x5'
  }
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

I am missing something somewhere. changing the font , I like the font, but no real effect.

I have tried both ways at dialog: size = nil, size = '', from reading the SIZE attribute in iup documentation, and misunderstanding the non-informational documentation there.

I still get this (albiet with a font I like better)
Untitled.png
Untitled.png (160.52 KiB) Viewed 5128 times
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

Are you running just the code you posted here originally, plus the minor adjustments we have discussed?
Or are you running a different plugin script?

If you drag the edges of that small dialogue window to make it taller and wider, what is revealed?
Does it then look similar to the window I posted?

Do not use _ws_dsp.Size = '' as that will probably shrink the window.
This code should reset the window size & minsize where iup.NULL is needed not Lua nil which is very different.

Code: Select all

	_ws_dsp.Size = iup.NULL
	_ws_dsp.MinSize = iup.NULL
	iup.Refresh(_ws_dsp)
It is important that all the internal control elements of the dialog have been added before using the above code.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

ok, my screen resolution is 1366 x 768

I have not substantially altered the code I first posted, however to make it easy, I will post what I am running now.
this is what is in there if I expand the window by hand.
Untitled.png
Untitled.png (161.21 KiB) Viewed 5116 times

Code: Select all

--[[
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 )
http://webserver2.tecgraf.puc-rio.br/iup/en/ctrl/iupmatrix.html
http://webserver2.tecgraf.puc-rio.br/iup/en/elem/iuptree.html
]]


require 'iuplua'
iup.SetGlobal('CUSTOMQUITMESSAGE', 'YES')
iup.SetGlobal('UTF8MODE','YES')
iup.SetGlobal('UTF8MODE_FILE', 'NO')

WS_Abort  = 'Abort'
WS_CANCEL = false
WS_Cancel = 'Cancel'
WS_ENTER  = true
WS_Ignore = 'Ignore'
WS_OK     = 'OK'
WS_Retry  = 'Retry'

WS_ERR    = 2
WS_YES    = 'Yes'
WS_NO     = 'No'

local rtx = {}

function set_IO_io(options)

  local   IOfld = iup.text
  {
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }

  if options.value then
    IOfld.value = options.value
  else
    IOfld.value = ''
  end
  if options.visiblecolumns then
    IOfld.visiblecolumns = options.visiblecolumns
  end
  if options.filter then
    IOfld.filter = options.filter
  end
  if options.mask ~= nil then
    IOfld.mask = options.mask
  end

  return IOfld
end

function set_IO_o(options)
  local Ofld = iup.label
  {
    title        = options.value or '',
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }

  return Ofld
end

function _sfl_WRITE(siz)
  local _sfl = iup.gridbox
  {
    numdiv         = 5,
    dropdown       = 'NO',
    alignmentlin   = 'ACENTER',
    expandchildren = 'NO',
    gaplin         = '8',
    gapcol         = '32',
    margin         =  '4x4',
    orientation    = 'HORIZONTAL',
  }

  for k, v in pairs(siz) do

    -- this
    local opt = set_IO_io
    {
      --  name = opt, -- I want this to display 1 wide
      visiblecolumns = 1,
      readonly = 'NO',
    }
    _sfl:append(opt)

    local key = set_IO_o
    {
      name = k,
      value = k,
      readonly = 'YES',
    }
    _sfl:append(key)

    local M = set_IO_o
    {
      name   = 'M',
      value  = v.M,
    }
    _sfl:append(M)

    local X = set_IO_o
    {
      name = 'X',
      value = v.X,
    }
    _sfl:append(X)

    local B = set_IO_o
    {
      name   = 'B',
      value  = v.B,
    }
    _sfl:append(B)

  end
  return _sfl
end

function _sfl_CTL(_WS)
  local sfl = iup.vbox{iup.scrollbox{_WS}}

  local btn_ok = iup.button
  {
    name   = 'ENTER',
    title  = 'ENTER',
    action = function(self)
      _sfl_READC(_WS)
      rtx.rc  = WS_ENTER
      rtx.TAG = TAG
      return iup.CLOSE
    end
  }

  local btn_cancel = iup.button
  {
    name   = 'CANCEL',
    title  = 'CANCEL',
    action = function(self)
      rtx.rc  = WS_CANCEL
      rtx.TAG = ''
      return iup.CLOSE
    end
  }

  local fn_keys = iup.hbox{btn_ok, btn_cancel}

  local _ws_dsp = iup.dialog
  {
    font = 'Courier New, 10',
    title  = 'Column multipliers (y = mx + b)',
    margin = '8x8',
    iup.vbox{sfl, iup.hbox{fn_keys}},
  }

  -- this
  --[[
  local _ms = iup.Map(_ws_dsp)
  local _rs = _ws_dsp.rastersize
  local _ns = _ws_dsp.naturalsize
  if _rs then
    -- split the numbers but what do they mean and how to calc?
    -- documentation says calc this, but calc how, what is it showing me?
    local _wide, _high = _rs:match('(%d+)[X-x](%d+)')
  end
  _ws_dsp.size = _rs or _ns
  ]]
  return _ws_dsp
end -- fn _sfl_CTL

function _sfl_READC(_WS)

  for row = 1, _WS.numlin do
    local ent = iup.GetChild(_WS, (i - 1) * _WS.numcol)
    local __opt = ent.value
    local __key = iup.GetBrother(__opt)
  end
end

siz =
{
  ["adr"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["age"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ahn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ara"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["arm"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["bin"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["cem"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dir"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["dob"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dod"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dst"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dup"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["era"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["err"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["erx"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["fct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["fid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gen"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gli"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["gpi"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["gps"] = {["M"] = 0,["X"] = 1,["B"] = 4,},
  ["iid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["lbl"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["loc"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["mdt"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["mml"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["nam"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["nct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["ord"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["oth"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["plc"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptg"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptr"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["rgn"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rlt"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rmn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["rnk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["rte"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["sdf"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["sep"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["set"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["sex"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["src"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["svc"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["tim"] = {["M"] = 0,["X"] = 3,["B"] = 0,},
  ["trk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["war"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["web"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["yr"]  = {["M"] = 0,["X"] = 1,["B"] = 0,},
}

-- EXEC()
if not _WS then
  _WS = _sfl_WRITE(siz)
  _ws_dsp = _sfl_CTL(_WS)
end

_ws_dsp:show(iup.CENTER, iup.CENTER)
iup.MainLoop()
_ws_dsp:destroy()
return
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

Try the code I added to my previous posting regarding iup.NULL etc...

The differences between your system and mine may be due to the different IUP versions in FH v6.2 and FH v7.0.
Tomorrow I will run up my FH v6.2 system and try to reproduce your symptoms with that.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

I put it in the 2nd -- this area where I have iup.Map commented out
no change.
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

Mike, here is what I have working at present:
first question, does it work on yours at 7 and 5.3?

Code: Select all

--[[
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 )
http://webserver2.tecgraf.puc-rio.br/iup/en/ctrl/iupmatrix.html
http://webserver2.tecgraf.puc-rio.br/iup/en/elem/iuptree.html
]]


require 'iuplua'
iup.SetGlobal('CUSTOMQUITMESSAGE', 'YES')
iup.SetGlobal('UTF8MODE','YES')
iup.SetGlobal('UTF8MODE_FILE', 'NO')

WS_Abort  = 'Abort'
WS_CANCEL = false
WS_Cancel = 'Cancel'
WS_ENTER  = true
WS_Ignore = 'Ignore'
WS_OK     = 'OK'
WS_Retry  = 'Retry'

WS_ERR    = 2
WS_YES    = 'Yes'
WS_NO     = 'No'

local rtx = {}

function set_IO_io(options)

  local   IOfld = iup.text
  {
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }

  if options.value then
    IOfld.value = options.value
  else
    IOfld.value = ''
  end
  if options.visiblecolumns then
    IOfld.visiblecolumns = options.visiblecolumns
  end
  if options.filter then
    IOfld.filter = options.filter
  end
  if options.mask ~= nil then
    IOfld.mask = options.mask
  end

  return IOfld
end

function set_IO_o(options)
  local Ofld = iup.label
  {
    title        = options.value or '',
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }

  return Ofld
end

function _sfl_WRITE(siz)

  local _sfl = iup.gridbox
  {
    numdiv         = 5,
    dropdown       = 'NO',
    alignmentlin   = 'ACENTER',
    expandchildren = 'NO',
    gaplin         = '4',
    gapcol         = '32',
    margin         =  '4x4',
    orientation    = 'HORIZONTAL',
  }

  for k, v in pairs(siz) do

    -- this
    local opt = set_IO_io
    {
      --  name = opt, -- I want this to display 1 wide
      visiblecolumns = 1,
      readonly = 'NO',
    }
    _sfl:append(opt)

    local key = set_IO_o
    {
      name = k,
      value = k,
      readonly = 'YES',
    }
    _sfl:append(key)

    local M = set_IO_o
    {
      name   = 'M',
      value  = v.M,
    }
    _sfl:append(M)

    local X = set_IO_o
    {
      name = 'X',
      value = v.X,
    }
    _sfl:append(X)

    local B = set_IO_o
    {
      name   = 'B',
      value  = v.B,
    }
    _sfl:append(B)

  end
  return _sfl
end

function _sfl_CTL(_WS)
  local sfl = iup.vbox{iup.scrollbox{_WS}}

  local btn_ok = iup.button
  {
    name   = 'ENTER',
    title  = 'ENTER',
    action = function(self)
      _sfl_READC(_WS)
      rtx.rc  = WS_ENTER
      rtx.TAG = TAG
      return iup.CLOSE
    end
  }

  local btn_cancel = iup.button
  {
    name   = 'CANCEL',
    title  = 'CANCEL',
    action = function(self)
      rtx.rc  = WS_CANCEL
      rtx.TAG = ''
      return iup.CLOSE
    end
  }

  local fn_keys = iup.hbox{btn_ok, btn_cancel}

  local _ws_dsp = iup.dialog
  {
    font = 'Courier New, 10',
    title  = 'Column multipliers (y = mx + b)',
    margin = '8x8',
    iup.vbox{sfl, iup.hbox{fn_keys}},
  }

  -- this
  local _nds = _WS.numdiv
  local _ncs = _WS.numcol
  local _nls = _WS.numlin

  iup.Map(_ws_dsp)
  local _cz = _ws_dsp.charsize    -- '8x16'
  local _nz = _ws_dsp.naturalsize -- '168x143'
  local _sz = _ws_dsp.size        -- '84x72'

  local _w, _h = _sz:match('(%d+)[X-x](%d+)')
  local _xw = 1.75
  local _xh = 2
  _ws_dsp.size = ('%sx%s'):format(_w * _xw, _h * _xh)
--  _ws_dsp.size = _nz
 return _ws_dsp
end -- fn _sfl_CTL

function _sfl_READC(_WS)

  for row = 1, _WS.numlin do
    local ent = iup.GetChild(_WS, (i - 1) * _WS.numcol)
    local __opt = ent.value
    local __key = iup.GetBrother(__opt)
  end
end

siz =
{
  ["adr"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["age"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ahn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ara"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["arm"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["bin"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["cem"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dir"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["dob"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dod"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dst"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dup"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["era"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["err"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["erx"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["fct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["fid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gen"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gli"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["gpi"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["gps"] = {["M"] = 0,["X"] = 1,["B"] = 4,},
  ["iid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["lbl"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["loc"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["mdt"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["mml"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["nam"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["nct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["ord"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["oth"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["plc"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptg"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptr"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["rgn"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rlt"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rmn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["rnk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["rte"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["sdf"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["sep"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["set"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["sex"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["src"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["svc"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["tim"] = {["M"] = 0,["X"] = 3,["B"] = 0,},
  ["trk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["war"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["web"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["yr"]  = {["M"] = 0,["X"] = 1,["B"] = 0,},
}

-- EXEC()
if not _WS then
  _WS = _sfl_WRITE(siz)
  _ws_dsp = _sfl_CTL(_WS)
end

_ws_dsp:show(iup.CENTER, iup.CENTER)
iup.MainLoop()
_ws_dsp:destroy()
return
I have left the second -- this in there so you can find it.
iup.Refresh doesnt seem to be needed on mine, however iup.Map does

as usual, the running around trying to decipher the documentation is sort of wasted.
it appears as though rastersize is some conglomeration of some di minimus calculation that results in either
#width of size * 2, math.floor(height something)
or
#width of size * 2, height * 2 - 1

I tried size two ways, left the second commented, so you could uncomment and see the difference.

I doubt my constants 1.75 and 2 will scale as I add or subtract fields. and that the number of lines in the subfile (sfl, _WS, _ws_dsp, however you want to think of it, could be used in window sizing)
I need to add 2 headers to what I have, which will eventually be built from user definitions supplied at runtime.
one of the headers will be something like:
''
(thats why opt will be either one or two at build time
the second header will be something like:
' Opt KEY M X B'
based upon fields you want to get from the table and display (also user definitions supplied at runtime'

so it would kind of look like
Column multipliers (y = mx + b) _ □ X
1 = Select 3 = Change 4 = Delete 6 = Print 20 = Idunno
Opt KEY M X B
_ adr 0 4 1
_ age 0 6 0
_ ahn 0 6 0

But wait, Mike says

yes, I know, MFL loc only makes sense if you can show it as an iup.tree
most all of this would be easier if you just did it as iup.matrix

Well, prepared to be grilled for some time to come on this (and the original gbox post I posted, which this is the subset of (it includes the usrdfn (user defined) table of runtime parms

I hope this helps you sort of form in your mind, WHY even bother with?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

The difference between FH v 6.2 and FH v7.0 is due to a change in IUP for iup.scrollbox{...}
FH V6.2 uses IUP v3.11 whereas FH v7.0 use IUP v3.28
The IUP documentation for IupScrollBox says in its Notes:
So the IupScrollBox does not depend on its child size or expansion, and its natural size is always 0x0, except for the first time when it expands to the child natural size (since 3.19).
So for FH v6.2 IUP v3.11 the IupScrollBox natural size is always 0x0 which is why you see a shrunken dialogue.
That is too small.

But in FH v7.0 IUP v3.28 the IupScrollBox natural size expands to the child natural size which is what I see.
For large tables that is too tall.

Your latest script works in FH v6.2 IUP v3.11 but not in FH v7.0 IUP v3.28 because the dialogue has already expanded to the height of the table and your adjustment doubles that.

What works for both systems is:

Code: Select all

  iup.Map(_ws_dsp)        -- map the resource sizes
  local _sz = _WS.size    -- get size of the table
  local _w, _h = _sz:match('(%d+)[X-x](%d+)')
  _ws_dsp.size = ('%sx%s'):format(_w * 1.5,200)  -- table width x 1.5 and fixed height
BTW:
RasterSize uses pixel integer values as I explained earlier. So that varies from monitor to monitor depending on the screen resolution and font sizes. Therefore, adjusting RasterSize does not usually work on different systems.
Size uses fractions of a character font so is less dependant on screen resolution. Therefore, adjustments to Size are usually much more portable.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

I have incorporated it, thanks for the help Mike, looks good. now I have to try it with a small table and see if I can find the tipping point between showing it all and showing in 'pages'.

however, its off to more non-documented do now work as advertized (even by Scuri, at this point) for how to get the data out.

in _sfl_READC, I will only return 'changed records' in rtx{} with changed record defined as a valid number in opt (determining that valid number is a todo, I can restrict it to numbers, ok, but then I think I have to do a lookup on the valid values from _usrdfn user definition file. then show the error with a bgcolor and position the cursor there.....uff da.Thats for the next decade.

this screen is display, so really no matter what fields one wants shown, I want to readc opt and key (the values) from those fields, the rest is yadda, yadda, yadda, blah, blah, blah, I dont care, all that would be returned from this is opt, key so I dont need to read anything in other fields (which are output only at this point.

I can read opt, but not key. I set to the entry ok, I get opt as described by Scuri, but cannot get key as described.

I may have to go back to putting handles on things, which I really dont want to, if thats the only way I can address them. seems like it should be trivial, but it aint trivial to me.
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

--*add is the problem for now.
in vfy_parms, I build the header for columns in my subfile _hdr_col.

I then put it in an hbox, because what else would I put it in?
I intend to display it.
(still dont know why I have to hbox things twice. but not an issue at present)

as you can see the space is there but the text doesnt display. there is no iup.textbox, but I thought to myself its sorta like MLF Manage Location Plots or Statistics: line on Geocode Location plots tab.

I know it can be done, and it must be simple, but I have read as much opaque documentation and searched fruitlessly for examples of how to make that, and it might be that it is shown somewhere, in another not exactly form, and I just cannot see the solution. iup is extreme in frustration.

Code: Select all

--[[
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 )
http://webserver2.tecgraf.puc-rio.br/iup/en/ctrl/iupmatrix.html
http://webserver2.tecgraf.puc-rio.br/iup/en/elem/iuptree.html
]]


require 'iuplua'
iup.SetGlobal('CUSTOMQUITMESSAGE', 'YES')
iup.SetGlobal('UTF8MODE','YES')
iup.SetGlobal('UTF8MODE_FILE', 'NO')

WS_Abort  = 'Abort'
WS_CANCEL = false
WS_Cancel = 'Cancel'
WS_ENTER  = true
WS_Ignore = 'Ignore'
WS_OK     = 'OK'
WS_Retry  = 'Retry'

WS_ERR    = 2
WS_YES    = 'Yes'
WS_NO     = 'No'

-- local _ptr = {}
-- local rtx = {} -- return changed records via callback
-- local row = 0
-- local col = 0
local rtx = {}
local numdiv = 0
local sflsiz = 0
local _hdr_col = '  Opt  KEY '

_tbl =
{
  ["adr"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["age"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ahn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["ara"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["arm"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["bin"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["cem"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dir"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["dob"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dod"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["dst"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["dup"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["era"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["err"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["erx"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["fct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["fid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gen"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["gli"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["gpi"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["gps"] = {["M"] = 0,["X"] = 1,["B"] = 4,},
  ["iid"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["lbl"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["loc"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["mdt"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["mml"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["nam"] = {["M"] = 0,["X"] = 4,["B"] = 1,},
  ["nct"] = {["M"] = 0,["X"] = 8,["B"] = 0,},
  ["ord"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["oth"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["plc"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptg"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["ptr"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["rgn"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rlt"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["rmn"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["rnk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["rte"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["sdf"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["sep"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["set"] = {["M"] = 0,["X"] = 6,["B"] = 0,},
  ["sex"] = {["M"] = 0,["X"] = 1,["B"] = 0,},
  ["src"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["svc"] = {["M"] = 0,["X"] = 4,["B"] = 2,},
  ["tim"] = {["M"] = 0,["X"] = 3,["B"] = 0,},
  ["trk"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["war"] = {["M"] = 0,["X"] = 4,["B"] = 0,},
  ["web"] = {["M"] = 0,["X"] = 4,["B"] = 4,},
  ["yr"]  = {["M"] = 0,["X"] = 1,["B"] = 0,},
}

_usrdfn =
{
  -- optsiz = (1 or 2 ' '),
  ['fld'] = {[1] = 'M',   [2] = 'X', [3] = 'B',},
  ['buf'] = {[1] = 'var', [2] = 'o', [3] = 'o',},
}



function vfy_parms(_usrdfn, _tbl)

  if type(_usrdfn) ~= 'table' then
    error('definition not a table')
  end
  if type(_tbl) ~= 'table' then
    error('display not a table')
  end

  numdiv = #_usrdfn['fld'] + 2
  local numbuf = #_usrdfn['buf'] + 2
  if numdiv ~= numbuf then
    error('mismatch in user defined fields and buffers')
  end

  for _k ,_v in ipairs(_usrdfn['fld']) do
    _hdr_col = ('%s %s '):format(_hdr_col, _v)
    -- check for is %q etc
  end

  for k, v in ipairs(_usrdfn['buf']) do
    local _ub = _usrdfn['buf'][k]
    local _ok
    for _, _y in pairs({'o', 'io', 'var',}) do
      if _ub == _y then
        _ok = true
        break
      end
    end
    if not _ok then
      error('buffer value is not valid')
    end
  end

-- if not indexed index
  --[[
 for _, v in pairs(_tbl) do
    if type(v) == 'table' then
      istree = true
      break
    end
  end
]]

  return
end

local function _get_io()

  if _OBJ._buf == 'io' then
    _OBJ._io = 'io'
    _OBJ.readonly = 'NO'
    return
  end

  if _OBJ._buf == 'var' then
    -- send key of file and fld  decide if it should be 'io' or 'o'
    -- 'u' for planned expansion
    local _buf = cb_io('u', _OBJ._key, _OBJ._fld)

    if _buf == 'io' then
      _OBJ.readonly = 'NO'
      return
    end

    if _buf == 'o' then
      _OBJ.readonly = 'YES'
      return
    end
    error("cb_io returned value that is not 'o' or 'io'.")
  end
end -- fn _get_io

function set_io_IO(options)

  local   IOfld = iup.text
  {
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }

  if options.value then
    IOfld.value = options.value
  else
    IOfld.value = iup.NULL
  end
  if options.visiblecolumns then
    IOfld.visiblecolumns = options.visiblecolumns
  end
  if options.font then
    IOfld.font = options.font
  end
  if options.filter then
    IOfld.filter = options.filter
  end
  if options.mask ~= nil then
    IOfld.mask = options.mask
  end

  return IOfld
end

function set_io_O(options)
  local Ofld = iup.label
  {
    title        = options.value or iup.NULL,
    multiline    = options.multiline or 'NO',
    readonly     = options.readonly or 'NO'
  }
  if options.font then
    Ofld.font = options.font
  end
  if options.size then
    Ofld.size = options.size
  end

  return Ofld
end

function _sfl_WRITE(siz)

  local _sfl = iup.gridbox
  {
    numdiv         = 5,
    dropdown       = 'NO',
    expandchildren = 'NO',
    gaplin         = '1',
    gapcol         = '16',
    margin         = '4x4',
    font           = 'Courier New, 10',
    alignmentcol   = 'ALEFT',
    alignmentlin   = 'ABOTTOM',
    orientation    = 'HORIZONTAL',
  }

  --  for KEY, _ in pairs(_tbl) do -- _ = ARRAY
  for k, v in pairs(_tbl) do

    local opt = set_io_IO
    {
      name = opt,
      visiblecolumns = 1,
      readonly = 'NO',
    }
    _sfl:append(opt)

    local _key = set_io_O
    {
      name     = _key,
      value    = k,
      readonly = 'YES',
    }
    _sfl:append(_key)


    --  for ix, ufld in ipairs(_usrdfn) do
    --  local _ =
    --  {
    --    name          = _usrdfn.fld[ix],    -- FIELD NAME
    --    value         = _tbl[_usrdfn[s]],  -- FIELD VALUE from _tbl
    --    readonly      = 'YES',             -- YES, NO > crt_IO('var' > cb_io)
    --    multiline     = 'NO',              -- for now, one line.
    --  }
    --  _sfl:append(_)
    --   end

    local M = set_io_O
    {
      name   = 'M',
      value  = v.M,
      font           = 'Courier New, 10',
    }
    _sfl:append(M)

    local X = set_io_O
    {
      name = 'X',
      value = v.X,
      font           = 'Courier New, 10',
    }
    _sfl:append(X)

    local B = set_io_O
    {
      name   = 'B',
      value  = v.B,
      font           = 'Courier New, 10',
    }
    _sfl:append(B)

  end
  return _sfl
end

function _sfl_CTL(_WS)
  local sfl = iup.vbox{iup.scrollbox{_WS}}

  local btn_ok = iup.button
  {
    name   = 'ENTER',
    title  = 'ENTER',
    action = function(self)
      _sfl_READC(_WS)
      rtx.rc  = WS_ENTER
      rtx.TAG = TAG
      return iup.CLOSE
    end
  }

  local btn_cancel = iup.button
  {
    name   = 'CANCEL',
    title  = 'CANCEL',
    action = function(self)
      rtx.rc  = WS_CANCEL
      rtx.TAG = ''
      return iup.CLOSE
    end
  }
  --*add
  local hdr_col = iup.hbox{_hdr_col}
  local fn_keys = iup.hbox{btn_ok, btn_cancel}

  local _ws_dsp = iup.dialog
  {
    font = 'Courier New, 10',
    title  = 'Column multipliers (y = mx + b)',
    margin = '8x8',
    --*add
    iup.vbox{iup.hbox{hdr_col}, sfl, iup.hbox{fn_keys}},
  }

  -- this
  local _nds = _WS.numdiv
  local _ncs = _WS.numcol
  _ws_dsp.sflsiz = _WS.numlin
  slfziz = _WS.numlin

  iup.Map(_ws_dsp)
  local _cz = _ws_dsp.charsize    -- '8x16'
  local _nz = _ws_dsp.naturalsize -- '168x143'
  local _sz = _WS.size    -- get size of the table
  local _w, _h = _sz:match('(%d+)[X-x](%d+)')
  _ws_dsp.size = ('%sx%s'):format(_w * 1.6, 200)  -- table width x 1.5 and fixed height

  return _ws_dsp
end -- fn _sfl_CTL

function _sfl_READC(_WS)
--[[
iup.GetChild
iup.GetNextChild
iup.GetBrother
--iup.GetParent

Another option is to use the NAME attribute.
You set it on the element you want then use
IupGetDialogChild to retrieve the element given the NAME value.
]]

  for row = 1, _WS.sflsiz do

    local ent = iup.GetChild(_WS, (row - 1) * _WS.numcol)
    local opt = iup.GetBrother(ent)
    local key = iup.GetBrother(opt) -- ent._key.value
    if opt > '' then
      rtx[rtx + 1] = { _opt = opt, _key = key}
    end
  end
end

-- EXEC()
if not _WS then
  vfy_parms(_usrdfn, _tbl)
  _WS = _sfl_WRITE(_tbl)
  _ws_dsp = _sfl_CTL(_WS)
end

_ws_dsp:show(iup.CENTER, iup.CENTER)
iup.MainLoop()
_ws_dsp:destroy()

return
I do not know if a light will ever click on for me insofar as iup goes.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

Really Ron, you know better than that. :roll:
What must iup.hbox{...} contain?
It must only contain other IUP controls such as iup.button, iup.text, iup.label, etc, ...
_hdr_col is NOT an IUP control but a simple vanilla Lua text string!
So as far as IUP is concerned that iup.hbox contains nothing.

Checkout MLF Statistics: IUP coding and you will find:

Code: Select all

local lblPlotted    = iup.label{ Title=" "; Tip="Number of Locations with fully Plotted Latitude/Longitude"; }
local lblTentative  = iup.label{ Title=" "; Tip="Number of Locations with Tentative plot Latitude/Longitude"; }
local lblNoPlot     = iup.label{ Title=" "; Tip="Number of Locations with Blocked status or Not Found by Geocoder"; }
local lblInvalid    = iup.label{ Title=" "; Tip="Number of Locations with Invalid Request/Request Denied from Geocoder"; }
local lblNoData     = iup.label{ Title=" "; Tip="Number of Locations with no Latitude/Longitude and not yet Geocoded"; }
local lblPlotTotal  = iup.label{ Title=" "; Tip="Number of Locations listed in total"; }

iup.hbox{ lblPlotted; lblTentative; lblNoPlot; lblInvalid; lblNoData; lblPlotTotal; }

Notice how iup.hbox is full of iup.label controls.
Later, each Title is assigned the value of the statistic.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

as it happens, I don't know better than that, Mike, now I do.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

Check out the documentation for the Controls > Containers like iup.hbox, iup.vbox, etc.
They show the Lua syntax as:
iup.hbox{child, ...: ihandle} -> (ih: ihandle) [in Lua]
So every child parameter must be of type ihandle which means some other IUP entity.
It also returns an ihandle for the container.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

function _sfl_CTL(_WS)

local hdrcol =
iup.label
{
title = _hdr_col,
gaplin = '0',
gapcol = '0',
expand = 'NO',
alignmentcol = 'ALEFT',
alignmentlin = 'ATOP',
multiline = 'NO',
}
local hdr_col = iup.hbox{hdrcol}

local sfl = iup.vbox{iup.scrollbox{_WS}}

local btn_ok = iup.button
{
name = 'ENTER',
title = 'ENTER',
action = function(self)
_sfl_READC(_WS)
rtx.rc = WS_ENTER
rtx.TAG = TAG
return iup.CLOSE
end
}

local btn_cancel = iup.button
{
name = 'CANCEL',
title = 'CANCEL',
action = function(self)
rtx.rc = WS_CANCEL
rtx.TAG = ''
return iup.CLOSE
end
}
local fn_keys = iup.hbox{btn_ok, btn_cancel}

local _ws_dsp = iup.dialog
{
font = 'Courier New, 10',
title = 'Column multipliers (y = mx + b)',
margin = '8x8',
--*add
iup.vbox{iup.hbox{hdr_col}, sfl, iup.hbox{fn_keys}},
}

-- this
local _nds = _WS.numdiv
local _ncs = _WS.numcol
_ws_dsp.sflsiz = _WS.numlin
slfziz = _WS.numlin

iup.Map(_ws_dsp)
local _cz = _ws_dsp.charsize -- '8x16'
local _nz = _ws_dsp.naturalsize -- '168x143'
local _sz = _WS.size -- get size of the table
local _w, _h = _sz:match('(%d+)[X-x](%d+)')
_ws_dsp.size = ('%sx%s'):format(_w * 1.5, 200) -- table width x 1.5 and fixed height

return _ws_dsp
end -- fn _sfl_CTL

this is the _sfl_CTL function now, I cannot fathom where the space is coming from above and below the column header, I cannot even get rid of a little bit of it. Nevermind that I can think of no way to align it on the fly.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

margin = '8x8' on the iup.dialog affects all the component boxes.

So delete that and add margin = '8x8' to just the components you want to have margins.
Try changing each 8 to 0 and see what happens.

BTW: local _hdr_col = ' Opt KEY ' should use single spaces.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

thanks Mike, now it seems logical, at least a little.

I am going to have to come up with something to figure out how to space it, to align the header and fields.
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

This is a rudimentary mockup of a screen I am trying to create.
mt.png
mt.png (23.72 KiB) Viewed 4654 times
opt, will be the only input/output field on the line, in this screen.
I believe I have a plan to work out the indentation.

I have looked at iup.matrix and iup.tree.
I do not believe iup.tree will work for this.
here is the link for iup.matrix that I am looking at.
http://webserver2.tecgraf.puc-rio.br/iu ... Attributes

Some things are rather opaque to me.
I believe that column headings would go in row 0 and would sort of be stuck to the screen on scrolls, is that true?

i need to carry a hidden field on each record, that I can read and write, but that is not visible to the user. Am I missing something, I do not see a way to do that. Am I missing something in that regard?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup dialog questions. (I think)

Post by tatewise »

Yes, I think iup.matrix might work.
Beware of IUP features that are not supported in the FH v6.2.7 plugins, i.e. later than IUP v3.11.
Use tonumber(iup._VERSION) to check the IUP version supported.

Yes, row 0 and column 0 define non-scrollable Title rows and columns.
But you can leave those cells out if you don't want Title rows or columns.

I guess you are intending to insert leading spaces in cells to create the indents.

If you don't put the 'hidden' field into a matrix cell then the user cannot see it, but the plugin can still read/write that field.
Have I misunderstood the problem?
Are you saying you want a cell that you can read/write in the matrix, but that users cannot see?
How does the plugin differentiate you as a special user from all other users?
There needs to be some 'magic flag' that identifies you so the plugin can display or hide those cells.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: iup dialog questions. (I think)

Post by Ron Melby »

the hidden field would be the full key, so for example:

ADDR."St.Margarets...".sub
ADDR."St.Margarets....".lng and so on, for each row.

it wouldn't be an optional see or not see thing.
Just a big shortcut in computing, so when you choose lng I do not have to backtrack to calculate the key.

If you recall the routine you helped me work out to read _G and track paths, like os.rename, I would use that as my path builder (with only very slight modifications, since I would keep track of the ADDR key by itself to the table, for example, its a couple line change to add it before I run the table back thru, recursively) it would require my reading the table to build keys, then read the table to fill the matrix.

Mind you, I have not yet identified how I can programmatically see that a table should be displayed like this, but humanly I can, I have tried a couple ideas, but they didn't really pan out, but clearly, there are only really two types of tables, flat and complex.

I could indent with x'40' and then gsub it if necessary, later. but if I can carry the full key in the record, I do not need to bother with it. is it foolproof? No, but I don't think folks use any x'40' in tables for fh. But of course someone will.

Now again, if I do not have to calculate a key, and keep it hidden and accessable in the record so indent would be controlled by lvl from that _G exercise program we built. what is on the screen is for humans and what is hidden is for computers.

I am doing something similar but much simpler now with gridbox, to get the major functions worked out, and not hiding the key, and you remember perhaps the PLAC.dat file I do for my gps work where I add haversines and other information to lat long, and its probably 2000 or so entries, and it takes forever to load, forever to scroll, and the function keys do not display on it although they will on small test files, and the text layout is atrocious, so I am trying to see if I can do better with matrix.

Hopefully 5.3 et al is less buggy.
FH V.6.2.7 Win 10 64 bit
Post Reply