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 Mon 18 Dec 2017, 18:44
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GTKDialog: Refresh progressbar
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
johnmcenroy

Joined: 26 May 2017
Posts: 2

PostPosted: Fri 26 May 2017, 13:22    Post subject:  GTKDialog: Refresh progressbar  

Hello
Similar part of this code is in my little utility. How can progressbar be
updated when using function format32 ?
Thanks.
Code:

function format32 ()
 {
  mkfs.vfat -F32 -n USB -v /dev/sdb1
 }


MAIN_DIALOG='
<window title="ISO2USB" icon-name="gtk3-demo" resizable="false" decorated="true" width-request="500" height-request="750">
<vbox>
<hbox height-request="100">                       
  <frame>
   <progressbar>
    <label>Writing ...</label>
    <input> </input>
   </progressbar>
  </frame>
 </hbox>
</vbox
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 19

PostPosted: Sat 27 May 2017, 02:08    Post subject: Re: GTKDialog: Refresh progressbar  

johnmcenroy wrote:
Hello
Similar part of this code is in my little utility. How can progressbar be
updated when using function format32 ?
Thanks.
Code:

function format32 ()
 {
  mkfs.vfat -F32 -n USB -v /dev/sdb1
 }


MAIN_DIALOG='
<window title="ISO2USB" icon-name="gtk3-demo" resizable="false" decorated="true" width-request="500" height-request="750">
<vbox>
<hbox height-request="100">                       
  <frame>
   <progressbar>
    <label>Writing ...</label>
    <input> </input>
   </progressbar>
  </frame>
 </hbox>
</vbox


Probably like next.
It's pretty much accurate, not 100% but very close.
Code:
#!/bin/bash

usb_w()
{
strace -q -ewrite mkfs.vfat -F32 -n USB /dev/sdb1 2>&1 | awk '{
        count += $NF
            if (count % 10 == 0) {
               percent = count / total_size * 100
               printf "%3d\n", percent
               printf "Formating... "
               printf "%3d%%\n", percent
            }
         }
         END { print "" }' total_size=$(fdisk -l /dev/sdb1 | awk '/Disk.*sectors/{print $7}') count=0
echo done
}
export -f usb_w

export MAIN_DIALOG='
<vbox>
  <frame Progress>
    <text>
      <label>Formating /dev/sdb1</label>
    </text>
    <progressbar>
      <label>Formating sdb1</label>
      <input>/bin/bash -c usb_w</input>
      <action type="exit">Ready</action>
    </progressbar>
  </frame>
  <hbox>
   <button cancel></button>
  </hbox>
 </vbox>
'

gtkdialog --program=MAIN_DIALOG

Be carefull with what you are formating!
I wiped the the wrong partition with dd once. Sad
Back to top
View user's profile Send private message 
johnmcenroy

Joined: 26 May 2017
Posts: 2

PostPosted: Sat 27 May 2017, 02:53    Post subject:  

Thank you very much misko_2083. And can progressbar be updated by pushing button to activate function usb__w() ?
Button > usb_w > progressbar. Thanks.

Quote:
#!/bin/bash

usb_w()
{
strace -q -ewrite mkfs.vfat -F32 -n USB /dev/sdb1 2>&1 | awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d\n", percent
printf "Formating... "
printf "%3d%%\n", percent
}
}
END { print "" }' total_size=$(fdisk -l /dev/sdb1 | awk '/Disk.*sectors/{print $7}') count=0
echo done
}
export -f usb_w

export MAIN_DIALOG='
<vbox>
<frame Progress>
<text>
<label>Formating /dev/sdb1</label>
</text>
<progressbar>
<label>Formating sdb1</label>
<input>???</input>
<action type="exit">Ready</action>
</progressbar>
<button>
<label>Update Progressbar (usb_w)</label>
<action>usb_w</action>
</button>

</frame>
<hbox>
<button cancel></button>
</hbox>
</vbox>
'

gtkdialog --program=MAIN_DIALOG
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 19

PostPosted: Mon 29 May 2017, 20:06    Post subject:  

johnmcenroy wrote:
Thank you very much misko_2083. And can progressbar be updated by pushing button to activate function usb__w() ?
Button > usb_w > progressbar. Thanks.


Yes
Code:
#!/bin/bash

export temp_file="$(mktemp -u --tmpdir formatusb.XXXXXXXX)"
mkfifo "$temp_file"

trap "rm -f $temp_file" EXIT

umount /dev/sdb1

function format32()
{
strace -q -ewrite mkfs.vfat -F32 -n USB -v /dev/sdb1 2>&1 | awk '{
        count += $NF
            if (count % 10 == 0) {
               percent = count / total_size * 100
               printf "%3d\n", percent
               printf "%s %3d%%\n", msg, percent
            }
         }
         END { print "" }' total_size=$(fdisk -l /dev/sdb1 | awk '/Disk.*sectors/{print $7}') count=0 msg="Formating..." \
        | grep -v "^$" # skip empty lines

if [[ "${PIPESTATUS[0]}" -ne 0 ]]
 then   
   echo Error
 else
    echo 100
    echo Done
fi
}
export -f format32

export MAIN_DIALOG='
<vbox>
   <frame Progress>
      <text>
          <label>Formating /dev/sdb1</label>
      </text>
      <progressbar>
         <label>Ready</label>
         <input>bash -c "tail -f -n +1 $temp_file 2>/dev/null" &</input>
         <action type="refresh">Ready</action>
      </progressbar>
      <button>
          <label>Format /dev/sdb1</label>
          <action>bash -c "format32 2>&1 > $temp_file" &</action>
      </button>
   </frame>
<hbox>
   <button ok></button>
</hbox>
</vbox>
'

3<>$temp_file

gtkdialog --program=MAIN_DIALOG

exec 3>&-
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
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.0380s ][ Queries: 14 (0.0051s) ][ GZIP on ]