[Tkabber-dev] r395 - in trunk/plugins/vimage: . msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Sep 21 02:45:33 MSD 2010


Author: Rejjin
Date: 2010-09-21 02:45:33 +0400 (Tue, 21 Sep 2010)
New Revision: 395

Removed:
   trunk/plugins/vimage/libary/
Modified:
   trunk/plugins/vimage/msgs/ru.msg
   trunk/plugins/vimage/vimage.tcl
Log:
1) Fixed zoom bugs. 
2) Added a progress indicator. 
3) Added comments in code. 
4) Remove excess library "base64"

Modified: trunk/plugins/vimage/msgs/ru.msg
===================================================================
--- trunk/plugins/vimage/msgs/ru.msg	2010-09-20 21:14:26 UTC (rev 394)
+++ trunk/plugins/vimage/msgs/ru.msg	2010-09-20 22:45:33 UTC (rev 395)
@@ -15,4 +15,6 @@
 ::msgcat::mcset ru "Activate Tkabber window, if the picture downloaded." "Активировать окно Tkabber, если картинка загрузилась."
 ::msgcat::mcset ru "Use topmost window." "Отображать поверх всех окон."
 ::msgcat::mcset ru "Use toolwindow style." "Использовать новый стиль отображения окна."
-::msgcat::mcset ru "Maximum size of content (kb)." "Максимальный размер контента (кб)."
\ No newline at end of file
+::msgcat::mcset ru "Maximum size of content (kb)." "Максимальный размер контента (кб)."
+::msgcat::mcset ru "Adds a indicator bar downloading image." "Добавляет индикатор процесса загрузки изображения. "
+::msgcat::mcset ru "Zoom normal" "Нормальный размер"
\ No newline at end of file

Modified: trunk/plugins/vimage/vimage.tcl
===================================================================
--- trunk/plugins/vimage/vimage.tcl	2010-09-20 21:14:26 UTC (rev 394)
+++ trunk/plugins/vimage/vimage.tcl	2010-09-20 22:45:33 UTC (rev 395)
@@ -4,13 +4,11 @@
 
 	package require http
 	package require msgcat
+	package require base64
 	
 	set script_dir [file dirname [info script]]
 	::msgcat::mcload [file join $script_dir msgs]
 	
-	lappend ::auto_path [file join $script_dir libary]
-	package require base64
-	
 #	+++	( Get a supported image extensions )	
 	set extensions {gif|pixmap}
 	if { [catch { package require Img } ] == 0 } {
@@ -35,23 +33,24 @@
               -unloadcommand [namespace code unload]
 		return
     }
+	
+	hook::add finload_hook [namespace current]::create_custom_options
 }
 
+#################################################
+######################## load / unload plugin
 proc vimage::load {} {
-	hook::add draw_message_hook \
-			[namespace current]::draw_message 50
-	hook::add chat_win_popup_menu_hook \
-			[namespace current]::add_view_button 1
+	hook::add draw_message_hook [namespace current]::draw_message 50
+	hook::add chat_win_popup_menu_hook [namespace current]::add_view_button 1
 }
 
 proc vimage::unload {} {
-	hook::remove draw_message_hook \
-			[namespace current]::draw_message 50
-	hook::remove chat_win_popup_menu_hook \
-			[namespace current]::add_view_button 1
+	hook::remove draw_message_hook [namespace current]::draw_message 50
+	hook::remove chat_win_popup_menu_hook [namespace current]::add_view_button 1
 }
 
 #################################################
+######################## image process handle
 
 proc vimage::draw_message { chatid from type body extras } {
 	variable options
@@ -74,11 +73,15 @@
 	}
 }
 
-
-proc vimage::image_process { url chatwin } {
+proc vimage::image_process { url chatwin { type {} } } {
 	variable images
 	variable options
 	
+	if { $type eq "reload" } {
+		array unset images $url,*
+		image_process $url $chatwin
+	}
+	
 	if { ![info exist images($url,data)] } {
 		image_get $url $chatwin
 	} 
@@ -86,15 +89,19 @@
 	image_create $chatwin $url
 }
 
-
-proc vimage::image_reload { url chatwin } {
-	variable images
+proc vimage::image_comp_process { url chatwin } {
+	variable options
 	
-	array unset images $url,*
-	image_process $url $chatwin
+	set options_max_size_old $options(max_size)
+	set options(max_size) 2000
+	
+	image_process $url $chatwin reload
+	
+	set options(max_size) $options_max_size_old
 }
+#################################################
+######################## http_get content
 
-
 proc vimage::image_get { url chatwin } {
 	variable images
 	
@@ -114,6 +121,7 @@
 	variable images
 	
 	set images($url,data) [http::data $token]
+	del_progressbar
 	http::cleanup $token
 	change_state_url $url $chatwin end
 }
@@ -123,15 +131,19 @@
 	variable options
 	variable images
 	
-	puts $current
+	progressbar [namespace current]::progress $total
+	set [namespace current]::progress $current
 	
 	set max_size [expr {$options(max_size)*1024}]
 	if { $current > $max_size || $total > $max_size} {
 		set images($url,full) LARGE
+		del_progressbar
 		http::reset $token
 	}
 }
 
+#################################################
+######################## image work
 
 proc vimage::image_create { chatwin url } {
 	variable images
@@ -152,7 +164,31 @@
 	}
 }
 
