#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"

###############################################################
# Description:  popimage
#               A Tcl/Tk script that displays the image listed  
#               in the relevant ini file for the time listed in
#               that file.
#
#  Derived from a work by Fred Proctor & Will Shackleford
#  Author: 
#  License: GPL Version 2
#
#  Copyright (c) 2005 All rights reserved.
#
#  Last change:
# $Revision: 1.5 $
# $Author: rayhenry $
# $Date: 2006/03/12 15:18:18 $
###############################################################
#  INI variables include
#  [DISPLAY]
#  Introductory graphic
#  INTRO_GRAPHIC = emc2.gif
#  INTRO_TIME = 5
#  If time is set to zero no image is used
###############################################################


if {$argc < 1} {
  puts stderr "syntax: popimage <image file>"
  exit
}

. configure -borderwidth 0 -highlightthickness 0

set img [lindex $argv 0]

set imgtime 5
if {$argc > 1} {
  set imgtime [lindex $argv 1]
}
if {$imgtime <= 0} {
  set imgtime 5
}
# now convert imgtime to milliseconds
set imgtime [expr $imgtime * 1000]

if {! [file exists $img]} {
  puts stderr "can't find file $img"
  exit
}

if {[catch {image create photo image1 -file $img}]} {
  puts stderr "bad image file $img"
  exit
}

label .label -image image1 -borderwidth 0 -highlightthickness 0
pack .label

# Center popup in screen.

set xmax [winfo screenwidth .]
set ymax [winfo screenheight .]
set x [expr ($xmax - [image width image1] )  / 2]
set y [expr ($ymax - [image height image1] )  / 2]
wm geometry . "+$x+$y"
wm overrideredirect . 1

after $imgtime exit
