[Tkabber-dev] r1004 - in trunk/tkabber-plugins: . aniemoticons

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Mar 4 15:25:36 MSK 2007


Author: sergei
Date: 2007-03-04 15:25:34 +0300 (Sun, 04 Mar 2007)
New Revision: 1004

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/aniemoticons/anigif.tcl
Log:
	* aniemoticons/anigif.tcl: Code cleanup. Fixed bugs with image names,
	  which contain semicolon.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2007-03-04 11:08:04 UTC (rev 1003)
+++ trunk/tkabber-plugins/ChangeLog	2007-03-04 12:25:34 UTC (rev 1004)
@@ -6,6 +6,9 @@
 	* debug/debug.tcl, spy/spy.tcl: Use new unified search panel
 	  interface.
 
+	* aniemoticons/anigif.tcl: Code cleanup. Fixed bugs with image names,
+	  which contain semicolon.
+
 2006-03-03  Sergei Golovan <sgolovan at nes.ru>
 
 	* aniemoticons/*: Added new external plugin (moved from the main

Modified: trunk/tkabber-plugins/aniemoticons/anigif.tcl
===================================================================
--- trunk/tkabber-plugins/aniemoticons/anigif.tcl	2007-03-04 11:08:04 UTC (rev 1003)
+++ trunk/tkabber-plugins/aniemoticons/anigif.tcl	2007-03-04 12:25:34 UTC (rev 1004)
@@ -41,165 +41,166 @@
 #  0.9: Initial release
 # 
 
-namespace eval anigif {
+namespace eval ::anigif {
     variable image_number 0
+}
 
-    proc anigif2 {img list delay {idx 0}} {
-	if { $idx >= [llength $list]  } {
-	    set idx 0
-	    if { [set ::anigif::img(repeat,$img)] == 0} {
-		# Non-repeating GIF
-		::anigif::stop $img
-		return
-	    }
-	} 
-	set dispflag [lindex [set ::anigif::img(disposal,$img)] $idx]
-	switch -- "$dispflag" {
-	    "000" {
-		# Do nothing
-	    }
-	    "001" {
-		# Do not dispose
-	    }
-	    "100" {
-		# Restore to background
-		[set ::anigif::img(curimage,$img)] blank
-	    }
-	    "101" {
-		# Restore to previous - not supported
-		# As recommended, since this is not supported, it is set to blank
-		#### [set ::anigif::img(curimage,$img)] blank
-	    }
-	    default { puts "no match: $dispflag" }
-	}
-	[set ::anigif::img(curimage,$img)] copy [lindex $list $idx] ;# -subsample 2 2
-	if { [lindex $delay $idx] == 0 } {
+proc ::anigif::anigif2 {img list delay {idx 0}} {
+    if {$idx >= [llength $list]} {
+	set idx 0
+	if {$::anigif::img(repeat,$img) == 0} {
+	    # Non-repeating GIF
 	    ::anigif::stop $img
 	    return
 	}
-	# # #    update
-	set ::anigif::img(asdf,$img) "::anigif::anigif2 $img [list $list]"
-	set ::anigif::img(loop,$img) [after [lindex $delay $idx] "[set ::anigif::img(asdf,$img)] [list $delay] [expr {$idx + 1}]"]
-	set ::anigif::img(idx,$img) [incr idx]
+    } 
+    set dispflag [lindex $::anigif::img(disposal,$img) $idx]
+    switch -- "$dispflag" {
+	"000" {
+	    # Do nothing
+	}
+	"001" {
+	    # Do not dispose
+	}
+	"100" {
+	    # Restore to background
+	    $::anigif::img(curimage,$img) blank
+	}
+	"101" {
+	    # Restore to previous - not supported
+	    # As recommended, since this is not supported, it is set to blank
+	    #### [set ::anigif::img(curimage,$img)] blank
+	}
+	default { puts "no match: $dispflag" }
     }
+    $::anigif::img(curimage,$img) copy [lindex $list $idx] ;# -subsample 2 2
+    if {[lindex $delay $idx] == 0} {
+	::anigif::stop $img
+	return
+    }
+    # # #    update
+    set ::anigif::img(asdf,$img) [list ::anigif::anigif2 $img $list]
+    set ::anigif::img(loop,$img) \
+        [after [lindex $delay $idx] \
+    	   [list eval $::anigif::img(asdf,$img) [list $delay [expr {$idx + 1}]]]]
+    set ::anigif::img(idx,$img) [incr idx]
+}
 
+proc ::anigif::anigif {img fnam {idx 0}} {
+    variable image_number
 
-    proc anigif {img fnam {idx 0}} {
-	variable image_number
+    ::anigif::stop $img
 
-	set n 0
-	set images {}
-	set delay {}
-	set disposal {}
-	#set img anigifimage[incr image_number]
-	#set img [image create photo]
+    set n 0
+    set images {}
+    set delay {}
+    set disposal {}
+    #set img anigifimage[incr image_number]
+    #set img [image create photo]
 
-	image create photo $img
+    image create photo $img
 
-	set fin [open $fnam r]
-	fconfigure $fin -translation binary
-	set data [read $fin [file size $fnam]]
-	close $fin
+    set fin [open $fnam r]
+    fconfigure $fin -translation binary
+    set data [read $fin [file size $fnam]]
+    close $fin
 
-	# Find Loop Record
-	set start [string first "\x21\xFF\x0B" $data]
+    # Find Loop Record
+    set start [string first "\x21\xFF\x0B" $data]
 
-	if {$start < 0} {
-	    set repeat 0
-	} else {
-	    set repeat 1
-	}
+    if {$start < 0} {
+        set repeat 0
+    } else {
+        set repeat 1
+    }
 
-	# Find Control Records
-	set start [string first "\x21\xF9\x04" $data]
-	while {![catch "image create photo xpic$n$img \
-                              -file ${fnam} \
-                              -format \{gif89 -index $n\}"]} {
-	    set stop [string first "\x00" $data [expr {$start + 1}]]
-	    if {$stop < $start} {
-		break
-	    }
-	    set record [string range $data $start $stop]
-	    binary scan $record @4c1 thisdelay
-	    if {[info exists thisdelay]} {
+    # Find Control Records
+    set start [string first "\x21\xF9\x04" $data]
+    while {![catch {image create photo xpic$n$img \
+			  -file $fnam \
+			  -format [list gif89 -index $n]}]} {
+        set stop [string first "\x00" $data [expr {$start + 1}]]
+        if {$stop < $start} {
+	   break
+        }
+        set record [string range $data $start $stop]
+        binary scan $record @4c1 thisdelay
+        if {[info exists thisdelay]} {
+	    # Change to unsigned integer
+	    set thisdelay [expr {$thisdelay & 0xFF}];
 
-		# Change to unsigned integer
-		set thisdelay [expr {$thisdelay & 0xFF}];
+	    binary scan $record @2b3b3b1b1 -> disposalval userinput transflag
 
-		binary scan $record @2b3b3b1b1 -> disposalval userinput transflag
+	    lappend images pic$n$img
+	    image create photo pic$n$img
+	    pic$n$img copy xpic$n$img ;# -zoom 2 2
+	    image delete xpic$n$img
+	    lappend disposal $disposalval
 
-		lappend images pic$n$img
-		image create photo pic$n$img
-		pic$n$img copy xpic$n$img ;# -zoom 2 2
-		image delete xpic$n$img
-		lappend disposal $disposalval
+	    # Convert hundreths to thousandths for after
+	    set thisdelay [expr {$thisdelay * 10}]
 
-		# Convert hundreths to thousandths for after
-		set thisdelay [expr {$thisdelay * 10}]
+	    # If 0, set to fastest (25 ms min to seem to match browser default)
+	    if {$thisdelay == 0} {set thisdelay 40}
 
-		# If 0, set to fastest (25 ms min to seem to match browser default)
-		if {$thisdelay == 0} {set thisdelay 40}
+	    lappend delay $thisdelay
+	    unset thisdelay
 
-		lappend delay $thisdelay
-		unset thisdelay
+	    incr n
+	}
 
-		incr n
-	    }
-
-	    if {($start >= 0) && ($stop >= 0)} {
-		set start [string first "\x21\xF9\x04" $data [expr {$stop + 1}]]
-	    } else {
-		break
-	    }
+	if {($start >= 0) && ($stop >= 0)} {
+	    set start [string first "\x21\xF9\x04" $data [expr {$stop + 1}]]
+	} else {
+	    break
 	}
-	set ::anigif::img(repeat,$img) $repeat
-	set ::anigif::img(delay,$img) $delay
-	set ::anigif::img(disposal,$img) $disposal
-	set ::anigif::img(curimage,$img) $img
-	$img blank
-	$img copy pic0${img} ;# -subsample 2 2
-	#$img configure -image [set ::anigif::img(curimage,$img)]
+    }
+    set ::anigif::img(repeat,$img) $repeat
+    set ::anigif::img(delay,$img) $delay
+    set ::anigif::img(disposal,$img) $disposal
+    set ::anigif::img(curimage,$img) $img
+    $img blank
+    $img copy pic0${img} ;# -subsample 2 2
+    #$img configure -image [set ::anigif::img(curimage,$img)]
 
-	anigif2 $img $images $delay $idx
+    anigif2 $img $images $delay $idx
 
-	return $img
-    }
+    return $img
+}
 
-    proc stop {img} {
-	catch {
-	    after cancel [set ::anigif::img(loop,$img)]
-	}
+proc ::anigif::stop {img} {
+    catch {
+	after cancel $::anigif::img(loop,$img)
     }
+}
 
-    # TODO
-    proc restart {w {idx -1}} {
-	if {$idx == -1} {
-	    if { [lindex ::anigif::img(delay,$w) $idx] < 0 } {
-		set idx 0
-	    } else {
-		set idx [set ::anigif::img(idx,$w)]
-	    }
+# TODO
+proc ::anigif::restart {img {idx -1}} {
+    if {$idx == -1} {
+	if {[lindex $::anigif::img(delay,$img) $idx] < 0} {
+	    set idx 0
+	} else {
+	    set idx $::anigif::img(idx,$img)
 	}
-	catch {
-	    ::anigif::stop $w
-	    eval "[set ::anigif::img(asdf,$w)] [list [set ::anigif::img(delay,$w)]] $idx"
-	}
     }
+    catch {
+	::anigif::stop $img
+	eval $::anigif::img(asdf,$img) [list $::anigif::img(delay,$img) $idx]
+    }
+}
 
-    proc destroy {w} {
-	catch {
-	    ::anigif::stop $w
-	    set wlength [string length $w]
-	    foreach imagename [image names] {
-		if {[regexp {^pic\d+(.*)} $imagename -> tail] && \
-			[string equal $tail $w]} {
-		    image delete $imagename
-		}
+proc ::anigif::destroy {img} {
+    catch {
+	::anigif::stop $img
+	foreach imagename [image names] {
+	    if {[regexp {^pic\d+(.*)} $imagename -> tail] && [string equal $tail $img]} {
+		image delete $imagename
 	    }
-	    image delete $w
-	    array unset ::anigif::img *,$w
 	}
+	image delete $img
+	array unset ::anigif::img *,$img
     }
 }
 
 package provide anigif 2.0
+



More information about the Tkabber-dev mailing list