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 20 Oct 2014, 19:18
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to code a jpg viewer that advances with a Next button?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
oldyeller


Joined: 15 Nov 2011
Posts: 812
Location: Mishawaka IN

PostPosted: 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

timeline.png
 Description   
 Filesize   12.24 KB
 Viewed   356 Time(s)

timeline.png


Last edited by oldyeller on Wed 25 Sep 2013, 19:55; edited 1 time in total
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2525
Location: Moved from Hosla to www.eussenheim.de

PostPosted: 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

Question
Back to top
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 812
Location: Mishawaka IN

PostPosted: 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

Question

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
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2525
Location: Moved from Hosla to www.eussenheim.de

PostPosted: 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 Very Happy
Edit the config file $HOME/.config/viewnior/viewnior.conf and play
(I am a viewnior nooby, too Wink )
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
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1077

PostPosted: Wed 25 Sep 2013, 14:40    Post subject:  

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:
#!/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
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 812
Location: Mishawaka IN

PostPosted: 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
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: 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
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 812
Location: Mishawaka IN

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 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.0900s ][ Queries: 12 (0.0089s) ][ GZIP on ]