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 Wed 16 Oct 2019, 14:17
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 49 of 50 [742 Posts]   Goto page: Previous 1, 2, 3, ..., 47, 48, 49, 50 Next
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Thu 19 Sep 2019, 07:53    Post subject:  

Code:
export z
Back to top
View user's profile Send private message MSN Messenger 
achim

Joined: 13 Apr 2017
Posts: 47
Location: Germany

PostPosted: Thu 19 Sep 2019, 08:06    Post subject:  

@ Stemsee,

where exactly should I enter the code?
Back to top
View user's profile Send private message 
achim

Joined: 13 Apr 2017
Posts: 47
Location: Germany

PostPosted: Thu 19 Sep 2019, 08:22    Post subject:  

with "export z" I already tested yesterday, unfortunately did not work, strange
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Thu 19 Sep 2019, 08:49    Post subject:  

fredx181 wrote:
Hi achim, probably there are different ways, but what I would do is pipe to a yad --text-info dialog, like this:
Code:
cd $CAMERA/
(
z=0
for f in *.jpg; do name=`echo "${f%.*}"`; echo "Kopiervorgang des Bildes "$f" läuft..."
   rsync -t $CAMERA/"$f" $ZIEL/$DATE/;
   z=$(($z+1)); export z;

echo "Der Kopiervorgang des Bildes"

echo "$f"

echo "wird als laufende Nr. $z durchgeführt..."
echo "$z Bilder kopiert"
done
) | yad --text="Kopiervorgang des Bildes" --width=600 --height 200 --fixed --window-icon="$HOME/.icons/Movies-icon24.png" --text-info --wrap --tail \
--title="Verlaufskontrolle" --text-align=center --no-buttons

