Argolance asked the same question here in this forum about 2 months ago.smokey01 wrote:I'm still trying to find a way to enable/disable a button depending if a file exists or not
Basically 2 ways to achieve this: Either with a timer widget or with file-monitor attribute.
You were close. <input file> is supposed to display the button icon but even if the file is no image file file-monitor can still monitor it. In Argolance's thread I gave an example with 2 buttons, but it can be done with only 1 button. Hold your breath, this is going to be weird.I thought the <input file> option might work but apparently it only seems to display graphic files on the button widget, if they exist. I also tried it with tag attributes file-monitor and auto-refresh, no joy.
I thought that this would not work, but it does (I use leafpad since I don't have psip).
The script starts by creating an empty file (> /tmp/leafpad-file).
The function removes any tmp file that may exist, then runs the application. After the application finished, an empty string is written to the empty file. Apart from the filedate nothing changed, right?. Normally I would expect that this does not trigger a file-changed signal, but apparently it does.
Code: Select all
#!/bin/bash
> /tmp/leafpad-file
run_leafpad() {
leafpad
> /tmp/leafpad-file
}
export -f run_leafpad
echo -n '<window>
<vbox>
<button label="run_leafpad" file-monitor="true">
<variable>BUT</variable>
<input file>/tmp/leafpad-file</input>
<action signal="file-changed">enable:BUT</action>
<action signal="file-changed">break:</action>
<action>disable:BUT</action>
<action>run_leafpad &</action>
</button>
</vbox>
</window>' | gtkdialog -s
rm /tmp/leafpad-file
Using a timer would be more efficient as the timer monitors the file only as long as leafpad is running and not continuously as in above example:
Code: Select all
#!/bin/bash
run_leafpad() {
> /tmp/leafpad-file
leafpad
rm /tmp/leafpad-file
}
export -f run_leafpad
echo -n '<window>
<vbox>
<button label="run_leafpad">
<variable>BUT</variable>
<action>disable:BUT</action>
<action>enable:TIMER</action>
<action>run_leafpad &</action>
</button>
<timer visible="false" sensitive="false">
<variable>TIMER</variable>
<action condition="command_is_true( [ -e /tmp/leafpad-file ] && echo true )">break:</action>
<action>disable:TIMER</action>
<action>enable:BUT</action>
</timer>
</vbox>
</window>' | gtkdialog -s