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.

93 lines
2.7KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: DirTree.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 tixDirTree widget -- you can
  13. # use it for the user to select a directory. For example, an installation
  14. # program can use the tixDirList widget to ask the user to select the
  15. # installation directory for an application.
  16. #
  17. proc RunSample {w} {
  18. # Create the tixDirTree and the tixLabelEntry widgets on the on the top
  19. # of the dialog box
  20. #
  21. frame $w.top -border 1 -relief raised
  22. # Create the DirTree widget. By default it will show the current
  23. # directory (returned by [pwd])
  24. #
  25. #
  26. tixDirTree $w.top.dir -browsecmd "dtree:browse $w.top.ent"
  27. # When the user presses the ".." button, the selected directory
  28. # is "transferred" into the entry widget
  29. #
  30. # We use a LabelEntry to hold the installation directory. The user
  31. # can choose from the DirTree widget, or he can type in the directory
  32. # manually
  33. #
  34. tixLabelEntry $w.top.ent -label "Installation Directory:" -labelside top \
  35. -options {
  36. entry.width 25
  37. entry.textVariable demo_dtree_dir
  38. label.anchor w
  39. }
  40. bind [$w.top.ent subwidget entry] <Return> "dtree:okcmd $w"
  41. uplevel #0 set demo_dtree_dir [list [pwd]]
  42. pack $w.top.dir -side left -expand yes -fill both -padx 4 -pady 4
  43. pack $w.top.ent -side left -fill x -anchor c -padx 4 -pady 4
  44. # Use a ButtonBox to hold the buttons.
  45. #
  46. tixButtonBox $w.box -orientation horizontal
  47. $w.box add ok -text Ok -underline 0 -command "dtree:okcmd $w" \
  48. -width 6
  49. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  50. -width 6
  51. pack $w.box -side bottom -fill x
  52. pack $w.top -side top -fill both -expand yes
  53. }
  54. proc dtree:browse {ent filename} {
  55. uplevel #0 set demo_dtree_dir $filename
  56. }
  57. proc dtree:copy_name {w} {
  58. global demo_dtree_dir
  59. set demo_dtree_dir [$w cget -value]
  60. }
  61. proc dtree:okcmd {w} {
  62. global demo_dtree_dir
  63. tixDemo:Status "You have selected the directory $demo_dtree_dir"
  64. destroy $w
  65. }
  66. # This "if" statement makes it possible to run this script file inside or
  67. # outside of the main demo program "widget".
  68. #
  69. if {![info exists tix_demo_running]} {
  70. wm withdraw .
  71. set w .demo
  72. toplevel $w; wm transient $w ""
  73. RunSample $w
  74. bind $w <Destroy> "exit"
  75. }
上海开阖软件有限公司 沪ICP备12045867号-1