How to code a jpg viewer that advances with a Next button?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

How to code a jpg viewer that advances with a Next button?

#1 Post by oldyeller »

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: Select all

#! /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

Attachments
timeline.png
(12.24 KiB) Downloaded 563 times
Last edited by oldyeller on Wed 25 Sep 2013, 23:55, edited 1 time in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: How do I code this jpg viewer that advances with

#2 Post by L18L »

oldyeller wrote:.. change images with the next button ...
What about simply this:

Code: Select all

WORKDIR="/usr/local/Manna/timeline"
TL_DIR="$WORKDIR/btl"

viewnior $TL_DIR

:?:

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

Re: How do I code this jpg viewer that advances with

#3 Post by oldyeller »

L18L wrote:
oldyeller wrote:.. change images with the next button ...
What about simply this:

Code: Select all

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?

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: How do I code this jpg viewer that advances with

#4 Post by L18L »

oldyeller wrote:...Instead of clicking the arrow for the next one can it be set for the slideshow?
I do hope so :D
Edit the config file $HOME/.config/viewnior/viewnior.conf and play
(I am a viewnior nooby, too :wink: )

Code: Select all

[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

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#5 Post by SFR »

I also like Viewnior :wink: , 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: Select all

#!/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: Select all

#!/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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#6 Post by oldyeller »

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

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#7 Post by technosaurus »

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: Select all

#!/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 [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#8 Post by oldyeller »

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

Post Reply