* iup.GetParam boolean

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
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

iup.GetParam boolean

Post by DavidNewton » 28 Feb 2018 15:13

Just a curiosity.

I was playing with the various options with iup.GetParam to try to get some feel of it and I came across the follwing. Using the %b option with no extra [Yes,No] or whatever the result when checked is to return the initial value

Code: Select all

res, boo = iup.GetParam("Title", nil,"Tick: %b\n",100)
so the above piece of code returns a value of 100 for boo when checked and not the expected 1. I'm not sure if this is an undocumented feature, I have been unable to find any mention of it anywhere, and even if it is standard behaviour I cannot think of a use for it.

David

User avatar
tatewise
Megastar
Posts: 27084
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup.GetParam boolean

Post by tatewise » 28 Feb 2018 18:53

David,
It actually is nothing to do with whether the [parameter] is supplied.
If the user neither ticks nor unticks the boolean option, and just accepts the default setting then the initial value 100 is returned.
If either boolean option is specifically selected then the value 0 or 1 is returned.
So it offers a way of knowing whether the user has accepted the default, or specifically chosen an option.
Some other types of option work similarly.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: iup.GetParam boolean

Post by DavidNewton » 01 Mar 2018 00:12

Thanks Mike.
Crafty

David

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: iup.GetParam boolean

Post by DavidNewton » 03 Mar 2018 09:48

A slightly more general question about iup.GetParam checkboxes. I have written a plugin to help me to go through all the citations in my file to edit all the errors that have crept in via import/export. I am using iup.GetParam for the edit screen and just before the OK/Cancel buttons I have a check box to accept the changes. To pass the time!! I decided to learn a bit about callback functions and I have written one which changes the background screen colour if OK is clicked when the check box is not checked and I also changed the dialog title. When the check box is checked the screen colour is changed back. The colour changes work nicely but I am now left with the wrong title. I would like to change it back to the original which specifies the event details. Is there any way to do this with iup.GetParam

Code: Select all

function Check(dialog,param_index)
local	verify=iup.GetParamParam(dialog,5)
	if param_index==iup.GETPARAM_INIT then
		dialog.bgcolor='255 255 255'
		dialog.font='Segoe UI, 11'
	elseif param_index==iup.GETPARAM_OK and verify.value=='0' then
				dialog.bgcolor='000 200 200'
				dialog.title='Verify not checked'
				return 0
	elseif verify.value=='1' then
		dialog.bgcolor='255 255 255'
	end
	return 1
end

User avatar
tatewise
Megastar
Posts: 27084
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup.GetParam boolean

Post by tatewise » 03 Mar 2018 10:00

Yes, save the dialog.title in a global variable before you overwrite it with 'Verify not checked' then when you restore the dialog.bgcolor you can also restore the dialog.title to the global variable.
e.g.
DialogTitle = dialog.title
dialog.title = 'Verify not checked'
dialog.bgcolor = '000 200 200'


then when OK:
dialog.title = DialogTitle
dialog.bgcolor = '255 255 255'


Remember that from an Lua perspective, there is nothing 'magic' about IUP data structures.
They are just Lua tables, mostly holding numbers and strings and sometimes booleans in their sub-fields, although booleans are often represented by strings "YES" & "NO" or "ON" & "OFF".
i.e.
dialog is a standard Lua table, where sub-fields can be identified by integers t[2] or names t["two"].
dialog.title is standard Lua shorthand for dialog["title"] and it holds a standard Lua string of text.
dialog.bgcolor is also Lua shorthand for dialog["bgcolor"] and also holds a string of text.
But in that case the string represents numerical Red, Green, Blue colour levels.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: iup.GetParam boolean

Post by DavidNewton » 03 Mar 2018 11:15

Thanks again Mike, I didn't think of adding a global variable. I think it needs to be set up at the initialisation check of the dialog to ensure it's value matches the current dialog title.

David

User avatar
tatewise
Megastar
Posts: 27084
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: iup.GetParam boolean

Post by tatewise » 03 Mar 2018 12:34

Yes, you are absolutely correct.
Otherwise, it is upset if user traverses verify not checked branch several times, or not at all.

If that initialise branch was not available, then you could ensure it is only saved on first pass.
e.g.
DialogTitle = DialogTitle or dialog.title

and in verify.value == '1' branch only reset if it was saved:

dialog.title = DialogTitle or dialog.title

That is a cunning Lua technique that is the same as below.

if DialogTitle == nil then DialogTitle = dialog.title end
or
if not DialogTitle then DialogTitle = dialog.title end

Alternatively, set the global DialogTitle where you initialise dialog.title, then it is always available in verify.value == '1' branch.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: iup.GetParam boolean

Post by DavidNewton » 03 Mar 2018 13:38

As you say that is cunning. I have to say, as an absolute newcomer to callbacks, that for me the most exciting thing was being able to change the font size. My eyes have been suffering with the default 9 pt fonts.

David

Post Reply