You are not logged in.

#101 2019-01-09 12:33:11

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^ yes thats it, thanks damo.

--button=gtk-cancel:1 \
--button="Killall Conky":kill-conky \

Offline

#102 2019-01-09 13:54:07

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Yad conky chooser v0.2. Bit better looking than the list option. Bunsenlabs conky manager is a work of art, much better control. I wonder is there ability for yad to do what bl conky manager can do?

2019-01-09--1547041697_467x305_scrot.th.png

#!/bin/bash

yad --title="Conky Chooser" --form --center --on-top --width=300 --height=200 --window-icon=utilities-system-monitor --width=250 \
--field="NL-Conky":fbtn 'conky -c "/home/s7/.config/conky/nl.conky.conf"' \
--field="BL-Top Conky":fbtn 'conky -c"/home/s7/.config/conky/BL conkys/BL-Top.conkyrc"' \
--field="Bar-Conky":fbtn 'conky -c "/home/s7/.config/conky/bar.conky.conf"' \
--button="Killall Conky":kill-conky \
--button="Restart Conky":conkyrestart \
--button=gtk-cancel:1

Offline

#103 2019-01-09 19:48:02

damo
....moderator....
Registered: 2015-08-20
Posts: 4,586

Re: The great yad hacking thread

S7.L wrote:

... I wonder is there ability for yad to do what bl conky manager can do?

Well, the BL conky manager uses yad as the graphical interface for the script. Yad needs something behind the scenes to operate anything constructively!


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#104 2019-01-12 15:22:32

misko_2083
Member
Registered: 2016-05-24
Posts: 132

Re: The great yad hacking thread

Too bad there is no a way to detect anything within html dialog.

I haven't used that dialog much just played with some photo loading/preview.

https://i.imgur.com/Pugp1CRm.png
yad --width=800 --height=600 --html --uri=/home/misko/Desktop/test.html

test.html

 <!DOCTYPE html>
<html>
<body>



 <script src="https://code.jquery.com/jquery-2.2.4.min.js" async="async"></script>
    <link rel="stylesheet" media="all" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />

<style>
  .thumb {
    height: 300px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

example 1

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form1" runat="server">
  <input type='file' id="imgInp" />
  <img id="blah" class="thumb" src="#" alt="your image" />
</form>
<script>
function readURL(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#blah').attr('src', e.target.result);
    }

    reader.readAsDataURL(input.files[0]);
  }
}

$("#imgInp").change(function() {
  readURL(this);
});

</script>

<p>example 2</p>



<input type="file" id="files" style="display:none" accept="image/x-png,image/gif,image/jpeg" name="files[]" multiple />
<a href="javascript:;" onclick="getImage()"/>
    <img src="/usr/share/icons/Faenza/actions/32/gtk-open.png"/>
</a>
<output id="list"></output>

<script>
     function getImage(){
       $('#files').click();
     }
</script>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);

</script>
</body>
</html> 

Last edited by misko_2083 (2019-01-12 15:24:36)

Offline

#105 2019-01-13 15:22:08

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Using a bit different config...

yad --width 200 --height 400 --title "CONKY" --form --center --on-top --width=300 --height=200 --window-icon=utilities-system-monitor --width=250 \
    --form \
    --field="Conky Bar:BTN" 'conky -c  "/home/s7/.config/conky/bar.conky.conf"' \
    --field="Conky NL:BTN" 'conky -c  "/home/s7/.config/conky/nl.conky.conf"' \
    --field="Conky BL-Top:BTN" 'conky -c  "/home/s7/.config/conky/BL-Top.conf"' \
    --field="Restart Conky":fbtn "conkyrestart" \
    --field="Kill Conky":fbtn "kill-conky" \

2019-01-14-011841_1366x768_scrot.th.png

I would like to space those cancel and ok buttons better.

^just use this...

--button=gtk-close:1

Last edited by S7.L (2019-01-13 15:33:48)

Offline

#106 2019-01-14 00:02:09

misko_2083
Member
Registered: 2016-05-24
Posts: 132

Re: The great yad hacking thread

^ I gave it a shot with --html and yad v.40

#!/bin/bash

stdbuf -oL -eL yad --title="Conky Chooser" \
                    --width=400 --height=250 \
                    --html --uri="/home/misko/Desktop/test2.html" \
                    --button=gtk-cancel:1 \
                    --print-uri 2>&1 \
