yad icon indicating copy to clipboard operation
yad copied to clipboard

disabling a form button

Open step- opened this issue 1 year ago • 0 comments

Background of this new issue: https://github.com/v1cont/yad/issues/211.

At this point I'm convinced that a form button can't be disabled and then re-enabled within a single COMMAND (COMMAND is the value of the button field).

To be more precise, technically the button can be disabled and re-enabled, but the two operations happen almost simultaneously, so the user will experience an always-enabled button in practice.

The reason is that COMMAND's output is delivered back to yad all at once. It doesn't matter if COMMAND takes a long time to output: data will only be available when COMMAND ends. Involved code is here:

To demonstrate, consider the following test script. The first button - "can't disable # 1" - is schematically equivalent to the Frontend-for-find script in #211. The second button - "can't enable # 1" - demonstrates that disabling and enabling can't be done with a single process.

#!/bin/bash -a

# can't disable #1 for more than a fraction of a second because
# "@disabled@" and "@cantdisable" are delivered to yad together
cantdisable () {
: "1>"
	echo "1:@disabled@"
	sleep 3
	echo "1:@cantdisable"
: "<1"
}

# disable #1 but then it can't be re-enabled because stdout is closed
cantenable  () {
: "2>"
	echo "1:@disabled@"
	(
	: "daemonizing..."
	exec >&- 2>&-
	sleep 3
	echo "1:@cantdisable"
	)&
: "<2"
}

yad --center --use-interp='bash -xc "%s"' --form \
	--field="[1] can't disable #1:fbtn" "@cantdisable" \
	--field="[2] can't enable  #1:fbtn" "@cantenable" \
	--button=quit:0 --buttons-layout=center

Note: if you frantically press button 1, yad might crash because https://github.com/v1cont/yad/pull/214 and #217 haven't been merged yet.

Being able to disable a button while its long COMMAND is running is a desirable feature but it seems it can't be achieved - at least not easily enough - with a single COMMAND.

I think that yad itself should enable and disable a form button when it runs COMMAND; yad can transparently disable the button, run COMMAND, and re-enable the button when COMMAND exits. I can't think of a reason why it shouldn't work this way.

I have already prototyped a solution to this problem, which uncovered other issues that I'm now investigating. I will submit the solution and likely more pull requests soon.

step- avatar Jan 19 '23 06:01 step-