[PD-cvs] pd/src desire.tk,1.1.2.202,1.1.2.203

chunlee chunlee at users.sourceforge.net
Sun May 14 14:30:21 CEST 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15064

Modified Files:
      Tag: devel_0_39
	desire.tk 
Log Message:
the auto completion code in alpha.....


Index: desire.tk
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.tk,v
retrieving revision 1.1.2.202
retrieving revision 1.1.2.203
diff -C2 -d -r1.1.2.202 -r1.1.2.203
*** desire.tk	7 May 2006 23:56:54 -0000	1.1.2.202
--- desire.tk	14 May 2006 12:30:19 -0000	1.1.2.203
***************
*** 754,757 ****
--- 754,758 ----
  set look(buttonbar) 1
  set look(statusbar) 1
+ set look(showcomp) 10
  
  set look(extrapix) [switch $OS {
***************
*** 1340,1343 ****
--- 1341,1348 ----
      mset {x1 y1} [$self xy]
      puts "x1=$x1 y1=$y1"
+ 	puts "text === $@text"
+ 	set l {}
+ 	foreach char [split $@text ""] {lappend l [scan $char %c]}
+ 	puts "l == $l"
  #    puts "!!!!edit = $@edit!!!!"
      if {$@edit} {
***************
*** 1347,1351 ****
  	$self item TEXT text [l+ {2 2} [list $x1 $y1]] \
  		-font $font(str) -text $@text -fill $look(objectfg) -anchor nw
! 	puts "text = $@text"
      }
  }
--- 1352,1356 ----
  	$self item TEXT text [l+ {2 2} [list $x1 $y1]] \
  		-font $font(str) -text $@text -fill $look(objectfg) -anchor nw
! 
      }
  }
***************
*** 1374,1377 ****
--- 1379,1383 ----
  	#	-font $font(str) -fg red
  	#---------------------------------------
+ 	bind Text <Tab> "$self tab; continue"
  	text $t -height 1 -width [expr [string length $@text]+1] -relief flat \
  		-bg ${look(objectbg)} -borderwidth 0 -highlightthickness 0\
***************
*** 1381,1384 ****
--- 1387,1392 ----
  	bind $t <Control-Return> "$self key %W %x %y 10 %A 0"
  	bind $t <Return>         "$self unedit"
+ 	bind $t <Any-Enter> "puts \"keep compltion box please..........\" "
+ 	bind $t <Any-Leave> "puts \"destroy the compltion box please..........\" "
  	mset {cx cy} [$self xy]
  	#--------------------------------------- label completion
***************
*** 1397,1400 ****
--- 1405,1417 ----
  }
  
+ def* TextBox tab {} {
+ 	puts "continue..................."
+ 	if {[winfo exists .completion]} {
+ 	#completion focus_switch Down .completion.comp .$@canvas.c.${self}text
+ 	}
+ 	
+ 
+ }
+ 
  def* TextBox key {widget x y key iso shift} {
  	after 0 "$self after_key $widget"
***************
*** 1410,1413 ****
--- 1427,1444 ----
  	$widget configure -state normal
  	set @text [$widget get 1.0 1.end]
+ 	puts "text received after_key ----------------- $@text"
+ 	#set l {}
+ 	#foreach char [split $@text ""] {lappend l [scan $char %c]}
+ 	#set tab [lsearch $l 9]
+ 	#set l [lreplace $l $tab $tab]
+ 	#$widget delete 1.0 1.end
+ 	#set text {}
+ 	#foreach char $l {
+ 	#append text [format %c $char]
+ 	#}
+ 	#puts "l == $l ||| $tab ||| $text"
+ 	#$widget insert 1.0 $text
+ 	#set @text $text
+ 	
  	$self update_size
  	$self draw
***************
*** 3277,3283 ****
  def* ClassBrowser init {name x y textbox} {
  	set @name $name
! 	set @focus ""
  	set @x $x
  	set @y $y
  	# so that in completion mode, it know which textbox to switch the focus to
  	set @textbox $textbox
--- 3308,3318 ----
  def* ClassBrowser init {name x y textbox} {
  	set @name $name
! 	set @focus ".completion.comp"
  	set @x $x
  	set @y $y
+ 	set @size 0
+ 	set @width 0
+ 	set @height 0
+ 	set @select 0
  	# so that in completion mode, it know which textbox to switch the focus to
  	set @textbox $textbox
***************
*** 3286,3290 ****
  }
  
! def ClassBrowser fill_box {s listbox} {
  	set f .$self.cl
  	global class_list
--- 3321,3325 ----
  }
  
! def* ClassBrowser fill_box {s listbox} {
  	set f .$self.cl
  	global class_list
***************
*** 3295,3299 ****
  		if {[string length $s]==0 || [string first $s $class]>=0} {
  			#$f.1 insert end "$class : [say $class]"
! 			$listbox insert end "$class : [say $class]"
  			incr n
  		}
--- 3330,3336 ----
  		if {[string length $s]==0 || [string first $s $class]>=0} {
  			#$f.1 insert end "$class : [say $class]"
! 			set string "$class : [say $class]"
! 			$listbox insert end $string
! 			if {[string length $string] > [string length $@width]} {set @width [string length $string]}
  			incr n
  		}
***************
*** 3303,3306 ****
--- 3340,3345 ----
  	}
  	$listbox selection set 0 0
+ 	set @size [$listbox size]
+ 	puts "matches ::: $@size |||| width ::: $@width"
  }
  
***************
*** 3321,3328 ****
  }
  