because you want the last value assigned to z, not the first. So z gets updated on each iteration of the loop. You could write it to a file in /tmp ((NOTE BENE not '[' but '(( ))'

Code:
z=$((z + 1)); echo "z=$z" >/tmp/z
Back to top
View user's profile Send private message MSN Messenger 
achim

Joined: 13 Apr 2017
Posts: 47
Location: Germany

PostPosted: Thu 19 Sep 2019, 10:52    Post subject:  

Quote:

... You could write it to a file in /tmp ...


I would like to choose this option. Just how do I call the variable later - z=$(/tmp/z) ?
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Thu 19 Sep 2019, 10:58    Post subject:  

Code:
. /tmp/z

this imports the variable and its value into the script/command that calls it.

please note that the file in /tmp could be called anything .... /tmp/MYNAME
Code:
. /tmp/MYNAME
echo "$z"
12
you can check the contents with
Code:
cat /tmp/MYNAME
z=12
Back to top
View user's profile Send private message MSN Messenger 
misko_2083


Joined: 08 Nov 2016
Posts: 87

PostPosted: Thu 19 Sep 2019, 11:16    Post subject:  

stemsee wrote:
out of interest

non pipe version. type on commandline and hit enter to send.

How to make it send as it is being typed without newlines until return is hit??

Code:
while true; do read ound; echo "$ound"; done | yad --text-info --listen --width=200 --height=200


Code:
buffer="";  while true; do IFS='' read -N 1 ound;  [[ "${buffer}" == *$'\n'* ]] && buffer=""; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200


even better with --tail option
Code:
buffer="";  while true; do IFS='' read -N 1 ound; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200 --tail


stemsee wrote:

How to make it send as it is being typed without newlines until return is hit??

^It was hard to decode what the writer wanted to say. Very Happy
Back to top
View user's profile Send private message 
achim

Joined: 13 Apr 2017
Posts: 47
Location: Germany

PostPosted: Thu 19 Sep 2019, 11:48    Post subject:  

Hello stemsee,

now the script works! thanks again
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Sat 21 Sep 2019, 18:32    Post subject:  

misko_2083 wrote:
stemsee wrote:
out of interest

non pipe version. type on commandline and hit enter to send.

How to make it send as it is being typed without newlines until return is hit??

Code:
while true; do read ound; echo "$ound"; done | yad --text-info --listen --width=200 --height=200


Code:
buffer="";  while true; do IFS='' read -N 1 ound;  [[ "${buffer}" == *$'\n'* ]] && buffer=""; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200


even better with --tail option
Code:
buffer="";  while true; do IFS='' read -N 1 ound; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200 --tail


stemsee wrote:

How to make it send as it is being typed without newlines until return is hit??

^It was hard to decode what the writer wanted to say. Very Happy


I see the trick! refresh after each character while remembering all previous typing.

backspace is not possible!?

stemsee
Back to top
View user's profile Send private message MSN Messenger 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Sun 22 Sep 2019, 04:17    Post subject:  

stemsee wrote:
backspace is not possible!?

Try this:
Code:
while true ;do
   IFS='' read -rsN 1 ound
   if [[ $ound == $'\x7f' ]] ;then
      buffer=${buffer%?}
      echo -ne "\b" >&2
   else
      buffer=$buffer$ound
      echo -n "$ound" >&2
   fi
   echo -e "\f"
   echo "$buffer"
done | yad --text-info --width=200 --height=200 --tail
Added: read options -r (to allow direct entry of backslash character) and -s (to prevent ugly terminal output when entering backspace)
Removed: yad option --listen

@misko_2083: Clever approach Laughing
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2483
Location: In The Way

PostPosted: Sun 22 Sep 2019, 08:15    Post subject:  

@MochiMoppel
Amazingly good .... even does away with refresh flickers! .It could have been you who hacked Neo's cli?? Very Happy
Back to top
View user's profile Send private message MSN Messenger 
step

Joined: 04 May 2012
Posts: 1207

PostPosted: Mon 23 Sep 2019, 01:53    Post subject:  

@MochiMoppel, WOW! Thanks.
_________________
Fatdog64-802|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 87

PostPosted: Mon 23 Sep 2019, 07:56    Post subject:  

MochiMoppel wrote:

@misko_2083: Clever approach Laughing


It depends.
A few sentences and it's fine.
More new lines/chars - more refresh glitch.
Milions of characters in a variable and you run out of memory. Exclamation
Though, it's very unlikely that stemsee will use this method to write a book. Laughing
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 87

PostPosted: Mon 23 Sep 2019, 09:08    Post subject:  

Bit off topic:
Wanted to have something siimilar to the MATE desktop shutdown timer, only for the Xfce desktop.
It would run xfce4-session-logout -h after the timeout or a shutdown button click.
Yad does not let me change the text label so... resorted to c and gtk3.

Save next as timer.c
Code:

#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>

/* Shutdown timer */

static      gboolean continue_timer = FALSE;
static      gboolean start_timer = TRUE;
static      int sec_expired = 30;

/* Shutdown command here */
static      gchar      *command[] = { "xfce4-session-logout -h",NULL };
GError     *error = NULL;

static void
_quit_cb (GtkWidget *button, gpointer data)
{
    (void)button; (void)data; /* Avoid compiler warnings */
    gtk_main_quit();
    return;
}

static void
shutdown (GtkWidget *button, gpointer data)
{
    (void)button; (void)data; /* Avoid compiler warnings */
    g_spawn_command_line_async(*command, &error);
    if (error != NULL) {
        g_warning("unable to launch: %s", error->message);
        }
    gtk_main_quit();
}

static gboolean
_label_update(gpointer data)
{
    GtkLabel *label = (GtkLabel*)data;
    char buf[256];
    memset(&buf, 0x0, 256);
    snprintf(buf, 255, "Turning off computer in  %d seconds.", --sec_expired);
    if (sec_expired == 0)
        {
        g_spawn_command_line_async(*command, &error);
        if (error != NULL) {
            g_warning("unable to launch: %s", error->message);
            }
        gtk_main_quit();
        }
    gtk_label_set_label(label, buf);
    return continue_timer;
}


int main(void)
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *boxl;
    GtkWidget *shutdown_button;
    GtkWidget *cancel_button;
    GtkWidget *label;
    GtkWidget *question;

    gtk_init(NULL, NULL);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(window, 250, 120);
    gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
    gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
    gtk_window_stick (GTK_WINDOW (window));
    gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE);
    gtk_window_set_title (GTK_WINDOW (window), "Shutdown");
    g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit),
                    NULL);
    box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
    boxl = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);

    gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
    gtk_container_add(GTK_CONTAINER(window),boxl);

    question = gtk_label_new("\nAre you sure you want to shutdown?");
    label = gtk_label_new("Turning off computer in  30 seconds.");

    shutdown_button = gtk_button_new_with_label("Shutdown");
    g_signal_connect(G_OBJECT(shutdown_button), "clicked", G_CALLBACK(shutdown), shutdown_button);

    cancel_button = gtk_button_new_with_label("Cancel");
    g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(_quit_cb), NULL);

    gtk_box_pack_start (GTK_BOX(boxl), question, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX(boxl), label, TRUE, TRUE, 0);

    gtk_box_pack_start (GTK_BOX (box), cancel_button, TRUE, TRUE, 10);
    gtk_box_pack_start (GTK_BOX(box), shutdown_button, TRUE, TRUE, 10);
    gtk_box_pack_start (GTK_BOX(boxl), box, TRUE, TRUE, 10);

    gtk_widget_show_all(window);

    g_timeout_add_seconds(1, _label_update, label);
    continue_timer = TRUE;
    start_timer = TRUE;

    gtk_main();
    return 0;
}


