SFR wrote:
Surely it would be nice if there was an easier way, but there isn't, to my knowledge.
You can do it The Right Way™ in pure GTK+ (e.g. via C, Python, etc.) using
gtk-entry-set-visibility, but AFAIK Gtkdialog does not implement a mechanism to change widget's specific properties on the fly, except for a couple of them that are common to all widgets (sentitive, visible).
Gtkdialog does use gtk-entry-set-visibility function but only during first initialisation.
Current gtkdialog (since ver 0.7.21) recognises the sensitive states: true, false, or password during that initialisation. That additional 'password' state really refers to gtk-entry-set-visibility, rather than actual GTK GtkWidget sensitive state, which only includes true or false (grayed out or not).
Adding additional sensitive states and associated logic (as was done for 'password' itself), it is possible to toggle at least some widget states 'on-the-fly' via a checkbox refresh action. For example, I am currently trying out an experimental gtkwialog compile that includes extra sensitive state 'toggle_password' (each time the entry is refreshed via a checkbox). I'm still however considering whether the approach is good and what additional 'sensitive' state name(s) to actually use in practice, before any possible gtkwialog release with that extra functionality. The resultant sh/gtkwialog code is certainly a bit simpler than the hide/show password entry-box workarounds described earlier. The following straightforward code, for example, works with my experimental gtkwialog compile:
Code: Select all
#!/bin/bash
[ -z $GTKDIALOG ] && GTKDIALOG=gtkwialog
MAIN_DIALOG='
<window>
<vbox>
<frame Also working>
<entry>
<sensitive>toggle_password</sensitive>
<variable>ENTRY</variable>
<default>Password</default>
</entry>
<checkbox>
<variable>CHKBOX</variable>
<label>Show/Hide Password</label>
<action>refresh:ENTRY</action>
</checkbox>
</frame>
<hbox>
<button ok></button>
<button cancel></button>
</hbox>
</vbox>
</window>
'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
I'll post further about it if I decide to proceed with/publish that addition; just hesitant to adopt a new strategy (since once formalised hard to take it back...) in case a better approach is found. I'm hesitant because I'm not sure if overloading sensitive with additional states is best mechanism (despite that already being done for 'password' state itself) - it is certainly easy to apply. Might instead be better to have a new 'Directive' for such on-the-fly refresh additions, which I have yet to think of a suitable name for... However, I'm inclined towards these additional 'sensitive' states to toggle between since it involves only a little bit extra code to implement. If you feel you have any use for this facility, let me know since it is not worth further consideration if not likely to be used anyway.
wiak
Note: gif created using weX screencapture along with its utility button to fredx181's gifenc-yad utility. On looking at it, according to checkbox label, I should of course make password show on clicking check box, rather than hide on click...