mousetrack.htm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <HTML>
  2. <HEAD><TITLE>Python Scripting sample: Mouse tracking</TITLE></HEAD>
  3. <BODY BGCOLOR="#FFFFFF" TOPMARGIN=8>
  4. <FONT SIZE=5>
  5. <TABLE Border=0><TR VALIGN=MIDDLE><TD>
  6. <A ID="Image"> <IMG
  7. SRC="file:..\..\..\..\..\win32com\html\image\pycom_blowing.gif"
  8. ALT="Clickable Map Image" HEIGHT=113 WIDTH=624 BORDER=0></A>
  9. </TD></TR>
  10. <TR><TD>&nbsp;</TD></TR>
  11. <TR VALIGN=MIDDLE><TD VALIGN=MIDDLE ALIGN=CENTER><FONT SIZE=5><INPUT
  12. TYPE="text" NAME="TxtLinkDescription" SIZE=50></FONT></TD></TR></TABLE>
  13. </FONT>
  14. <P>
  15. A mouse tracking demo. Move the mouse over the image above...
  16. <SCRIPT Language="Python">
  17. <!--
  18. # Remember the last location clicked
  19. #print "here we go", 1
  20. mx = my = 0
  21. # class for rectangle testing
  22. class rect:
  23. def __init__(self, lowx, lowy, upx, upy, desc, url):
  24. self.lowx, self.lowy, self.upx, self.upy, self.desc, self.url = \
  25. lowx, lowy, upx, upy, desc, url
  26. def inside(self, x, y):
  27. # print (x,y), "inside", self.desc,
  28. result = self.lowx <= x <= self.upx and self.lowy <= y <= self.upy
  29. # print result
  30. return result
  31. def mouse_move(self):
  32. # print "move", self.desc
  33. ax.TxtLinkDescription.Value = coords + " - " + self.desc
  34. def onclick(self):
  35. # print "click", self.desc
  36. ax.TxtLinkDescription.Value = coords +" click! " + `self.url`
  37. if self.url: ax.location = self.url
  38. blows = "Blows away "
  39. rects =[rect(12,48,59,101,blows+"Visual Basic", ""),
  40. rect(107,0,172,58,blows+"Internet Explorer", ""),
  41. rect(193,0,261,56,blows+"Microsoft Access", ""),
  42. rect(332,43,392,93,blows+"Microsoft Word", ""),
  43. rect(457,52,521,99,blows+"Microsoft Excel", ""),
  44. rect(537,12,613,85,"Python blows them all away!", "http://www.python.org"),
  45. ]
  46. default = rect(0,0,0,0,"Click on an icon","")
  47. def Image_MouseMove(s, b, x, y):
  48. global mx, my, coords
  49. coords =`(x,y)`
  50. # print coords,
  51. mx, my = x, y
  52. for r in rects:
  53. if r.inside(x,y):
  54. # print r.desc
  55. r.mouse_move()
  56. break
  57. else:
  58. # print default.desc
  59. default.mouse_move()
  60. def Image_OnClick():
  61. for r in rects:
  62. if r.inside(mx,my):
  63. r.onclick()
  64. break
  65. -->
  66. </SCRIPT>
  67. <P>
  68. </FONT>
  69. </BODY>
  70. </HTML>