Deps: on debian, install libgtk-3-dev
and compile with:
Code:
gcc  -o timer -fPIC timer.c `pkg-config --cflags --libs gtk+-3.0`

Then run the binary ./timer


Far, far away off the topic and common sense Smile
over the seven mountains, seven rivers and seven seas, guarded by seven giants and seven dragons...
there is a sleeping fox in a wallpaper trapped.
https://www.deviantart.com/misko-2083/art/Resting-Fox-3840x2160-759980131
https://www.deviantart.com/misko-2083/art/Sleepy-Fox-Beach-4k-Misko-2083-802523362
Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License.
For the full resolution there is a download button in the deviant arts page.
Back to top
View user's profile Send private message 
rufwoof


Joined: 24 Feb 2014
Posts: 3541

PostPosted: Mon 23 Sep 2019, 16:49    Post subject:  

This will do the same using yad, with the button labels you prefer. Just modify the SHUTDOWNCOMMAND to actually run your shutdown command instead of running geany
Code:
#!/bin/bash

SHUTDOWNCOMMAND=geany

(  echo "99" ; sleep 1
   echo "90" ; sleep 1
   echo "80" ; sleep 1
   echo "70" ; sleep 1
   echo "60" ; sleep 1
   echo "50" ; sleep 1
   echo "40" ; sleep 1
   echo "30" ; sleep 1
   echo "20" ; sleep 1
   echo "10" ; sleep 1 ) |
  yad --progress --title="$TITLE $VERSION" --text=" Are you sure you want to shutdown? \n\n Turning off computer in 10 seconds \n\n Press Cancel to abort shutdown " \
  --percentage=0 --auto-close --auto-kill --button=CANCEL:1 --button=SHUTDOWN:0
[[ $? -eq 0 ]] && $SHUTDOWNCOMMAND

_________________
( ͡° ͜ʖ ͡°) :wq
Fatdog multi-session usb

echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 49 of 50 [742 Posts]   Goto page: Previous 1, 2, 3, ..., 47, 48, 49, 50 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.3792s ][ Queries: 12 (0.1983s) ][ GZIP on ]