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.

91 lines
2.4KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: DirDlg.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 tixDirSelectDialog widget:
  13. # it allows the user to select a directory.
  14. #
  15. proc RunSample {w} {
  16. # Create an entry for the user to input a directory. If he can't
  17. # bother to type in the name, he can press the "Browse ..." button
  18. # and call up the diretcory dialog
  19. #
  20. frame $w.top -border 1 -relief raised
  21. tixLabelEntry $w.top.ent -label "Select A Directory:" -labelside top \
  22. -options {
  23. entry.width 25
  24. entry.textVariable demo_ddlg_dirname
  25. label.anchor w
  26. }
  27. bind [$w.top.ent subwidget entry] <Return> "ddlg:okcmd $w"
  28. uplevel #0 set demo_ddlg_dirname {}
  29. button $w.top.btn -text "Browse ..." -command "ddlg:browse"
  30. pack $w.top.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4
  31. pack $w.top.btn -side left -anchor s -padx 4 -pady 4
  32. # Use a ButtonBox to hold the buttons.
  33. #
  34. tixButtonBox $w.box -orientation horizontal
  35. $w.box add ok -text Ok -underline 0 -command "ddlg:okcmd $w" \
  36. -width 6
  37. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  38. -width 6
  39. pack $w.box -side bottom -fill x
  40. pack $w.top -side top -fill both -expand yes
  41. }
  42. # Pop up a directory selection dialog
  43. #
  44. proc ddlg:browse {} {
  45. set dialog .dirdlg_popup
  46. if ![winfo exists $dialog] {
  47. tixDirSelectDialog $dialog
  48. }
  49. $dialog config -command ddlg:select_dir
  50. $dialog popup
  51. }
  52. proc ddlg:select_dir {dir} {
  53. global demo_ddlg_dirname
  54. set demo_ddlg_dirname $dir
  55. }
  56. proc ddlg:okcmd {w} {
  57. global demo_ddlg_dirname
  58. if {$demo_ddlg_dirname != {}} {
  59. tixDemo:Status "You have selected the directory $demo_ddlg_dirname"
  60. } else {
  61. tixDemo:Status "You haven't selected any directory"
  62. }
  63. destroy $w
  64. }
  65. # This "if" statement makes it possible to run this script file inside or
  66. # outside of the main demo program "widget".
  67. #
  68. if {![info exists tix_demo_running]} {
  69. wm withdraw .
  70. set w .demo
  71. toplevel $w; wm transient $w ""
  72. RunSample $w
  73. bind $w <Destroy> exit
  74. }
上海开阖软件有限公司 沪ICP备12045867号-1