+proc vimage::image_scale { im xfactor { yfactor 0 } } {
+	set mode -subsample
+	if { abs($xfactor) < 1 } {
+		set xfactor [expr { round(1./$xfactor) }]
+	} elseif { $xfactor >= 0 && $yfactor >= 0 } {
+		set mode -zoom
+	}
+	
+	if { $yfactor == 0 } {
+		set yfactor $xfactor
+	}
+	
+	set dest [image create photo]
+	$dest copy $im -shrink $mode $xfactor $yfactor
+	.fullshow.image configure -image $dest
+}
 
+proc vimage::image_scale_normal { url } {
+	variable images
+	.fullshow.image configure -image $images($url,full)
+}
+
+#################################################
+######################## process urls
+
 proc vimage::change_state_url { url chatwin type } {
 	variable options
 	
@@ -176,25 +212,9 @@
 	}
 }
 
+#################################################
+######################## view image
 
-proc vimage::image_scale { im xfactor { yfactor 0 } } {
-	set mode -subsample
-	if { abs($xfactor) < 1 } {
-		set xfactor [expr { round(1./$xfactor) }]
-	} elseif { $xfactor >= 0 && $yfactor >= 0 } {
-		set mode -zoom
-	}
-	
-	if { $yfactor == 0 } {
-		set yfactor $xfactor
-	}
-	
-	set dest [image create photo]
-	$dest copy $im -shrink $mode $xfactor $yfactor
-	.fullshow.image configure -image $dest
-}
-
-
 proc vimage::image_full_show { w url } {
 	variable images
 	variable options
@@ -230,6 +250,8 @@
 	bind .fullshow <3> [list [namespace current]::popup_menu %X %Y $images($url,full) $url]
 }
 
+#################################################
+######################## popup menu
 
 proc vimage::add_view_button { m chatwin X Y x y } {
 	variable options
@@ -263,7 +285,7 @@
 	
 	$m add command \
 		-label [::msgcat::mc "Reload"] \
-		-command [list [namespace current]::image_reload $url $chatwin] \
+		-command [list [namespace current]::image_process $url $chatwin reload] \
 		-state $ist
 	
 	$m add command \
@@ -275,18 +297,6 @@
 }
 
 
-proc vimage::image_comp_process { url chatwin } {
-	variable options
-	
-	set options_max_size_old $options(max_size)
-	set options(max_size) 2000
-	
-	image_reload $url $chatwin
-	
-	set options(max_size) $options_max_size_old
-}
-
-
 proc vimage::popup_menu { X Y img url } {
 
     set m .fs_popup
@@ -306,12 +316,16 @@
 		-menu [menu $m.zoom -tearoff 0]	
 	$m.zoom add command -label [::msgcat::mc "Zoom in"] \
 		-command [list [namespace current]::image_scale $img 2]
+	$m.zoom add command -label [::msgcat::mc "Zoom normal"] \
+		-command [list [namespace current]::image_scale_normal $url]
 	$m.zoom add command -label [::msgcat::mc "Zoom out"] \
 		-command [list [namespace current]::image_scale $img 0.5]
     
     tk_popup $m $X $Y
 }
 
+#################################################
+######################## menu tools
 
 proc vimage::image_save { url } {
 	variable options
@@ -336,16 +350,61 @@
 	close $fileid
 }
 
+#################################################
+######################## progressbar
 
+proc vimage::progressbar { varname {max 0} } {
+	variable options
+	
+	set win .mainframe.status.prgf
+	
+	if {!$options(use_progressbar)} {
+		return
+	}
+	
+	if {![winfo exist $win] || [winfo exist $win.prb]} {
+		return
+	}
+	
+	ProgressBar $win.prb \
+		-type nonincremental_infinite \
+		-variable $varname \
+		-foreground yellow \
+		-relief groove
+		
+	if {$max != 0} {
+		$win.prb configure \
+			-maximum $max \
+			-type normal
+	}
+	
+	pack $win.prb -padx 2
+}
+
+proc vimage::del_progressbar { } {
+	catch { destroy .mainframe.status.prgf.prb }
+}
+
+#################################################
+######################## utils
+
 proc vimage::option_exist option {
 	return [expr {[lsearch -exact [wm attributes .] -$option] >= 0}]
 }
 
-namespace eval vimage {
-	variable options 
+#################################################
+######################## custom options init
+
+proc vimage::create_custom_options { } {
+	variable options
 	
-	custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber	
-    custom::defgroup Vimage [::msgcat::mc "Vimage options"] -group Plugins	
+	custom::defgroup Plugins \
+	[::msgcat::mc "Plugins options."] \
+	-group Tkabber	
+	
+    custom::defgroup Vimage \
+	[::msgcat::mc "Vimage options"] \
+	-group Plugins	
 		
 	custom::defvar options(active_is_message) 1 \
 	[::msgcat::mc "Download image when a draw new message."] \
@@ -362,6 +421,10 @@
 	custom::defvar options(activate_tkabber) 1 \
 	[::msgcat::mc "Activate Tkabber window, if the picture downloaded."] \
 	-type boolean -group Vimage
+	
+	custom::defvar options(use_progressbar) 1 \
+	[::msgcat::mc "Adds a indicator bar downloading image."] \
+	-type boolean -group Vimage
 
 	if { [option_exist topmost] } {
 		custom::defvar options(topmost) 0 \



More information about the Tkabber-dev mailing list