gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: OptMenu.tcl,v 1.3 2001/12/09 05:31:07 idiscovery Exp $
  4. #
  5. # Tix Demostration Program
  6. #
  7. # This sample program is structured in such a way so that it can be
  8. # executed from the Tix demo program "widget": it must have a
  9. # procedure called "RunSample". It should also have the "if" statment
  10. # at the end of this file so that it can be run as a standalone
  11. # program using tixwish.
  12. # This file demonstrates the use of the tixOptionMenu widget -- you can
  13. # use it for the user to choose from a fixed set of options
  14. #
  15. set opt_options {text formatted post html tex rtf}
  16. set opt_labels(text) "Plain Text"
  17. set opt_labels(formatted) "Formatted Text"
  18. set opt_labels(post) "PostScript"
  19. set opt_labels(html) "HTML"
  20. set opt_labels(tex) "LaTeX"
  21. set opt_labels(rtf) "Rich Text Format"
  22. proc RunSample {w} {
  23. catch {uplevel #0 unset demo_opt_from}
  24. catch {uplevel #0 unset demo_opt_to }
  25. # Create the tixOptionMenu's on the top of the dialog box
  26. #
  27. frame $w.top -border 1 -relief raised
  28. tixOptionMenu $w.top.from -label "From File Format : " \
  29. -variable demo_opt_from \
  30. -options {
  31. label.width 19
  32. label.anchor e
  33. menubutton.width 15
  34. }
  35. tixOptionMenu $w.top.to -label "To File Format : " \
  36. -variable demo_opt_to \
  37. -options {
  38. label.width 19
  39. label.anchor e
  40. menubutton.width 15
  41. }
  42. # Add the available options to the two OptionMenu widgets
  43. #
  44. # [Hint] You have to add the options first before you set the
  45. # global variables "demo_opt_from" and "demo_opt_to". Otherwise
  46. # the OptionMenu widget will complain about "unknown options"!
  47. #
  48. global opt_options opt_labels
  49. foreach opt $opt_options {
  50. $w.top.from add command $opt -label $opt_labels($opt)
  51. $w.top.to add command $opt -label $opt_labels($opt)
  52. }
  53. uplevel #0 set demo_opt_from html
  54. uplevel #0 set demo_opt_to post
  55. pack $w.top.from $w.top.to -side top -anchor w -pady 3 -padx 6
  56. # Use a ButtonBox to hold the buttons.
  57. #
  58. tixButtonBox $w.box -orientation horizontal
  59. $w.box add ok -text Ok -underline 0 -command "opt:okcmd $w" \
  60. -width 6
  61. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  62. -width 6
  63. pack $w.box -side bottom -fill x
  64. pack $w.top -side top -fill both -expand yes
  65. # Let's set some nice bindings for keyboard accelerators
  66. #
  67. bind $w <Alt-f> "focus $w.top.from"
  68. bind $w <Alt-t> "focus $w.top.to"
  69. bind $w <Alt-o> "[$w.box subwidget ok] invoke; break"
  70. bind $w <Alt-c> "[$w.box subwidget cancel] invoke; break"
  71. }
  72. proc opt:okcmd {w} {
  73. global demo_opt_from demo_opt_to opt_labels
  74. tixDemo:Status "You wanted to convert file from $opt_labels($demo_opt_from) to $opt_labels($demo_opt_to)"
  75. destroy $w
  76. }
  77. # This "if" statement makes it possible to run this script file inside or
  78. # outside of the main demo program "widget".
  79. #
  80. if {![info exists tix_demo_running]} {
  81. wm withdraw .
  82. set w .demo
  83. toplevel $w; wm transient $w ""
  84. RunSample $w
  85. bind $w <Destroy> {if {"%W" == ".demo"} exit}
  86. }
上海开阖软件有限公司 沪ICP备12045867号-1