Author |
Message |
oldyeller

Joined: 15 Nov 2011 Posts: 888 Location: Alaska
|
Posted: Tue 24 Sep 2013, 20:47 Post subject:
How to code a jpg viewer that advances with a Next button? Subject description: Solved |
|
Hello Everyone,
I am trying to put together a image viewer that I can change images with the next button instead of using the menubar to change the images. Any help would be great.
Code: |
#! /bin/bash
#Copyright 2013 GPL
#Bible Time Line - author - oldyeller
if [ "`which gtkdialog4`" ]; then
GTKDIALOG=gtkdialog4
elif [ "`which gtkdialog3`" ]; then
GTKDIALOG=gtkdialog3
else
GTKDIALOG=gtkdialog
fi
WORKDIR="/usr/local/Manna/timeline"
TL_DIR="$WORKDIR/btl"
export MAIN_DIALOG='
<window title="Bible TimeLine viewer" icon-name="Com" skip-taskbar-hint="false">
<vbox>
<menubar>
<menu label="Timeline" use-underline="true">
<menuitem stock-id="gtk-open" label="1">
<action>cat '$TL_DIR'/timeline1.jpg > '$TL_DIR'.jpg</action>
<action>refresh:IMAGE</action>
</menuitem>
<menuitem stock-id="gtk-open" label="2">
<action>cat '$TL_DIR'/timelinetemplete.jpg > '$TL_DIR'.jpg</action>
<action>refresh:IMAGE</action>
</menuitem>
<menuitem stock-id="gtk-open" label="3">
<action>cat '$TL_DIR'/Mannagreen.jpg > '$TL_DIR'.jpg</action>
<action>refresh:IMAGE</action>
</menuitem>
<menuitem stock-id="gtk-open" label="4">
<action>cat '$TL_DIR'/Ocean-Sunset.jpg > '$TL_DIR'.jpg</action>
<action>refresh:IMAGE</action>
</menuitem>
<menuitem stock-id="gtk-open" label="5">
<action>cat '$TL_DIR'/Mannared.jpg > '$TL_DIR'.jpg</action>
<action>refresh:IMAGE</action>
</menuitem>
</menu>
</menubar>
<vbox scrollable="true" width="700" height="500" space-expand="true" space-fill="true">
<pixmap>
<variable>IMAGE</variable>
<input file>'$TL_DIR'.jpg</input>
</pixmap>
</vbox>
<hbox>
<button>
<label>NEXT</label>
<variable>NEXT</variable>
<action>cat '$TL_DIR'/timelinetemplete.jpg > '$TL_DIR'.jpg</action>
<action>refresh:IMAGE</action>
</button>
</hbox>
</vbox>
<action signal="hide">exit:Exit</action>
</window>
'
$GTKDIALOG --center --program=MAIN_DIALOG
|
 |
Description |
|
Filesize |
12.24 KB |
Viewed |
544 Time(s) |

