[Tkabber-dev] r141 - trunk/plugins/stripes

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Oct 12 02:54:44 MSD 2008

Author: kostix
Date: 2008-10-12 02:54:44 +0400 (Sun, 12 Oct 2008)
New Revision: 141

 * Modified to work using the new hook draw_message_post_hook
   introduced in the Tkabber mainline at revision 1503.
 * Cleaned up the code, misc stylistic fixes.
 * Code reformatted to match the style used in Tkabber code.

stripes/README: Provided actual plugin description.

Modified: trunk/plugins/stripes/README
--- trunk/plugins/stripes/README	2008-10-11 21:55:52 UTC (rev 140)
+++ trunk/plugins/stripes/README	2008-10-11 22:54:44 UTC (rev 141)
@@ -1,65 +1,63 @@
-"Singularity" -- main interface plugin for Tkabber.
+"Stripes" -- chat plugin for Tkabber.
 I. The Idea
-When you chat with someone in Tkabber, the corresponding chat
-window is opened for the full JID of that person (it is a JID
-with the resource part: node at server/resource). Since your peers
-can normally log into their XMPP accounts several times at once
-(with a different resource each time) Tkabber maintains clear
-distinction between these full JIDs.
-On the other hand, most people seldom chat from several
-connections to their account at once -- quite more often they
-move between two or more XMPP clients located in places which
-are geographically quite apart, such as their home and office.
-In this case it may be convenient to maintain just one chat
-window open for each person you're chatting with -- for
-instance, you start chatting whith your peer when he/she is at
-home, then your peer moves to their office and sends a message
-from the new location; at this point it might be convenient not
-to have two chat windows -- old and new -- open, but just the
-new one.
+This plugin allows to colorize backgrounds of the whole
+messages placed in the conversation logs of Tkabber chat
+windows. Backgrounds of even and odd messages can be
+configured separately from each other (or not configured
+at all).
-This plugin implements the described functionality: when the new
-window for a one-on-one chat is about to be opened the plugin
-checks whether there are any active chat sessions with the same
-bare JID (that is, without the "/resource" part) as that of the
-new chat. If there are, they are closed with their conversation
-log and input history preserved, the new chat window is opened
-and then the saved data is inserted into the new window. 
-So effectively this plugin makes Tkabber keep just one chat
-window per bare JID open.
-The plugin does not touch MUC private chats because in them
-resource part of the room JID is used to designate participants'
+II. Usage
+The colors of even and odd messages can be manipulated using the
+Tk option database resources which are:
-II. Usage
+* Chat.oddBackground for odd messages.
-Just install this plugin as usually and restart Tkabber.
-Currently there's no UI to control the plugin's behaviour.
+* Chat.evenBackground for even messages.
+When the particular resource is not defined, it's not used thus
+not affecting the appearance of the corresponding messages.
-III. Bugs and limitations
+By default these resources are not defined.
-* Tkabber is currently unable to actually "switch" a chat window
-  from one JID to another, so this plugin works by closing the
-  existing window(s) and opening the new one. While in tabbed
-  mode this looks mostly OK, in windowed mode this may be
-  annoying because the new window will most probably not appear
-  at the same location and layer as the closed window.
+The color may be specified in any form accepted by Tk which mean
+any named color (from the X server's color database on
+systems using X Window or listed in [1] on other systems) or the
+color specification such as #RRGGBB.
+For the strict explanation or color specifications read [2].
-* For some unknown reason the first line of the input history is
-  lost when the chat state is transferred to the newly opened
-  window.
-* If there are several chat windows to be closed when the new
-  one is about to be opened, the order in which their
-  conversation logs and input history records are collected
-  is undefined.
+III. Examples
+1) To set up gray colors using the Tkabber configuration file
+   add these lines to your config.tcl file:
+# Colors for the stripes plugin:
+option add *Chat.oddBackground  gray77
+option add *Chat.evenBackground gray84
+2) To do the same using XRDB (systems based on X Window):
+! Colors for the stripes plugin:
+Tkabber*Chat.oddBackground:  AntiqueWhite
+Tkabber*Chat.evenBackground: bisque
+IV. Bugs and limitations
+* Changing any color resource at runtime won't affect already
+  opened chat windows.
+V. Links
+1. http://www.tcl.tk/man/tcl8.5/TkCmd/colors.htm
+2. http://www.tcl.tk/man/tcl8.5/TkLib/GetColor.htm
 # vim:tw=64:noet

