You are not logged in.

#1 2016-01-07 06:36:47

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Yad notes

Damo's rewritten a lot of scripts to use yad (now in the BL repo) instead of zenity, and to keep things tidy I thought I'd better switch too so we don't have to have both apps installed. In the process of rewriting a simple notification window I ran into a couple of things - now worked around - and thought I'd drop it here for future reference. Feel free to add your own findings/hints/etc. (Especially @Damo!)

While Damo and I were playing around with icons , images and yad we discovered a couple of things:
*) Full image paths always work, but --image= then displays the image at full size, not icon size.
*) Short icon names (like gtk-ok or firefox) also work if the image is in an icon theme or in /usr/share/pixmaps, but if it's in an icon theme --image resizes it, if it's in pixmaps it's displayed full size. ( --window-icon always resizes images icon-size.)

For these reasons we made an icon /usr/share/icons/hicolor/scalable/places/distributor-logo-bunsenlabs.svg and a symlink /usr/share/pixmaps/bunsenlabs-flame.svg pointing to it. Developers can use distributor-logo-bunsenlabs for icon-size or bunsenlabs-flame for full-size. (That's the idea anyway, see below.)

The initial code (from bl-lock):

zenity --info --title="Lock screen info:" --text="Lock screen has detected you are running a live session.\nThe username needed to unlock the screen is \"user\" and the password is \"live\".\nThis notice will only be displayed once per live session."

This was changed (borrowing from Damo's code) to:

yad --image="distributor-logo-bunsenlabs" --center --borders=20 --window-icon=distributor-logo-bunsenlabs --button=gtk-ok --on-top --title='Lock screen info:' --text="Lock screen has detected you are running a live session.\nThe username needed to unlock the screen is \"user\" and the password is \"live\".\nThis notice will only be displayed once per live session." 

First issue: the --image could have been gtk-dialog-info for a match with with the zenity dialogue but I wanted to try our new BL icon distributor-logo-bunsenlabs.
Unfortunately:

Screenshot_070116_ubuntuicon.jpg

Ubuntu!! If the image was renamed to eg distributor-bunsenlabs or pretty much anything else it worked OK. Among all the distributor-logo-something icons there's one called distributor-logo.svg, which is a copy of distributor-logo-ubuntu.svg (and .png), and that was taking precedence over ours! It took quite some time tweaking and googling, but eventually I found this post, and this page. Apparently it's not a bug it's built into GTK and yad just uses it. If an icon with parts-separated-by-dashes isn't found, instead of going down to inherited themes, and ultimately to hicolor as the freedesktop icon specification demands, it just chops off the last part of the name and tries what's left! wtf?

Finally resorted to adding a symlink named 'bunsenlabs.svg' pointing to the real icon, so devs can get a BL icon with --image="bunsenlabs".
Another workaround would be to add the icon to our Faenza-Bunsen icon theme, but if users switched icon theme it would be lost.
Another workaround would be to go back to --image="gtk-dialog-info" of course. 
(btw the --window-icon suffered from none of this weirdness.)

Second issue: there's an old zenity bug where a long text would cause the bottom of the window to go way down, as if it was allowing enough height for the window when squeezed into its minimum width. (eg here) It looked as if yad was inheriting this bug. Actually I cheated with the last screenshot - it should have been like this:
Screenshot_070116_high.jpg
This one took a long time. Eventually I found a post (sorry forgot to keep the link sad ) with a workaround: add

--fixed

to the options.
"--fixed
              Make window fixed width and height."
Whatever that means. Anyway it seems to do the job.

I also tried compiling yad 0.33.0 from Sourceforge. After a single patch (had to add src/html.c to  po/POTFILES.in but I don't know if it had been left out for a good reason...) it compiled, and also seemed to work free of that height bug. If anyone would like to play with it there's an amd64 version here. (Text wrapping seems to be different.)

---------------------------

btw @damo there seems to be a certain amout of evidence that the yad developer was thinking of icon-sized images for --image (like zenity's):
https://groups.google.com/d/msg/yad-com … hhxnAoAQAJ
"pictures sets by --image option have a size of GTK_ICON_SIZE_DIALOG by default it is a 48x48 px"
and
https://code.google.com/p/yad/issues/detail?id=8
"stock images specified in --image use GTK_ICON_SIZE_DIALOG and it's size depends on current gtk theme settings"

Last edited by johnraff (2016-01-07 07:06:12)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#2 2016-01-07 10:50:52

damo
....moderator....
Registered: 2015-08-20
Posts: 5,830

Re: Yad notes

Thanks for your explorations smile

Using `--image="distributor-logo-bunsenlabs"` I get the Debian logo, even though `distributor-logo.svg` is the ubuntu logo! (scrot is "current focus" btw)

yad --image="distributor-logo-bunsenlabs" --center --fixed  --borders=20 --window-icon=distributor-logo-bunsenlabs --button=gtk-ok --on-top --title='Lock screen info:' --text="Lock screen has detected you are running a live session. \
\nThe username needed to unlock the screen is \"user\" and the password is \"live\". \
\nThis notice will only be displayed once per live session." 

0AVkLX8Q.png

Making a symlink, and using `--image="bunsenlabs"` as you describe, works properly:

ln -s /usr/share/icons/hicolor/scalable/places/distributor-logo-bunsenlabs.svg /usr/share/icons/hicolor/scalable/places/bunsenlabs.svg

PpqhpV5l.png


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2016-01-07 15:11:24

hhh
Meep!
Registered: 2015-09-17
Posts: 9,301
Website

Re: Yad notes

^In this dialog example, why is there a background on the flame? Shouldn't that be transparent? And if so, could we have 2 logos corresponding to Bunsen light and Dark themes?

Online

#4 2016-01-07 15:18:35

damo
....moderator....
Registered: 2015-08-20
Posts: 5,830

Re: Yad notes

hhh wrote:

^In this dialog example, why is there a background on the flame? Shouldn't that be transparent? And if so, could we have 2 logos corresponding to Bunsen light and Dark themes?

The reason is that only one logo is needed for any theme. I agree that it would look better if there was a transparent background, which is OK for Bunsen themes which we maintain. It would cause problems with other themes though. We decided that this was the simplest solution for now - maybe it can be improved for a future release wink

A single coloured logo, with alpha,  could work though smile


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#5 2016-01-07 15:45:06

hhh
Meep!
Registered: 2015-09-17
Posts: 9,301
Website

Re: Yad notes

OK, food for thought. Off to work, ciao for now!

Online

#6 2016-01-08 01:46:19

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

damo wrote:

Using `--image="distributor-logo-bunsenlabs"` I get the Debian logo, even though `distributor-logo.svg` is the ubuntu logo!

Weirder still! Is there no other distributor-logo.* higher up the chain somewhere? Is there even a distributor.* with the Debian swirl?? Why can't GTK just follow the freedesktop rules anyway?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#7 2016-01-08 01:50:31

hhh
Meep!
Registered: 2015-09-17
Posts: 9,301
Website

Re: Yad notes

johnraff wrote:

Why can't GTK just follow the freedesktop rules anyway?

#firstworldproblems


monkey

Online

#9 2016-01-11 06:38:07

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

damo wrote:
hhh wrote:

^In this dialog example, why is there a background on the flame? Shouldn't that be transparent? And if so, could we have 2 logos corresponding to Bunsen light and Dark themes?

The reason is that only one logo is needed for any theme. I agree that it would look better if there was a transparent background, which is OK for Bunsen themes which we maintain. It would cause problems with other themes though. We decided that this was the simplest solution for now - maybe it can be improved for a future release wink

A single coloured logo, with alpha,  could work though smile

Agree the current default icon (in /usr/share/icons/hicolor) looks a bit spartan. It's a fallback, in case there's no "distributor-logo-bunsenlabs" in the current icon theme - which there isn't at the moment. We can add such icons to any themes we supply, but if the user switches to a theme with no BL icon (shock!) they'll get the fallback.

If one of our graphics geniuses had the time to make a set of pretty icons, we could anyway put them in the dark and light variants of bunsen-faenza-icon-theme.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#10 2016-01-11 06:43:51

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

Two questions for @damo:

I notice you use both decorated and undecorated dialog windows. I'd like to maintain style consistency with your stuff in my code - what are your criteria for choosing one or the other?

In your scripts you use '--button=OK:0' but '--button=gtk-cancel:1' and the other gtk-things for other buttons. Why not also use '--button=gtk-ok:0' for consistency?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#11 2016-01-11 11:23:04

damo
....moderator....
Registered: 2015-08-20
Posts: 5,830

Re: Yad notes

^ The undecorated ones are for pop-up type boxes for info or input, which will be dismissed quickly. I think a decorated window to ask for an OK? looks very odd. Decorated windows are ones I've judged the user might want to keep around for a while, or move about the desktop.

The `gtk-ok` thing is an aesthetic choice. I personally prefer flat, minimal buttons generally, and with some themes the OK button icon is quite fugly and unecessary imo. I guess there are some inconsistencies in my choices, but they are what they are hmm

I'm not precious about the buttons, so go with what works best. Decorated/undecorated depending on function is more important I think.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#12 2016-01-12 03:06:25

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

^Thanks. Actually I agree about gtk-ok: that tickmark is really overdone. I was just thinking about consistency with the other buttons. The only possible advantage with the gtk-* things might be that they are automatically translated in other locales. I haven't tested that though (it does happen with the gtk.STOCK_CANCEL button in bl-exit), and will stick, like you, with a plain OK for now.

Could you give me an example or two of the kind of window that should be decorated?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#13 2016-01-12 05:18:56

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: Yad notes

I can give you an example the other direction. Let's say you have a file dialog and want to pop up a confirm on file deletion, that would need to be an undecorated window, because it is a child window of another window.

Think of it like this, the dialog I posted in the other thread you started is actually closer to an application than a dialog (it is really just a graphical wrapper around a cli command) but we could consider it an application. Thus, it should look and behave like an application, with window decorations (minimize, close, ability to drag it around etc.) Simple confirmation windows, especially when a child window to an application should usually be undecorated. Also,, in the instance where you would absolutely require input (hard to name one off the top of my head), undecorating the window makes it much tougher to just cancel out of the dialog.

Offline

#14 2016-01-12 12:06:19

damo
....moderator....
Registered: 2015-08-20
Posts: 5,830

Re: Yad notes

Example dialogs:

VjMPxqFW.jpg U6HbJpi9.jpg JNAyNIss.jpg atqEMJhr.jpg wsQ3lhIH.jpg s4HGlJcI.jpg


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#15 2016-01-12 21:12:44

ututo
Member
Registered: 2015-09-29
Posts: 279

Re: Yad notes

I'll leave this here...
distributor_logo_bunsenlabs1_svg_Inkscape_001.jpg

svg files: blue, dark, light, grey

Last edited by ututo (2016-01-12 23:20:14)


BunsenLabs on deviantArt
Don't touch my git!

Offline

#16 2016-01-12 22:26:42

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: Yad notes

Oh those are nice. You keep improving them   big_smile

Offline

#17 2016-01-12 22:38:24

damo
....moderator....
Registered: 2015-08-20
Posts: 5,830

Re: Yad notes

^ He has the touch doesn't he? big_smile

Great work!


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#18 2016-01-15 06:21:28

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

@ututo those are really nice!

@damo thanks - I think I've got it now. Most of my dialogs will be undecorated.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#19 2016-01-15 14:02:43

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,046

Re: Yad notes

ututo wrote:

I'll leave this here...

And of course I took them 'here'  smile
Nice stuff, thank you.


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.

Offline

#20 2016-01-19 08:13:40

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

I was wondering about putting something like this in bunsen-common's bl-include.cfg
It would make it easier to keep some uniformity of style between different scripts' popups and possibly save developers some typing:

yad_common_args=('--window-icon=distributor-logo-bunsenlabs' '--center' '--borders=20')
yad_popup_args=('--undecorated' '--fixed' '--on-top')
yad_question(){
    yad --text="$1" --button=Yes:0 --button=No:1 "${yad_common_args[@]}" "${yad_popup_args[@]}"
    }
yad_info(){
    yad --text="$1" --button=OK "${yad_common_args[@]}" "${yad_popup_args[@]}"
    }
yad_error(){
    yad --text="$1" --button=OK "${yad_common_args[@]}" "${yad_popup_args[@]}" --image=dialog-error
    }

Devs could source bl-include.cfg (it often is anyway) and add something like

yad_common_args+=('--title=Dropbox Installation' '--image=dropbox')

at the top of a particular script before running the functions like

yad_info 'here's my message'

(The --image=... at the end of yad_error overrules what might have already been set in yad_common_args. It feels hacky but seems to work.)

Would something like that be any use?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#21 2016-01-19 08:29:13

damo
....moderator....
Registered: 2015-08-20
Posts: 5,830

Re: Yad notes

^ That looks like an elegant idea. The main issue I see would be that any scripts using it would not be portable without some additional tweaking (ie include the functions within the individual scripts), but it brings a nice consistency to the BL configuration.

It could go in bl-include.cfg now I guess, but do you anticipate the current yad scripts to be converted for this release?


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#22 2016-01-19 09:41:51

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Yad notes

And scripts not using yad can include

unset -v yad-common-args yad-popup-args
unset -f yad_info yad_error

after sourcing bl-include.cfg -- to make it clear they are **not** using yad.

Offline

#23 2016-01-20 07:36:28

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

damo wrote:

The main issue I see would be that any scripts using it would not be portable without some additional tweaking (ie include the functions within the individual scripts)

Of course that applies to any scripts that source bl-include.cfg - but as you say, they could paste in the necessary functions. And of course no-one would be obliged to use that file - it's just a convenience.

It could go in bl-include.cfg now I guess, but do you anticipate the current yad scripts to be converted for this release?

No, no, no way... this is just something I threw out for comments. With RC2 breathing down our necks this isn't the time for any major refactoring, right?

Actually, those three functions are so similar, and simple, I'm wondering if just supplying the default argument arrays might be enough, and letting people modify them at will.

The goal is to make the functions (if used) as simple as possible with the default arguments, but easy to modify.
So, yad_info 'message' should work, but it would be nice to be able to change the default values if you want, eg:
yad_info --image='something_different' --fixed=0 (to remove the --fixed option)
I'm sure it can be done (I'm thinking associative arrays, overwriting the keys) but it would need some playing with to get the code nice and simple.

@xaos52 Good point. Although there's a long list of other functions in that file that a particular script might not actually be using...


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#24 2016-01-20 09:55:26

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,553
Website

Re: Yad notes

I don't know if this would be overkill, but it seems to work. Pass any of the functions yad_question, yad_info or yad_error extra arguments and they'll be added to or overwrite the defaults. --option=0 to remove one. The only thing not done yet (I have to stop now) is to cope with multiple buttons. At present any option passed more than once will erase the previous one, so you can't add new buttons this way. Maybe few people would want to do something like that without writing a new command anyway?

yad_common_args=('--window-icon=distributor-logo-bunsenlabs' '--center' '--borders=20')
yad_popup_args=('--undecorated' '--fixed' '--on-top')
yad_question(){
    declare -A argsetter
    local argsetter=()
    local yadargs=()
    setargs "$@"
    yad  '--button=Yes:0' '--button=No:1' "${yadargs[@]}"
}
yad_info(){
    declare -A argsetter
    local argsetter=()
    local yadargs=()
    setargs "$@"
    yad '--button=OK' "${yadargs[@]}"
}
yad_error(){
    declare -A argsetter
    local argsetter=()
    local yadargs=()
    setargs '--image=dialog-error' "$@"
    yad '--button=OK' "${yadargs[@]}"
}

setargs(){
    local i key value
    for i in "${yad_common_args[@]}" "${yad_popup_args[@]}"
    do
        IFS='=' read key value <<<"$i"
        argsetter[$key]="$value"
    done
    i=key=value=
    for i in "$@"
    do
        IFS='=' read key value <<<"$i"
        [[ $value = 0 ]] && {
            unset "argsetter[$key]"
            continue
        }
        [[ $key = --* ]] || {
            argsetter[--text]="$key"
            continue
        }
        argsetter[$key]="$value"
    done
    i=
    for i in "${!argsetter[@]}"
    do
        if [[ ${argsetter[$i]} ]]
        then
            yadargs+=("$i=${argsetter[$i]}")
        else
            yadargs+=("$i")
        fi
    done
}

...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#25 2016-01-20 13:42:56

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Yad notes

This seems to do the trick.
Included button handling with resetting of buttons implemented.

features:
° You can reset a previously defined button only if you use the 'ID' form of  the button.
   --button=tesxt:ID
   where ID is numeric
° To reset an already defined button with ID 4: append '--button=0:4' to the arguments
° You cannot create a button with text '0', since that is used for resetting a previously set button.

Did some testing, but it is not guaranteed error free.

yad_common_args=('--window-icon=distributor-logo-bunsenlabs' '--center' '--borders=20')
yad_popup_args=('--undecorated' '--fixed' '--on-top')
yad_question(){
    local yadargs=()
    _yad_setargs "$@"
    yad  "${yadargs[@]}"
}
yad_info(){
    local yadargs=()
    _yad_setargs "$@"
    yad '--button=OK' "${yadargs[@]}"
}
yad_error(){
    local yadargs=()
    _yad_setargs '--image=dialog-error' "$@"
    yad '--button=OK' "${yadargs[@]}"
}
# is needle in haystack?
# hasElement needle haystack
#   where haystack is an (non-associative) array
hasElement () {
  local e
  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
  return 1
}
# Internal helper script
_yad_setargs(){
    # Catch direct calls
    case "${FUNCNAME[1]}" in
        yad_question|yad_info|yad_error)
            :;;
        *)
            return 1
            ;;
    esac
    local i key value
    local button_with_id_pattern='^(.*):([0-9]+)$'
    declare -A argsetter
    local argsetter=()
    for i in "${yad_common_args[@]}" "${yad_popup_args[@]}"
    do
        IFS='=' read -r key value <<<"$i"
        [[ "$key" = --button ]] &&
            [[ "$value" =~ $button_with_id_pattern ]] &&
            key=--button"${BASH_REMATCH[2]}"
        argsetter[$key]="$value"
    done
            
    i=key=value=
    for i in "$@"
    do
        IFS='=' read -r key value <<<"$i"
        # Don't accept zero values e.g. --button=
        [[ -z "$value" ]] && continue
        [[ "$key" = --button ]] && 
            [[ "$value" =~ $button_with_id_pattern ]] && {
                key="--button${BASH_REMATCH[2]}"
                value="${BASH_REMATCH[1]}"
            }
        [[ $value = 0 ]] && {
            hasElement "$key" "${!argsetter[@]}" && {
            unset "argsetter[$key]"
            continue
            } || {
                # Don't create a key with value 0 - that is reserved for resetting
                # already defined buttons
                continue
            }
        }
        [[ $key = --* ]] || {
            argsetter[--text]="$key"
            continue
        }
        argsetter[$key]="$value"
    done

    i=
    for i in "${!argsetter[@]}"
    do
        local arg="$i"
        [[ "$arg" =~ ^(--button)([0-9]+)$ ]] && arg="${BASH_REMATCH[1]}"
        if [[ ! -z "${argsetter[$i]}" ]]
        then
            yadargs+=("$arg=${argsetter[$i]}")
        else
            yadargs+=("$arg")
        fi
    done
    return 0
}

Edit:
Example:

yad_question --button=OK:2 --button=NO:3 --arg1=argument1 --arg2=argument2  text1 text2 text3 --button=0:2

Of the text arguments only the last one will survive. Anyhow, yad only keeps the last --text= argument supplied.
Button 2 is canceled out. Only one button remains.

Offline

Board footer

Powered by FluxBB