| while read -r line; do
     case ${line##*/} in
      gg)
        conky -c  "/home/s7/.config/conky/bar.conky.conf" ;;
      bb)
        conky -c  "/home/s7/.config/conky/nl.conky.conf" ;;
      ee)
        conky -c  "/home/s7/.config/conky/BL-Top.conf" ;;
      restart)
        conkyrestart ;;
      kill)
        kill-conky ;;
      *) echo "unknown command" ;;
     esac
done

And here's "frontend" smile in test2.html
-javascript prevents context menu popup-

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.body {
  background-color: #CECECE;
}

.btn {
  border: 2px solid black;
  background-color: white;
  color: black;
  padding: 14px 28px;
  font-size: 16px;
  cursor: pointer;
}

/* Green */
.bar {
  border-color: #4CAF50;
  color: green;
  text-decoration: none;
}

.bar:hover {
  background-color: #4CAF50;
  color: white;
}

/* Blue */
.bl {
  border-color: #2196F3;
  color: dodgerblue;
  text-decoration: none;
}

.bl:hover {
  background: #2196F3;
  color: white;
  text-decoration: none;
}

/* Orange */
.bltop {
  border-color: #ff9800;
  color: orange;
  text-decoration: none;
}

.bltop:hover {
  background: #ff9800;
  color: white;
  text-decoration: none;
}

/* Red */
.restart{
  border-color: #f44336;
  color: red;
  text-decoration: none;
}

.restart:hover {
  background: #f44336;
  color: white;
}

/* Gray */
.default {
  border-color: #000000;
  color: black;
  text-decoration: none;
}

.default:hover {
  background: #000000;
  color: white;
  text-decoration: none;
}
</style>

<script type="text/javascript">
    if (document.addEventListener) { // IE >= 9; other browsers
        document.addEventListener('contextmenu', function(e) {
            //here you do nothing on right-click
            e.preventDefault();
        }, false);
    } else { // IE < 9
        document.attachEvent('oncontextmenu', function() {
            alert("You've tried to open context menu");
            window.event.returnValue = false;
        });
    }
</script>

</head>
<body class="body">

<div 
 style="-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;" 
 unselectable="on"
 onselectstart="return false;" 
 onmousedown="return false;">
<h1>S7.Conky</h1>

<a href="gg" class="btn bar">Bar</a>
<a href="bb" class="btn bl">BL</a>
<a href="ee" class="btn bltop">BL-Top</a>
<br></br>
<br></br>
<a href="restart" class="btn restart">Restart Conky</a>
<a href="kill" class="btn default">Stop Conky</a>

</div>

</body>
</html>

Scrrenshot
4Uup5ez.gif
Sorry about bad looking buttons, I'm not a web developer. smile

Offline

#107 2019-01-15 11:16:54

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^ Thats very cool misko thankyou, is that something like electron? I wouldnt have a clue how to do that sort of thing, ive dabbled a bit in html and css but not ever puting it together with say a bash script.

Offline

#108 2019-01-16 14:06:20

misko_2083
Member
Registered: 2016-05-24
Posts: 132

Re: The great yad hacking thread

S7.L this is something like Ubuntu Mate Welcome screen. Except with UMW it's used python webkit for front end and in back end it's python. Like having two layers that communicate.
One that is used to interact with user and the other one to do everything else.

With python much more can be done with ease, like creating and modifying the front end.
With Yad's webkit that would probably be hard to do. Though as a simple launcher like "launch and forget" it can be useful.

Offline

#109 2019-02-04 11:52:05

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Im trying to create my own cancel button instead of using the gtk cancel button shipped with yad, i think i have it figured but i dont like the fact this command kills all instances of yad, i just want it to cancel the exit dialog only, so basically kill itself lol. Is that possible? Im using the --no-buttons flag so it doesn't show the cancel or ok buttons.

yad --no-buttons --form --width=250 --center --on-top --undecorated --text-align="center" --text="Exit Artix" \
--field="logout":fbtn "openbox --exit" \
--field="reboot":fbtn "sudo reboot" \
--field="poweroff":fbtn "sudo poweroff" \
--field="lock":fbtn "slock" \
--field="cancel":fbtn "yad-cancel" \

Edit:

Probably not the best solution but it works, find and kill a process in regex.

Found here: https://stackoverflow.com/questions/351 … -and-regex

script is called "yad-cancel" and gets called by last field fbtn in the yad script.

#!/bin/bash

kill $(ps aux | awk '/Exit Artix/ {print $2}')

