Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 23 Oct 2018, 00:03
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
YAD - Tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 34 of 35 [516 Posts]   Goto page: Previous 1, 2, 3, ..., 32, 33, 34, 35 Next
Author Message
Mike Walsh


Joined: 28 Jun 2014
Posts: 4260
Location: King's Lynn, UK.

PostPosted: Thu 06 Sep 2018, 10:02    Post subject:  

Hi again, Fred.

Okay; here's 'Mk 2'.






I've used the extra code you supplied to add the 'Full-screen' selector. Have added another 'cmd_function' to permit enabling/disabling of the status-bar in full-screen mode (it appears to be hard-coded in normal viewing mode, and isn't switchable.)

Also added an 'info' button, which brings up a second YAD 'text' window, explaining some of the functions.....and a 'Quit' button, to exit.

Code:
#!/bin/sh
#
# Launcher for the 'Q.I.V Slideshow' © Mike Walsh, Sep 2018 - with thanks to the 'Puppy' crew (and Fredx181 in particular) for assistance
#
export load_cmd='@bash -c "button_cmd %1 %2 %3 %4 %5 %6"'

function button_cmd () {
[ $3 = TRUE ] && FS="-f" || FS=""
[ $4 = FALSE ] && SB="-i" || SB=""
qiv -s $FS $SB -m -t -d $2 $1
}
export -f button_cmd

yad  --center --window-icon=/usr/local/lib/X11/pixmaps/qiv.png --title="Q.I.V Slideshow" --form --width=450 --text="     Please make your selections:-" \
--form --field="Choose image directory:-:MDIR" '/root' \
--field="Select timeout interval:-:NUM" '1' \
--field="Fullscreen:CHK" "TRUE" \
--field="Enable/disable status bar (full-screen only):CHK" "FALSE" \
--field="Run  Q.I.V  slideshow":fbtn "$load_cmd" \
--button="Information":qiv-gui-info.sh --button="Quit":1


I've left the '-m -t' flags in the exec stanza as they are. That way, resizing of images is entirely automatic; IMHO, that's better left as default behaviour.

I think it's fair to say I'm slowly getting the hang of this 'variables' stuff. I'll get there eventually!


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 3485
Location: holland

PostPosted: Thu 06 Sep 2018, 12:44    Post subject:  

