Hey there, This looks like cleaner code! I didn't look at it thoroughly but it looks nice. Can anyone review his (Cristofaro) code and test please ? Now Cristofaro, just study for your exam, we'll talk again in 9 days, ok ? :)
Thanks KaKaRoTo ----- Forwarded message from [EMAIL PROTECTED] ----- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [Amsn-commits] SF.net SVN: amsn: [7802] trunk/amsn Revision: 7802 http://svn.sourceforge.net/amsn/?rev=7802&view=rev Author: dpcris85 Date: 2007-01-17 17:13:24 -0800 (Wed, 17 Jan 2007) Log Message: ----------- A lot of fixes to my dpbrowser implementation :) Now the dpbrowser doesn't use global variables anymore, but "stores" the path of the selected image by regenerating everytime the image displaypicture_std_$target. For translators: needed three new translations: mypics -> My Display Pictures cachedpicsfor -> Cached Display Pictures for selectcontact -> Select a contact Modified Paths: -------------- trunk/amsn/abook.tcl trunk/amsn/gui.tcl trunk/amsn/utils/dpbrowser/dpbrowser.tcl Modified: trunk/amsn/abook.tcl =================================================================== --- trunk/amsn/abook.tcl 2007-01-17 23:09:11 UTC (rev 7801) +++ trunk/amsn/abook.tcl 2007-01-18 01:13:24 UTC (rev 7802) @@ -1362,7 +1362,7 @@ # The custom display pic frame label $nbSettings.fNick.lDispl -text "[trans customdp]:" frame $nbSettings.fNick.fDispl -relief flat - set customdp_$email [::abook::getContactData $email customdp] + set customdp_$email [::abook::getContactData $email customdp ""] image create photo customdp_img_$email -file [set customdp_$email] label $nbSettings.fNick.fDispl.dp -image customdp_img_$email -borderwidth 0 -relief flat @@ -1615,10 +1615,11 @@ # as the actual change is done through the PropOk procedure proc ChangeCustomDp { email w } { global customdp_$email + set customdp_$email [::abook::getContactData $email customdp ""] dpBrowser $email tkwait window .dpbrowser catch {image delete customdp_img_$email} - image create photo customdp_img_$email -file customdp_$email + image create photo customdp_img_$email -file [set customdp_$email] $w.fNick.fDispl.dp configure -image customdp_img_$email -borderwidth 0 -relief flat } Modified: trunk/amsn/gui.tcl =================================================================== --- trunk/amsn/gui.tcl 2007-01-17 23:09:11 UTC (rev 7801) +++ trunk/amsn/gui.tcl 2007-01-18 01:13:24 UTC (rev 7802) @@ -1762,28 +1762,7 @@ $win.picmenu add command -label "[trans showuserpic $user]" \ -command "::amsn::ChangePicture $win \[::skin::getDisplayPicture $user\] \[trans showuserpic $user\]" } - #Load Change Display Picture window - $win.picmenu add separator - $win.picmenu add command -label "[trans changedisplaypic]..." -command [list after 0 dpBrowser] - foreach user $users { - $win.picmenu add command -label "[trans changecustomuserpic $user]" \ - -command "autoChangeCustomDp $user" - } - #Section to remove custom display pictures - set first_one 0 - foreach user $users { - if {[::abook::getContactData $user customdp ] != ""} { - # The separator is added only if the section is really going to be draw - if {$first_one == "0"} { - $win.picmenu add separator - set first_one 1 - } - $win.picmenu add command -label "[trans removecustomuserpic $user]" \ - -command "autoRemoveCustomDp $user" - } - } - set user [$win.f.bottom.pic.image cget -image] if { $user != "displaypicture_std_none" && $user != "displaypicture_std_self" } { #made easy for if we would change the image names @@ -7126,7 +7105,7 @@ } proc dpBrowser { {target_user "self" } } { - global selected_path selected_image HOME + global HOME package require dpbrowser @@ -7154,14 +7133,13 @@ # Select current DP (custom or not) for target user if { $target_user != "self" } { - if { [::abook::getContactData $target_user customdp] != "" } { + if { [::abook::getContactData $target_user customdp ""] != "" } { set image_name [::abook::getContactData $target_user customdp ""] } else { set image_name [::abook::getContactData $target_user displaypicfile ""] } if {$image_name != ""} { set selected_path [file join $HOME displaypic cache [filenoext $image_name].png] - set selected_image "[filenoext $selected_path].png" } } @@ -7169,24 +7147,24 @@ # First column # ################ frame $w.mydpstitle -bd 0 - label $w.mydpstitle.text -text "My cached display pictures:" -font bboldf + label $w.mydpstitle.text -text "[trans mypics]:" -font bboldf #clear cache button ? pack $w.mydpstitle.text -side left frame $w.moredpstitle -bd 0 - label $w.moredpstitle.text -text "Dp's in cache for:" -font bboldf + label $w.moredpstitle.text -text "[trans cachedpicsfor]:" -font bboldf #combobox to choose user which configures the widget with -user $user set combo $w.moredpstitle.combo combobox::combobox $combo -highlightthickness 0 -width 22 -font splainf -exportselection true -command "configuredpbrowser $target_user" -editable false -bg #FFFFFF $combo list delete 0 end - $combo list insert end "Select a contact:" + $combo list insert end "[trans selectcontact]:" foreach contact $contactlist { #put the name of the device in the widget $combo list insert end $contact if {$contact == $target_user} { - set selection [expr [$combo list index end] - 1] + set selection [expr {[$combo list index end] - 1}] } } @@ -7202,28 +7180,28 @@ pack $w.moredpstitle.text -side left pack $w.moredpstitle.combo -side right - ::dpbrowser $w.mydps -width 3 -user self -command [list updateDpBrowserSelection $w.mydps] -mode selector -createtempimg 1 + ::dpbrowser $w.mydps -width 3 -user self -command [list updateDpBrowserSelection $w.mydps $target_user] -mode selector - ::dpbrowser $w.moredps -width 3 -user $selected_user -command [list updateDpBrowserSelection $w.moredps] -mode selector -createtempimg 1 + ::dpbrowser $w.moredps -width 3 -user $selected_user -command [list updateDpBrowserSelection $w.moredps $target_user] -mode selector ################# # second column # ################# #preview - label $w.dppreviewtxt -text "Preview:" + label $w.dppreviewtxt -text "[trans preview]:" if {$target_user == "self"} { label $w.dppreview -image displaypicture_std_self } else { - if { $image_name == "" } { + if { $image_name == "" || [catch {image create photo displaypicture_std_$target_user -file $selected_path -format cximage}] } { label $w.dppreview -image displaypicture_std_none } else { - label $w.dppreview -image [image create photo [TmpImgName] -file $selected_path -format cximage] + label $w.dppreview -image displaypicture_std_$target_user } } #browse button - button $w.browsebutton -command "set selected_path \[pictureChooseFile\]" -text "[trans browse]..." + button $w.browsebutton -command "pictureChooseFile $target_user" -text "[trans browse]..." #under this button is space for more buttons we'll make a frame for so plugins can pack stuff in this frame frame $w.pluginsframe -bd 0 @@ -7234,7 +7212,7 @@ # lower pane # ################# frame $w.lowerpane -bd 0 - button $w.lowerpane.ok -text "[trans ok]" -command "set_displaypic \${selected_image} $target_user;destroy $w" + button $w.lowerpane.ok -text "[trans ok]" -command "set_displaypic $target_user;destroy $w" button $w.lowerpane.cancel -text "[trans cancel]" -command "destroy .dpbrowser" pack $w.lowerpane.ok $w.lowerpane.cancel -side right -padx 5 @@ -7253,12 +7231,15 @@ #lower pane grid $w.lowerpane -row 7 -column 0 -columnspan 2 -sticky e -padx 2 -pady 2 + + if { $target_user != "self" } { + bind $w <Destroy> "catch { image delete displaypicture_std_$target_user}" + } } - proc configuredpbrowser {target combowidget selection} { #puts "$combowidget $selection" - if {$selection == "Select a contact:"} {set selection ""} + if {$selection == "[trans selectcontact]:"} {set selection ""} if {$selection == $target} { [winfo toplevel $combowidget].moredps configure -user $selection -showcurrent 0 } else { @@ -7267,21 +7248,19 @@ } # This procedure is called back from the dpbrowser pane when a picture is selected -proc updateDpBrowserSelection { browser } { - global selected_image image_name - +proc updateDpBrowserSelection { browser target } { set w [winfo toplevel $browser] - catch {image delete $selected_image} - # Get the path of the selected image and unselect all images in the other pane set selection [$browser getSelected] - set selected_image [lindex $selection 1] - set temp_image [lindex $selection 2] + set file [lindex $selection 1] -# set image_name [image create photo [TmpImgName] -file $selected_image -format cximage] - $w.dppreview configure -image $temp_image - set selected_image "[filenoext $selected_image].png" -#FIXME: $image_name is never destroyed -> memleak + set old_image [$w.dppreview cget -image] + $w.dppreview configure -image "" + if { $old_image != "displaypicture_std_none" } { + catch {image delete $old_image} + } + status_log "will be created displaypicture_std_$target with filename $file" + $w.dppreview configure -image [image create photo displaypicture_std_$target -file $file -format cximage] } @@ -7327,8 +7306,8 @@ -proc pictureChooseFile { } { - global HOME selected_image image_names +proc pictureChooseFile { target } { + global HOME set file [chooseFileDialog "" "" "" "" open [list [list [trans imagefiles] [list *.gif *.GIF *.jpg *.JPG *.bmp *.BMP *.png *.PNG]] [list [trans allfiles] *]]] @@ -7348,20 +7327,17 @@ dpBrowser } - set image_name [image create photo [TmpImgName] -file [::skin::GetSkinFile "displaypic" "[filenoext [file tail $file]].png"] -format cximage] - status_log $image_name red - .dpbrowser.dppreview configure -image $image_name - set selected_image "[filenoext [file tail $file]].png" - + image create photo displaypicture_std_$target -file [::skin::GetSkinFile "displaypic" "[filenoext [file tail $file]].png"] -format cximage + .dpbrowser.dppreview configure -image displaypicture_std_$target set desc_file "[filenoext [file tail $file]].dat" set fd [open [file join $HOME displaypic $desc_file] w] status_log "Writing description to $desc_file\n" puts $fd "[clock format [clock seconds] -format %x]\n[filenoext [file tail $file]].png" close $fd - - lappend image_names $image_name - status_log "Created $image_name\n" - + + # Redraw dpBrowser's upper pane + .dpbrowser.mydps configure -user self + return "[filenoext [file tail $file]].png" } else { status_log "Error converting $file: $res\n" @@ -7415,8 +7391,10 @@ return $dpsize } -proc set_displaypic { file { email "self" } } { - global image_name +proc set_displaypic { { email "self" } } { + set file "" + catch {set file [displaypicture_std_$email cget -file]} + if { $email == "self" } { catch {image delete displaypicture_std_self} catch {image delete displaypicture_not_self} @@ -7427,7 +7405,6 @@ load_my_smaller_pic ::MSN::changeStatus [set ::MSN::myStatus] save_config - catch {image delete $image_name} } else { status_log "set_displaypic: Setting displaypic to displaypicture_std_none\n" blue clear_disp @@ -7436,8 +7413,7 @@ ::MSN::changeStatus [set ::MSN::myStatus] } } else { - set temp [filenoext $file] - status_log "$temp" + catch {image delete displaypicture_std_$email} global customdp_$email set customdp_$email $file } @@ -7459,30 +7435,6 @@ } } -# Through these function the custom DP can be changed without using the properties screen -proc autoChangeCustomDp { email } { - global customdp_$email - dpBrowser $email - tkwait window .dpbrowser - # Backup old custom dp - set old_customdp [::abook::getContactData $email customdp ""] - if {[set customdp_$email] != $old_customdp} { - # Store custom dp - ::abook::setAtomicContactData $email customdp [set customdp_$email] - # Update display picture - ::skin::getDisplayPicture $email 1 - ::skin::getLittleDisplayPicture $email 1 - } -} - -proc autoRemoveCustomDp { email } { - # Remove custom dp - ::abook::setAtomicContactData $email customdp "" - # Update display picture - ::skin::getDisplayPicture $email 1 - ::skin::getLittleDisplayPicture $email 1 -} - ###################### Protocol Debugging ########################### if { $initialize_amsn == 1 } { global degt_protocol_window_visible degt_command_window_visible Modified: trunk/amsn/utils/dpbrowser/dpbrowser.tcl =================================================================== --- trunk/amsn/utils/dpbrowser/dpbrowser.tcl 2007-01-17 23:09:11 UTC (rev 7801) +++ trunk/amsn/utils/dpbrowser/dpbrowser.tcl 2007-01-18 01:13:24 UTC (rev 7802) @@ -60,7 +60,9 @@ set dps_per_row $options(-width) if {$email == "self"} { - set shipped_dps [glob -nocomplain -directory [file join skins default displaypic] *.dat] + foreach dat_file [glob -nocomplain -directory [file join skins default displaypic] *.dat] { + lappend shipped_dps [::skin::GetSkinFile displaypic [file tail $dat_file]] + } set user_dps [glob -nocomplain -directory [file join $HOME displaypic] *.dat] set files [concat $shipped_dps $user_dps] set pic_in_use "" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Amsn-commits mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/amsn-commits ----- End forwarded message ----- ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Amsn-devel mailing list Amsn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amsn-devel