The time now is Sun 22 Apr 2018, 20:24
All times are UTC - 4 |
Page 44 of 85 [1265 Posts] |
Goto page: Previous 1, 2, 3, ..., 42, 43, 44, 45, 46, ..., 83, 84, 85 Next |
Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Sun 15 Jan 2012, 19:42 Post subject:
|
|
It often comes up how to get wget to give you the percent complete (for progress bars), so I grokked it out to work with Xdialog (I am working on some gtk1 stuff right now) - perhaps someone would like to tweak it for gtkdialog?
Code: | download_progress(){
while ([ $# -gt 0 ]) do
wget -v $1 -o /dev/stdout | while read LINE; do
case $LINE in
*%*)LINE=${LINE##*..};echo ${LINE%%%*};;
esac
done |Xdialog --gauge "Download progress ($# files remaining.)
Current file is:
$1" 0 0
shift
done
} |
and here is one for curl:
{export your CURL_PARAMETERS first}
Code: | upload_progress(){
curl --progress-bar $CURL_PARAMETERS 2>&1 \
| tr "\r" "\n"|sed "s,# *,,gm" \
| Xdialog --title "Progress" --gauge "$1 \n transfering ..." 0 0
} |
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
Dougal

Joined: 19 Oct 2005 Posts: 2504 Location: Hell more grotesque than any medieval woodcut
|
Posted: Tue 17 Jan 2012, 14:28 Post subject:
|
|
technosaurus wrote: | It often comes up how to get wget to give you the percent complete (for progress bars), so I grokked it out to work with Xdialog (I am working on some gtk1 stuff right now) - perhaps someone would like to tweak it for gtkdialog? |
Gtkdialog enables you to run a shell inside the progressbar element, so you can just sort the wget output inside it... that's what I did with the dhcpcd progressbars (note that with gtkdialog, when you echo a number, it is used for the percentage, while echoing text changes what's displayed in the progressbar).
_________________ What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 3217
|
Posted: Sat 21 Jan 2012, 04:39 Post subject:
Subject description: Combo-Checklist |
|
Here's one solution to a combo-checklist. I was looking for a simple way to create a useable array for the whole checklist.
Code: |
#!/bin/sh
#Combo-Checklist example
export NUM="5"
function funcChkCreate() {
for ((i=1;i<"$NUM";i++)); do
echo '<checkbox>
<label>NAME '"$i"'</label>
<variable>STAT'"$i"'</variable>
</checkbox>'
done
}
ComboCheck() {
echo
for ((i=1;i<"$NUM";i++)); do
eval echo "NAME ${i}=""\$STAT${i}" >/tmp/out
var[$i]=`cat /tmp/out`
echo "${var[$i]}"
done
}
export -f ComboCheck
export MAIN_DIALOG='
<vbox height="150" scrollable="true">
'"$(funcChkCreate)"'
<hbox>
<button>
<label>ComboCheck</label>
<action>ComboCheck</action>
</button>
<button ok></button>
</hbox>
</vbox>
'
gtkdialog --program=MAIN_DIALOG
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 2420 Location: Germany
|
Posted: Sat 21 Jan 2012, 04:52 Post subject:
|
|
jpeps wrote: | Here's one solution to a combo-checklist. I was looking for a simple way to create a useable array for the whole checklist. |
Hi.
I think it would be more comfortable to have the buttons outside the scrollable section.
Code: |
#!/bin/sh
#Combo-Checklist example
export NUM="15"
function funcChkCreate() {
for ((i=1;i<"$NUM";i++)); do
echo '<checkbox>
<label>NAME '"$i"'</label>
<variable>STAT'"$i"'</variable>
</checkbox>'
done
}
ComboCheck() {
echo
for ((i=1;i<"$NUM";i++)); do
eval echo "NAME ${i}=""\$STAT${i}" >/tmp/out
var[$i]=`cat /tmp/out`
echo "${var[$i]}"
done
}
export -f ComboCheck
export MAIN_DIALOG='
<vbox>
<vbox height="150" scrollable="true">
'"$(funcChkCreate)"'
</vbox>
<vbox>
<hbox>
<button>
<label>ComboCheck</label>
<action>ComboCheck</action>
</button>
<button ok></button>
</hbox>
</vbox>
</vbox>'
gtkdialog --program=MAIN_DIALOG |
Description |
|
Filesize |
10.49 KB |
Viewed |
1139 Time(s) |

|
_________________ LazY Puppy
RSH's DNA
SARA B.
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 3217
|
Posted: Sat 21 Jan 2012, 05:16 Post subject:
|
|
Good idea, RSH. I just incorporated that into gnewpet.
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 2420 Location: Germany
|
Posted: Sat 21 Jan 2012, 05:27 Post subject:
|
|
I did play a little with that script, to understand how it works. Something has made me a little disturbed.
By giving 5 as NUM i always get only 4 arguments back.
I think it is because of
Code: | for ((i=1;i<"$NUM";i++)); do |
This one: i<"$NUM means - smaller as $NUM, but 5 is not smaller as $NUM.
So i-1<"$NUM works well and gives back 5 arguments.
In PASCAL i would write i<=$NUM, but i don't know the correct syntax in bash to use <=$NUM.
I do know:
equals = if a = b - and
unequals = if a != b
How do i write in bash a <= b ?
_________________ LazY Puppy
RSH's DNA
SARA B.
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 3217
|
Posted: Sat 21 Jan 2012, 05:42 Post subject:
|
|
RSH wrote: |
By giving 5 as NUM i always get only 4 arguments back.
|
Typically, you start with i=0. This is just a template, so NUM is irrelevant. In practice, the labels would be names from a list with NUM being the number of lines.
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 1655
|
Posted: Sun 22 Jan 2012, 07:44 Post subject:
How to handle a variable inside 'edit' field? |
|
How to handle a variable inside <edit>'s <default></default> or <input></input> tags?
I wrote simple encryption tool that operates on temporary files, but it should be done on variables, for security reasons.
Anyway, as an example, let's say I have:
Code: | #! /bin/sh
message="Something"
change () {
message="Completely different something"
echo $message # for debugging
}
export -f change
export MAIN='
<vbox>
<edit>
<variable>VAR</variable>
<default>'"$message"'</default>
</edit>
<button>
<action>change</action>
<action>refresh:VAR</action>
<label>Refresh</label>
</button>
</vbox>
'
gtkdialog -p MAIN
echo $message #for debugging also |
...and it doesn't work, 'edit' field isn't refreshed at all.
Also, tried for 256 ways to put a variable between <input></input> tags - unsuccessfully.
The odd thing is that when I press "Refresh" button, the 'message' variable is changed (first 'echo'), but on exit it returns to its previous state (second 'echo').
AFAIK variables in Bash are global by default..?
How can I do it and is it possible at all?
TIA & Greetings!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 4988 Location: Ontario
|
Posted: Mon 23 Jan 2012, 14:50 Post subject:
|
|
I'm working on an improved bacon recorder and
I used a 'refresh' of a variable successfully.
The variable SAVEFOLDER was defined earlier in the script.
Code: |
<hbox>
<text><label>"Save Folder (path)"</label></text>
<entry tooltip-text=" Folder destination for recording ">
<input>cat "$WORKDIR/SAVEFOLDER"</input>
<variable>SAVEFOLDER</variable>
</entry>
<button tooltip-text=" Folder selector ">
<input file>/usr/local/share/icons/folder-open.png</input>
<action>Xdialog --title "Choose Directory to save recording" --stdout --no-buttons --no-cancel --dselect /mnt 32 80 > $WORKDIR/SAVEFOLDER</action>
<action>refresh:SAVEFOLDER</action>
</button>
<button tooltip-text="Path Examples">
<input file stock="gtk-info"></input>
<action>info_dialog</action>
</button>
</hbox>
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 1655
|
Posted: Mon 23 Jan 2012, 16:43 Post subject:
|
|
Hi don570
You're absolutely right and a variable refresh works fine with <text><label> or <entry><input> (and even with <button><label>!),
but for unknown reason it doesn't want to cooperate with <edit><default> and <edit><input>.
I can use only <input file> to be able to refresh it.
On the other hand I'm new to GTKDialog and it may be some stupid mistake in my code,
but on the other hand again, I tried so many combinations and nothing...
I'm totally confused by this...
Thanks anyway
EDIT:
My first example was a bit fuzzy, here's another one where refreshing doesn't work:
Code: | #!/bin/sh
export MAIN='
<vbox>
<edit>
<variable>VAR</variable>
<default>'"`date`"'</default>
</edit>
<button>
<action>refresh:VAR</action>
<label>Refresh</label>
</button>
</vbox>
'
gtkdialog -p MAIN
|
Greetings!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Mon 23 Jan 2012, 21:23 Post subject:
|
|
SFR,
This works -
Code: |
export MAIN='
<vbox>
<entry>
<variable>VAR</variable>
<input>date</input>
</entry>
<button>
<action>refresh:VAR</action>
<label>Refresh</label>
</button>
</vbox>
'
gtkdialog3 -p MAIN |
Generally, only "<variable>VAR</variable>" variables get set on a "refresh:VAR" command. Variables like "$message" are set once and if a "child process" (such as a function) is begun in an attempt to reset a variable, it isn't visible to the parent (original gtkdialog program).
You'll notice that frequently /tmp files are used to hold variables so that they can be referenced in those cases.
Cheers,
s
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 1655
|
Posted: Tue 24 Jan 2012, 06:58 Post subject:
|
|
seaside wrote: | This works -
Code: |
export MAIN='
<vbox>
<entry>
<variable>VAR</variable>
<input>date</input>
</entry>
<button>
<action>refresh:VAR</action>
<label>Refresh</label>
</button>
</vbox>
'
gtkdialog3 -p MAIN |
|
Yes, this works, but after deeper reflection I think that GTKDialog simply doesn't provide this mechanism in <edit> widget.
entry widget definition:
Quote: | Code: | <entry tag_attr="value"...>
<default>text</default>
<variable>varname</variable>
<height>value</height>
<width>value</width>
<input>command</input>
<input file>filename</input>
<sensitive>state</sensitive>
<action>activity</action>...
<action signal="type">activity</action>...
<action type="function">parameter</action>...
<output file>filename</output>
</entry> |
|
There are <input file> AND <input> directives available. All right.
edit widget definition:
Quote: | Code: | <edit tag_attr="value"...>
<default>state</default>
<variable>varname</variable>
<height>value</height>
<width>value</width>
<input file>filename</input>
<sensitive>state</sensitive>
<action signal="type">activity</action>...
<output file>filename</output>
</edit> |
|
There's ONLY <input file> directive...
But nevermind - I can use 'shred' to delete temp files in a secure way.
seaside wrote: | Generally, only "<variable>VAR</variable>" variables get set on a "refresh:VAR" command. Variables like "$message" are set once and if a "child process" (such as a function) is begun in an attempt to reset a variable, it isn't visible to the parent (original gtkdialog program).
You'll notice that frequently /tmp files are used to hold variables so that they can be referenced in those cases. |
Thanks for clarification, I suspected something like that, but wasn't sure how exactly it works.
Thanks again to all of you & Greetings
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6541 Location: Valåmoen, Norway
|
Posted: Wed 01 Feb 2012, 11:03 Post subject:
|
|
I will explain the new event-handling in Pmusic 2.4.0. It is a smarter way to update gui on non-user-actions. User-actions is mouse-clicks and key-entries, and is the common way to interact between user and gui. An example of updating the gui on a non-user-action in Pmusic is the loading of id3-tags for files shown in the file-browser....
When clicking on a directory, the browser field refreshes and shows the content of the new directory. Now, Pmusic continues with a background process to read the id3 information of the files. When finished, the browser field should be updated by the new info. - Without the user to click anywhere.
The solution is to either use a <progressbar> which runs its <action> when reaches 100% or a <timer> which acts at a given interval. Older Pmusic releases used the <progressbar> solution while recent code uses a <timer>. Both solutions has the downside that they uses an amount of cpu power. In a complex gui with several non-user actions this could end up with several cpu-hungry <timers> updating their unique widget(s) of the gui.
Pmusic has used 2 <timers> running constantly to update their defined gui-part. You might think that 1 <timer> would be enough, - it could refresh all wanted widgets - it wouldn't harm if the refreshing didn't change anything. BUT, refreshing has an effect on the focus handling. It simply resets the focus, which means that:
- scrolling in <table> is moved to top.
- what you are about to write in an <entry> is cleared.
- Your selected item in the <tree> is not selected anymore
- ...
The idea of Pmusic 2.4.0 was to update all kinds of trackinfo (meta-tags, lyrics, albumart, discography, ...) when a new track starts playing. This would not be possible with the underlaying event-handling in Pmusic because it would either suck you cpu-power (with several <timers>), or a global refreshing would make it impossible to be a user (because of focus issues). Also, there is a fact that too many refreshing <action> on a <timer> will increase cpu-usage as well.
So the solution has been to add ONE <timer>, which refreshes a small set of <checkboxes> that (if true) refreshes a single or group of widgets.
<checkboxes> can be set true or false by their <input file>, so we can simply 'echo true' to its <input file>. The <timer> runs its <actions> each second, and the <checkbox> will be refreshed by its <input file>. The code could look like this:
Code: | <checkbox visible="false">
<label>a</label>
<variable>UPDATE_GUI</variable>
<input>cat /path/UPDATE_GUI</input>
<action>if true refresh:PLAYLIST</action>
<action>if true refresh:ARTWORK</action>
<action>if true refresh:BUTTON_PLAY</action>
<action>if true echo false > /path/UPDATE_GUI</action>
<action>if true refresh:UPDATE_GUI</action>
</checkbox> |
All actions will run only if value is true. To avoid more than one refreshing we reset <input file> and the <checkbox> value to false. Now it will be silent until next time we 'echo true > inputfile'.
_________________ Stardust resources
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 3217
|
Posted: Wed 01 Feb 2012, 11:54 Post subject:
|
|
Wouldn't it be posible to eliminate the timer altogether? If something like a new track gets played, an input file gets flagged and the checkbox gets refreshed.
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6541 Location: Valåmoen, Norway
|
Posted: Wed 01 Feb 2012, 12:04 Post subject:
|
|
jpeps wrote: | Wouldn't it be posible to eliminate the timer altogether? If something like a new track gets played, an input file gets flagged and the checkbox gets refreshed. | What will make the checkbox reread the inputfile?
_________________ Stardust resources
|
Back to top
|
|
 |
|
Page 44 of 85 [1265 Posts] |
Goto page: Previous 1, 2, 3, ..., 42, 43, 44, 45, 46, ..., 83, 84, 85 Next |
|
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
|