tk image display problem

Started by frontera000, August 07, 2006, 04:10:33 PM

Previous topic - Next topic

frontera000

hi



i am a novice newlisp hobbyist.


Quoteset myimage [image create photo -file /home/bob/hacks/xyz.gif]



 label .imagedisplayer -image $myimage

 pack .imagedisplayer


when run with wish, this displays image xyz.gif



i tried to do the same in newlisp-tk
Quote
(context 'fiv)

(define (fiv4)

  (tk [text]

      set myimage [image create photo -file /home/bob/hacks/xyz.gif]

       label .imagedisplayer -image $myimage

        pack .imagedisplayer

        [/text]))



(context 'MAIN)



(tk "wm withdraw .")

(fiv:fiv4)




when newlisp-tk is used to run this file it does not work.



any help? thanks.

m i c h a e l

#1
Hi frontera000!



I don't normally use newlisp-tk, but I did some experiments with your code and discovered a few things:



  I can only get the tk function to work if I make the string passed into it one line, like this:


    (tk {set myimage [image create photo -file /data/Desktop/pixel.gif] label .imagedisplayer -image $myimage pack .imagedisplayer}))

  Once this was accepted, it complained about this:



    can't read "myimage": no such variable



Hope this gives you some help in determining what to do next.



m i c h a e l

frontera000

#2
thanks all.



i re-coded it:


Quote
(define (fiv4)

  (set 'myimage (tk " image create photo -file /home/bob/hacks/xyz.gif"))

  (tk (append "label .imagedisplayer -image " myimage))

  (tk " pack .imagedisplayer"))


which helped.



still...


Quote(tk "wm withdraw .")


seemed to hide things.  



when i take it out the image flickered between main newlisp-tk and fiv4 windows.



i will look into doing this without newlisp-tk.  i plan to follow tcltk.lsp example.



thanks again

Lutz

#3
Don't do (tk "wm withdraw .") , it will hide your main window, but the label .imagedisplayer, which holds the picture is part of the main window . (dot).



The following worked for me:



(define (fiv4)
(tk [text]
toplevel .mywin
set myimage [image create photo -file /Users/lutz/Desktop/recursion.gif]
label .mywin.imagedisplayer -image $myimage
pack .mywin.imagedisplayer
[/text]))


it creates a special window mywin for the picture. Now you can do (tk "wm withdraw .") to hide the main window and you could bring it back when the picture window gets closed. Look into Demo.lsp how this is done for the window hosting the demo menu.



Lutz

frontera000

#4
this one works :


Quote
(map set '(myin tcout) (pipe))

(map set '(tcin myout) (pipe))

(process "wish" tcin tcout)



(write-buffer myout

[text]

set myimage [image create photo -file /home/bob/hacks/xyz.gif]

label .imagedisplayer -image $myimage

pack .imagedisplayer

[/text])



(while (read-line myin)

        (eval-string (current-line)))


via newlisp (not newlisp-tk).



however i still need to figure out how to end the program properly.  the eval-string sits and waits for a line at the end, after the window is destroyed.



[/quote]

Lutz

#5
Look for tcltk.lsp in the newlisp-x.x.x/examples directory in the source distribution. It is built similar to yours but has the following statement at the end:


bind . <Destroy> {puts {(exit)}}

this will send an (exit) command to newLISP via the eval-string loop. The program also shows how to handle callbacks from button pushes.



Lutz

frontera000

#6
i was trying to write something that will download and display photos from the flickr for my flat-screen TV at home.

a kind of cross platform screensaver...



here is what i wrote. you will need to fill in the api key you get from flickr.com.



there are probably lots of errors in this code. things like not cleaning up right...



on windows, the newlisp-tk.exe won't work with this due to lack of Img package. i use the activetcl distribution which has this package -- required for JPG support.  do run newlisp-tk using activetcl, you will need to get the source for newlisp-tk.tcl and make it run on windows with wish.exe that comes with activetcl.  the only thing i had to do was to fix the path names for the freewrap/images directory.



on linux, as long as you have tkimg package installed so that "package require Img" works with your wish, everything should run fine.



anyway, enjoy...


Quote




(set 'api "/services/rest")

(set 'apikey "your-own-flickr-api-key-goes-here")

(set 'host "http://flickr.com">http://flickr.com")

(set 'email "")

(set 'password "")



(define (doget method auth params)

  (setq url (append host api "/?api_key=" apikey "&method=" method))

  (if (list? params)

   (setq url (append url "&" (urlencode params))))

  (if (not (nil? auth))

   (setq url (append url "&email=" email "&password=" password)))

  (setq xmldata (get-url url)))





(define (urlencode params)

  (setq urlstring "")

  (dolist (param1 params)

   (if (not (= urlstring ""))

    (setq urlstring (append urlstring "&")))

   (setq urlstring (append urlstring (nth 0 param1) "=" (nth 1 param1)))))



(define (xmlconvert data)

  (xml-type-tags nil nil nil nil)

  (setq sxmldata (xml-parse data (+ 1 2 4 8 16))))

 

(define (getphotos data)

  (if (ref 'photo sxmldata)

   (setq photolist (slice (data (chop (ref 'photo data) 2)) 2 -1))

   (setq photolist '())))



(define (handlephotos sxmldata)

  (dolist (aphoto (getphotos sxmldata))

   (setq pr (first (rest aphoto)))

   (print (format "http://static.flickr.com/%25s/%25s_%25s_o.jpg">http://static.flickr.com/%s/%s_%s_o.jpg" (lookup

      'server pr)

     (lookup 'id pr)

     (lookup 'secret pr)))))



(define (fiv)

  (tk "package require Img")

  (tk "destroy .fivwin")

  (tk "toplevel  .fivwin")

 

  (tk "wm geometry .fivwin [winfo screenwidth .]x[winfo screenheight .]+0+0")

 

  ;; uncomment the following lines to make display "fullscreen"

  ;;(tk "bind .fivwin <Key> {destroy .fivwin}")

  ;;(tk "bind .fivwin <Motion> {destroy .fivwin}")

  ;;(tk "bind .fivwin <Button> {destroy .fivwin}")

  ;;(tk "wm overrideredirect .fivwin yes; focus -force .fivwin")



  (setq picture (tk "image create photo "))

  (tk (append "label .fivwin.picture  -image " picture))

  (tk "pack .fivwin.picture")



  (setq xmldata

            (doget "flickr.interestingness.getList" nil  

             '(("per_page" "10")("page" "1"))))      ;; how many per page , from which page

  (setq sxmldata (xmlconvert xmldata))

 

  (if (ref 'photo sxmldata)

   (setq photolist (slice (sxmldata (chop (ref 'photo sxmldata) 2)) 2 -1))

   (exit))

   

  (dolist (aphoto photolist)

     (if (= "0" (tk "winfo exists .fivwin"))

        (exit))

    (setq photodesc (first (rest aphoto)))

    (setq photourl (format "http://static.flickr.com/%25s/%25s_%25s_o.jpg">http://static.flickr.com/%s/%s_%s_o.jpg"

                            (lookup 'server photodesc)

                            (lookup 'id photodesc)

                            (lookup 'secret photodesc)))

    (tk "update idletasks")



    (setq file (last (parse photourl "/")))

    (write-file file (get-url photourl))

    (tk (append picture " configure -file " file))

(delete-file file))

   

   

)