Posted to tcl by emiliano at Thu Feb 05 03:03:20 GMT 2009view pretty

package require Tk 8.5
catch {package require Img}
package require img::jpeg
#package require tktray
package require http

ttk::setTheme clam

proc getMap {} {
    global config
    set fd [open $config(tmpfile) w]
    fconfigure $fd -encoding binary -translation binary
    set tok [http::geturl $config(url) -channel $fd -binary 1]
    http::cleanup $tok
    close $fd
}

proc setImage {} {
    global config
    $config(image) configure -file $config(tmpfile)
    #after idle [list .c configure -scrollregion [.c bbox all]]
    file delete $config(tmpfile)
}

proc mainLoop { s } {
    after [expr { 1000 * $s }] [info level 0]
    getMap
    setImage
    wm state . normal
}


set config(image) [image create photo]
set config(url) \
http://www.smn.gov.ar/pronos/satelite/CONAE/Latest/smn_local_goes10_imager_LATEST_ctt.jpg
set config(tmpfile) /tmp/[string trim [expr {[clock clicks] % [pid] }]].jpg

wm state . withdrawn
canvas .c -xscrollcommand {.sx set} -yscrollcommand {.sy set} \
    -scrollregion { -50 0 1014 768 }
ttk::scrollbar .sx -command {.c xview} -orient horizontal
ttk::scrollbar .sy -command {.c yview} -orient vertical
grid .c .sy -sticky news
grid .sx -sticky news
grid columnconfigure . 0 -weight 1
grid rowconfigure . 0 -weight 1
.c create image {0 0} -anchor nw -image $config(image)


mainLoop 1800
bind all <p> {puts [winfo width .c]}

=============================================================================
The image showed is 964 pixels width x 768 pixels height.

When the image fit in the canvas width, the vertical scrolling becomes
notoriously sluggish, in my case when the canvas width is 966 (I guess
this value is width of the canvas area + 2 * canvas borderwidth).

When the image doesn't fit in the canvas width, the vertical scrolling
is normal (smooth).

The difference is notorious when dragging the vertical scrollbar thumb

Comments

Posted by emiliano at Thu Feb 05 21:00:38 GMT 2009 [text] [code]

this new code is smaller and shows the same behaviour package require Tk 8.5 package require Tcl 8.5 canvas .c -xscrollcommand {.sx set} -yscrollcommand {.sy set}\ -bg white -borderwidth 0 -highlightthickness 0 ttk::scrollbar .sx -command {.c xview} -orient horizontal ttk::scrollbar .sy -command {.c yview} -orient vertical grid .c .sy -sticky news grid .sx -sticky news grid columnconfigure . 0 -weight 1 grid rowconfigure . 0 -weight 1 set w [expr {int([winfo screenwidth .]*0.85)}] set h [expr {int([winfo screenheight .]*0.85)}] set img [image create photo -width $w -height $h] $img put black -to 0 0 $w $h .c create image {0 0} -image $img -anchor nw .c configure -scrollregion [.c bbox all]