skins.tcl

来自「Linux下的MSN聊天程序源码」· TCL 代码 · 共 903 行 · 第 1/3 页

TCL
903
字号
##########################################################################             skins.tcl - aMSN Skins System (0.95B)                  ####  ----------------------------------------------------------------  ####   If you want to add any option to skins system, please, be sure   ####    of commenting out your code and keep your values in a proper    ####      section of settings.xml, so the system remains coherent       ##########################################################################namespace eval ::skin {	variable preview_skin_change 0	################################################################	# ::skin::getKey (key, [default])	# This procedure get the value of a skin's configuration key	# supplied by $key and returns it. If the given key doesn't	# exists, it will return $default if supplied, or "" if not.	# Arguments:	#  - key => The requested skin's configurarion key.	#  - default => [NOT REQUIRED] the fallback value.	proc getKey {key {default ""}} {		if { [info exists ::skin_setting($key)] } {			return [::set ::skin_setting($key)]		} else {			return $default		}	}	################################################################	# ::skin::setKey (key, value)	# This procedure assigns a value (supplied by $value) to a 	# skin's configuration key supplied by $key. It returns nothing.	# Arguments:	#  - key => The name of the skin's configurarion key.	#  - value => The data assigned to $key	proc setKey {key value} {		::set ::skin_setting($key) $value	}	################################################################	# ::skin::InitSkinDefaults ()	# Here we set every data wich depends on skins to default, so we	# can load a skin without problems.	proc InitSkinDefaults { } {		global emoticon_number emotions emotions_names emotions_data		set emoticon_number 0		set emotions_names [list]		if { [info exists emotions] } {unset emotions}		if { [info exists emotions_data] } {unset emotions_data}		::skin::setKey bigstate_xpad 0		::skin::setKey bigstate_ypad 3				::skin::setKey mystatus_xpad 5		::skin::setKey mystatus_ypad 0				::skin::setKey mailbox_xpad 5		::skin::setKey mailbox_ypad 0				::skin::setKey contract_xpad 5		::skin::setKey contract_ypad 0				::skin::setKey expand_xpad 5		::skin::setKey expand_ypad 0			}	################################################################	# ::skin::setPixmap (pixmap_name, pixmap_file [, location])	# This procedure sets the image name -- file name association 	# in order to load pictures on demand.	# Arguments:	#  - pixmap_name => Name of the image resource to be used in amsn	#  - pixmap_file => The image file	#  - location => [NOT REQUIRED, defaults to pixmaps]	#                Which folder in skins the file is under (eg pixmaps or smileys)	#  - fblocation => [NOT REQUIRED] Directory to check if file not found in the skins (for plugins)	proc setPixmap {pixmap_name pixmap_file {location pixmaps} {fblocation ""}} {		variable ${location}_names		variable ${location}_fblocation		set ${location}_names($pixmap_name) $pixmap_file		set ${location}_fblocation($pixmap_name) $fblocation	}	################################################################	# ::skin::loadPixmap (pixmap_name [, location])	# Checks if the image was previously loaded, or we need to load	# it. This way, the pixmaps will be loaded first time they're 	# used, on demand. It returns the image resource to be used.	# Arguments:	#  - pixmap_name => Name of the image resource to be used in amsn	#  - location => [NOT REQUIRED, defaults to pixmaps]	#                Which folder in the skins folder the file is under (eg pixmaps or smileys)	proc loadPixmap {pixmap_name {location pixmaps}} {		# Check if pixmap is already loaded		variable loaded_${location}		if { [info exists loaded_${location}($pixmap_name)] } {			return [set loaded_${location}($pixmap_name)]		}		# Not loaded, so let's load it		variable ${location}_names		variable ${location}_fblocation		if { ! [info exists ${location}_names($pixmap_name) ] } {			return ""		}		#for better image naming convention		switch "$location" {				smileys {					set naming "emoticonStd_std"				}				pixmaps {					set naming "uiElement_std"				}				default {					set naming $location				}		}		#If the loading pixmap is corrupted (like someone stupid trying to change the smileys by himself and is doing something bad), just show a null picture		if { [catch {set loaded_${location}($pixmap_name) [image create photo ${naming}_${pixmap_name} -file [::skin::GetSkinFile ${location} [set ${location}_names($pixmap_name)] \			"" [set ${location}_fblocation($pixmap_name)]] -format cximage] } res ] } {		 	status_log "Error while loading pixmap $res"		 	set loaded_${location}($pixmap_name) [image create photo ${naming}_${pixmap_name} -file [::skin::GetSkinFile pixmaps null \			 -format cximage]]		 }			return [set loaded_${location}($pixmap_name)]	}	################################################################	# ::skin::getNoDisplayPicture ([skin_name])	# Checks if the image was previously loaded, or we need to load	# it. This way, the displaypicture_std_none will be loaded first time it's used.	# It always returns 'displaypicture_std_none', is always the same name (static).	# Arguments:	#  - skin_name => [NOT REQUIRED] Overrides the current skin.	proc getNoDisplayPicture { {skin_name ""} } {		variable loaded_images		if { [info exists loaded_images(displaypicture_std_none)] } {			return displaypicture_std_none		}		image create photo displaypicture_std_none -file [::skin::GetSkinFile displaypic nopic.gif $skin_name] -format cximage		set loaded_images(displaypicture_std_none) 1		return displaypicture_std_none	}	proc getDisplayPicture { email {force 0}} {		global HOME						set picName displaypicture_std_$email				if {[catch {image width $picName}] == 0  && $force == 0} {			return $picName		}		set filename [::abook::getContactData $email displaypicfile ""]		set file "[file join $HOME displaypic cache ${filename}].png"		if { $filename != "" && [file readable "[file join $HOME displaypic cache ${filename}].png"] } {			catch {image create photo $picName -file "$file" -format cximage}		} else {			# We do like that to have a better update of the image when switching from no pic to another			#image create photo $picName -file [::skin::GetSkinFile displaypic nopic.gif] -format cximage			image create photo $picName			$picName copy [::skin::getNoDisplayPicture]			set file [::skin::GetSkinFile displaypic nopic.gif]		}				if {[catch {image width $picName} res]} {			#status_log "Error while loading $picName: $res"			image create photo $picName			$picName copy [::skin::getNoDisplayPicture]			set file [::skin::GetSkinFile displaypic nopic.gif]		}				if { [catch {::picture::GetPictureSize $file} cursize] } {			#Corrupted image.. might as well delete it and redownload it some other time..			status_log "Error opening $file: $cursize\n"			catch {file delete $file}		} elseif { [::config::getKey autoresizedp] && ![::picture::IsAnimated $file] && $cursize != "96x96"} {			::picture::Resize $picName 96 96		}		if { [catch {image height displaypicture_tny_$email} height] == 0} {			#Little DP exists so we have to update it			::skin::getLittleDisplayPicture $email $height 1		}		return $picName	}	proc getLittleDisplayPicture { email height {force 0}} {		global HOME		set picName displaypicture_tny_$email				if {[catch {image width $picName}] == 0  && $force == 0} {			return $picName		}		set filename [::abook::getContactData $email displaypicfile ""]		set file "[file join $HOME displaypic cache ${filename}].png"		if { $filename != "" && [file readable $file] } {			catch {image create photo $picName -file "$file" -format cximage}		} else {			image create photo $picName			$picName copy [::skin::getNoDisplayPicture]			set file [::skin::GetSkinFile displaypic nopic.gif]		}				if {[catch {image width $picName} res]} {			#status_log "Error while loading $picName: $res"			image create photo $picName			$picName copy [::skin::getNoDisplayPicture]			set file [::skin::GetSkinFile displaypic nopic.gif]		}				if { [catch {::picture::GetPictureSize $file} cursize] } {			status_log "Error opening $file: $cursize\n"			return ""		}		set animated [::picture::IsAnimated $file]		if { $animated == 0 } {			::picture::ResizeWithRatio $picName $height $height			return $picName		} else {			set tmpPic [imageTemp]  ;#gets destroyed			$tmpPic copy $picName			image delete $picName			image create photo $picName			$picName copy $tmpPic			image delete $tmpPic			::picture::ResizeWithRatio $picName $height $height			return $picName		}		return ""	}	#Convert a display picture from a user to another size	proc ConvertDPSize {user width height} {		if {[catch {			::picture::Resize [getDisplayPicture $user] $width $height		} res]} {			msg_box $res		}	}	################################################################	# ::skin::getColorBar ([skin_name])	# Creates the special image that is placed below of the nickname	# in the contacts' list. It returns the image resource.	# Arguments:	#  - skin_name => [NOT REQUIRED] Overrides the current skin.	proc getColorBar { {skin_name ""} } {		# Get the contact list width		global pgBuddyTop		global pgbuddy_colorbar_width		set win_width [winfo width [winfo parent $pgBuddyTop]]		# Avoid deleting/recreating the colorbar every CL refresh!		if { [info exists pgbuddy_colorbar_width] && $pgbuddy_colorbar_width == $win_width } {			return uiDynamicElement_mainbar		}		set width $win_width		# Delete old uiDynamicElement_mainbar, and load colorbar		# The colorbar will be loaded as follows:		# [first 10 px][11th px repeating to fill][the rest of the colorbar]		catch {image delete uiDynamicElement_mainbar}		set barheight [image height [loadPixmap colorbar]]		set barwidth [image width [loadPixmap colorbar]]		set barendwidth [expr {$barwidth - 11}]		if { $width < $barwidth } {			set width $barwidth		}		set barendstart [expr {$width - $barendwidth}]		# Create the color bar copying from the pixmap		image create photo uiDynamicElement_mainbar -width $width -height $barheight		uiDynamicElement_mainbar blank		uiDynamicElement_mainbar copy [loadPixmap colorbar] -from 0 0 10 $barheight		uiDynamicElement_mainbar copy [loadPixmap colorbar] -from 10 0 11 $barheight -to 10 0 $barendstart $barheight		uiDynamicElement_mainbar copy [loadPixmap colorbar] -from [expr {$barwidth - $barendwidth}] 0 $barwidth $barheight -to $barendstart 0 $width $barheight		set pgbuddy_colorbar_width $win_width		set ::skin::loaded_images(colorbar) 1		return uiDynamicElement_mainbar	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?