! def ClassBrowser info {} {
! 	set f .$self.cl
! 	set i [$f.1 curselection]
! 	set class [lindex [$f.1 get $i] 0]
  	pd pd update-class-info $class $self info_callback
  }
--- 3360,3366 ----
  }
  
! def* ClassBrowser info {listbox} {
! 	set i [$listbox curselection]
! 	set class [lindex [$listbox get $i] 0]
  	pd pd update-class-info $class $self info_callback
  }
***************
*** 3338,3342 ****
  			pack [frame $f] -side top -fill both -expand yes
  			pack [label .$self.title -text ""] -side top
! 			listbox $f.1 -width 50 -height 20 -yscrollcommand "$f.2 set"
  			scrollbar $f.2 -command "$f.1 yview"
  			text    $f.3 -width 30 -height 20 -yscrollcommand "$f.4 set"
--- 3376,3381 ----
  			pack [frame $f] -side top -fill both -expand yes
  			pack [label .$self.title -text ""] -side top
! 			listbox $f.1 -width 50 -height 20 -yscrollcommand "$f.2 set" \
! 						 -activestyle none
  			scrollbar $f.2 -command "$f.1 yview"
  			text    $f.3 -width 30 -height 20 -yscrollcommand "$f.4 set"
***************
*** 3359,3363 ****
  			pack $b -side bottom -fill x -expand no
  			$self fill_box "" $f.1
! 			#bind $f.1 <Button-1> "after 1 \"$self info\""
  			bind $f.1 <Button-1> "after 1 \"$self focus_switch Up $b.2 $f.1 \""
  			bind $f.1 <KeyPress> "after 1 \"$self focus_switch %K $b.2 $f.1 \""
--- 3398,3402 ----
  			pack $b -side bottom -fill x -expand no
  			$self fill_box "" $f.1
! 			#bind $f.1 <Button-1> "after 1 \"$self info $f.1 \""
  			bind $f.1 <Button-1> "after 1 \"$self focus_switch Up $b.2 $f.1 \""
  			bind $f.1 <KeyPress> "after 1 \"$self focus_switch %K $b.2 $f.1 \""
***************
*** 3367,3400 ****
  		}
  		completion {
! 			#puts "name ::: $@name | textbox :: $@textbox"
  			set canvas $@name
! 			set f .$@name.c.comp
! 			listbox $f -width 20 -height 10 -relief raised -bg red
  			
! 			.$@name.c create window [expr $@x+2] [expr $@y+2] \
! 			-window $f -anchor nw -tags "$self"
! 			#-window $f -anchor nw -tags "${canvas}Completebox $canvas"
! 			$self fill_box "" $f
! 			bind $f <Button-1> "after 1 \"$self focus_switch Up $@textbox $f \""
! 			bind $f <KeyPress> "after 1 \"$self focus_switch %K $@textbox $f \""
! 			bind $@textbox <KeyPress> "after 1 \"$self focus_switch %K $@textbox $f \""
  			
  		}
  	}
  }
  
