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.

105 lines
3.0KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: EFileDlg.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 tixExFileSelectDialog widget --
  13. # This is a neat file selection dialog that will make your apps look
  14. # real good!
  15. #
  16. proc RunSample {w} {
  17. # Create an entry for the user to input a filename. If he can't
  18. # bother to type in the name, he can press the "Browse ..." button
  19. # and call up the file dialog
  20. #
  21. frame $w.top -border 1 -relief raised
  22. tixLabelEntry $w.top.ent -label "Select A File:" -labelside top \
  23. -options {
  24. entry.width 25
  25. entry.textVariable demo_efdlg_filename
  26. label.anchor w
  27. }
  28. bind [$w.top.ent subwidget entry] <Return> "efdlg:okcmd $w"
  29. uplevel #0 set demo_efdlg_filename {}
  30. button $w.top.btn -text "Browse ..." -command "efdlg:browse"
  31. pack $w.top.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4
  32. pack $w.top.btn -side left -anchor s -padx 4 -pady 4
  33. # Use a ButtonBox to hold the buttons.
  34. #
  35. tixButtonBox $w.box -orientation horizontal
  36. $w.box add ok -text Ok -underline 0 -command "efdlg:okcmd $w" \
  37. -width 6
  38. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  39. -width 6
  40. pack $w.box -side bottom -fill x
  41. pack $w.top -side top -fill both -expand yes
  42. }
  43. # Pop up a file selection dialog
  44. #
  45. proc efdlg:browse {} {
  46. # [Hint]
  47. # The best way to use an ExFileSelectDialog is not to create one yourself
  48. # but to call the command "tix filedialog". This command creates one file
  49. # dialog box that is shared by different parts of the application.
  50. # This way, your application can save resources because it doesn't
  51. # need to create a lot of file dialog boxes even if it needs to input
  52. # file names at a lot of different occasions.
  53. #
  54. set dialog [tix filedialog tixExFileSelectDialog]
  55. $dialog config -command efdlg:select_file
  56. $dialog subwidget fsbox config -filetypes {
  57. {{*} {* -- All files}}
  58. {{*.txt} {*.txt -- Text files}}
  59. {{*.c} {*.c -- C source files}}
  60. }
  61. wm transient $dialog ""
  62. $dialog popup
  63. }
  64. proc efdlg:select_file {file} {
  65. global demo_efdlg_filename
  66. set demo_efdlg_filename $file
  67. }
  68. proc efdlg:okcmd {w} {
  69. global demo_efdlg_filename
  70. if {$demo_efdlg_filename != {}} {
  71. tixDemo:Status "You have selected the file $demo_efdlg_filename"
  72. } else {
  73. tixDemo:Status "You haven't selected any file"
  74. }
  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> exit
  86. }
上海开阖软件有限公司 沪ICP备12045867号-1