|
Last edited by oldyeller on Wed 25 Sep 2013, 19:55; edited 1 time in total
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3431 Location: www.eussenheim.de/
|
Posted: Wed 25 Sep 2013, 10:20 Post subject:
Re: How do I code this jpg viewer that advances with Subject description: a Next button |
|
oldyeller wrote: | .. change images with the next button ... |
What about simply this: Code: | WORKDIR="/usr/local/Manna/timeline"
TL_DIR="$WORKDIR/btl"
viewnior $TL_DIR
|
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 888 Location: Alaska
|
Posted: Wed 25 Sep 2013, 13:04 Post subject:
Re: How do I code this jpg viewer that advances with Subject description: a Next button |
|
L18L wrote: | oldyeller wrote: | .. change images with the next button ... |
What about simply this: Code: | WORKDIR="/usr/local/Manna/timeline"
TL_DIR="$WORKDIR/btl"
viewnior $TL_DIR
|  |
Thanks L18L, This does work very nice though. Can this also be done with what I have?
Instead of clicking the arrow for the next one can it be set for the slideshow?
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3431 Location: www.eussenheim.de/
|
Posted: Wed 25 Sep 2013, 14:08 Post subject:
Re: How do I code this jpg viewer that advances with Subject description: a Next button |
|
oldyeller wrote: | ...Instead of clicking the arrow for the next one can it be set for the slideshow? |
I do hope so
Edit the config file $HOME/.config/viewnior/viewnior.conf and play
(I am a viewnior nooby, too )
Code: | [prefs]
zoom-mode=0
fit-on-fullscreen=true
show-hidden=false
smooth-images=true
confirm-delete=true
reload-on-save=false
show-toolbar=false
start-maximized=false
slideshow-timeout=5
behavior-wheel=1
behavior-click=0
behavior-modify=0
jpeg-quality=100
png-compression=9 |
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 1655
|
Posted: Wed 25 Sep 2013, 14:40 Post subject:
|
|
I also like Viewnior , but to not leave the original question unanswered, here's an ad hoc example; can do both things at the same time (button + slideshow):
Code: | #!/bin/bash
export PICDIR="/usr/share/backgrounds/"
export MAXPIX=$(find "$PICDIR" -type f | wc -l)
echo 0 > /tmp/pic_index
nextpicplease () {
INDEX=$(</tmp/pic_index)
((INDEX++))
[ $INDEX -gt $MAXPIX ] && INDEX=1
ln -sfT $(find "$PICDIR" -type f | tail -n $INDEX | head -n 1) /tmp/piclink
echo $INDEX > /tmp/pic_index
}
export -f nextpicplease && nextpicplease
export MAIN='
<window resizable="false" width-request="600" height-request="400">
<vbox>
<frame>
<pixmap space-fill="true" space-expand="true">
<variable>PIC</variable>
<width>500</width>
<height>300</height>
<input file>/tmp/piclink</input>
</pixmap>
</frame>
<hbox>
<timer visible="false" interval="5">
<action>nextpicplease</action>
<action>refresh:PIC</action>
</timer>
<button>
<label>Next</label>
<action>nextpicplease</action>
<action>refresh:PIC</action>
</button>
</hbox>
</vbox>
</window>'
[ `which gtkdialog4` ] && GTKDIALOG=gtkdialog4 || GTKDIALOG=gtkdialog
$GTKDIALOG -cp MAIN |
BTW, I just recalled that some time ago I wrote yet another, simple image viewer:
Code: | #!/bin/bash
# =============================================================================
# SGIV (Simple GtkDialog Image Viewer) by SFR'2013
# Displays pics from PIC_DIR with thumbnails in the left pane
# =============================================================================
#PIC_DIR="$1"
PIC_DIR=/usr/share/backgrounds
TEMP_PIC=/tmp/temp_pic_$$
INITIAL_PIC="`ls $PIC_DIR/* | head -1`"
ln -sfT "$INITIAL_PIC" "$TEMP_PIC"
export MAIN='
<window title="Simple Gtkdialog Image Viewer" width-request="800" height-request="600">
<hbox>
<vbox>
<expander space-fill="true" space-expand="true">
<vbox scrollable="true">'
for i in $PIC_DIR/*; do
MAIN=$MAIN'
<button relief="2" image-position="2" width-request="128" height-request="128">
<width>100</width>
<height>100</height>
<label>'`basename "${i%%.*}"`'</label>
<input file>'$i'</input>
<action>ln -sfT "'$i'" '$TEMP_PIC'</action>
<action>refresh:VIEW</action>
<action signal="key-release-event">ln -sfT "'$i'" '$TEMP_PIC'</action>
<action signal="key-release-event">refresh:VIEW</action>
</button>'
done
MAIN=$MAIN'
</vbox>
<label>" "</label>
</expander>
</vbox>
<vbox scrollable="true" space-expand="true" space-fill="true">
<pixmap>
<variable>VIEW</variable>
<input file>'$TEMP_PIC'</input>
</pixmap>
</vbox>
</hbox>
</window>
'
[ `which gtkdialog4` ] && GTKDIALOG=gtkdialog4 || GTKDIALOG=gtkdialog
$GTKDIALOG -cp MAIN
rm -f $TEMP_PIC |
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
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 888 Location: Alaska
|
Posted: Wed 25 Sep 2013, 19:54 Post subject:
|
|
Hi All,
@L18L
Thanks that worked great will keep that in mind for a later use.
@SFR
That is just what I was looking for thank you. All I have to do is just make some minor adjustments and all will be just fine.
Thanks again two them both of you.
Cheers
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Wed 25 Sep 2013, 23:50 Post subject:
|
|
recent gtkdialog (as of http://code.google.com/p/gtkdialog/source/detail?r=451) have an auto-refresh property which you can utilize by having the refresh button cat the next jpeg to current.jpg
Code: | #!/bin/bash
next_jpg(){
set -- $(cat $JVDIR/jpglist)
next=$1
cat $next > $JVDIR/current.jpg
shift
echo $@ $next >$JVDIR/jpglist #update the list
}
export -f next_jpg
export JVDIR=/root/my-documents/tmp
echo /usr/share/backgrounds/*.jpg >jpglist
cat /usr/share/backgrounds/default.jpg > current.jpg
echo '<window><vbox>
<pixmap auto-refresh="true">
<width>640</width><height>480</height>
<input file>'$JVDIR'/current.jpg</input>
</pixmap>
<button>
<input file stock="gtk-go-forward"></input>
<action>next_jpg</action>
</button>
</vbox></window>' |gtkdialog4 -s | ... pretty basic, but you can add from there ... maybe better to use SFRs refresh code because the autorefresh has significant delay
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 888 Location: Alaska
|
Posted: Fri 27 Sep 2013, 13:14 Post subject:
|
|
Hi technosaurus,
It does have just a little lag to it, But does work nice.
Thanks for the information on this, something to remember.
Thanks to all of you for your help with this.
Cheers
|
Back to top
|
|
 |
|