* fhUtils(...) Defaults Error?

For plugin authors to discuss plugin programming
Post Reply
User avatar
Mark1834
Megastar
Posts: 2689
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

fhUtils(...) Defaults Error?

Post by Mark1834 »

I need to check whether a file name selected with iup file dialog contains non-ASCII characters. If I set both UTF8MODE and UTF8MODE_FILE to ‘YES’ manually, it works as intended, but setting defaults via fhUtils() forces UTF8MODE_FILE to its default value of ‘NO’ and results in Unicode filenames not being returned correctly.

I’m the first to admit that character coding and locales is not my strongest suit, but surely that’s the wrong default isn’t it? The iup manual says explicitly that both parameters must be set to ‘YES’ to support Unicode.

PS - typo alert in the thread title - I can’t change it, but could an admin correct it for future searching please…🙂
Mark Draper
User avatar
ColeValleyGirl
Megastar
Posts: 5690
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: fhUtils(...) Defaults Error?

Post by ColeValleyGirl »

User avatar
Mark1834
Megastar
Posts: 2689
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: fhUtils(...) Defaults Error?

Post by Mark1834 »

Correct me if I've missed something, but if the option is set to 'NO', basic file selection does not work for Unicode files, and if set to 'YES', graphics libraries don't work.

I thought part of the reason for writing fhUtils() and fhFileUtils() was to make it easier for new and improving authors to use more advanced features. IMO, graphics library integration is far further up the learning curve and more specialised than basic file selection, so just reinforces my view that it is the wrong default (particularly as the library documentation says specifically that using fhUtils to set defaults enables UTF file support - it doesn't).
Mark Draper
User avatar
tatewise
Megastar
Posts: 29041
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: fhUtils(...) Defaults Error?

Post by tatewise »

Mark, I think that is not quite correct.
iup.SetGlobal("UTF8MODE_FILE", "YES") enables Unicode filenames for most purposes.
It does not prevent the use of CD or IM libraries but does not allow them to use Unicode filenames.
The filenames must conform to an ANSI-encoded path just for those libraries.
However, I agree the fhUtils(...) setting of iup.SetGlobal("UTF8MODE_FILE", "NO") is incorrect.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Mark1834
Megastar
Posts: 2689
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: fhUtils(...) Defaults Error?

Post by Mark1834 »

Thanks for the clarification - I had omitted the "for Unicode files" qualifier at the end of the first paragraph.
Mark Draper
User avatar
ColeValleyGirl
Megastar
Posts: 5690
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: fhUtils(...) Defaults Error?

Post by ColeValleyGirl »

Mark1834 wrote: 27 Jul 2024 12:17 Correct me if I've missed something, but if the option is set to 'NO', basic file selection does not work for Unicode files, and if set to 'YES', graphics libraries don't work.
As it says in the article I referred you to:
File Handling Within IUP and Associated Libraries CD and IM
IUP supports ‘ANSI’ paths by default in iup.filedlg (a file selection dialog), and the DROPFILE_CB callback (supporting file drag-and-drop onto an IUP dialog).

To support UTF-8 file paths in these contexts:

iup.SetGlobal("UTF8MODE_FILE", "YES")

However, this will not allow the CD or IM libraries (supporting graphics and digital images) to read or save files with Unicode characters in their path. If you can’t be certain that a file path doesn’t contain Unicode characters you should create a temporary file copy with an ANSI-encoded path (using os.tmpname) while working with those libraries, and copy the results to the target file when done.
The example code given includes:

Code: Select all

require ('iuplua') 
fh = require('fhUtils')
fh.setIupDefaults() --initialise fhUtils
iup.SetGlobal("CUSTOMQUITMESSAGE","YES") --initialise IUP
iup.SetGlobal("UTF8MODE", "YES") -- Configure IUP to use UTF-8 on the user interface.
iup.SetGlobal("UTF8MODE_FILE", "YES")  --Configure IUP to use UTF-8 file names if you intend to use IUP file selection dialog
I thought part of the reason for writing fhUtils() and fhFileUtils() was to make it easier for new and improving authors to use more advanced features. IMO, graphics library integration is far further up the learning curve and more specialised than basic file selection, so just reinforces my view that it is the wrong default (particularly as the library documentation says specifically that using fhUtils to set defaults enables UTF file support - it doesn't).
The default should be changed in the next release; I have no idea when that will be. However, the Knowledgebase article recommendations work.

P.S. I believe the default was set on the assumption that users would be accessing file names in their system locale, which is probably right more often than not; and it would allow the graphics libraries to work consistently.
Post Reply