! def* ClassBrowser focus_switch {key focus1 focus2} {
  	#focus2 = listbox :: focus1 = whatever
  	if {$key != "Down" & $key != "Up"} {
  		if {$@focus == $focus2} {
! 		if {[regexp {^[a-zA-Z]{1}$} $key]} {.$self.butt.2 insert end $key}
  		}
! 		focus $focus1
! 		set @focus $focus1
! 		$self fill_box [$focus1 get] $focus2
  	} else {
  		focus $focus2
  		set @focus $focus2
! 		if {$@name == "browser"} {$self info}	
  	}
  }
--- 3406,3553 ----
  		}
  		completion {
! 			toplevel .$self
! 			#$self test_focus 
! 			#wm overrideredirect .$self 1
  			set canvas $@name
! 			set f .$self.comp
! 			set rootx [winfo rootx .$@name.c]
! 			set rooty [winfo rooty .$@name.c]
! 			set max [wm maxsize .$self]
! 			if {[regexp {x([0-9a-z]{6,8})text$} $@textbox textself]} {
! 				set cut [string first "text" $textself]
! 				set textself [string range $textself 0 [expr $cut -1]]
! 				}
! 			mset {x1 y1 x2 y2} [$textself bbox]
! 			if {$look(showcomp) <= 20} {
! 				set @height $look(showcomp)} else {set @height 20}
! 			listbox $f -width $@width -height $@height -relief flat -bg red -selectbackground yellow \
! 					   -activestyle dotbox
! 			$self fill_box [$@textbox get 1.0 1.end] $f
! 			$f configure -width $@width
! 			set box_width [winfo reqwidth $f] 
! 			set box_height [winfo reqheight $f] 	
! 			pack $f	-side left
  			
! 			.$self configure -width $box_width
! 			.$self configure -height $box_height
  			
+ 			#test the right edge of the screen, assuming the left edge has enough space
+ 			if {[expr $x1+$rootx+$box_width] < [lindex $max 0]} {
+ 				set box_x [expr $x1+$rootx]
+ 			} else {
+ 				set box_x [expr $x2 - $box_width + $rootx]
+ 			}
+ 			#test the lower edge of the screen, assuming the upper edge has enough space
+ 			if {[expr $y2+$rooty+$box_height] < [lindex $max 1]} {
+ 				set box_y [expr $y2 + 5 + $rooty]
+ 			} else {
+ 				set box_y [expr $y1 - $box_height - 2 + $rooty]
+ 			}
+ 
+ 			wm geometry .$self [winfo reqwidth .$self]x[winfo reqheight .$self]+$box_x+$box_y
+ 					
+ 			bind $f <Button-1> "after 1 \"$self focus_switch Up $@textbox $f \""
+ 			bind $f <KeyPress> "$self focus_switch %K $@textbox $f"
+ 			bind $f <Return> "after 1 \"$self complete $f \""
+ 			bind Text <Tab> "$self tab $@textbox $f; continue"
+ 			#bind $@textbox <KeyPress> "after 1 \"$self focus_switch %K $@textbox $f \""
+ 			bind $@textbox <KeyPress> "$self focus_switch %K $@textbox $f"
+ 			#bind $@textbox <Tab> "after 1 \"$self tab %K $@textbox $f \""
+ 			focus .$self.comp
  		}
  	}
  }
  
