home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / tcl / 1839 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  2.5 KB

  1. Path: sparky!uunet!mcsun!sunic!chalmers.se!etek.chalmers.se!fy.chalmers.se!jacob
  2. From: jacob@fy.chalmers.se (Jacob Hallen)
  3. Newsgroups: comp.lang.tcl
  4. Subject: Possible tk bug and some questions
  5. Message-ID: <1992Nov16.055950.1700@fy.chalmers.se>
  6. Date: 16 Nov 92 05:59:50 GMT
  7. Sender: jacob@fy.chalmers.se
  8. Organization: Chalmers University of Technology, G|teborg, Sweden
  9. Lines: 65
  10.  
  11. QUESTIONS
  12.  
  13. - Is it possible to warp the mouse pointer from inside tk?
  14. - Is it possible to have one binding of an event (<1> for instance) in the
  15.   canvas in general, and a different binding of the same event inside
  16.   an item of the canvas?
  17.  
  18.  
  19. POSSIBLE TK BUG
  20.  
  21. The code below does the following:
  22. - Create a rectangle inside the canvas
  23. - Read a string to put in the middle of the rectangle. This is done by
  24.   creating a window with an Ok button and an entry box.
  25. - Bind events to the rectangle and the text
  26.  
  27. The problem is this:
  28. If I have the outcommented grabs in place, I need tp press a mouse
  29. button before I get the Any-events in my canvas. Is this as it should be?
  30.  
  31. ************************************************************************
  32. proc scrollNmread { nm } {
  33.   global xName;
  34.   set xName ["$nm.entry" get]
  35. }
  36. proc scrollMkname {{ nm .nameentry }} { 
  37.   global xName;
  38.   set xName "";
  39.   toplevel $nm;
  40.   entry $nm.entry -state normal -width 20 -relief sunken
  41.     button $nm.bt -text Ok\
  42.       -command "scrollNmread $nm";
  43.   bind $nm.entry <Key-Return> "scrollNmread $nm";
  44.   pack append $nm $nm.entry {top expand} $nm.bt {bottom filly}
  45. #  grab $nm;
  46.   set a [focus]
  47.   focus $nm.entry;
  48.   tkwait variable xName;
  49. #  grab none;
  50.   focus $a;
  51.   destroy $nm;
  52.   return $xName 
  53. }
  54.  
  55. proc scrollMkroom {canvas x y} {
  56.   set bg pink2;
  57.   set x [$canvas canvasx $x];
  58.   set y [$canvas canvasy $y];
  59.   set id [ $canvas create rect [expr $x-40] [expr $y-20]\
  60.       [expr $x+40] [expr $y+20] -outline black -fill $bg -tags rect ];
  61.   set id2 [$canvas create text $x $y -text [scrollMkname] \
  62.     -anchor center -tags text];
  63.       
  64.   $canvas bind $id <Any-Enter> "scrollEnter $canvas";
  65.   $canvas bind $id <Any-Leave> "scrollLeave $canvas";
  66.   $canvas bind $id <Double-1> "scrollButton $canvas";
  67.   $canvas bind $id <1> "scrollStartDrag $canvas %x %y";
  68.   $canvas bind $id <B1-Motion> "scrollDrag $canvas %x %y";
  69.  
  70.   $canvas bind $id2 <Any-Enter> "scrollEnter $canvas";
  71.   $canvas bind $id2 <Any-Leave> "scrollLeave $canvas";
  72.   $canvas bind $id2 <Double-1> "scrollButton $canvas";
  73.   $canvas bind $id2 <1> "scrollStartDrag $canvas %x %y";
  74.   $canvas bind $id2 <B1-Motion> "scrollDrag $canvas %x %y";
  75. }
  76.