Modified: trunk/plugins/stripes/stripes.tcl
--- trunk/plugins/stripes/stripes.tcl	2008-10-11 21:55:52 UTC (rev 140)
+++ trunk/plugins/stripes/stripes.tcl	2008-10-11 22:54:44 UTC (rev 141)
@@ -12,59 +12,61 @@
 # option add *Chat.evenBackground gray84
 namespace eval stripes {
-	variable state
+    variable state
-	hook::add open_chat_post_hook \
-		[namespace current]::tweak_chat_window
-	hook::add draw_message_hook \
-		[namespace current]::on_draw_message 10
+    hook::add open_chat_post_hook \
+	[namespace current]::setup_chat_window
+    hook::add draw_message_post_hook \
+	[namespace current]::on_message_drawn
-proc stripes::tweak_chat_window {chatid type} {
-	variable state
+proc stripes::setup_chat_window {chatid type} {
+    variable state
-	set cw [::chat::chat_win $chatid]
+    set cw [::chat::chat_win $chatid]
+    set mw [::chat::winid $chatid]
-	set mw [::chat::winid $chatid]
-	set bgodd  [option get $mw oddBackground Chat]
-	if {$bgodd != "" } {
-		$cw tag config ODD -background $bgodd
-	}
-	set bgeven [option get $mw evenBackground Chat]
-	if {$bgeven != "" } {
-		$cw tag config EVEN -background $bgeven
-	}
+    set bgodd [option get $mw oddBackground Chat]
+    if {$bgodd != ""} {
+	$cw tag configure odd -background $bgodd
+    }
+    set bgeven [option get $mw evenBackground Chat]
+    if {$bgeven != ""} {
+	$cw tag configure even -background $bgeven
+    }
-	set state($cw,last) 1.0
-	set state($cw,tag) EVEN
+    set state($cw,last) 1.0
+    set state($cw,tag) odd
-	bind $cw <Destroy> +[list [namespace current]::cleanup $cw %W]
+    bind $cw <Destroy> +[list [namespace current]::cleanup $cw %W]
 proc stripes::cleanup {w1 w2} {
-	if {![string equal $w1 $w2]} return
+    if {![string equal $w1 $w2]} return
-	variable state
-	array unset state $w1,*
+    variable state
+    unset state($w1,last)
+    unset state($w1,tag)
-proc stripes::on_draw_message {chatid from type body x} {
-	variable state
-	set cw [::chat::chat_win $chatid]
+proc stripes::on_message_drawn {chatid from type body x} {
+    variable state
-	# Analyze previous message:
-	set last $state($cw,last)
-	set now [$cw index {end - 1 char}]
-	if {[$cw compare $last < $now]} {
-		$cw tag add $state($cw,tag) $last $now
-		if {[string equal $state($cw,tag) EVEN]} {
-			set state($cw,tag) ODD
-		} else {
-			set state($cw,tag) EVEN
-		}
+    set cw [::chat::chat_win $chatid]
+    upvar 0 state($cw,last) last
+    upvar 0 state($cw,tag)  tag
+    set now [$cw index {end - 1 char}]
+    if {[$cw compare $last < $now]} {
+	$cw tag add $tag $last $now
+	if {[string equal $tag even]} {
+	    set tag odd
+	} else {
+	    set tag even
+    }
-	# Save last pos:
-	set state($cw,last) $now
+    set last $now
+# vim:ts=8:sw=4:sts=4:noet

More information about the Tkabber-dev mailing list