! def ClassBrowser complete {listbox} {
! 	puts "complete me!!!!"
! 	if {[regexp {x([0-9a-z]{6,8})text$} $@textbox obj]} {
! 		set cut [string first "text" $obj]
! 		set obj [string range $obj 0 [expr $cut -1]]
! 	}
! 	set i [$listbox curselection]
! 	set class [lindex [$listbox get $i] 0]
! 	$@textbox delete 1.0 1.end
! 	$@textbox insert 1.0 $class
! 	$obj unedit
! 	#.$@name.c delete $self
! 	#destroy .$@name.c.comp
! 	destroy .$self
! 
! }
! 
! def ClassBrowser test_focus {} {
! 	if {[winfo exists .$self]} {
! 		after 500 $self test_focus
! 		puts "focus is:   [focus] || viewable: [winfo viewable .$self]"
! 		
! 		}
! 	}
! 
! def* ClassBrowser tab {textbox listbox} {
! 	set $@focus $listbox
! 	$self focus_switch Down $textbox $listbox
! 	}
! 
! def ClassBrowser focus_switch {key focus1 focus2} {
  	#focus2 = listbox :: focus1 = whatever
+ 	if {[regexp {x([0-9a-z]{6,8})text$} $@textbox textself]} {
+ 		set cut [string first "text" $textself]
+ 		set textself [string range $textself 0 [expr $cut -1]]
+ 	}
  	if {$key != "Down" & $key != "Up"} {
+ 	puts "------> focus_switch received none down/up key => $key"
  		if {$@focus == $focus2} {
! 		puts "------> focus_switch focus = $focus2"
! 		if {[regexp {^[a-zA-Z]{1}$} $key]} {
! 			switch $self {
! 				browser {.$self.butt.2 insert end $key}
! 				completion {
! 				puts "------> focus_switch focus2 receives letter key $key"
! 					$focus1 insert 1.end $key
! 					$textself after_key $@textbox
! 					$self fill_box [$focus1 get 1.0 1.end] $focus2
! 				puts "------> focus_switch focus = $focus1"
! 					focus $focus1
! 					set @focus $focus1	
! 				}
! 			  }
! 			}
! 			
! 			if {$key == "BackSpace"} {focus $focus1; set @focus $focus1}
  		}
! 		
! 		# continue tabbing will go through the matches
! 		if {$key == "Tab"} {
! 		set next [expr [$focus2 index active] + 1] 
! 		puts "------> focus_switch fuck! move to the item $@select!! [$focus2 index active]"
! 		if {$next >= [expr $@size - 1]} {
! 		$focus2 activate 0} else {
! 			#puts "------ [$focus2 yview] ------"
! 			$focus2 activate $next
! 			$focus2 selection clear 0 [expr $@size - 1] 
! 			$focus2 selection set $next $next 
! 			if {$next >= [expr $@height - 1]} {$focus2 yview scroll 1 units}
! 			}
! 		}
! 		
! 		switch $self {
! 			browser {$self fill_box [$focus1 get] $focus2} 
! 			completion {
! 				if {$@focus == $focus1 & $key != "Tab"} {
! 					puts "------> focus_switch receives $key @ $@focus"
! 					#if {[regexp {^[a-zA-Z]{1}$} $key]} {$focus1 insert 1.end $key}
! 					$self fill_box [$focus1 get 1.0 1.end] $focus2
! 					#hum, no idea why i need after 1 for it to work...
! 					after 1 $textself after_key $@textbox
! 					}
! 				}
! 			}
! 
! 		
  	} else {
  		focus $focus2
  		set @focus $focus2
! 		set @select 0
! 		if {$@name == "browser"} {$self info $focus2}	
  	}
  }
***************
*** 3452,3456 ****
  	#---------------------------------------
  	mset {x1 y1 x2 y2} [$self bbox]
! 	ClassBrowser new_as completion $@canvas $x2 $y1	$widget
  }
  
--- 3605,3609 ----
  	#---------------------------------------
  	mset {x1 y1 x2 y2} [$self bbox]
! 	ClassBrowser new_as completion $@canvas $x1 $y1	$widget
  }
  
***************
*** 3656,3662 ****
  proc balloon {w help} {
      bind $w <Any-Enter> "after 500 [list balloon:show %W [list $help]]"
!     bind $w <Any-Leave> "destroy %W.balloon"
    }
!   proc balloon:show {w arg} {
      if {[eval winfo containing  [winfo pointerxy .]]!=$w} {return}
      set top $w.balloon
--- 3809,3816 ----
  proc balloon {w help} {
      bind $w <Any-Enter> "after 500 [list balloon:show %W [list $help]]"
!     bind $w <Any-Leave> "destroy %W.balloon; puts \"destroy balloon\" "
    }
!   
! proc balloon:show {w arg} {
      if {[eval winfo containing  [winfo pointerxy .]]!=$w} {return}
      set top $w.balloon





More information about the Pd-cvs mailing list