Combo box with "endless" scrolling

40 views
Skip to first unread message

Judge Richter

unread,
Sep 20, 2024, 10:22:35 AMSep 20
to yad-common
Hi,

i don't know the correct expression in english. I have a combo box where i can select the hour (00..23). When i click the box or move the mouse over the box and use the wheel i can scroll from 0 to 23 and then scrolling stops. It would be great when the scrolling starts again with 0 - thats what i mean with "endless".

Is this possible?

~

unread,
Sep 25, 2024, 3:12:46 PMSep 25
to yad-common
I think what you are describing is similar to the endless rotation of the hour hand of a 24-hour clock dial. Mathematically, it can be described with "modular arithmetic" also known as "clock arithmetic". Another way to describe your case is for the combo box to start at 0, increase by 1 up to 23 then "wrap around" again at 0, endlessly. Unfortunately, I don't think yad has a built-in way to wrap around a combo box. However, by combining yad with a shell command, you could achieve what you need. I'm going to show you one way. You will likely need to adapt it to your use case. This is the command line, I'm using markdown syntax (backticks) to indicate literal code pieces:

```sh

vals='!0!1!2!3!4!5!6!7!8!9!10!11!12!13!14!15!16!17!18!19!20!21!22!23!24';
yad --form --changed-action="sh -xc '[ \$2 -eq 24 ] && echo "1:$vals"' changed" --field=WRAP:CB "$vals"

```

Explanation

`vals=...` holds the list of discrete combo box values 0 through 24. 24 must be selected (or scrolled to) to make the combo box wrap around back to zero.

`--form` is the yad dialog that houses the combo box.

`--changed-action=` introduces a shell command that runs every time the combo box value changes, hence the command runs 24 times for a complete wrap-around.

`sh -xc '[ \$2 -eq 24 ] && echo "1:$vals" changed'` is the command just mentioned. When it receives, in `$2`, the value 24 from the combo box, the command emits a new round of values (`$vals`) directed at the first (`1:`) field of the combo box. "changed" is just a placeholder with no special meaning.  I left in an "x" in "-xc" to shown (in a terminal window) when the command runs. Delete "x" when you finalize your own command.

`--field=WRAP:CB` is the first field. "WRAP" is just a label. Replace it with whatever you need.

`"$vals"` initializes the combo box.

Reply all
Reply to author
Forward
0 new messages