Hi Mike, congrats ! it's working well.
Just one thing (but I don't intend to put you on more stress than you possibly are already Smile )
I didn't really notice earlier, but I see you are using the "MDIR" option (multiple directories) for the directory select field.
(EDIT: So I assumed that your intention is to make it work with multiple directories)
However multiple directories is supported by qiv, it doesn't work when trying to select more than one directory.
The following should work with "MDIR" (added DIRS variable), but the directory names cannot contain spaces.
(supporting that should probably be possible also, but needs more complex code)

Code:
#!/bin/sh
#
# Launcher for the 'Q.I.V Slideshow' © Mike Walsh, Sep 2018 - with thanks to the 'Puppy' crew (and Fredx181 in particular) for assistance
#
export load_cmd='@bash -c "button_cmd %1 %2 %3 %4 %5 %6"'

function button_cmd () {
DIRS=$(echo $1 | sed 's|!| |g')
[ $3 = TRUE ] && FS="-f" || FS=""
[ $4 = FALSE ] && SB="-i" || SB=""
qiv -s $FS $SB -m -t -d $2 $DIRS
}
export -f button_cmd

yad --center --window-icon=/usr/local/lib/X11/pixmaps/qiv.png --title="Q.I.V Slideshow" --form --width=450 --text="     Please make your selections:-" \
--field="Choose image directory:-:MDIR" '/root' \
--field="Select timeout interval:-:NUM" '1' \
--field="Fullscreen:CHK" "TRUE" \
--field="Enable/disable status bar (full-screen only):CHK" "FALSE" \
--field="Run  Q.I.V  slideshow":fbtn "$load_cmd" \
--button="Information":qiv-gui-info.sh --button="Quit":1


Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4260
Location: King's Lynn, UK.

PostPosted: Thu 06 Sep 2018, 14:16    Post subject:  

Hi, Fred.

Mm! I've just discovered that about 'no spaces allowed in the directory name'.....literally this last few minutes.

Back in Xenial64 ATM. Couldn't work out why it was giving a problem with the 64-bit version, because this same directory viewed fine in the 32-bit version before I changed the space for an under-slash.....

Heigh-ho; never mind. It's behaving itself now.

(*shrug*)


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 3485
Location: holland

PostPosted: Fri 07 Sep 2018, 09:27    Post subject:  

Hi Mike, I couldn't resist trying to improve Smile
Selecting multiple directories works and directory names may contain spaces now.(oh, and added checkbox: "Recursively include all files")
Code:
#!/bin/bash
#
# Launcher for the 'Q.I.V Slideshow' © Mike Walsh, Sep 2018 - with thanks to the 'Puppy' crew (and Fredx181 in particular) for assistance
# fredx181 20180907, supports now selecting multiple directories and directory names containing spaces
# and added checkbox "Recursively include all files"
#
export load_cmd='@bash -c "button_cmd %1 %2 %3 %4 %5 %6"'

function button_cmd () {
[ $3 = TRUE ] && FS="-f" || FS=""
[ $4 = FALSE ] && SB="-i" || SB=""
[ $5 = TRUE ] && RC="-u" || RC=""
OLDIFS="$IFS"
IFS=$'\n'
qiv -s $FS $SB $RC -m -t -d $2 $(echo -e "$1" | tr '!' '\n')
IFS=$OLDIFS
}
export -f button_cmd

yad --center --window-icon=/usr/local/lib/X11/pixmaps/qiv.png --title="Q.I.V Slideshow" --form --width=450 --text="     Please make your selections:-" \
--field="Choose image directory:-:MDIR" '/root' \
--field="Select timeout interval:-:NUM" '1' \
--field="Fullscreen:CHK" "TRUE" \
--field="Enable/disable status bar (full-screen only):CHK" "FALSE" \
--field="Recursively include all files:CHK" "FALSE" \
--field="Run  Q.I.V  slideshow":fbtn "$load_cmd" \
--button="Information":qiv-gui-info.sh --button="Quit":1


Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4260
Location: King's Lynn, UK.

PostPosted: Sat 08 Sep 2018, 07:18    Post subject:  

Hi, Fred.

Hah! Y'know, this is in danger of turning into 'Fred's Q.I.V slideshow GUI...'... Laughing Laughing

Nah, you do what you like with it, mate. I know you like playing around with code; if, in the long run, this benefits the whole community by trying out new things (which can then be incorporated into other apps, etc.)......I'm all for that.

This was only a one-off 'experiment' on my part, trying things out for myself. You have fun with it.


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
step

Joined: 04 May 2012
Posts: 1093

PostPosted: Sat 08 Sep 2018, 15:10    Post subject:  

MochiMoppel wrote:
step wrote:
I think my original intent was to output all "\n"s as newlines, including the "\n"s that are stored in $MULTILINE, so %b is correct (you were).
%s instead would only expand the "\n"s that separate the variables in printf %s "$MULTILINE\n$TYPELESS\n$FONT\n$COLOUR".
Well, yes, %b is correct but redundant, %s would be wrong, it would not even expand the "\n"s that separate the variables since the whole argument is one big string and it doesn't matter if the "\n"s are in the variables or between them. Just try it. The only difference to echo -e is that there is no final linefeed, making find "some_string" the same as echo -en "some_string". Only if you want to emulate echo -e you would need %b. The whole thing then would have to look like this: printf "%b\n" "some_string_with_escape_codes_in_it" . Confused? I hope not.

In embracing %b I was thinking of some not-so-common, but very possible cases, such as the example below. printf %b seems to be the most portable and error free of the four options.
Code:

# echo -e '%s\n%'
%s
%
# printf '%s\n' '%s\n%'
%s\n%
# printf '%b\n' '%s\n%'
%s
%
# printf '%s\n%'

sh: printf: `%': missing format character
#

_________________
Fatdog64-721|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 872

PostPosted: Tue 11 Sep 2018, 10:05    Post subject: close-on-unfocus Fails On Xtahr  

On xtahr, --close-on-unfocus option fails in the following command. The yad window stays open. The close-on-unfocus option works as expected in StretchDog and Linux Mint (hm, neither of which are puppies).

Code:
#!/bin/sh
yad --scale --min-value 10 --max-value 1000 --value 600 --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --close-on-unfocus --hide-value


i can't test in other puppies atm, as xtahr is my only installed puppy Shocked

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3485
Location: holland

PostPosted: Tue 11 Sep 2018, 12:59    Post subject: Re: close-on-unfocus Fails On Xtahr  

johnywhy wrote:
On xtahr, --close-on-unfocus option fails in the following command. The yad window stays open. The close-on-unfocus option works as expected in StretchDog and Linux Mint (hm, neither of which are puppies).

Code:
#!/bin/sh
yad --scale --min-value 10 --max-value 1000 --value 600 --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --close-on-unfocus --hide-value


i can't test in other puppies atm, as xtahr is my only installed puppy Shocked


Probably the included yad version in xtahr is too old, support for "--close-on-unfocus" is with newer version, e.g. 0.38 or higher.

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4260
Location: King's Lynn, UK.

PostPosted: Tue 11 Sep 2018, 14:52    Post subject:  

@ johnywhy:-

I agree with Fred. A number of new 'options' have been made in the last 2 or 3 releases of YAD, so like as not you want a newer version.

It's extremely easy to compile YAD for yourself. Follow Smokey01's instructions, in the very first edition of the Puppy Newsletter - "Compiling YAD":-

http://smokey01.com/newsletters/2017/January/0001-PuppyLinuxNewsletter-January2017.html#17

This is one item nobody should provide for you here. I honestly believe that every potential , and existing Puppian out there, even if they've never done so before, should at least compile YAD for themselves. It's incredibly easy, and only takes a couple of minutes.

If a complete nincompoop like me can do it, you must be able to..! ;D

EDIT:- Looks like there's something wrong with the version of YAD included in X-Tahr. I've had a copy of X-Tahr 2.0 for a while, so I opened 'er up and had a look at YAD. Instead of getting a version number from

Code:
yad --version


...I got a whole raft of error messages, mostly relating to 'glib_critical' and 'g_type_init'. So it's definitely a new version needed, I think.....and for '--close-on-unfocus', it'll need to be at least v.0.38.0 or later.


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------


Last edited by Mike Walsh on Tue 11 Sep 2018, 16:40; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website 
johnywhy


Joined: 20 Aug 2011
Posts: 872

PostPosted: Tue 11 Sep 2018, 15:09    Post subject:  

happy to compile Very Happy
thx for links

(hopefully, future puppies will bundle the latest version)

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4260
Location: King's Lynn, UK.

PostPosted: Tue 11 Sep 2018, 16:45    Post subject:  

johnywhy wrote:
happy to compile Very Happy
thx for links

(hopefully, future puppies will bundle the latest version)


@ johnywhy:-

Well, I know the two Xenialpups (32- & 64-bit) do both come with new versions. 32-bit Xenial comes with v0.38.0, 64-bit Xenial with v0.40.0. Upup Bionic comes with v0.40.0, too.

(Don't forget, you'll need the X-Tahr 2.0 devx SFS loaded for this.)


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
misko_2083


Joined: 08 Nov 2016
Posts: 55

PostPosted: Wed 12 Sep 2018, 05:38    Post subject: Re: close-on-unfocus Fails On Xtahr  

johnywhy wrote:
On xtahr, --close-on-unfocus option fails in the following command. The yad window stays open. The close-on-unfocus option works as expected in StretchDog and Linux Mint (hm, neither of which are puppies).

i can't test in other puppies atm, as xtahr is my only installed puppy Shocked

The workaround is using xprop to monitor the changes in _NET_ACTIVE_WINDOW of the root window property and exit or kill the yad PID (with SIGUSR1 or SIGUSR2 signal) when that property changes.

From yad manual:
Code:
USER DEFINED SIGNALS
       SIGUSR1
              Close dialog with 0 exit code.

       SIGUSR2
              Close dialog with 1 exit code.


That property contains the XID (X window ID) of the active window and changes when another window gets in focus.

Code:
xprop -spy -root _NET_ACTIVE_WINDOW | read net_active_win ; exit
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4260
Location: King's Lynn, UK.

PostPosted: Wed 12 Sep 2018, 16:01    Post subject:  

Hey, Fred.

Been having a shufti at johnywhy's 'Basic Brightness slider'. Now, I like the idea.....'cept it doesn't work for me.

I have an AMD CPU, not Intel.
I have absolutely nowt showing in '/sys/class/backlight'. The directory exists.....but it's empty.
I'm using an external monitor (it's a desktop).....not a lappie with built-in display.

--------------------------------------------
I've tried out several items that are supposed to do the job. 'Xbacklight'; nope. 'Xgamma'; mmmm....kind of ('cept it's really messing around with the gamma ramp, rather like RedShift does, instead of true brightness adjustment).

Perseverance pays off, it seems. I eventually found summat that would work for my setup.

From here:- https://askubuntu.com/questions/149054/how-to-change-lcd-brightness-from-command-line-or-via-script

Apparently, most modern kernels detect your primary monitor as something like 'LVDS1' (???)

By using the code

Code:
xrandr -q | grep " connected"


...the respondent probably gave a readout of his own monitor, which resulted in

Code:
LVDS1 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 331mm x 207mm


And by substituting the first item into this command:-

Code:
xrandr --output LVDS1 --brightness 0.5


.....it would set the respondent's screen to 50% of its brightness range. As it stood, though, it just kept throwing me errors.....and babbling on about CRT screens! Shocked

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

Running that first command gives me

Code:
# xrandr -q | grep " connected"
VGA-0 connected 1024x768+0+0 (normal left inverted right x axis y axis) 304mm x 228mm


Substiting VGA-0 into that command, like so:-

Code:
xrandr --output VGA-0 --brightness 0.5


.....works beautifully..!!

Min (0) is full 'dark'; max (1.0) is full 'bright'. You can use steps as small as .01, and the difference between them does show up. Now then; I've got a favour to ask.....of you, or anyone else who'd care to give some examples.

So far, I've got a tray icon set-up, and a script for my slider itself. Fairly straight-forward stuff. Tray icon:-

Code:
#!/bin/sh
#
#YAD 'one-liner' from musher0 / fredx181, to place executable tray icon in notification area
#
yad --notification --text="Brightness control" --command='/usr/local/bin/EMBC.sh' --image='/usr/local/lib/X11/pixmaps/Bright.png' 2>/dev/null



....and this is what I have so far for the slider:-


Code:
#!/bin/sh
#
# Slider for adjusting brightness on external monitor
#
yad --undecorated --on-top --geometry=450x70+550+650 --scale --value=75 --print-partial --button="Done":1


I was going to use '--close-on-unfocus', till I found that you've got to have something else 'open' to click on for that to work. Apparently, ROX's 'pinboard' doesn't count as a window as such.....unlike most 'standard' DE's. Johny was doing this in the Dogs; I've no idea what you use in those.

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

So:-

How would I translate a hundred .01-sized 'steps' to 100 percentage points on that slider? Variables, obviously, but, er.....how? (*Pretty please.....with sprinkles on?*) "bats eyelashes"

Any ideas as to the easiest way? Johny's translated the full available 'range' in 'sys/class/backlight, etc.', to the scale.......whereas I want to use 100, fixed-size'steps'. I can't really translate Johny's script to my requirements, 'cos I just don't know how to modify it.

I can grovel with the best of 'em..! Embarassed Rolling Eyes Laughing I really am a 'noob' at this stuff.....but (as my old mum used to say when we were nippers), 'If you never ask.....'


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 3485
Location: holland

PostPosted: Thu 13 Sep 2018, 05:30    Post subject:  

Hi Mike, with the help of johnywhy's script and your xrandr findings, I found that these work for me using xrandr:

The yad slider style from you with the 'Done' button:
Code:
#!/bin/bash

# detect monitor
MON=$(xrandr -q | grep " connected" | cut -f1 -d ' ')
# find current xrandr brightness value
XR=$(xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1)
BrCur=`awk "BEGIN {print $XR*100}"` # calculate, so e.g. 0.5 gets 50
BrMax="100"
BrMin="5"
yad --undecorated --on-top --geometry=450x70+550+650 --scale --value $BrCur --print-partial --min-value $BrMin --max-value $BrMax --button="Done":1 | while read BrNew; do
# division using awk, so xrandr value gets e.g. 0.5 rather than 50
xrandr --output $MON --brightness $(awk "BEGIN {print $BrNew/100}")
done


The yad slider style from johnywhy:
Code:
#!/bin/bash

# detect monitor
MON=$(xrandr -q | grep " connected" | cut -f1 -d ' ')
# find current xrandr brightness value
XR=$(xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1)
BrCur=`awk "BEGIN {print $XR*100}"` # calculate, so e.g. 0.5 gets 50
BrMax="100"
BrMin="5"
yad --scale --min-value $BrMin --max-value $BrMax --value $BrCur --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --hide-value --close-on-unfocus | while read BrNew; do
# division using awk, so xrandr value gets e.g. 0.5 rather than 50
xrandr --output $MON --brightness $(awk "BEGIN {print $BrNew/100}")
done

I used awk for the calculations because the more simple bash calculation (like johnywhy used) didn't work, e.g. doesn't accept 0.1 or 0.7 (bash can operate only on integers)

EDIT: Tip: yad --geometry accepts negative values, so to get it at "bottom-right", you can use e.g.:
Code:
--geometry=450x70-50-50

And it will appear at bottom-right, no matter what resolution you have.

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4260
Location: King's Lynn, UK.

PostPosted: Thu 13 Sep 2018, 09:17    Post subject:  

Hi, Fred.

Well, thank you! (I wasn't expecting a solution straight off the bat, but.....anyway, I gotta learn this stuff, little by little.....)

Question, if I may? Is 'awk' actually a separate language used within Bash? I see from the one of the many man pages on this that it's a

Quote:
"pattern-directed scanning and processing language"


(from here.)

I must confess, it seems a pretty powerful function in its own right. I'm slowly beginning to understand how Bash scripting is able to perform so much, simply by using combinations of various things together like this.....

I see you're using the '*' symbol in the print statement. Am I right in thinking that here it's simply being used as the 'multiplication' symbol, rather than a 'wild card'?

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

Anyway; just tried it out, and.....it works beautifully, Fred. The whole reason I wanted to do this was because I liked the idea of a straight-forward true 'brightness' control; RedShift has one built-in, as you know, but it's actually manipulating the gamma ramp, and (on my monitor at least) I get slightly odd side-effects from it.

I gave Johny's a try, but I rather suspect that /sys/class/backlight is used exclusively by lappies, rather than desktops.....in very much the same way that a lot of the ACPI stuff is used more by laptops than desktops. And I also figured that I can't be the only one who would benefit from this.....I'd like this to be available to the whole community.

Why should laptops have all the fun? Laughing

That being the case, I'm going to have a bit more of a play around with the slider appearance - 'tart it up' a bit more, if you like - and I'll run up a .pet package for it. I'll probably supply a recent version of YAD for it, too, but I'll do so as a separate package this time, rather than building it in. I need to experiment with some of the older Pup's versions of YAD, and see if they'll work with everything I've utilised.

I still think having an up-to-date version of YAD is a good idea for all (very easy to compile, and it's fully backward-compatible, after all).....but it's not a high priority for everyone, I dare say.

BTW - I see why you set 5 as a minimum! That way, if you should happen to take your cursor away from the slider, you can just about see to return it to the correct place again. Although I may just raise that to 10; I don't think anyone wants a completely black screen, do they? And, er.....point taken about the 'negative' geometry values. The values I used put it in the right place for my screen, but it's an old 1024x768 monitor. Most folks have far higher-res monitors these days, so for them it would end up being nearer the middle! (*D'oh..!*)

Gracias, mi amigo!


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 34 of 35 [516 Posts]   Goto page: Previous 1, 2, 3, ..., 32, 33, 34, 35 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1795s ][ Queries: 12 (0.0645s) ][ GZIP on ]