-----------------------------------------
-- Image Browser
-- this shows any jpg images located in
-- your current directory.
-----------------------------------------
include GtkEngine.e
include std/filesys.e
include std/sequence.e
enum PREV, NEXT
integer index = (2-1)
constant WIDTH = 300, HEIGHT = 300
-- get list of available jpg's;
-- could append gifs, xpm, png, etc if wanted
object files = dir("*.jpg")
if atom(files) then
Error(0,"Sorry",
"No *.jpg files found",
"in this directory",
GTK_BUTTONS_CLOSE)
abort(1)
else
files = vslice(files,D_NAME)
end if
constant n = length(files)
-- create main window;
constant win = create(GtkWindow)
connect(win,"destroy",quit)
set(win,"default size",WIDTH,HEIGHT)
set(win,"title",files[1])
set(win,"position",GTK_WIN_POS_CENTER)
-- create nav buttons;
constant btn1 = create(GtkButton,"gtk-quit")
constant btn2 = create(GtkButton,"gtk-go-back")
constant btn3 = create(GtkButton,"gtk-go-forward")
-- load the first pix;
object img = create(GtkImage,"~/demos/7300.jpg")
object pix = create(GdkPixbuf,"from_file_at_size=>" & files[index],WIDTH,HEIGHT)
set(img,"from pixbuf",pix)
set(btn2,"sensitive",FALSE)
-----------------------------------------
function ShowPix(atom ctl, atom param)
-----------------------------------------
if param = 1 then
index += 1
else
index -= 1
end if
if index < 1 then index = 1 end if
if index > n then index = n end if
-- enable/disable nav buttons as appropriate;
set(btn2,"sensitive",(index!=1))
set(btn3,"sensitive",(index!=n))
-- load the selected photo;
pix = create(GdkPixbuf,"from_file_at_size=>" & files[index],WIDTH,-1)
set(img,"from pixbuf",pix)
-- set window title to show filename;
set(win,"title",files[index])
return 1
end function
constant show_pix = call_back(routine_id("ShowPix"))
constant panel = create(GtkVBox)
add(win,panel)
add(panel,img)
constant btnbox = create(GtkHButtonBox)
set(btnbox,"layout",2)
pack(panel,-btnbox)
connect(btn1,"clicked",quit)
connect(btn2,"clicked",show_pix,0)
connect(btn3,"clicked",show_pix,1)
add(btnbox,{btn1,btn2,btn3})
show_all(win)
main()
--------------------------------------------------------------------------------
-- Copyright 2010 by Irv Mullins All code released under the LGPL
--------------------------------------------------------------------------------