Edit 2. No need for grep.

Last edited by S7.L (2019-02-04 14:35:15)

Offline

#110 2019-02-04 15:21:59

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Ok so i figured it out in the one script instead of calling another with the use of a function. Very cool smile

#!/bin/bash

yad-cancel() {
	kill $(ps aux | awk '/Exit Artix/ {print $2}')
}

yad --no-buttons --form --width=250 --center --on-top --undecorated --text-align="center" --text="Exit Artix" \
--field="logout":fbtn "openbox --exit" \
--field="reboot":fbtn "sudo reboot" \
--field="poweroff":fbtn "sudo poweroff" \
--field="lock":fbtn "slock" \
yad-cancel --field="cancel":fbtn ""\

Offline

#111 2019-02-04 17:46:27

damo
....moderator....
Registered: 2015-08-20
Posts: 4,586

Re: The great yad hacking thread

Or get the process id when you first start yad, then use that to kill it

yad
yadPID=$!

...

kill $yadPID

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#112 2019-02-05 00:14:49

misko_2083
Member
Registered: 2016-05-24
Posts: 132

Re: The great yad hacking thread

You can use the variable YAD_PID
but first export the function.

#!/usr/bin/env bash

yad-cancel() {
	kill -USR1 $YAD_PID
}
export -f yad-cancel

yad --no-buttons --form --width=250 \
--center --on-top --undecorated --text-align="center" \
--text="Exit Artix" \
--field="logout":fbtn "openbox --exit" \
--field="reboot":fbtn "sudo reboot" \
--field="poweroff":fbtn "sudo poweroff" \
--field="lock":fbtn "slock" \
--field="cancel":fbtn "bash -c yad-cancel"

If you use SIGUSR1 exit is 0
with SIGUSR2 exit is 1.

Offline

#113 2019-02-05 08:16:31

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^^ thanks for that damo and misko, seems my script was way off and stopped working which is weird because it was working yesterday.

I actually tried " Kill -USR1 $YAD_PID" in the functionbut was unsure how to call in the field button, so that helped me understand a bit better misko, thanks.

so export -f

Options
      -f   The names refer to shell functions; 
           otherwise the names refer to shell variables.

and bash -c

      -c        If the -c option is present, then commands are read from the
                 first non-option argument command_string.  If there are
                 arguments after the command_string, the first argument is
                 assigned to $0 and any remaining arguments are assigned to
                 the positional parameters.  The assignment to $0 sets the
                 name of the shell, which is used in warning and error
                 messages.

Offline

#114 2019-02-05 13:25:45

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Back again, i love yad.

I cant take full credit for this as i found it here http://smokey01.com/yad/.

But i modified it to suit, so this is a feh wallpaper picker, unfortunatly it just shows you a list of where you keep your wallpapers and when you double click a directory item in the list it sets the background wallpaper in scale mode eg; --bg-scale.
This could be hacked so much more to be similar to nitrogen i think.

So once you set an image to background feh in its awesomeness created ~/.fehbg script you can autostart from .xinitrc or openbox autostart or where programs you autostart are.

#!/usr/bin/env bash

yad --title="--dclick-action=CMD" --width=700 --height=400 --separator=" " --list --dclick-action="feh --bg-scale" --column=Fehpicker $HOME/Pictures/Walls/*

scrot..

2019-02-05-232531_1366x768_scrot.th.png

Offline

#115 2019-02-05 16:20:15

misko_2083
Member
Registered: 2016-05-24
Posts: 132

Re: The great yad hacking thread

^ very handy

just one thing yad list complains about file names with some special characters.

(yad:8206): Gtk-WARNING **: Failed to set text from markup due to error parsing markup: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp;

It's best to use --no-markup for that reason

yad --title="Feh picker" --width=700 --height=400 --separator=" " --list  --no-markup --dclick-action="feh --bg-scale" --column=Fehpicker $HOME/Pictures/*

Offline

#116 2019-02-06 10:54:57

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^ I didn't get that gtk warning when i run it from the terminal but i will definitely take your word for it and add it in.

Offline

#117 2019-02-06 19:12:11

misko_2083
Member
Registered: 2016-05-24
Posts: 132

Re: The great yad hacking thread

S7.L wrote:

^ I didn't get that gtk warning when i run it from the terminal but i will definitely take your word for it and add it in.

It happens when you have an ampersand '&' in the filename.
You can try:

yad --list --column="1" "&"

Offline

Board footer

Powered by FluxBB